Replace arrays.each with Array.prototype.forEach

See #441.
redux
David Majda 8 years ago
parent 2a6a058c9c
commit b044a021c4

@ -1,7 +1,6 @@
"use strict";
var arrays = require("../utils/arrays"),
objects = require("../utils/objects");
var objects = require("../utils/objects");
var compiler = {
/*
@ -59,7 +58,7 @@ var compiler = {
for (stage in passes) {
if (passes.hasOwnProperty(stage)) {
arrays.each(passes[stage], function(p) { p(ast, options); });
passes[stage].forEach(function(p) { p(ast, options); });
}
}

@ -282,7 +282,7 @@ function generateBytecode(ast) {
var generate = visitor.build({
grammar: function(node) {
arrays.each(node.rules, generate);
node.rules.forEach(generate);
node.consts = consts;
},

@ -1182,7 +1182,7 @@ function generateJS(ast, options) {
parts.push(indent2(generateInterpreter()));
parts.push('');
} else {
arrays.each(ast.rules, function(rule) {
ast.rules.forEach(function(rule) {
parts.push(indent2(generateRuleFunction(rule)));
parts.push('');
});

@ -25,7 +25,7 @@ function removeProxyRules(ast, options) {
var indices = [];
arrays.each(ast.rules, function(rule, i) {
ast.rules.forEach(function(rule, i) {
if (isProxyRule(rule)) {
replaceRuleRefs(ast, rule.name, rule.expression.name);
if (!arrays.contains(options.allowedStartRules, rule.name)) {
@ -36,7 +36,7 @@ function removeProxyRules(ast, options) {
indices.reverse();
arrays.each(indices, function(i) { ast.rules.splice(i, 1); });
indices.forEach(function(i) { ast.rules.splice(i, 1); });
}
module.exports = removeProxyRules;

@ -1,7 +1,6 @@
"use strict";
var GrammarError = require("../../grammar-error"),
arrays = require("../../utils/arrays"),
objects = require("../../utils/objects"),
visitor = require("../visitor");
@ -17,7 +16,7 @@ function reportDuplicateLabels(ast) {
},
choice: function(node, env) {
arrays.each(node.alternatives, function(alternative) {
node.alternatives.forEach(function(alternative) {
check(alternative, objects.clone(env));
});
},

@ -1,7 +1,6 @@
"use strict";
var objects = require("../utils/objects"),
arrays = require("../utils/arrays");
var objects = require("../utils/objects");
/* Simple AST node visitor builder. */
var visitor = {
@ -22,7 +21,7 @@ var visitor = {
return function(node) {
var extraArgs = Array.prototype.slice.call(arguments, 1);
arrays.each(node[property], function(child) {
node[property].forEach(function(child) {
visit.apply(null, [child].concat(extraArgs));
});
};
@ -36,7 +35,7 @@ var visitor = {
visit.apply(null, [node.initializer].concat(extraArgs));
}
arrays.each(node.rules, function(rule) {
node.rules.forEach(function(rule) {
visit.apply(null, [rule].concat(extraArgs));
});
},

@ -1,7 +1,6 @@
"use strict";
var arrays = require("./utils/arrays"),
objects = require("./utils/objects");
var objects = require("./utils/objects");
var peg = {
/* PEG.js version (uses semantic versioning). */
@ -45,7 +44,7 @@ var peg = {
passes: convertPasses(peg.compiler.passes)
};
arrays.each(plugins, function(p) { p.use(config, options); });
plugins.forEach(function(p) { p.use(config, options); });
return peg.compiler.compile(
config.parser.parse(grammar),

@ -56,14 +56,6 @@ var arrays = {
return arrays.indexOf(array, valueOrPredicate) !== -1;
},
each: function(array, iterator) {
var length = array.length, i;
for (i = 0; i < length; i++) {
iterator(array[i], i);
}
},
map: function(array, iterator) {
var length = array.length,
result = new Array(length),

Loading…
Cancel
Save