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

undefined as default parameter is preserved since 5.16.6 #1366

Closed
ericfortis opened this issue Apr 5, 2023 · 2 comments
Closed

undefined as default parameter is preserved since 5.16.6 #1366

ericfortis opened this issue Apr 5, 2023 · 2 comments

Comments

@ericfortis
Copy link

ericfortis commented Apr 5, 2023

terser input

function foo(a = undefined) { return a; }
alert(foo())

terser output or error (5.16.6+)

alert(function(n=undefined){return n}());

Expected result (5.15.5)

alert(function(n){return n}());

Why do I write signatures like that?
In WebStorm, there's a "Signature Mismatch" inspection but it doesn't handle optional parameters. Therefore, in those cases I add undefined as default value.

@fabiosantoscode
Copy link
Collaborator

I'm noticing more than a few optimization opportunities here (all that should be just alert(void 0) but the default parameter is being preserved because removing it changes the function's .length property.

I guess it can be done if we know about all the function's calls.

@fabiosantoscode
Copy link
Collaborator

I'm pushing a partial fix (it's really fast and easy to detect a function is an IIFE). For your case (which I'm sure is not just IIFE) you can try disabling the keep_fargs option, which makes functions' lengths not important, and therefore = undefined considered safe to remove.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants