@@ -11590,22 +11590,29 @@ Compressor.prototype.compress = function(node) {
|
|||||||
if (seq !== self) return seq.optimize(compressor);
|
if (seq !== self) return seq.optimize(compressor);
|
||||||
}
|
}
|
||||||
if (compressor.option("assignments") && lazy_op[self.operator]) {
|
if (compressor.option("assignments") && lazy_op[self.operator]) {
|
||||||
var assign = self.right;
|
var right = self.right;
|
||||||
// a || (a = x) ---> a = a || x
|
// a || (a = x) ---> a = a || x
|
||||||
// a && (a = x) ---> a = a && x
|
// a && (a = x) ---> a = a && x
|
||||||
if (self.left instanceof AST_SymbolRef
|
if (self.left instanceof AST_SymbolRef
|
||||||
&& assign instanceof AST_Assign
|
&& right instanceof AST_Assign
|
||||||
&& assign.operator == "="
|
&& right.operator == "="
|
||||||
&& self.left.equals(assign.left)) {
|
&& self.left.equals(right.left)) {
|
||||||
return make_node(AST_Assign, self, {
|
var left = right.left.clone();
|
||||||
|
var assign = make_node(AST_Assign, self, {
|
||||||
operator: "=",
|
operator: "=",
|
||||||
left: assign.left,
|
left: left,
|
||||||
right: make_node(AST_Binary, self, {
|
right: make_node(AST_Binary, self, {
|
||||||
operator: self.operator,
|
operator: self.operator,
|
||||||
left: self.left,
|
left: self.left,
|
||||||
right: assign.right,
|
right: right.right,
|
||||||
}),
|
}),
|
||||||
}).optimize(compressor);
|
});
|
||||||
|
left.fixed = function() {
|
||||||
|
return assign.right;
|
||||||
|
};
|
||||||
|
left.fixed.assigns = [ assign ];
|
||||||
|
left.definition().references.push(left);
|
||||||
|
return assign.optimize(compressor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (compressor.option("comparisons")) switch (self.operator) {
|
if (compressor.option("comparisons")) switch (self.operator) {
|
||||||
|
|||||||
@@ -803,3 +803,23 @@ issue_4924_2: {
|
|||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
node_version: ">=15"
|
node_version: ">=15"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_5670: {
|
||||||
|
options = {
|
||||||
|
assignments: true,
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(a, b) {
|
||||||
|
a && a && (a = b += "") || console.log("PASS");
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function(a, b) {
|
||||||
|
a = a,
|
||||||
|
console.log("PASS");
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user