Skip to content

jsc.transform.optimizer.jsonify removes decimals in numbers #10421

@teleginzhenya

Description

@teleginzhenya

Describe the bug

If there is a decimal number inside object with jsc.transform.optimizer.jsonify enabled, decimal part is removed.

Reproduction:
jsc.transform.optimizer.jsonify enabled

jsc.transform.optimizer.jsonify disabled

Seems like it always have been like that?

Input code

const someObject = {
  'foo': {first: 0.1, second: 5}
}

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "target": "es5",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    },
    "transform": {
      "optimizer": {
        "jsonify": {
          "minCost": 0
        }
      }
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}

Link to the code that reproduces this issue

https://play.swc.rs/?version=1.11.24&code=H4sIAAAAAAAAA0vOzysuUSjOz031T8pKTS5RsFWo5lJQUE%2FLz1e3UqhOyywqLrFSMNAz1FEoTk3Oz0uxUjCt5aoFAAbWZJs3AAAA&config=H4sIAAAAAAAAA21QMQ7DIAzc84rIc4cu7dC1cx%2BBqBMRBYxsIjWN8vcCCWlSdQF8PvvumKq6hk403OopPmPhFQvyVkdERhfUKyKA2irRbHyAU%2Bl2klqN6gUzNC8dCIpbDHlKLisdeiLBQl8xa5xpxr2gJusZRY7ERFWu7fG%2FHCsnDbHdLyIfjDXvQ5xsmX4ki5E7SbJ83uC52t%2FpzIJg6TlkJ%2BuvhdHjkvUKX1JJtqUAI48yGXjAav4ATVRsRYEBAAA%3D

SWC Info output

No response

Expected behavior

Decimal part from numbers should not be removed

Actual behavior

Decimal part from number is removed

Version

1.10.12

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions