Skip to content

Commit

Permalink
convert [].forEach() to for-loops
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl committed Feb 2, 2017
1 parent 307616b commit 02c5ca6
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions lib/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,9 @@ var AST_SimpleStatement = DEFNODE("SimpleStatement", "body", {
function walk_body(node, visitor) {
if (node.body instanceof AST_Statement) {
node.body._walk(visitor);
} else for (var i = 0, len = node.body.length; i < len; i++) {
node.body[i]._walk(visitor);
}
else node.body.forEach(function(stat){
stat._walk(visitor);
});
};

var AST_Block = DEFNODE("Block", "body", {
Expand Down Expand Up @@ -302,12 +301,13 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", {
var args = [];
var parameters = [];

arg_parameter_pairs.forEach(function(pair) {
for (var i = 0, len = arg_parameter_pairs.length; i < len; i++) {
var pair = arg_parameter_pairs[i];
var splitAt = pair.lastIndexOf(":");

args.push(pair.substr(0, splitAt));
parameters.push(pair.substr(splitAt + 1));
});
}

var wrapped_tl = "(function(" + parameters.join(",") + "){ '$ORIG'; })(" + args.join(",") + ")";
wrapped_tl = parse(wrapped_tl);
Expand Down Expand Up @@ -339,7 +339,8 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", {
return MAP.splice(self.body);
case "$EXPORTS":
var body = [];
to_export.forEach(function(sym){
for (var i = 0, len = to_export.length; i < len; i++) {
var sym = to_export[i];
body.push(new AST_SimpleStatement({
body: new AST_Assign({
left: new AST_Sub({
Expand All @@ -350,7 +351,7 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", {
right: new AST_SymbolRef(sym),
}),
}));
});
}
return MAP.splice(body);
}
}
Expand All @@ -369,9 +370,9 @@ var AST_Lambda = DEFNODE("Lambda", "name argnames uses_arguments", {
_walk: function(visitor) {
return visitor._visit(this, function(){
if (this.name) this.name._walk(visitor);
this.argnames.forEach(function(arg){
arg._walk(visitor);
});
for (var i = 0, len = this.argnames.length; i < len; i++) {
this.argnames[i]._walk(visitor);
}
walk_body(this, visitor);
});
}
Expand Down Expand Up @@ -531,9 +532,9 @@ var AST_Definitions = DEFNODE("Definitions", "definitions", {
},
_walk: function(visitor) {
return visitor._visit(this, function(){
this.definitions.forEach(function(def){
def._walk(visitor);
});
for (var i = 0, len = this.definitions.length; i < len; i++) {
this.definitions[i]._walk(visitor);
}
});
}
}, AST_Statement);
Expand Down Expand Up @@ -571,9 +572,9 @@ var AST_Call = DEFNODE("Call", "expression args", {
_walk: function(visitor) {
return visitor._visit(this, function(){
this.expression._walk(visitor);
this.args.forEach(function(arg){
arg._walk(visitor);
});
for (var i = 0, len = this.args.length; i < len; i++) {
this.args[i]._walk(visitor);
}
});
}
});
Expand All @@ -596,9 +597,9 @@ var AST_Sequence = DEFNODE("Sequence", "expressions", {
},
_walk: function(visitor) {
return visitor._visit(this, function(){
this.expressions.forEach(function(expression) {
expression._walk(visitor);
});
for (var i = 0, len = this.expressions.length; i < len; i++) {
this.expressions[i]._walk(visitor);
}
});
}
});
Expand Down Expand Up @@ -695,9 +696,9 @@ var AST_Array = DEFNODE("Array", "elements", {
},
_walk: function(visitor) {
return visitor._visit(this, function(){
this.elements.forEach(function(el){
el._walk(visitor);
});
for (var i = 0, len = this.elements.length; i < len; i++) {
this.elements[i]._walk(visitor);
}
});
}
});
Expand All @@ -709,9 +710,9 @@ var AST_Object = DEFNODE("Object", "properties", {
},
_walk: function(visitor) {
return visitor._visit(this, function(){
this.properties.forEach(function(prop){
prop._walk(visitor);
});
for (var i = 0, len = this.properties.length; i < len; i++) {
this.properties[i]._walk(visitor);
}
});
}
});
Expand Down

0 comments on commit 02c5ca6

Please sign in to comment.