Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Required leading zeroes are removed from numeric object keys with compress #6051

Closed
alattalatta opened this issue Oct 5, 2022 · 1 comment · Fixed by #6052
Closed

Required leading zeroes are removed from numeric object keys with compress #6051

alattalatta opened this issue Oct 5, 2022 · 1 comment · Fixed by #6052
Assignees
Labels
Milestone

Comments

@alattalatta
Copy link

Describe the bug

With compress turned on, SWC optimizes numeric string keys in objects and get rid of quotes. But this behavior is too aggressive and breaks codes when the said keys start with zeroes.

Input code

const o = { '010': '', '123': 'bar' }
console.log(o)

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": false
    },
    "target": "es5",
    "loose": false,
    "minify": {
      "compress": {
        "arguments": false,
        "arrows": true,
        "booleans": true,
        "booleans_as_integers": false,
        "collapse_vars": true,
        "comparisons": true,
        "computed_props": true,
        "conditionals": true,
        "dead_code": true,
        "directives": true,
        "drop_console": false,
        "drop_debugger": true,
        "evaluate": true,
        "expression": false,
        "hoist_funs": false,
        "hoist_props": true,
        "hoist_vars": false,
        "if_return": true,
        "join_vars": true,
        "keep_classnames": false,
        "keep_fargs": true,
        "keep_fnames": false,
        "keep_infinity": false,
        "loops": true,
        "negate_iife": true,
        "properties": true,
        "reduce_funcs": false,
        "reduce_vars": false,
        "side_effects": true,
        "switches": true,
        "typeofs": true,
        "unsafe": false,
        "unsafe_arrows": false,
        "unsafe_comps": false,
        "unsafe_Function": false,
        "unsafe_math": false,
        "unsafe_symbols": false,
        "unsafe_methods": false,
        "unsafe_proto": false,
        "unsafe_regexp": false,
        "unsafe_undefined": false,
        "unused": true,
        "const_to_let": true,
        "pristine_globals": true
      },
      "mangle": false
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}

Playground link

https://play.swc.rs/?version=1.3.4&code=H4sIAAAAAAAAA0vOzysuUchXsFWoVlA3MDRQt1JQV9dRUDc0MgYxkxKL1BVqebmSgcryc1L1cvLTNfI1ARCZHCY1AAAA&config=H4sIAAAAAAAAA22TQZLjIAxF7%2BJ1b2cWfYDZzRkoAsKhByOXJNJxpXL3Fo4NcTI76%2FEliy9xG77YDZ%2B3YbbEQPWLlyz2OnwOsszAjuIsw8cgrCjYxHDXwNIIohLgX3qWEBm2049hijmGpVZyOM0EzPVbM8oEWbjpLBF%2BayhUNDohJrD5LTaWTcwCI1BPdZiSnRnMxVLLqH%2BzFBnzARUBb2bC%2BYlmHyVi1mI782C9ceihgUjgJF6gS7SGSjJrY62TFXo4lXGs7j2UcLGpWGm14LraoH9seWeMLCaUzC%2Fo0OkDPS65qWIwBFIo75ovjPngwz8A7TNZ5mwn6JkrDzqHozL8RxVz0CHK0qhOuHeVYdTLmRhDu2HtGkhid4vAFwf1hq4X3%2BDhQhw9GAhB3W7J%2FB3FnXuxuokYWqiu2dBn8AjNvk9HWlfgDf7RruR5HBufrJxfGS%2FTCdNbiQnkjP4NqxGCr5B0e6%2FzKy3Zg9oM%2FumgcA3bmurwBU2qT233WRdCc8yY8NTWV1%2FkZPPY1vJeAfpSwW01b32qv4d7f537OvHfTbgW%2BgFVtfDUDwQAAA%3D%3D

Expected behavior

While '123' becomes 123, the '010' remains as it is.

{ '010': '', 123: 'bar' }

Actual behavior

'010' becomes 10, making o['010'] failing.

{ 10: '', 123: 'bar' }

Version

1.2.240 ~ 1.3.4

Additional context

Possible cause: #5548

@kdy1 kdy1 self-assigned this Oct 5, 2022
@kdy1 kdy1 added this to the Planned milestone Oct 5, 2022
@kdy1 kdy1 closed this as completed in #6052 Oct 5, 2022
kdy1 added a commit that referenced this issue Oct 5, 2022
**Description:**

We should not optimize if the key starts with `0`.

**Related issue:**

 - Closes #6051.
@kdy1 kdy1 modified the milestones: Planned, v1.3.5 Oct 6, 2022
@swc-bot
Copy link
Collaborator

swc-bot commented Nov 5, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Nov 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants