diff --git a/lib/6to5/transformation/modules/common.js b/lib/6to5/transformation/modules/common.js index 267c4ca677..8ab054cf5d 100644 --- a/lib/6to5/transformation/modules/common.js +++ b/lib/6to5/transformation/modules/common.js @@ -98,14 +98,12 @@ CommonJSFormatter.prototype.export = function (node, nodes) { if (t.isVariableDeclaration(declar)) { var decl = declar.declarations[0]; - if (decl.init) { - decl.init = util.template("exports-assign", { - //inherits: node, + decl.init = util.template("exports-assign", { + //inherits: node, - VALUE: decl.init, - KEY: decl.id - }); - } + VALUE: decl.init, + KEY: decl.id + }); nodes.push(declar); } else { diff --git a/lib/6to5/transformation/transformers/es6-modules.js b/lib/6to5/transformation/transformers/es6-modules.js index cfcd991f5c..3b7148cf67 100644 --- a/lib/6to5/transformation/transformers/es6-modules.js +++ b/lib/6to5/transformation/transformers/es6-modules.js @@ -1,3 +1,4 @@ +var t = require("../../types"); var _ = require("lodash"); exports.ImportDeclaration = function (node, parent, file) { @@ -18,6 +19,13 @@ exports.ExportDeclaration = function (node, parent, file) { var nodes = []; if (node.declaration) { + // make sure variable exports have an initialiser + // this is done here to avoid duplicating it in the module formatters + if (t.isVariableDeclaration(node.declaration)) { + var declar = node.declaration.declarations[0]; + declar.init = declar.init || t.identifier("undefined"); + } + file.moduleFormatter.export(node, nodes, parent); } else { _.each(node.specifiers, function (specifier) {