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 should check type of assignment target before merging assignments #8718

Open
hyp3rflow opened this issue Mar 8, 2024 · 0 comments
Assignees
Labels
Milestone

Comments

@hyp3rflow
Copy link
Sponsor Contributor

Describe the bug

Currently in replace_seq_assignment step, we don't check the type of target.
however, if the type of target differs, the total count of actual operations matters.

Input code

let a = '';
console.log((a += 1, a += 2))

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,
        "passes": 3
      },
      "mangle": false
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.4.6&code=H4sIAAAAAAAAA8tJLVFIVLBVUFe35krOzyvOz0nVy8lP19BIVNC2VTDUUQDTRpqaAAJDHUQpAAAA&config=H4sIAAAAAAAAA32UO5LbMAyGe5%2FCozpF4iJFDrBdzsChSVCmlw8NAXqt2fHdA1Gy11lD6iR8%2BAESAPG52%2B%2B7M5ruz%2F6TP%2Fln0AWhPP7ZgmMifWVLByZqNMUP1P240zNOyOmA0Ey3mXSkSw%2FUVHj4eTgsii7kjHBXLLbok3fjc06T41AA8cnGVg5ZIyTC%2F%2FULK%2FljAlTqs%2F2YcwCdNojSqHwi6KFIgU0OQQ8I6qKLEGU6qS4es5RigpXAqqHkQeTJevI5cc5XakFbZbIFAfkChvwFJBnnYllCvp5wn4YtHGvftz5%2FU8NFh6pJyAnX1hI%2BrRD1lD2ScjVJJZzhSg1muBT3u9I7VYBqSa%2B6c%2FZppSfvAFyBoBGTjiDFbR6O52lN7TaVPjkeWRoFzvMt3TJBz0VV3juhslNloJCXulnAVgNTZY10nAWvlA%2B9BQXO8awIofHDkzlJSWkcIDsBcH%2B1k6ZqBurxClf49CA28BvfkuQBWzyiptM6xTEec9hIEIFO2W44cCsor%2BPCW%2BI6rPOaLPBogBVdKjbwugT4AVBWoe3Ll9ng58ERVR%2FyUVwTA895a%2BKvxXZ7LOeoU%2F%2B1BOb9vFscuphtbXDZ%2FFPT5339u%2Ftyuq%2Fmx206j3%2Fvyukku9s%2FdoKzJEUGAAA%3D

SWC Info output

No response

Expected behavior

let a = '';
console.log('12')

or don't minify it

Actual behavior

let a = '';
console.log((a += 3))

which results '3'

Version

1.4.6

Additional context

No response

@hyp3rflow hyp3rflow added the C-bug label Mar 8, 2024
@kdy1 kdy1 added this to the Planned milestone Mar 11, 2024
@kdy1 kdy1 assigned kdy1 and unassigned kdy1 Mar 11, 2024
@kdy1 kdy1 self-assigned this Mar 20, 2024
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