add util.ensureExpressionType which will change a node from a declaration to an expression

This commit is contained in:
Sebastian McKenzie 2014-10-17 11:48:25 +11:00
parent 41ab47dde8
commit aeac003dc8
3 changed files with 10 additions and 6 deletions

View File

@ -44,7 +44,7 @@ exports.VariableDeclaration = function (node, parent, file) {
};
if (node.type === "FunctionDeclaration") {
node.type = "FunctionExpression";
util.ensureExpressionType(node);
var declar = b.variableDeclaration("var", [
b.variableDeclarator(node.id, callNode())
]);

View File

@ -72,11 +72,7 @@ var pushExportDeclaration = function (node, parent, nodes) {
var declar = node.declaration;
if (node.default) {
if (declar.type === "FunctionDeclaration") {
declar.type = "FunctionExpression";
} else if (declar.type === "ClassDeclaration") {
declar.type = "ClassExpression";
}
util.ensureExpressionType(declar);
nodes.push(util.template("exports-default", {
VALUE: declar

View File

@ -24,6 +24,14 @@ exports.list = function (val) {
return val ? val.split(",") : [];
};
exports.ensureExpressionType = function (node) {
node.type = {
FunctionDeclaration: "FunctionExpression",
ClassDeclaration: "ClassExpression"
}[node.type] || node.type;
return node;
};
exports.getUid = function (parent, file) {
var node;