fix up types.toStatement and return an expressionStatement if all else fails
This commit is contained in:
@@ -119,18 +119,12 @@ t.toStatement = function (node, ignore) {
|
||||
} else if (t.isFunction(node)) {
|
||||
mustHaveId = true;
|
||||
newType = "FunctionDeclaration";
|
||||
} else {
|
||||
return t.expressionStatement(node);
|
||||
}
|
||||
|
||||
if (mustHaveId && !node.id) {
|
||||
newType = false;
|
||||
}
|
||||
|
||||
if (!newType) {
|
||||
if (ignore) {
|
||||
return false;
|
||||
} else {
|
||||
throw new Error("cannot turn " + node.type + " to a statement");
|
||||
}
|
||||
throw new Error("the type " + node.type + " needs an id in order to be transformed into a statement");
|
||||
}
|
||||
|
||||
node.type = newType;
|
||||
|
||||
Reference in New Issue
Block a user