-
-
Notifications
You must be signed in to change notification settings - Fork 374
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
assignment in switch statement corrupts program #445
Comments
What also fixes the issue is to avoid the re-declaration of |
Hey there! Thank you for your report. Could you try to come up with a minimal reproduction of the bug? A whole repository is a bit big to find bugs inside, and it's probably possible to reproduce this in a minimal way. |
I tried, but it's very difficult as any change (e.g. simplification) resulted in a different result on the minifier. I suspect it has to do with the variable shadowing. const |
This is probably unrelated to that issue since you can only reproduce that with a catch block specifically, which has a tricky implementation due to historical reasons (old Uglify code is var-centric and the catch block binding is the only block scoped variable in oldjs, and to make that trickier there's a nasty IE8 bug which changes scoping rules for that binding) If simple shadowed variables were the issue it would've been fixed years ago. |
I've managed to remove most of the input code and create a single JS file which is executable and outputs either PASS or FAIL, which is what we use in most of our tests:
Eventually the purpose of creating the perfectly minimal reproduction of an error is to use that directly in the compress tests. However this is still a tad big, I'm thinking I can make this smaller still by ditching some of the state in it. |
I got this further down. I think I'm ready to devise a fix.
|
Terser 4.2.1
git clone https://github.com/aeschli/sample-terser-bug
cd sample-terser-bug
,npm i
,npm test
compiles a sample module
created a minified variant (see https://github.com/aeschli/sample-terser-bug/blob/662548260936142a48e9c0d2ad65e69001bb296d/package.json#L10)
Runs a test against both the original (json.js) and it's minified (json.pack.js) variant.
The test shows that the outputs are not the same.
The issue is in
https://github.com/aeschli/sample-terser-bug/blob/662548260936142a48e9c0d2ad65e69001bb296d/json.pack.js#L75
The switch statement also does an assignment to
n
.n
is already used for the length of the input string of the scanner.n
is unnecessaryThe corresponding line is
https://github.com/aeschli/sample-terser-bug/blob/662548260936142a48e9c0d2ad65e69001bb296d/json.js#L117
A workaround is to set
hoist_funs
totrue
The text was updated successfully, but these errors were encountered: