ensureBlock on multiple node replacements - fixes #229
This commit is contained in:
@@ -50,6 +50,10 @@ function traverse(parent, callbacks, opts) {
|
||||
if (result != null) {
|
||||
updated = true;
|
||||
node = obj[key] = result;
|
||||
|
||||
if (_.contains(t.STATEMENT_OR_BLOCK_KEYS, key) && !t.isBlockStatement(obj)) {
|
||||
t.ensureBlock(obj, key);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ var addAssert = function (type, is) {
|
||||
};
|
||||
};
|
||||
|
||||
t.STATEMENT_OR_BLOCK_KEYS = ["consequent", "body"];
|
||||
|
||||
//
|
||||
|
||||
t.VISITOR_KEYS = require("./visitor-keys");
|
||||
@@ -167,8 +169,9 @@ t.isValidIdentifier = function (name) {
|
||||
return _.isString(name) && esutils.keyword.isIdentifierName(name) && !esutils.keyword.isKeywordES6(name, true);
|
||||
};
|
||||
|
||||
t.ensureBlock = function (node) {
|
||||
node.body = t.toBlock(node.body, node);
|
||||
t.ensureBlock = function (node, key) {
|
||||
key = key || "body";
|
||||
node[key] = t.toBlock(node[key], node);
|
||||
};
|
||||
|
||||
t.toStatement = function (node, ignore) {
|
||||
|
||||
Reference in New Issue
Block a user