combine export declaration assignments into variable declarations

This commit is contained in:
Sebastian McKenzie
2014-11-07 12:31:31 +11:00
parent 469a522300
commit e8d4806b45

View File

@@ -51,23 +51,32 @@ CommonJSFormatter.prototype.export = function (node, nodes) {
VALUE: ref
}, true));
} else {
var id = declar.id;
var assign;
if (t.isVariableDeclaration(declar)) {
id = declar.declarations[0].id;
var decl = declar.declarations[0]
if (decl.init) {
decl.init = util.template("exports-assign", {
VALUE: decl.init,
KEY: decl.id
});
}
nodes.push(declar);
} else {
assign = util.template("exports-assign", {
VALUE: declar.id,
KEY: declar.id
}, true);
nodes.push(declar);
nodes.push(assign);
if (t.isFunctionDeclaration(declar)) {
assign._blockHoist = true;
}
}
var assign = util.template("exports-assign", {
VALUE: id,
KEY: id
}, true);
nodes.push(declar);
if (t.isFunctionDeclaration(declar)) {
assign._blockHoist = true;
}
nodes.push(assign);
}
};