From 02019d4d8f728817809d1e51d7889ae11f3e8d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alu=C3=ADsio=20Augusto=20Silva=20Gon=C3=A7alves?= Date: Sun, 18 Jan 2015 21:18:25 -0200 Subject: [PATCH] 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. --- lib/6to5/transformation/modules/amd.js | 6 +++++- .../optional-self-contained/runtime-amd/expected.js | 5 +---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/6to5/transformation/modules/amd.js b/lib/6to5/transformation/modules/amd.js index 0eb61407b2..6d06ddbe46 100644 --- a/lib/6to5/transformation/modules/amd.js +++ b/lib/6to5/transformation/modules/amd.js @@ -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"; diff --git a/test/fixtures/transformation/optional-self-contained/runtime-amd/expected.js b/test/fixtures/transformation/optional-self-contained/runtime-amd/expected.js index 17b753e8c5..928902ba02 100644 --- a/test/fixtures/transformation/optional-self-contained/runtime-amd/expected.js +++ b/test/fixtures/transformation/optional-self-contained/runtime-amd/expected.js @@ -1,8 +1,5 @@ -define(["exports", "6to5-runtime/6to5", "6to5-runtime/core-js", "6to5-runtime/regenerator", "someModule"], function (exports, _to5Runtime6to5, _to5RuntimeCoreJs, _to5RuntimeRegenerator, _someModule) { +define(["exports", "6to5-runtime/6to5", "6to5-runtime/core-js", "6to5-runtime/regenerator", "someModule"], function (exports, _to5Runtime, _core, _regeneratorRuntime, _someModule) { "use strict"; - var _to5Runtime = _to5Runtime6to5; - var _core = _to5RuntimeCoreJs; - var _regeneratorRuntime = _to5RuntimeRegenerator; var foo = _to5Runtime.interopRequire(_someModule); });