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
Incorrect handling of function default params when shadowed #1478
Comments
This is indeed a bug. And an incredibly hard one to fix. I think this is because there's a scope for the function's default parameters, and another for the function's variables. Thanks for reporting! |
Cool, thanks! Yeah, function scopes are a pain. |
I think the advanced bits of this problem are impossible to fix such as the scope of function(x, f = (() => x)) {
var x;
var y = x; // reading the argument `x`
x = 2; // creating `var x`
return [ x, y, f() ];
}(1); This returns |
Bug report
While we encountered this in our codebase, I can also repro with https://try.terser.org/
Version (complete output of
terser -V
or specific git commit)Complete CLI command or
minify()
options usedterser
inputterser
output or errorExpected result
t
in the output is undefined in global scope. In our case, it appears that it was getting assigned to another function -- leading to some really weird stuff. However, in the original case, it just doesn't work. By changingconst exp
toconst e
, the param default is handled correctly asexp
.Now, if you change
const exp = easing(10);
to beconst e = easing(10);
, you get correct output:A coworker happened to try with esbuild:
https://esbuild.github.io/try/#dAAwLjE5LjgALS1taW5pZnkAZXhwb3J0IGNvbnN0IGV4cCA9ICh0KSA9PiAxIDsKCmV4cG9ydCBmdW5jdGlvbiBzbW9vdGhEYW1wKGVhc2luZyA9IGV4cCkgewogIGNvbnN0IGV4cCA9IGVhc2luZygxMCk7IAp9
The text was updated successfully, but these errors were encountered: