fix corner cases in collapse_vars (#4591)

fixes #4590
This commit is contained in:
Alex Lam S.L
2021-01-24 14:15:43 +00:00
committed by GitHub
parent a36c5472d2
commit fd7ad8e779
5 changed files with 32 additions and 2 deletions

View File

@@ -2413,7 +2413,8 @@ merge(Compressor.prototype, {
if (expr instanceof AST_This) return rhs_exact_match;
if (expr.is_truthy()) return rhs_fuzzy_match(true, return_false);
if (expr.is_constant()) {
return rhs_fuzzy_match(expr.evaluate(compressor), rhs_exact_match);
var ev = expr.evaluate(compressor);
if (!(ev instanceof AST_Node)) return rhs_fuzzy_match(ev, rhs_exact_match);
}
if (!(lhs instanceof AST_SymbolRef)) return false;
if (!invariant(expr)) return false;
@@ -2436,7 +2437,8 @@ merge(Compressor.prototype, {
return true;
}
if (node.is_constant()) {
return !node.evaluate(compressor) == !value;
var ev = node.evaluate(compressor);
if (!(ev instanceof AST_Node)) return !ev == !value;
}
}
return fallback(node);

View File

@@ -44,3 +44,19 @@ Number: {
expect_stdout: "-1148098955808013200"
node_version: ">=10"
}
issue_4590: {
options = {
collapse_vars: true,
}
input: {
A = 1;
0n || console.log("PASS");
}
expect: {
A = 1;
0n || console.log("PASS");
}
expect_stdout: "PASS"
node_version: ">=10"
}

View File

@@ -5608,6 +5608,7 @@ collapse_rhs_array: {
collapse_rhs_boolean_1: {
options = {
collapse_vars: true,
evaluate: true,
}
input: {
var a, b;
@@ -5633,6 +5634,7 @@ collapse_rhs_boolean_1: {
collapse_rhs_boolean_2: {
options = {
collapse_vars: true,
evaluate: true,
}
input: {
var a;
@@ -5667,6 +5669,7 @@ collapse_rhs_boolean_3: {
booleans: true,
collapse_vars: true,
conditionals: true,
evaluate: true,
}
input: {
var a, f, g, h, i, n, s, t, x, y;
@@ -5720,6 +5723,7 @@ collapse_rhs_function: {
collapse_rhs_number: {
options = {
collapse_vars: true,
evaluate: true,
}
input: {
var a, b;
@@ -5799,6 +5803,7 @@ collapse_rhs_regexp: {
collapse_rhs_string: {
options = {
collapse_vars: true,
evaluate: true,
}
input: {
var a, b;

View File

@@ -2138,6 +2138,7 @@ issue_3497: {
issue_3515_1: {
options = {
collapse_vars: true,
evaluate: true,
reduce_vars: true,
unused: true,
}
@@ -2189,6 +2190,7 @@ issue_3515_2: {
issue_3515_3: {
options = {
collapse_vars: true,
evaluate: true,
unused: true,
}
input: {
@@ -2256,6 +2258,7 @@ function_assign: {
issue_3598: {
options = {
collapse_vars: true,
evaluate: true,
reduce_vars: true,
unused: true,
}

View File

@@ -979,6 +979,7 @@ collapse_vars_2_strict: {
collapse_rhs_true: {
options = {
collapse_vars: true,
evaluate: true,
pure_getters: true,
}
input: {
@@ -1015,6 +1016,7 @@ collapse_rhs_true: {
collapse_rhs_false: {
options = {
collapse_vars: true,
evaluate: true,
pure_getters: false,
}
input: {
@@ -1051,6 +1053,7 @@ collapse_rhs_false: {
collapse_rhs_strict: {
options = {
collapse_vars: true,
evaluate: true,
pure_getters: "strict",
}
input: {
@@ -1087,6 +1090,7 @@ collapse_rhs_strict: {
collapse_rhs_setter: {
options = {
collapse_vars: true,
evaluate: true,
pure_getters: "strict",
}
input: {