avoid evaluate of compound assignment after dead_code transform (#2861)

fixes #2860
This commit is contained in:
Alex Lam S.L
2018-02-01 16:18:29 +08:00
committed by GitHub
parent 102f994b9d
commit aa664dea0a
3 changed files with 79 additions and 0 deletions

View File

@@ -5358,6 +5358,7 @@ merge(Compressor.prototype, {
if (in_try(level, parent instanceof AST_Throw)) break; if (in_try(level, parent instanceof AST_Throw)) break;
if (is_reachable(def.scope, [ def ])) break; if (is_reachable(def.scope, [ def ])) break;
if (self.operator == "=") return self.right; if (self.operator == "=") return self.right;
def.fixed = false;
return make_node(AST_Binary, self, { return make_node(AST_Binary, self, {
operator: self.operator.slice(0, -1), operator: self.operator.slice(0, -1),
left: self.left, left: self.left,

View File

@@ -879,3 +879,41 @@ unsafe_builtin: {
z; z;
} }
} }
issue_2860_1: {
options = {
dead_code: true,
evaluate: true,
reduce_vars: true,
}
input: {
console.log(function(a) {
return a ^= 1;
}());
}
expect: {
console.log(function(a) {
return 1 ^ a;
}());
}
expect_stdout: "1"
}
issue_2860_2: {
options = {
dead_code: true,
evaluate: true,
inline: true,
passes: 2,
reduce_vars: true,
}
input: {
console.log(function(a) {
return a ^= 1;
}());
}
expect: {
console.log(1);
}
expect_stdout: "1"
}

View File

@@ -5467,3 +5467,43 @@ chained_assignments: {
} }
expect_stdout: "5eadbeef" expect_stdout: "5eadbeef"
} }
issue_2860_1: {
options = {
dead_code: true,
evaluate: true,
reduce_vars: true,
}
input: {
console.log(function(a) {
return a ^= 1;
a ^= 2;
}());
}
expect: {
console.log(function(a) {
return 1 ^ a;
}());
}
expect_stdout: "1"
}
issue_2860_2: {
options = {
dead_code: true,
evaluate: true,
inline: true,
passes: 2,
reduce_vars: true,
}
input: {
console.log(function(a) {
return a ^= 1;
a ^= 2;
}());
}
expect: {
console.log(1);
}
expect_stdout: "1"
}