use more performant plugin methods

This commit is contained in:
Tobias Koppers 2017-07-20 08:02:20 +02:00
parent d9e01d4a5f
commit 2d9252c838
2 changed files with 25 additions and 46 deletions

View File

@ -370,7 +370,7 @@ class Parser extends Tapable {
const param = this.evaluateExpression(expr.callee.object); const param = this.evaluateExpression(expr.callee.object);
if(!param) return; if(!param) return;
const property = expr.callee.property.name || expr.callee.property.value; const property = expr.callee.property.name || expr.callee.property.value;
return this.applyPluginsBailResult("evaluate CallExpression ." + property, expr, param); return this.applyPluginsBailResult2("evaluate CallExpression ." + property, expr, param);
}); });
this.plugin("evaluate CallExpression .replace", function(expr, param) { this.plugin("evaluate CallExpression .replace", function(expr, param) {
if(!param.isString()) return; if(!param.isString()) return;
@ -733,20 +733,20 @@ class Parser extends Tapable {
prewalkImportDeclaration(statement) { prewalkImportDeclaration(statement) {
const source = statement.source.value; const source = statement.source.value;
this.applyPluginsBailResult("import", statement, source); this.applyPluginsBailResult2("import", statement, source);
statement.specifiers.forEach(function(specifier) { statement.specifiers.forEach(function(specifier) {
const name = specifier.local.name; const name = specifier.local.name;
this.scope.renames.set(name, null); this.scope.renames.set(name, null);
this.scope.definitions.add(name); this.scope.definitions.add(name);
switch(specifier.type) { switch(specifier.type) {
case "ImportDefaultSpecifier": case "ImportDefaultSpecifier":
this.applyPluginsBailResult("import specifier", statement, source, "default", name); this.applyPluginsBailResult4("import specifier", statement, source, "default", name);
break; break;
case "ImportSpecifier": case "ImportSpecifier":
this.applyPluginsBailResult("import specifier", statement, source, specifier.imported.name, name); this.applyPluginsBailResult4("import specifier", statement, source, specifier.imported.name, name);
break; break;
case "ImportNamespaceSpecifier": case "ImportNamespaceSpecifier":
this.applyPluginsBailResult("import specifier", statement, source, null, name); this.applyPluginsBailResult4("import specifier", statement, source, null, name);
break; break;
} }
}, this); }, this);
@ -756,7 +756,7 @@ class Parser extends Tapable {
let source; let source;
if(statement.source) { if(statement.source) {
source = statement.source.value; source = statement.source.value;
this.applyPluginsBailResult("export import", statement, source); this.applyPluginsBailResult2("export import", statement, source);
} else { } else {
this.applyPluginsBailResult1("export", statement); this.applyPluginsBailResult1("export", statement);
} }
@ -764,7 +764,7 @@ class Parser extends Tapable {
if(/Expression$/.test(statement.declaration.type)) { if(/Expression$/.test(statement.declaration.type)) {
throw new Error("Doesn't occur?"); throw new Error("Doesn't occur?");
} else { } else {
if(!this.applyPluginsBailResult("export declaration", statement, statement.declaration)) { if(!this.applyPluginsBailResult2("export declaration", statement, statement.declaration)) {
const originalDefinitions = this.scope.definitions; const originalDefinitions = this.scope.definitions;
const tracker = new TrackingSet(this.scope.definitions); const tracker = new TrackingSet(this.scope.definitions);
this.scope.definitions = tracker; this.scope.definitions = tracker;
@ -773,7 +773,7 @@ class Parser extends Tapable {
this.scope.definitions = originalDefinitions; this.scope.definitions = originalDefinitions;
for(let index = newDefs.length - 1; index >= 0; index--) { for(let index = newDefs.length - 1; index >= 0; index--) {
const def = newDefs[index]; const def = newDefs[index];
this.applyPluginsBailResult("export specifier", statement, def, def, index); this.applyPluginsBailResult4("export specifier", statement, def, def, index);
} }
} }
} }
@ -786,9 +786,9 @@ class Parser extends Tapable {
{ {
const name = specifier.exported.name; const name = specifier.exported.name;
if(source) if(source)
this.applyPluginsBailResult("export import specifier", statement, source, specifier.local.name, name, specifierIndex); this.applyPluginsBailResult5("export import specifier", statement, source, specifier.local.name, name, specifierIndex);
else else
this.applyPluginsBailResult("export specifier", statement, specifier.local.name, name, specifierIndex); this.applyPluginsBailResult4("export specifier", statement, specifier.local.name, name, specifierIndex);
break; break;
} }
} }
@ -812,7 +812,7 @@ class Parser extends Tapable {
this.scope.definitions = originalDefinitions; this.scope.definitions = originalDefinitions;
for(let index = 0, len = newDefs.length; index < len; index++) { for(let index = 0, len = newDefs.length; index < len; index++) {
const def = newDefs[index]; const def = newDefs[index];
this.applyPluginsBailResult("export specifier", statement, def, "default"); this.applyPluginsBailResult3("export specifier", statement, def, "default");
} }
} }
} }
@ -820,21 +820,21 @@ class Parser extends Tapable {
walkExportDefaultDeclaration(statement) { walkExportDefaultDeclaration(statement) {
this.applyPluginsBailResult1("export", statement); this.applyPluginsBailResult1("export", statement);
if(/Declaration$/.test(statement.declaration.type)) { if(/Declaration$/.test(statement.declaration.type)) {
if(!this.applyPluginsBailResult("export declaration", statement, statement.declaration)) { if(!this.applyPluginsBailResult2("export declaration", statement, statement.declaration)) {
this.walkStatement(statement.declaration); this.walkStatement(statement.declaration);
} }
} else { } else {
this.walkExpression(statement.declaration); this.walkExpression(statement.declaration);
if(!this.applyPluginsBailResult("export expression", statement, statement.declaration)) { if(!this.applyPluginsBailResult2("export expression", statement, statement.declaration)) {
this.applyPluginsBailResult("export specifier", statement, statement.declaration, "default"); this.applyPluginsBailResult3("export specifier", statement, statement.declaration, "default");
} }
} }
} }
prewalkExportAllDeclaration(statement) { prewalkExportAllDeclaration(statement) {
const source = statement.source.value; const source = statement.source.value;
this.applyPluginsBailResult("export import", statement, source); this.applyPluginsBailResult2("export import", statement, source);
this.applyPluginsBailResult("export import specifier", statement, source, null, null, 0); this.applyPluginsBailResult5("export import specifier", statement, source, null, null, 0);
} }
prewalkVariableDeclaration(statement) { prewalkVariableDeclaration(statement) {
@ -1438,7 +1438,7 @@ class Parser extends Tapable {
}; };
const state = this.state = initialState || {}; const state = this.state = initialState || {};
this.comments = comments; this.comments = comments;
if(this.applyPluginsBailResult("program", ast, comments) === undefined) { if(this.applyPluginsBailResult2("program", ast, comments) === undefined) {
this.prewalkStatements(ast.body); this.prewalkStatements(ast.body);
this.walkStatements(ast.body); this.walkStatements(ast.body);
} }

View File

@ -2,11 +2,7 @@
# yarn lockfile v1 # yarn lockfile v1
abbrev@1: abbrev@1, abbrev@1.0.x:
version "1.1.0"
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.0.tgz#d0554c2256636e2f56e7c2e5ad183f859428d81f"
abbrev@1.0.x:
version "1.0.9" version "1.0.9"
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.0.9.tgz#91b4792588a7738c25f35dd6f63752a2f8776135" resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.0.9.tgz#91b4792588a7738c25f35dd6f63752a2f8776135"
@ -1072,7 +1068,7 @@ destroy@~1.0.4:
version "1.0.4" version "1.0.4"
resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80" resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80"
diff@3.2.0: diff@3.2.0, diff@^3.1.0:
version "3.2.0" version "3.2.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-3.2.0.tgz#c9ce393a4b7cbd0b058a725c93df299027868ff9" resolved "https://registry.yarnpkg.com/diff/-/diff-3.2.0.tgz#c9ce393a4b7cbd0b058a725c93df299027868ff9"
@ -1080,10 +1076,6 @@ diff@^2.2.1:
version "2.2.3" version "2.2.3"
resolved "https://registry.yarnpkg.com/diff/-/diff-2.2.3.tgz#60eafd0d28ee906e4e8ff0a52c1229521033bf99" resolved "https://registry.yarnpkg.com/diff/-/diff-2.2.3.tgz#60eafd0d28ee906e4e8ff0a52c1229521033bf99"
diff@^3.1.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-3.3.0.tgz#056695150d7aa93237ca7e378ac3b1682b7963b9"
diffie-hellman@^5.0.0: diffie-hellman@^5.0.0:
version "5.0.2" version "5.0.2"
resolved "https://registry.yarnpkg.com/diffie-hellman/-/diffie-hellman-5.0.2.tgz#b5835739270cfe26acf632099fded2a07f209e5e" resolved "https://registry.yarnpkg.com/diffie-hellman/-/diffie-hellman-5.0.2.tgz#b5835739270cfe26acf632099fded2a07f209e5e"
@ -2192,7 +2184,6 @@ jade@^1.11.0:
jstransformer "0.0.2" jstransformer "0.0.2"
mkdirp "~0.5.0" mkdirp "~0.5.0"
transformers "2.1.0" transformers "2.1.0"
uglify-js "^2.4.19"
void-elements "~2.0.1" void-elements "~2.0.1"
with "~4.0.0" with "~4.0.0"
@ -2600,7 +2591,7 @@ minimalistic-crypto-utils@^1.0.0, minimalistic-crypto-utils@^1.0.1:
dependencies: dependencies:
brace-expansion "^1.1.7" brace-expansion "^1.1.7"
minimist@0.0.8: minimist@0.0.8, minimist@~0.0.1:
version "0.0.8" version "0.0.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
@ -2608,10 +2599,6 @@ minimist@1.2.0, minimist@^1.2.0:
version "1.2.0" version "1.2.0"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284" resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"
minimist@~0.0.1:
version "0.0.10"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf"
mkdirp@0.5.1, mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1: mkdirp@0.5.1, mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1:
version "0.5.1" version "0.5.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
@ -3402,11 +3389,7 @@ randombytes@^2.0.0, randombytes@^2.0.1:
dependencies: dependencies:
safe-buffer "^5.1.0" safe-buffer "^5.1.0"
range-parser@^1.0.3: range-parser@^1.0.3, range-parser@~1.0.3:
version "1.2.0"
resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.0.tgz#f49be6b487894ddc40dcc94a322f611092e00d5e"
range-parser@~1.0.3:
version "1.0.3" version "1.0.3"
resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.0.3.tgz#6872823535c692e2c2a0103826afd82c2e0ff175" resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.0.3.tgz#6872823535c692e2c2a0103826afd82c2e0ff175"
@ -3572,7 +3555,7 @@ request@2.42.0:
stringstream "~0.0.4" stringstream "~0.0.4"
tough-cookie ">=0.12.0" tough-cookie ">=0.12.0"
request@2.79.0: request@2.79.0, request@^2.34, request@^2.72.0:
version "2.79.0" version "2.79.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.79.0.tgz#4dfe5bf6be8b8cdc37fcf93e04b65577722710de" resolved "https://registry.yarnpkg.com/request/-/request-2.79.0.tgz#4dfe5bf6be8b8cdc37fcf93e04b65577722710de"
dependencies: dependencies:
@ -3597,7 +3580,7 @@ request@2.79.0:
tunnel-agent "~0.4.1" tunnel-agent "~0.4.1"
uuid "^3.0.0" uuid "^3.0.0"
request@^2.34, request@^2.72.0, request@^2.81.0: request@^2.81.0:
version "2.81.0" version "2.81.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.81.0.tgz#c6928946a0e06c5f8d6f8a9333469ffda46298a0" resolved "https://registry.yarnpkg.com/request/-/request-2.81.0.tgz#c6928946a0e06c5f8d6f8a9333469ffda46298a0"
dependencies: dependencies:
@ -3958,11 +3941,7 @@ sshpk@^1.7.0:
jsbn "~0.1.0" jsbn "~0.1.0"
tweetnacl "~0.14.0" tweetnacl "~0.14.0"
statuses@1: statuses@1, statuses@~1.2.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.3.1.tgz#faf51b9eb74aaef3b3acf4ad5f61abf24cb7b93e"
statuses@~1.2.1:
version "1.2.1" version "1.2.1"
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.2.1.tgz#dded45cc18256d51ed40aec142489d5c61026d28" resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.2.1.tgz#dded45cc18256d51ed40aec142489d5c61026d28"
@ -4240,7 +4219,7 @@ ua-parser-js@^0.7.9:
version "0.7.14" version "0.7.14"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.14.tgz#110d53fa4c3f326c121292bbeac904d2e03387ca" resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.14.tgz#110d53fa4c3f326c121292bbeac904d2e03387ca"
uglify-js@^2.4.19, uglify-js@^2.6, uglify-js@^2.8.29: uglify-js@^2.6, uglify-js@^2.8.29:
version "2.8.29" version "2.8.29"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.29.tgz#29c5733148057bb4e1f75df35b7a9cb72e6a59dd" resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.29.tgz#29c5733148057bb4e1f75df35b7a9cb72e6a59dd"
dependencies: dependencies: