fix incorrect context in variable substitution (#1791)
`AST_Node.optimize()` is context-aware, so don't cache its results to be used elsewhere. Also fixed a few cases of AST corruption and beef up safety of `pure_getters`.
This commit is contained in:
@@ -1866,3 +1866,75 @@ delay_def: {
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
booleans: {
|
||||
options = {
|
||||
booleans: true,
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function(a) {
|
||||
if (a != 0);
|
||||
switch (a) {
|
||||
case 0:
|
||||
return "FAIL";
|
||||
case false:
|
||||
return "PASS";
|
||||
}
|
||||
}(false));
|
||||
}
|
||||
expect: {
|
||||
console.log(function(a) {
|
||||
if (!1);
|
||||
switch (!1) {
|
||||
case 0:
|
||||
return "FAIL";
|
||||
case !1:
|
||||
return "PASS";
|
||||
}
|
||||
}(!1));
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
side_effects_assign: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
var a = typeof void (a && a.in == 1, 0);
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
var a = typeof void (a && a.in);
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
}
|
||||
|
||||
pure_getters: {
|
||||
options = {
|
||||
pure_getters: true,
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
try {
|
||||
var a = (a.b, 2);
|
||||
} catch (e) {}
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
try {
|
||||
var a = (a.b, 2);
|
||||
} catch (e) {}
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user