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
var
use before defined incorrect, let
/const
TDZ errors masked by tree shaking
#4101
Comments
There might be a relatively simple fix for this. Consider the addition of these synthetically introduced redundant valueless
--- misc.js
+++ misc2.js
@@ -1,3 +1,4 @@
(function bug1() {
+ var on; // <----- introduce synthetically
var first = state();
var on = true;
@@ -12,4 +13,5 @@
for (var b = 2; --b >= 0; ) {
(function() {
+ var c; // <----- introduce synthetically
var c = function() {
return 1;
The test now passes:
Since |
True, but this basically means that all var variables are completely deoptimized. I.e. this would be more or less equivalent to just not track any values for var variables. Which would be a huge loss. But for now, I see no way to fix this without breaking analysis short of implementing basic flow analysis, which would be huge in and off itself. The only quick fix I see would be to introduce a flag to decide if we deoptimize all var variables. |
At least in this case there might be a heuristic to remedy the situation: var c = function() {
return 1;
}(c && (a = "FAIL")); as there are no assignments or updates to the |
@lukastaegert It appears that this bug is not limited to Given an incorrectly written program with a runtime TDZ violation:
Here's the expected runtime error:
And here's the actual incorrect result produced with rollup:
Notice that rollup produced no error or warning:
If the rollup user does not test their code without rollup, or with Minifiers such as uglify-js and terser strive to preserve the behavior of good or bad code with a garbage-in/garbage-out philosophy:
|
Here's a simpler example of a TDZ failure:
The runtime error is masked by rollup:
uglify-js 3.13.8 correctly preserves the TDZ error:
However, terser 5.7.0 has a bug:
|
var
bugs - use before definedlet
and const
TDZ errors masked by tree shaking, and var
use before defined incorrect
let
and const
TDZ errors masked by tree shaking, and var
use before defined incorrectvar
use before defined incorrect, let
/const
TDZ errors masked by tree shaking
Workaround for the var-use-before-defined bugs by deoptimizing all The only workaround for the masking of These two issues above are result of the same underlying variable analysis problems. A proper fix for either would resolve both issues. |
Repro
Expected Behavior
Actual Behavior
The text was updated successfully, but these errors were encountered: