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)) { if (t.isVariableDeclaration(declar)) {
var decl = declar.declarations[0]; var decl = declar.declarations[0];
if (decl.init) { decl.init = util.template("exports-assign", {
decl.init = util.template("exports-assign", { //inherits: node,
//inherits: node,
VALUE: decl.init, VALUE: decl.init,
KEY: decl.id KEY: decl.id
}); });
}
nodes.push(declar); nodes.push(declar);
} else { } else {

View File

@ -1,3 +1,4 @@
var t = require("../../types");
var _ = require("lodash"); var _ = require("lodash");
exports.ImportDeclaration = function (node, parent, file) { exports.ImportDeclaration = function (node, parent, file) {
@ -18,6 +19,13 @@ exports.ExportDeclaration = function (node, parent, file) {
var nodes = []; var nodes = [];
if (node.declaration) { 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); file.moduleFormatter.export(node, nodes, parent);
} else { } else {
_.each(node.specifiers, function (specifier) { _.each(node.specifiers, function (specifier) {