fix AST corruption
This commit is contained in:
parent
1a8c9dfdc4
commit
1d1a8575dd
|
|
@ -3055,8 +3055,9 @@ merge(Compressor.prototype, {
|
||||||
if (this.expression instanceof AST_Seq) {
|
if (this.expression instanceof AST_Seq) {
|
||||||
var seq = this.expression;
|
var seq = this.expression;
|
||||||
var x = seq.to_array();
|
var x = seq.to_array();
|
||||||
this.expression = x.pop();
|
var e = this.clone();
|
||||||
x.push(this);
|
e.expression = x.pop();
|
||||||
|
x.push(e);
|
||||||
seq = AST_Seq.from_array(x).transform(compressor);
|
seq = AST_Seq.from_array(x).transform(compressor);
|
||||||
return seq;
|
return seq;
|
||||||
}
|
}
|
||||||
|
|
@ -3110,9 +3111,14 @@ merge(Compressor.prototype, {
|
||||||
if (e instanceof AST_Binary
|
if (e instanceof AST_Binary
|
||||||
&& (self.operator == "+" || self.operator == "-")
|
&& (self.operator == "+" || self.operator == "-")
|
||||||
&& (e.operator == "*" || e.operator == "/" || e.operator == "%")) {
|
&& (e.operator == "*" || e.operator == "/" || e.operator == "%")) {
|
||||||
self.expression = e.left;
|
return make_node(AST_Binary, self, {
|
||||||
e.left = self;
|
operator: e.operator,
|
||||||
return e;
|
left: make_node(AST_UnaryPrefix, e.left, {
|
||||||
|
operator: self.operator,
|
||||||
|
expression: e.left
|
||||||
|
}),
|
||||||
|
right: e.right
|
||||||
|
});
|
||||||
}
|
}
|
||||||
// avoids infinite recursion of numerals
|
// avoids infinite recursion of numerals
|
||||||
if (self.operator != "-"
|
if (self.operator != "-"
|
||||||
|
|
@ -3131,23 +3137,25 @@ merge(Compressor.prototype, {
|
||||||
if (this.left instanceof AST_Seq) {
|
if (this.left instanceof AST_Seq) {
|
||||||
var seq = this.left;
|
var seq = this.left;
|
||||||
var x = seq.to_array();
|
var x = seq.to_array();
|
||||||
this.left = x.pop();
|
var e = this.clone();
|
||||||
x.push(this);
|
e.left = x.pop();
|
||||||
|
x.push(e);
|
||||||
return AST_Seq.from_array(x).optimize(compressor);
|
return AST_Seq.from_array(x).optimize(compressor);
|
||||||
}
|
}
|
||||||
if (this.right instanceof AST_Seq && !this.left.has_side_effects(compressor)) {
|
if (this.right instanceof AST_Seq && !this.left.has_side_effects(compressor)) {
|
||||||
var assign = this.operator == "=" && this.left instanceof AST_SymbolRef;
|
var assign = this.operator == "=" && this.left instanceof AST_SymbolRef;
|
||||||
var root = this.right;
|
var root = this.right.clone();
|
||||||
var cursor, seq = root;
|
var cursor, seq = root;
|
||||||
while (assign || !seq.car.has_side_effects(compressor)) {
|
while (assign || !seq.car.has_side_effects(compressor)) {
|
||||||
cursor = seq;
|
cursor = seq;
|
||||||
if (seq.cdr instanceof AST_Seq) {
|
if (seq.cdr instanceof AST_Seq) {
|
||||||
seq = seq.cdr;
|
seq = seq.cdr = seq.cdr.clone();
|
||||||
} else break;
|
} else break;
|
||||||
}
|
}
|
||||||
if (cursor) {
|
if (cursor) {
|
||||||
this.right = cursor.cdr;
|
var e = this.clone();
|
||||||
cursor.cdr = this;
|
e.right = cursor.cdr;
|
||||||
|
cursor.cdr = e;
|
||||||
return root.optimize(compressor);
|
return root.optimize(compressor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3558,7 +3566,7 @@ merge(Compressor.prototype, {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (d.should_replace) {
|
if (d.should_replace) {
|
||||||
return best_of_expression(d.should_replace.clone(true).optimize(compressor), fixed.clone(true));
|
return best_of_expression(d.should_replace.optimize(compressor), fixed).clone(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1897,3 +1897,22 @@ booleans: {
|
||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
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"
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user