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

minifier: Removing parentheses around objects and tagged templates causes syntax errors #9930

Open
tmdghks opened this issue Jan 23, 2025 · 0 comments
Labels
Milestone

Comments

@tmdghks
Copy link

tmdghks commented Jan 23, 2025

Describe the bug

Currently, the minifier removes parentheses enclosing an object and a template literal.

In this case, the minifier also removes parentheses within a try statement, causing a syntax error.

Input code

try { 
    ( { 0 : 0 } ``); 
} catch {}

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "target": "es2022",
    "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
      }
      
      
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": false
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.10.9&code=H4sIAAAAAAAAAyspqlSoVuBSAAINIMNAwQqIaxUSEjStFbhqFZITS5IzFKprAeLD84EnAAAA&config=H4sIAAAAAAAAA32UwZLaMAyG730KJuceOhx66AP0ts%2FgMbYczDpWxpJZMju8exUnsHRROAX06ZdsSdbnj92uO5Hr%2Fuw%2B5af8GW0hKPf%2FYqEps72IpQM3WHIljtz9vNETzSjYRNBM14V0bEsP3FS0%2F7Xfr4ouIRLcFKttiDmG6TGnw2EsQPRgE6uErANkpv%2F1Kyv4MQMu9dF%2BQExg8wtiLJmYGXooWmCHKdmRwJxtUaLMJ7UlEmopZlgZvBkLjirPPnLELDmfqQfrjUMPCooFHMczaDLJJbJMcj3lPg17ONS%2Bb33%2BpoazTdWykhMurSVyWiXqESOxCTVrJVzgRg0WuBb3uzIGU4Bryc%2B6E8a80ZN3AKlAskTZDqDFbR5B5mlLHV4qYw4ysjwpXOZbu2WGXopqYgxKZefKQOGodbOArw7myjrtOCveKB9FDwZCkFlRQtNHZHfUkvI0AgYFSH9t0KZqAeb%2BCjf4%2FCBe4L9yS9YHbPUYLB%2B3KU3DAdOLBAPwEf0LB2kF4zYusiUu4zav2YOMBnjVpVIDz0tAHgCjSW1fPs2GPA%2BJaPqEh681sTpc1%2B%2FjZ7a1LdwN6GvbAetun9u6bOTf3ZfTbfnez9tFerspl8V%2B%2FQdL7qcXKAYAAA%3D%3D

SWC Info output

No response

Expected behavior

try { 
    ( { 0 : 0 } ``);  // there should be parentheses
} catch {}

Actual behavior

try {
    {
        0: 0
    }``;
} catch  {}

Version

1.10.9

Additional context

No response

@tmdghks tmdghks added the C-bug label Jan 23, 2025
@kdy1 kdy1 added this to the Planned milestone Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants