From af4009694a226b2fb78c8c93d04fa32fcaa0b0f2 Mon Sep 17 00:00:00 2001 From: Lars Kappert Date: Sun, 4 Jan 2015 12:53:05 +0100 Subject: [PATCH] Simplify AMD export declaration fn to re-use CommonJS one --- lib/6to5/transformation/modules/amd.js | 32 ++++---------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/lib/6to5/transformation/modules/amd.js b/lib/6to5/transformation/modules/amd.js index af44fe85ea..56387fafb4 100644 --- a/lib/6to5/transformation/modules/amd.js +++ b/lib/6to5/transformation/modules/amd.js @@ -1,6 +1,7 @@ module.exports = AMDFormatter; var DefaultFormatter = require("./_default"); +var CommonFormatter = require("./common"); var util = require("../../util"); var t = require("../../types"); var _ = require("lodash"); @@ -96,37 +97,12 @@ AMDFormatter.prototype.importSpecifier = function (specifier, node, nodes) { ])); }; -AMDFormatter.prototype.exportDeclaration = function (node, nodes) { +AMDFormatter.prototype.exportDeclaration = function (node) { if (node.default) { - var declar = node.declaration; - var assign; - - // exports = VALUE; - var templateName = "exports-default"; - - if (t.isFunction(declar) || !this.hasNonDefaultExports) { - assign = util.template(templateName, { - VALUE: this._pushStatement(declar, nodes) - }, true); - - // hoist to the top if this default is a function - nodes.push(this._hoistExport(declar, assign, 3)); - return; - } else { - // this export isn't a function so we can't hoist it to the top so we need to set it - // at the very end of the file with something like: - // - // module.exports = Object.assign(exports["default"], exports) - // - - assign = util.template("amd-export-default-assign", true); - assign._blockHoist = 0; - - nodes.push(assign); - } + this.passModuleArg = true; } - DefaultFormatter.prototype.exportDeclaration.apply(this, arguments); + CommonFormatter.prototype.exportDeclaration.apply(this, arguments); }; AMDFormatter.prototype.exportSpecifier = function (specifier, node, nodes) {