swc-project / swc

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

Semicolon needed for stripped modifiers followed by `[` in strip mode #9681

Closed branchseer closed 2 weeks ago

branchseer commented 3 weeks ago

Describe the bug

For modifiers followed by computed properties [...] like private ['bar'] = 2, when the modifier(s) get stripped without semicolon, [...] may become the subscript part of the expression in the class element before.

Input code

class A {
    foo = 1
    private ['bar'] = 2
}

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": false
    },
    "target": "es2022",
    "loose": true,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "commonjs"
  },
  "minify": false,
  "isModule": true
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.7.40&code=H4sIAAAAAAAAA0vOSSwuVnBUqOZSAIK0%2FHwFWwVDMLugKLMssSRVIVo9KbFIPRYobsRVywUA1%2FC5JzAAAAA%3D&config=H4sIAAAAAAAAA1VPSQ7DIAy85xXI5x4qjv1DH4GoExGxCTtSUZS%2FFxKg7c2e8SzeJyFgJQ0PsZexLFElwjT2glD2rN4FAc4RSScTGW6dZarUrCzhCR0XA6zSglxVSPIuZVOADYGwwJw2bJAz3sz5N1IHFxMSdeeR5pRfLP4HTi0UXHhtJ9leqXVrgeLmgl8Jvpc9cbiDoWeX12rT8QEVPE3nGwEAAA%3D%3D&strip-types=

SWC Info output

No response

Expected behavior

Output:

class A {
   foo = 1
   ;['bar'] = 2
}

Actual behavior

Output:

class A {
   foo = 1['bar'] = 2
}

Version

1.7.40

Additional context

No response