swc-project / swc

Rust-based platform for the Web
https://swc.rs
Apache License 2.0
31.21k stars 1.23k forks source link

compress.arguments = true brokes arr["a space b"] #7009

Closed rentalhost closed 1 year ago

rentalhost commented 1 year ago

Describe the bug

When compress.arguments is true it brokes index accesses when index is string and matches /^[a-z]/i. Only example1 will fail.

Input code

export const example1 = (param) =>
  param => param["There is something wrong!"];

export const example2 = (param) =>
  param => param["123 is fine"];

export const example3 = (param) =>
  param => param["! That is fine !"];

export const example4 = (param) =>
  param => param[" space in start works fine"];

export const example5 = (param) =>
  param => param[123];

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "target": "es2022",
    "loose": false,
    "minify": {
      "compress": {
        "arguments": true,
        "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.37&code=H4sIAAAAAAAAA4XPvQ6CQBAE4P6eYqDSEtDK4FPQEYsNWbmL3k%2F2LoHH95TQSa6bZr7M8Bq8JEzexQReyYY3N%2BhxCiRkz%2BjvCvjlHLcw1oNmYZiI6C0nbdyMRbybq%2FpxU4r%2FkG2JbNruCz6N40OkKyEVBk1pd3A851KSEANN%2BaJDTJTbi5dXYd21YOaHufoBjMAqg3ABAAA%3D&config=H4sIAAAAAAAAA22TQZLjIAxF7%2BJ1FlNZ9KIPMLs%2BA6WAcOjByIVEOq5U7j7CsXGc9M56%2FhLiS9y6b7bd560bITPm%2BsVTErh2nx3aAdjmMEp3UJkiD5HxfugEco9SJXz8czzq70jEuAgO3RBS8FMtZmkYMzLXb00qAybRQHJRGeRMPy06EUWE9BYbYBOSYI%2BZ2wmWYoSR0Vwgt4x6GOTAlHaoCDozZhqfaHJBAiUttjKH4Iwlhw2EjFbCBTeJ1lBJYm2sdTJDh6fS99W%2FhxIvEAtIq4XX2QU9seWdKbAYXxK%2FoF2nD%2FS45KIK3mSUktOq%2BaaQdj78Q9Q%2BIzAnGHDLnLnXMeyV%2FhdVSF5nKFOjOuCtq4S9Xs6E4NsNa9eYJWxuZXTFYr2h3YovcHchDg4Neq9ut2T%2BCWLPWzGZRiTfQnUN%2FDaDR2jWfdrTugJv8K92Jc%2FjWPgAcn5lPA0nim8lBpQzuTesRgi9wqzbex1faUkO1WZ0Tz8K17CtqQ5fyMT62FafdSE0x%2FSRTm199U0OkPq2lvcKyJUKbrN582P96O7b41zXib8W4VzoP9zQhRURBAAA

Expected behavior

export const example1 = (param)=>(param)=>param.["There is something wrong!"[;
export const example2 = (param)=>(param)=>param["123 is fine"];
export const example3 = (param)=>(param)=>param["! That is fine !"];
export const example4 = (param)=>(param)=>param[" space in start works fine"];
export const example5 = (param)=>(param)=>param[123];

Actual behavior

export const example1 = (param)=>(param)=>param.There is something wrong!;
export const example2 = (param)=>(param)=>param["123 is fine"];
export const example3 = (param)=>(param)=>param["! That is fine !"];
export const example4 = (param)=>(param)=>param[" space in start works fine"];
export const example5 = (param)=>(param)=>param[123];

Version

1.3.37

Additional context

No response

swc-bot commented 1 year ago

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.