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

Some minification optimisations break function hoisting #2558

Closed
PaulBlanche opened this issue Oct 27, 2021 · 1 comment · Fixed by #2564
Closed

Some minification optimisations break function hoisting #2558

PaulBlanche opened this issue Oct 27, 2021 · 1 comment · Fixed by #2564
Labels
Milestone

Comments

@PaulBlanche
Copy link

On my projet, one of the dependencies is url-search-params-polyfill.

When i try to minify my projet, some minify optimisation breaks this dependency : REPL link

I belive swc tries to "flip" this condition : https://github.com/jerrybendy/url-search-params-polyfill/blob/c03102a7971c190284e2503805c4939e830c4ebc/index.js#L32-L34, without hoisting the function declaration URLSearchParamsPolyfill. This function stays in the scope of the "flipped" if block :

...if(!j||!k||!l||!m){function p(a){....

Conditional function declaration hoisting dependends on the agent (chrome and firefox hoist the name, but the function is undefined, ie hoists nothing, safari hoists the whole function MDN)

In the same situation, terser seems to exclude function declaration from the flipped condition (the function is declared after the end of the flipped condition).

@kdy1 kdy1 modified the milestones: v1.2.105, v1.2.106 Oct 27, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Oct 28, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Oct 28, 2021
kdy1 added a commit that referenced this issue Oct 28, 2021
swc_ecma_minifier:
 - Don't change depth of function while negating if statements. (#2558)

swc_ecma_transforms_optimization:
 - `dead_branch_remover`: Preserve `this`. (#2465, #2466)

swc:
 - Make `toplevel` default to true if `module` is true. (#2254)
@kdy1 kdy1 mentioned this issue Oct 28, 2021
10 tasks
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 21, 2022

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 21, 2022
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.

3 participants