Skip to content

Commit

Permalink
rename AST_Seq to AST_Sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl committed Feb 2, 2017
1 parent a5416f9 commit 307616b
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 50 deletions.
2 changes: 1 addition & 1 deletion bin/extract-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion bin/uglifyjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lib/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
75 changes: 39 additions & 36 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
});
}
Expand Down Expand Up @@ -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);
Expand All @@ -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 ]
});
}
Expand Down Expand Up @@ -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]);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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){
Expand Down Expand Up @@ -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
});
});
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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 = [];
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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)
});
}
Expand Down Expand Up @@ -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
});
});
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
});
}
Expand All @@ -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);
}
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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
});
}
Expand Down Expand Up @@ -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 ]
});
}
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions lib/mozilla-ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions lib/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Expand Down Expand Up @@ -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 ) ||
Expand Down
2 changes: 1 addition & 1 deletion lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions lib/propmangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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]);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down

0 comments on commit 307616b

Please sign in to comment.