module export variable declaration initializer default - fixes #264
This commit is contained in:
parent
b688154aee
commit
e97e916b5c
@ -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 {
|
||||||
|
|||||||
@ -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) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user