swc-project / swc

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

Mangle should respect params usage even there is `eval` callExpression exist #7094

Closed IWANABETHATGUY closed 1 year ago

IWANABETHATGUY commented 1 year ago

Describe the bug

image As you can see the variable should not mangle to e since there is already used by the first param

Input code

function useSyncExternalStore$2(e, T, C) {
    const V = T();
    return V;
}
eval();

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "target": "es2015",
    "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": "commonjs"
  },
  "minify": false,
  "isModule": "unknown"
}

Playground link

https://play.swc.rs/?version=1.3.41&code=H4sIAAAAAAAAA%2BNKK81LLsnMz1MoLU4NrsxLdq0oSS3KS8wJLskvSlUx0kjVUQjRUXDWVKjmUgCC5Py84hKFMAVbhRANTWuwUFFqSWlRnkKYNVctV2pZYg5IHAA56ekqVwAAAA%3D%3D&config=H4sIAAAAAAAAA3VUQW7jMAz8i845tAUWWPQBe9s3CIpFOUpl0RApJ0aQv5dKbClO2ps5GlLkcKyLOlKnPi9qNIkglS%2BaI5uz%2BlTQDYa65EdWO6EJ5EwguO4Um9QDFwp9vL3%2FkeOASLAQdmrw0bu5FOtwGBMQlW9JygNEpsozKeFJQk5Zoj1iABNfYm1I%2B8jQQ2qpHYZgRgI9mVQzym0mecK4gTKD1WPC8QGN1rPHKMVWzIKxukMLFfAJOvYTNIrUEEokaax2cgMt7HPfFwHvTJhMyIZrLTjfZJAba94BPbF2OdITtOn0Dt2HXFje6QScU1w5R%2FRxo8MXgPQZDFE0A7TMG%2B5kD1um%2B4Hlo5Ml8lxR2XDrKkIvw2nvXZ2wdA2JfVMrgc0dlAm7VnwBNwORt6DBOVG7JtPJc3doxXgeAV0NRTXj2g7uoV79tEWLBV7Af9IVP65jwQfDh2eM5mGP4aXEAHxA%2BwKLEIzPYBL3nsdnNEcLIjPYh4NMJaw2leUz6lD%2BtlVnMYTk6D7gvtpXfsrBxL7Y8qIYxwAThO1Gf%2FXDD5hcMpUFL1ZcjQd%2F286M%2BMi%2Fv62PwrV0gDYvHci25HkQ5QeMR1LX9iastej%2FwpaZvyKeorp%2BA7typZyNBAAA

Expected behavior

function useSyncExternalStore$2(e, n, t) {
    let a = n(); // any variable expect `e` 
    return a;
}
eval();

Actual behavior


function useSyncExternalStore$2(e, n, t) {
    let e = n(); // the variable should not mangle to `e` since there is already used by first param, 
    return e;
}
eval();

Version

1.3.41

Additional context

No response

IWANABETHATGUY commented 1 year ago

One more thing, If you disable the eval call, then the code works fine.

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.