swc-project / swc

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

Minifier outputs invalid `1=1=1=0` assignment #7500

Closed mischnic closed 1 year ago

mischnic commented 1 year ago

Describe the bug

The minified output is invalid JS.

Input code

var globalArray = [1, 1, 1];
module.exports = function () {
    var localArray = globalArray;
    localArray[0] = localArray[1] = localArray[2] = 0;
    return localArray;
};

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": 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": {
        "toplevel": false,
        "keep_classnames": false,
        "keep_fnames": false,
        "keep_private_props": false,
        "ie8": false,
        "safari10": false
      }
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": true,
  "isModule": true
}

Playground link

https://play.swc.rs/?version=1.3.62&code=H4sIAAAAAAAAAytLLFJIz8lPSsxxLCpKrFSwVYg21FEAoVhrrtz8lNKcVL3UioL8opJioFxaaV5ySWZ%2BnoKGpkI1lwIQlAH15%2BQnI7QjGWYNVoGQjTaIBSpA4hui8Y1AfAOItqLUktKiPCRZa65aay4An7JK8a8AAAA%3D&config=H4sIAAAAAAAAA42VS47bMAxA93OKwOsu2kWLogformcQFItylMqiIVKZBIPcvbRsZzJj2ugmiPn4ESmSens5HJoztc2vw5v8lY%2FBZoL8%2BBYJ3RLbq0gaaHtLbQ4DN18WeqYReRsJqug%2BkYZt7oCrFX2f1ZuISLCoz7I%2BpOBvzwFb7IcMRE8ykYq%2F0kNi%2Bmg%2Fs4yvI%2BBcnuVHxAg27RBjyYTE0EHWHLcYox0IzMVmxct4UpsDoRZihIXBmSHjoPLkAgdMEnNNHVhnWnSgoJCh5XABzUxiiVkiSU%2FJp2IHx9J19ZI%2FWcPFxmJZiQnXeiVyWsXrCQOx8SVpJZzgRg0mOBf3s2XwJgOXnNZ2Zwxp407%2BAkgFoiVKtgfNb9Xw0k9b1n7XMiQvLcs3hUt%2Fa1km6KSoJgSvVHasDGQO2m1mcKWFsbKtdpwZb5SPggMD3kuvKK7pNXB70oLybQD0CpD7tV7rqgmYxxRu8HEgdvBvyZL1Bps1esunbUq3%2FohxJ0APfEK3oyBXwbiNs2yJ67DNS3IgrQFOVSlUwXoJyAAwmliX5ao3ZDzEo%2BkiHt%2FXxKxwfyzh3qauzvvTvmQcIlwgbrXxf4zILpWzXcauXiZ7Nb3wU2tKK4MXvn398GZIKi%2FLb02q6dGVp4RqT05vyY%2FmXWl5OZaqNYH%2BLIa1Tvd%2FDWFcTeAGAAA%3D

Expected behavior

Probably something like

return globalArray[0]=globalArray[1]=globalArray[2]=0,globalArray

Actual behavior

var globalArray=[1,1,1];module.exports=function(){return 1=1=1=0,globalArray};

Version

1.3.62

Additional context

Reported in https://github.com/parcel-bundler/parcel/issues/9076

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.