fix up types.toStatement and return an expressionStatement if all else fails

This commit is contained in:
Sebastian McKenzie
2014-11-14 09:14:49 +11:00
parent b9fe1475c2
commit 740193b1e2

View File

@@ -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;