aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-12-01 03:18:20 +0800
committerGitHub <noreply@github.com>2017-12-01 03:18:20 +0800
commitc58d3936a3c145b883e3e4537d503c690514a456 (patch)
treefca37a0ceaa87fafeabefde21bc4c2c767ce7dfe
parent18302bf8e9507bbb661986e37cf66a95e6017271 (diff)
downloadtracifyjs-c58d3936a3c145b883e3e4537d503c690514a456.tar.gz
tracifyjs-c58d3936a3c145b883e3e4537d503c690514a456.zip
fix corner case in call binding (#2541)
-rw-r--r--lib/compress.js37
-rw-r--r--test/compress/issue-973.js3
2 files changed, 18 insertions, 22 deletions
diff --git a/lib/compress.js b/lib/compress.js
index dc761948..6bdd1599 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -701,7 +701,7 @@ merge(Compressor.prototype, {
function make_sequence(orig, expressions) {
if (expressions.length == 1) return expressions[0];
return make_node(AST_Sequence, orig, {
- expressions: expressions
+ expressions: expressions.reduce(merge_sequence, [])
});
}
@@ -758,6 +758,7 @@ merge(Compressor.prototype, {
} else {
array.push(node);
}
+ return array;
}
function as_statement_array(thing) {
@@ -1397,13 +1398,7 @@ merge(Compressor.prototype, {
function cons_seq(right) {
n--;
var left = prev.body;
- if (!(left instanceof AST_Sequence)) {
- left = make_node(AST_Sequence, left, {
- expressions: [ left ]
- });
- }
- merge_sequence(left.expressions, right);
- return left.transform(compressor);
+ return make_sequence(left, [ left, right ]).transform(compressor);
};
var n = 0, prev;
for (var i = 0, len = statements.length; i < len; i++) {
@@ -2501,7 +2496,7 @@ merge(Compressor.prototype, {
if (var_defs.length > 1 && (!def.value || sym.orig.indexOf(def.name) > sym.eliminated)) {
compressor.warn("Dropping duplicated definition of variable {name} [{file}:{line},{col}]", template(def.name));
if (def.value) {
- merge_sequence(side_effects, make_node(AST_Assign, def, {
+ side_effects.push(make_node(AST_Assign, def, {
operator: "=",
left: make_node(AST_SymbolRef, def.name, def.name),
right: def.value
@@ -2515,7 +2510,7 @@ merge(Compressor.prototype, {
if (def.value) {
if (side_effects.length > 0) {
if (tail.length > 0) {
- merge_sequence(side_effects, def.value);
+ side_effects.push(def.value);
def.value = make_sequence(def.value, side_effects);
} else {
body.push(make_node(AST_SimpleStatement, node, {
@@ -2530,14 +2525,14 @@ merge(Compressor.prototype, {
}
} else if (sym.orig[0] instanceof AST_SymbolCatch) {
var value = def.value && def.value.drop_side_effect_free(compressor);
- if (value) merge_sequence(side_effects, value);
+ if (value) side_effects.push(value);
def.value = null;
head.push(def);
} else {
var value = def.value && def.value.drop_side_effect_free(compressor);
if (value) {
compressor.warn("Side effects in initialization of unused variable {name} [{file}:{line},{col}]", template(def.name));
- merge_sequence(side_effects, value);
+ side_effects.push(value);
} else {
compressor[def.name.unreferenced() ? "warn" : "info"]("Dropping unused variable {name} [{file}:{line},{col}]", template(def.name));
}
@@ -2868,7 +2863,7 @@ merge(Compressor.prototype, {
var node = nodes[i].drop_side_effect_free(compressor, first_in_statement);
changed |= node !== nodes[i];
if (node) {
- merge_sequence(ret, node);
+ ret.push(node);
first_in_statement = false;
}
}
@@ -2983,7 +2978,7 @@ merge(Compressor.prototype, {
var expr = last.drop_side_effect_free(compressor);
if (expr === last) return this;
var expressions = this.expressions.slice(0, -1);
- if (expr) merge_sequence(expressions, expr);
+ if (expr) expressions.push(expr);
return make_sequence(this, expressions);
});
})(function(node, func){
@@ -3692,7 +3687,7 @@ merge(Compressor.prototype, {
trim_right_for_undefined();
if (end > 0 && compressor.option("cascade")) trim_left_for_assignment();
if (end == 0) {
- self = maintain_this_binding(compressor.parent(), self, expressions[0]);
+ self = maintain_this_binding(compressor.parent(), compressor.self(), expressions[0]);
if (!(self instanceof AST_Sequence)) self = self.optimize(compressor);
return self;
}
@@ -4044,10 +4039,10 @@ merge(Compressor.prototype, {
var ll = self.left.evaluate(compressor);
if (!ll) {
compressor.warn("Condition left of && always false [{file}:{line},{col}]", self.start);
- return maintain_this_binding(compressor.parent(), self, self.left).optimize(compressor);
+ return maintain_this_binding(compressor.parent(), compressor.self(), self.left).optimize(compressor);
} else if (ll !== self.left) {
compressor.warn("Condition left of && always true [{file}:{line},{col}]", self.start);
- return maintain_this_binding(compressor.parent(), self, self.right).optimize(compressor);
+ return maintain_this_binding(compressor.parent(), compressor.self(), self.right).optimize(compressor);
}
if (compressor.option("booleans") && compressor.in_boolean_context()) {
var rr = self.right.evaluate(compressor);
@@ -4067,10 +4062,10 @@ merge(Compressor.prototype, {
var ll = self.left.evaluate(compressor);
if (!ll) {
compressor.warn("Condition left of || always false [{file}:{line},{col}]", self.start);
- return maintain_this_binding(compressor.parent(), self, self.right).optimize(compressor);
+ return maintain_this_binding(compressor.parent(), compressor.self(), self.right).optimize(compressor);
} else if (ll !== self.left) {
compressor.warn("Condition left of || always true [{file}:{line},{col}]", self.start);
- return maintain_this_binding(compressor.parent(), self, self.left).optimize(compressor);
+ return maintain_this_binding(compressor.parent(), compressor.self(), self.left).optimize(compressor);
}
if (compressor.option("booleans") && compressor.in_boolean_context()) {
var rr = self.right.evaluate(compressor);
@@ -4509,10 +4504,10 @@ merge(Compressor.prototype, {
if (cond !== self.condition) {
if (cond) {
compressor.warn("Condition always true [{file}:{line},{col}]", self.start);
- return maintain_this_binding(compressor.parent(), self, self.consequent);
+ return maintain_this_binding(compressor.parent(), compressor.self(), self.consequent);
} else {
compressor.warn("Condition always false [{file}:{line},{col}]", self.start);
- return maintain_this_binding(compressor.parent(), self, self.alternative);
+ return maintain_this_binding(compressor.parent(), compressor.self(), self.alternative);
}
}
var negated = cond.negate(compressor, first_in_statement(compressor));
diff --git a/test/compress/issue-973.js b/test/compress/issue-973.js
index fee05dfc..a9fcd84f 100644
--- a/test/compress/issue-973.js
+++ b/test/compress/issue-973.js
@@ -1,7 +1,8 @@
this_binding_conditionals: {
options = {
conditionals: true,
- evaluate : true
+ evaluate: true,
+ side_effects: true,
};
input: {
(1 && a)();