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

SWC minify mangle cause function parameter name collision with function name #9542

Closed
suguanYang opened this issue Sep 10, 2024 · 1 comment · Fixed by #9546
Closed

SWC minify mangle cause function parameter name collision with function name #9542

suguanYang opened this issue Sep 10, 2024 · 1 comment · Fixed by #9546
Assignees
Labels
Milestone

Comments

@suguanYang
Copy link

suguanYang commented Sep 10, 2024

Describe the bug

before minify

function n(i) {
    var r1 = t[i];
    if (void 0 !== r1) return r1.exports;
    var o1 = t[i] = {
        exports: {}
    };
    return e[i](o1, o1.exports, n), o1.exports;
}

after minified:

  function n(n) {
      var r = t[n];
      if (void 0 !== r) return r.exports;
      var i = t[n] = {
          exports: {}
      };
      return e[n](i, i.exports, n), i.exports;
  }

this is the __webpack_require__ function, it will pass it self to another fucntion call,
but the parameter i was renamed to n which same as the function name after minified thus cause a runtime error, `n is not a function', and I can reproduce it since @swc/core@1.3.102

Input code

function test() {
  (function (module) {
    function FormatSendData(data) {}
    eval();
  })();

  function n(i) {
    var r1 = t[i];
    if (void 0 !== r1) return r1.exports;
    var o1 = (t[i] = {
      exports: {},
    });
    return e[i](o1, o1.exports, n), o1.exports;
  }
}
test();

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "transform": null,
    "target": "es2015",
    "loose": false,
    "externalHelpers": false,
    "minify": {
      "mangle": true,
      "compress": true
    }
  },
  "module": {
    "type": "es6"
  },
  "isModule": true,
  "minify": false
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.7.24&code=H4sIAAAAAAAAA02QwQrCMAyG732KeEthiLtadhNfwKN4KDaDwtZKzYYgfXez1o1dmuTv%2F%2F0N7afwZB8DML0ZNXwVAPariGN000BVBtj0a0yj5RsFd7Fs0ckhnlxMNNsBtZE%2B66WqHRfQr1mzTZBa6IDv%2FmGK5HvAOXoHJzh0ndxqSMRTCtIe6fOKid9mg%2BMC40JLrZnyeHWdZZmmSFlX4h9EYsfYNkKviQ0EvZ%2FL5iqr%2BiFG%2FQD0Y8rwIgEAAA%3D%3D&config=H4sIAAAAAAAAA32QS2oDMRBE9z7FoLUXdiAm5ATZ5AyhkUtGTutDt8Z4ML57NF%2FGwclKUr1StVS3TdOYs1rz3tzqth4yiUKWc1W0i4WuVTGwgdSKz8VsZ3rWHjlixSDdR2KKUFSXJFQaW%2BZZJjmhDGH6stu%2FTkGGU1LMQZOGa4FE4g9whugvGnz0rls%2FNFA8MVZKPy9lxgX8eHlA30D%2BskyqkQL0L4f7l2bxFyqoa8rPTB5vT1QlR%2BL3u4fmlu6qwaaQBdonFmmnZjeTw4R0bFcfNaXLGCs9mMXk9XO29RHjxbmzcer9B1ovmo%2F%2FAQAA

SWC Info output

No response

Expected behavior

do not collision between function name and function parameter when function close over it self in its frame

Actual behavior

No response

Version

1.7.24

Additional context

No response

@suguanYang suguanYang changed the title SWC minify cause function parameter name collision with function name SWC minify mangle cause function parameter name collision with function name Sep 10, 2024
@kdy1 kdy1 added this to the Planned milestone Sep 10, 2024
@Austaras Austaras self-assigned this Sep 10, 2024
@kdy1 kdy1 closed this as completed in e2242c4 Sep 12, 2024
@kdy1 kdy1 modified the milestones: Planned, v1.7.28 Sep 24, 2024
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 24, 2024

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.

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

4 participants