diff --git a/bin/extract-props.js b/bin/extract-props.js index 5b33e1ab9ec..7ce7d31e0a4 100755 --- a/bin/extract-props.js +++ b/bin/extract-props.js @@ -50,7 +50,7 @@ function getProps(filename) { try { (function walk(node){ node.walk(new U2.TreeWalker(function(node){ - if (node instanceof U2.AST_Seq) { + if (node instanceof U2.AST_Sequence) { walk(node.expressions[node.expressions.length - 1]); return true; } diff --git a/bin/uglifyjs b/bin/uglifyjs index d40c53a3f7b..4d4d1be0838 100755 --- a/bin/uglifyjs +++ b/bin/uglifyjs @@ -538,7 +538,7 @@ function getOptions(flag, constants) { } } ast.walk(new UglifyJS.TreeWalker(function(node){ - if (node instanceof UglifyJS.AST_Seq) return; // descend + if (node instanceof UglifyJS.AST_Sequence) return; // descend if (node instanceof UglifyJS.AST_Assign) { var name = node.left.print_to_string({ beautify: false }).replace(/-/g, "_"); var value = node.right; diff --git a/lib/ast.js b/lib/ast.js index e8a4305e9a6..ffb9907f17c 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -582,13 +582,13 @@ var AST_New = DEFNODE("New", null, { $documentation: "An object instantiation. Derives from a function call since it has exactly the same properties" }, AST_Call); -var AST_Seq = DEFNODE("Seq", "expressions", { +var AST_Sequence = DEFNODE("Sequence", "expressions", { $documentation: "A sequence expression (comma-separated expressions)", $propdoc: { expressions: "[AST_Node*] array of expressions (at least two)" }, add: function(node) { - if (node instanceof AST_Seq) { + if (node instanceof AST_Sequence) { [].push.apply(this.expressions, node.expressions); } else { this.expressions.push(node); diff --git a/lib/compress.js b/lib/compress.js index 98ee9db36e2..e4183b1d80b 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -227,7 +227,7 @@ merge(Compressor.prototype, { function maintain_this_binding(parent, orig, val) { if (parent instanceof AST_Call && parent.expression === orig) { if (val instanceof AST_PropAccess || val instanceof AST_SymbolRef && val.name === "eval") { - return make_node(AST_Seq, orig, { + return make_node(AST_Sequence, orig, { expressions: [ make_node(AST_Number, orig, { value: 0 }), val ] }); } @@ -733,7 +733,7 @@ merge(Compressor.prototype, { && (!seq || seq.body.expressions.length < compressor.sequences_limit)) { if (!seq) { seq = make_node(AST_SimpleStatement, stat, { - body: make_node(AST_Seq, stat, { expressions: [] }) + body: make_node(AST_Sequence, stat, { expressions: [] }) }); } seq.body.add(stat.body); @@ -752,10 +752,10 @@ merge(Compressor.prototype, { function cons_seq(right) { ret.pop(); var left = prev.body; - if (left instanceof AST_Seq) { + if (left instanceof AST_Sequence) { left.add(right); } else { - left = make_node(AST_Seq, left, { + left = make_node(AST_Sequence, left, { expressions: [ left, right ] }); } @@ -856,7 +856,7 @@ merge(Compressor.prototype, { else if (node instanceof AST_Call) { node.expression = transform(node.expression); } - else if (node instanceof AST_Seq) { + else if (node instanceof AST_Sequence) { // Eliminated by PR #1451 anyway node.expressions[0] = transform(node.expressions[0]); } @@ -933,7 +933,7 @@ merge(Compressor.prototype, { def(AST_Assign, function(){ return this.operator == "=" && this.right.is_boolean(); }); - def(AST_Seq, function(){ + def(AST_Sequence, function(){ return this.expressions[this.expressions.length - 1].is_boolean(); }); def(AST_True, return_true); @@ -956,7 +956,7 @@ merge(Compressor.prototype, { def(AST_Assign, function(compressor){ return (this.operator == "=" || this.operator == "+=") && this.right.is_string(compressor); }); - def(AST_Seq, function(compressor){ + def(AST_Sequence, function(compressor){ return this.expressions[this.expressions.length - 1].is_string(compressor); }); def(AST_Conditional, function(compressor){ @@ -1216,10 +1216,10 @@ merge(Compressor.prototype, { return this.expression; return basic_negation(this); }); - def(AST_Seq, function(compressor){ + def(AST_Sequence, function(compressor){ var expressions = this.expressions.slice(0); expressions.push(expressions.pop().negate(compressor)); - return make_node(AST_Seq, this, { + return make_node(AST_Sequence, this, { expressions: expressions }); }); @@ -1337,7 +1337,7 @@ merge(Compressor.prototype, { def(AST_PropAccess, function(compressor){ return !compressor.option("pure_getters"); }); - def(AST_Seq, function(compressor){ + def(AST_Sequence, function(compressor){ return this.expressions.some(function(expression, index) { return expression.has_side_effects(compressor); }); @@ -1540,7 +1540,7 @@ merge(Compressor.prototype, { } else { if (side_effects.length > 0) { side_effects.push(x.value); - x.value = make_node(AST_Seq, x.value, { + x.value = make_node(AST_Sequence, x.value, { expressions: side_effects }); side_effects = []; @@ -1549,12 +1549,15 @@ merge(Compressor.prototype, { } } if (side_effects.length > 0) { + if (side_effects.length == 1) { + side_effects = side_effects[0]; + } else { + side_effects = make_node(AST_Sequence, node, { + expressions: side_effects + }); + } side_effects = make_node(AST_BlockStatement, node, { - body: [ make_node(AST_SimpleStatement, node, { - body: make_node(AST_Seq, node, { - expressions: side_effects - }) - }) ] + body: [ make_node(AST_SimpleStatement, node, { body: side_effects }) ] }); } else { side_effects = null; @@ -1690,7 +1693,7 @@ merge(Compressor.prototype, { self.body.splice(i, 1); continue; } - if (expr instanceof AST_Seq + if (expr instanceof AST_Sequence && (assign = expr.expressions[0]) instanceof AST_Assign && assign.operator == "=" && (sym = assign.left) instanceof AST_Symbol @@ -1704,7 +1707,7 @@ merge(Compressor.prototype, { if (expr.expressions.length == 2) { self.body[i].body = expr.expressions[1]; } else { - self.body[i].body = make_node(AST_Seq, expr, { + self.body[i].body = make_node(AST_Sequence, expr, { expressions: expr.expressions.slice(1) }); } @@ -2103,7 +2106,7 @@ merge(Compressor.prototype, { }, []); if (assignments.length == 0) return null; if (assignments.length == 1) return assignments[0]; - return make_node(AST_Seq, this, { + return make_node(AST_Sequence, this, { expressions: assignments }); }); @@ -2324,7 +2327,7 @@ merge(Compressor.prototype, { return self; }); - OPT(AST_Seq, function(self, compressor){ + OPT(AST_Sequence, function(self, compressor){ if (!compressor.option("side_effects")) return self; var expressions = self.expressions.slice(0); var start = 0, last = expressions.length - 1, end = last; @@ -2355,7 +2358,7 @@ merge(Compressor.prototype, { return maintain_this_binding(compressor.parent(), self, expressions[end]); } if (start > 0 || end < last) { - return make_node(AST_Seq, self, { + return make_node(AST_Sequence, self, { expressions: expressions.slice(start) }); } @@ -2371,11 +2374,11 @@ merge(Compressor.prototype, { AST_Unary.DEFMETHOD("lift_sequences", function(compressor){ if (compressor.option("sequences")) { - if (this.expression instanceof AST_Seq) { + if (this.expression instanceof AST_Sequence) { var x = this.expression.expressions.slice(0); this.expression = x.pop(); x.push(this); - return make_node(AST_Seq, this, { + return make_node(AST_Sequence, this, { expressions: x }).transform(compressor); } @@ -2402,9 +2405,9 @@ merge(Compressor.prototype, { // typeof always returns a non-empty string, thus it's // always true in booleans compressor.warn("Boolean expression always true [{file}:{line},{col}]", self.start); - if (self.expression.has_side_effects(compressor)) { - return make_node(AST_Seq, self, { - expressions: [ self.expression, make_node(AST_True, self) ] + if (e.has_side_effects(compressor)) { + return make_node(AST_Sequence, self, { + expressions: [ e, make_node(AST_True, self) ] }); } return make_node(AST_True, self); @@ -2426,21 +2429,21 @@ merge(Compressor.prototype, { AST_Binary.DEFMETHOD("lift_sequences", function(compressor){ if (compressor.option("sequences")) { - if (this.left instanceof AST_Seq) { + if (this.left instanceof AST_Sequence) { var x = this.left.expressions.slice(0); this.left = x.pop(); x.push(this); - return make_node(AST_Seq, this, { + return make_node(AST_Sequence, this, { expressions: x }).transform(compressor); } - if (this.right instanceof AST_Seq + if (this.right instanceof AST_Sequence && this instanceof AST_Assign && !has_side_effects_or_prop_access(this.left, compressor)) { var x = this.right.expressions.slice(0); this.right = x.pop(); x.push(this); - return make_node(AST_Seq, this, { + return make_node(AST_Sequence, this, { expressions: x }).transform(compressor); } @@ -2540,7 +2543,7 @@ merge(Compressor.prototype, { if ((ll.length > 1 && !ll[1]) || (rr.length > 1 && !rr[1])) { compressor.warn("Boolean && always false [{file}:{line},{col}]", self.start); if (self.left.has_side_effects(compressor)) { - return make_node(AST_Seq, self, { + return make_node(AST_Sequence, self, { expressions: [ self.left, make_node(AST_False) ] }).optimize(compressor); } @@ -2559,7 +2562,7 @@ merge(Compressor.prototype, { if ((ll.length > 1 && ll[1]) || (rr.length > 1 && rr[1])) { compressor.warn("Boolean || always true [{file}:{line},{col}]", self.start); if (self.left.has_side_effects(compressor)) { - return make_node(AST_Seq, self, { + return make_node(AST_Sequence, self, { expressions: [ self.left, make_node(AST_True) ] }).optimize(compressor); } @@ -2774,11 +2777,11 @@ merge(Compressor.prototype, { OPT(AST_Conditional, function(self, compressor){ if (!compressor.option("conditionals")) return self; // This looks like lift_sequences(), should probably be under "sequences" - if (self.condition instanceof AST_Seq) { + if (self.condition instanceof AST_Sequence) { var expressions = self.condition.expressions.slice(0); self.condition = expressions.pop(); expressions.push(self); - return make_node(AST_Seq, self, { + return make_node(AST_Sequence, self, { expressions: expressions }); } @@ -2830,7 +2833,7 @@ merge(Compressor.prototype, { && !consequent.expression.has_side_effects(compressor) && consequent.expression.equivalent_to(alternative.expression)) { if (consequent.args.length == 0) { - return make_node(AST_Seq, self, { + return make_node(AST_Sequence, self, { expressions: [ self.condition, consequent ] }); } @@ -2862,7 +2865,7 @@ merge(Compressor.prototype, { && consequent.equivalent_to(alternative)) { var consequent_value = consequent.evaluate(compressor)[0]; if (self.condition.has_side_effects(compressor)) { - return make_node(AST_Seq, self, { + return make_node(AST_Sequence, self, { expressions: [ self.condition, consequent_value ] }); } else { diff --git a/lib/mozilla-ast.js b/lib/mozilla-ast.js index 17945957012..e97d61919f4 100644 --- a/lib/mozilla-ast.js +++ b/lib/mozilla-ast.js @@ -149,7 +149,7 @@ }); }, SequenceExpression: function(M) { - return new AST_Seq({ + return new AST_Sequence({ start : my_start_token(M), end : my_end_token(M), expressions: M.expressions.map(from_moz) @@ -336,7 +336,7 @@ }; }); - def_to_moz(AST_Seq, function To_Moz_SequenceExpression(M) { + def_to_moz(AST_Sequence, function To_Moz_SequenceExpression(M) { return { type: "SequenceExpression", expressions: M.expressions.map(to_moz) diff --git a/lib/output.js b/lib/output.js index 43b07614610..dac9ffbc4bc 100644 --- a/lib/output.js +++ b/lib/output.js @@ -577,7 +577,7 @@ function OutputStream(options) { || p instanceof AST_Call && p.expression === this; }); - PARENS(AST_Seq, function(output){ + PARENS(AST_Sequence, function(output){ var p = output.parent(); return p instanceof AST_Call // (foo, bar)() or foo(1, (2, 3), 4) || p instanceof AST_Unary // !(foo, bar, baz) @@ -1080,7 +1080,7 @@ function OutputStream(options) { AST_Call.prototype._codegen(self, output); }); - AST_Seq.DEFMETHOD("_do_print", function(output){ + AST_Sequence.DEFMETHOD("_do_print", function(output){ this.expressions.forEach(function(node, index) { if (index > 0) { output.comma(); @@ -1092,7 +1092,7 @@ function OutputStream(options) { node.print(output); }); }); - DEFPRINT(AST_Seq, function(self, output){ + DEFPRINT(AST_Sequence, function(self, output){ self._do_print(output); // var p = output.parent(); // if (p instanceof AST_Statement) { @@ -1344,7 +1344,7 @@ function OutputStream(options) { if (p instanceof AST_Statement && p.body === node) return true; // TODO: update this function in utils.js instead after PR #1451 - if ((p instanceof AST_Seq && p.expressions[0] === node) || + if ((p instanceof AST_Sequence && p.expressions[0] === node) || (p instanceof AST_Call && p.expression === node && !(p instanceof AST_New) ) || (p instanceof AST_Dot && p.expression === node ) || (p instanceof AST_Sub && p.expression === node ) || diff --git a/lib/parse.js b/lib/parse.js index 8807d87cfcd..95406f75360 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -1535,7 +1535,7 @@ function parse($TEXT, options) { next(); commas = true; } - return exprs.length == 1 ? exprs[0] : new AST_Seq({ + return exprs.length == 1 ? exprs[0] : new AST_Sequence({ start : start, expressions : exprs, end : peek() diff --git a/lib/propmangle.js b/lib/propmangle.js index efa334f8643..9e083394056 100644 --- a/lib/propmangle.js +++ b/lib/propmangle.js @@ -216,7 +216,7 @@ function mangle_properties(ast, options) { try { (function walk(node){ node.walk(new TreeWalker(function(node){ - if (node instanceof AST_Seq) { + if (node instanceof AST_Sequence) { walk(node.expressions[node.expressions.length - 1]); return true; } @@ -239,7 +239,7 @@ function mangle_properties(ast, options) { function mangleStrings(node) { return node.transform(new TreeTransformer(function(node){ - if (node instanceof AST_Seq) { + if (node instanceof AST_Sequence) { var last = node.expressions.length - 1; node.expressions[last] = mangleStrings(node.expressions[last]); } diff --git a/lib/transform.js b/lib/transform.js index 1e572fd6c47..112e5f28799 100644 --- a/lib/transform.js +++ b/lib/transform.js @@ -174,7 +174,7 @@ TreeTransformer.prototype = new TreeWalker; self.args = do_list(self.args, tw); }); - _(AST_Seq, function(self, tw){ + _(AST_Sequence, function(self, tw){ self.expressions = do_list(self.expressions, tw); });