Drop unnecessary dynamic import redeclaration in AMD

Instead of assigning the import a name and them declaring a new
variabled referencing that name, output the import already with
the destination name, since we know there must be no collisions
because these IDs are also generated.
This commit is contained in:
Aluísio Augusto Silva Gonçalves
2015-01-18 21:18:25 -02:00
parent c81cc5cda0
commit 02019d4d8f
2 changed files with 6 additions and 5 deletions

View File

@@ -87,7 +87,11 @@ AMDFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
var key = t.getSpecifierName(specifier);
var ref = this._push(node);
if (t.isImportBatchSpecifier(specifier) || _.contains(this.file.dynamicImports, node)) {
if (_.contains(this.file.dynamicImports, node)) {
// Prevent unnecessary renaming of dynamic imports.
this.ids[node.source.value] = key;
return;
} else if (t.isImportBatchSpecifier(specifier)) {
// import * as bar from "foo";
} else if (t.isSpecifierDefault(specifier) && !this.noInteropRequire) {
// import foo from "foo";