add util.ensureExpressionType which will change a node from a declaration to an expression
This commit is contained in:
parent
41ab47dde8
commit
aeac003dc8
@ -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())
|
||||
]);
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user