-
-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
simplify's loop rewriting incorrectly removes preceding variable declarations #824
Comments
I cannot reproduce this issue with babel-preset-minify@0.4.0 and babel-preset-env, I can see that polymer tools is using a custom plugins list for compiling to es5, Is there any reason you cannot switch to preset env? Just asking, so that we can drop support for |
re, preset-env: One reason is that there's a bug in the class transform, so we had to pin to an earlier version. Another is that preset-env doesn't appear to let us control which plugins are included very well, and only covers ES2015, so the utility is low for us. We require out toolchain allow for no-compile builds for two current browsers, so we control which plugins are allow so that we don't support JS features that can't be run without compilation. IOW, preset-env is focused on which browsers to compile to, and we want to enforce which browsers we won't compile for, and therefore exclude plugins they might require. |
@justinfagnani Thanks for the detailed explanation. That answers my question. Can you give details on the babel core, babel-preset-2015 and minify version used? I tried different combinations and could not reproduce it somehow. May be i am missing something here. The REPL is using an older version. |
@justinfagnani A couple of notes: preset env by default is actually ["env", {
exclude: ['transform-async-to-generator'],
targets: {
chrome: 49,
firefox: 52,
ios: 10,
},
}] |
I seem to be able to reproduce this with: const babel = require('babel-core');
console.log(babel.transform(`
let foo;
while (0) {}
console.log(foo);
`, {presets: ['minify', 'env']}).code);
// Prints: "use strict";console.log(foo); with package.json: {
"name": "babelbug", "version": "1.0.0", "description": "", "main": "index.js", "scripts": {"test": "echo \"Error: no test specified\" && exit 1"}, "author": "", "license": "", "private": true,
"dependencies": {
"babel-core": "^6.26.3",
"babel-preset-env": "^1.6.1",
"babel-preset-minify": "^0.5.0-alpha.34c3efe9"
}
} I don't know whether any other information is relevant/useful. Same with |
Testing more, all minify passes disabled gives (correctly): "use strict";var foo=void 0;while(0){}console.log(foo); Applying "use strict";for(var foo=void 0;0;);console.log(foo); Applying "use strict";console.log(foo); |
Input Code
Actual Output
Details
Minimal repro in the sandbox here.
Passing
simplify: false
tobabel-preset-minify
resolves the issue.It looks like what's happening is that the loop is rewritten to a for loop, then preceding statements are sometimes moved into the initialization segment of the for loop. But if the initialization segment is empty, or if the entire for loop is removed, then the declarations are lost.
Note that this does not require the loop to be completely deleted, and that more than one preceding statement can be lost. Our original code that prompted this looks roughly like:
Sandbox
And we're seeing the declarations for both foo and bar deleted.
The text was updated successfully, but these errors were encountered: