Skip to content

Commit ab36859

Browse files
committed
feat(parser): increase parse optimization by switching forEach to for
1 parent a01eeb6 commit ab36859

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

‎lib/Parser.js‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -580,9 +580,10 @@ Parser.prototype.walkExportNamedDeclaration = function walkExportNamedDeclaratio
580580
var pos = this.scope.definitions.length;
581581
this.walkStatement(statement.declaration);
582582
var newDefs = this.scope.definitions.slice(pos);
583-
newDefs.reverse().forEach(function(def, idx) {
584-
this.applyPluginsBailResult("export specifier", statement, def, def, idx);
585-
}, this);
583+
for(var index = newDefs.length - 1; index >= 0; index--) {
584+
var def = newDefs[index];
585+
this.applyPluginsBailResult("export specifier", statement, def, def, index);
586+
}
586587
}
587588
}
588589
}
@@ -608,9 +609,10 @@ Parser.prototype.walkExportDefaultDeclaration = function walkExportDefaultDeclar
608609
var pos = this.scope.definitions.length;
609610
this.walkStatement(statement.declaration);
610611
var newDefs = this.scope.definitions.slice(pos);
611-
newDefs.forEach(function(def) {
612+
for(var index = 0; index <= newDefs.length - 1; index++) {
613+
var def = newDefs[index];
612614
this.applyPluginsBailResult("export specifier", statement, def, "default");
613-
}, this);
615+
}
614616
}
615617
} else {
616618
this.walkExpression(statement.declaration);
@@ -638,11 +640,14 @@ Parser.prototype.walkClassDeclaration = function walkClassDeclaration(statement)
638640
};
639641

640642
Parser.prototype.walkSwitchCases = function walkSwitchCases(switchCases) {
641-
switchCases.forEach(function(switchCase) {
642-
if(switchCase.test)
643+
for(var index = 0; index <= switchCases.length - 1; index++) {
644+
var switchCase = switchCases[index];
645+
646+
if(switchCase.test) {
643647
this.walkExpression(switchCase.test);
648+
}
644649
this.walkStatements(switchCase.consequent);
645-
}, this);
650+
}
646651
};
647652

648653
Parser.prototype.walkCatchClause = function walkCatchClause(catchClause) {

‎yarn.lock‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2280,7 +2280,7 @@ lodash.words@^3.0.0:
22802280
dependencies:
22812281
lodash._root "^3.0.0"
22822282

2283-
lodash@^4.0.0, lodash@^4.14.0, lodash@^4.17.3, lodash@^4.3.0:
2283+
lodash@^4.0.0, lodash@^4.14.0, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.3.0:
22842284
version "4.17.4"
22852285
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
22862286

@@ -3546,6 +3546,10 @@ signal-exit@^3.0.0:
35463546
version "3.0.2"
35473547
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
35483548

3549+
simple-git@^1.65.0:
3550+
version "1.65.0"
3551+
resolved "https://registry.yarnpkg.com/simple-git/-/simple-git-1.65.0.tgz#2364a534ae3a67668beaf2a165af04f47a268923"
3552+
35493553
sinon@^1.17.7:
35503554
version "1.17.7"
35513555
resolved "https://registry.yarnpkg.com/sinon/-/sinon-1.17.7.tgz#4542a4f49ba0c45c05eb2e9dd9d203e2b8efe0bf"

0 commit comments

Comments
 (0)