diff --git a/lib/6to5/modules/amd.js b/lib/6to5/modules/amd.js index e18076f7fc..e8858fbff3 100644 --- a/lib/6to5/modules/amd.js +++ b/lib/6to5/modules/amd.js @@ -75,28 +75,8 @@ AMDFormatter.prototype.importSpecifier = function (specifier, node, nodes) { }; AMDFormatter.prototype.exportSpecifier = function (specifier, node, nodes) { - var variableName = util.getSpecifierName(specifier); - - if (node.source) { - var object = this._push(node); - if (specifier.type === "ExportBatchSpecifier") { - // export * from "foo"; - nodes.push(util.template("exports-wildcard", { - OBJECT: object - }, true)); - } else { - // export { foo } from "test"; - nodes.push(util.template("exports-assign-key", { - VARIABLE_NAME: variableName.name, - OBJECT: object, - KEY: specifier.id - }, true)); - } - } else { - // export { foo }; - nodes.push(util.template("exports-assign", { - VALUE: specifier.id, - KEY: variableName - }, true)); - } + var self = this; + return this._exportSpecifier(function () { + return self._push(node); + }, specifier, node, nodes); }; diff --git a/lib/6to5/modules/common.js b/lib/6to5/modules/common.js index a5b99c78bc..7bbfe4528c 100644 --- a/lib/6to5/modules/common.js +++ b/lib/6to5/modules/common.js @@ -64,21 +64,20 @@ CommonJSFormatter.prototype.export = function (node, nodes) { } }; -CommonJSFormatter.prototype.exportSpecifier = function (specifier, node, nodes) { +CommonJSFormatter.prototype._exportSpecifier = function (getRef, specifier, node, nodes) { var variableName = util.getSpecifierName(specifier); if (node.source) { - var object = b.callExpression(b.identifier("require"), [node.source]); if (specifier.type === "ExportBatchSpecifier") { // export * from "foo"; nodes.push(util.template("exports-wildcard", { - OBJECT: object + OBJECT: getRef() }, true)); } else { // export { foo } from "test"; nodes.push(util.template("exports-assign-key", { VARIABLE_NAME: variableName.name, - OBJECT: object, + OBJECT: getRef(), KEY: specifier.id }, true)); } @@ -90,3 +89,9 @@ CommonJSFormatter.prototype.exportSpecifier = function (specifier, node, nodes) }, true)); } }; + +CommonJSFormatter.prototype.exportSpecifier = function (specifier, node, nodes) { + return this._exportSpecifier(function () { + return b.callExpression(b.identifier("require"), [node.source]); + }, specifier, node, nodes); +};