module export variable declaration initializer default - fixes #264

This commit is contained in:
Sebastian McKenzie 2014-12-09 23:15:43 +11:00
parent b688154aee
commit e97e916b5c
2 changed files with 13 additions and 7 deletions

View File

@ -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 {

View File

@ -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) {