fix weird path context state by clearing the context before we visit it
This commit is contained in:
@@ -1,2 +1 @@
|
||||
export { bare as FunctionExpression } from "../../helpers/name-method";
|
||||
export { bare as ArrowFunctionExpression } from "../../helpers/name-method";
|
||||
export { bare as FunctionExpression, bare as ArrowFunctionExpression } from "../../helpers/name-method";
|
||||
|
||||
@@ -34,6 +34,8 @@ export default class TraversalContext {
|
||||
if (visited.indexOf(path.node) >= 0) continue;
|
||||
visited.push(path.node);
|
||||
|
||||
path.setContext(this.parentPath, this, path.key);
|
||||
|
||||
if (path.visit()) {
|
||||
stop = true;
|
||||
break;
|
||||
|
||||
@@ -14,10 +14,6 @@ export default function traverse(parent, opts, scope, state, parentPath) {
|
||||
}
|
||||
|
||||
if (!opts) opts = {};
|
||||
if (!opts.enter) opts.enter = function () { };
|
||||
if (!opts.exit) opts.exit = function () { };
|
||||
if (!opts.shouldSkip) opts.shouldSkip = function () { return false; };
|
||||
|
||||
traverse.verify(opts);
|
||||
|
||||
// array of nodes
|
||||
@@ -41,6 +37,10 @@ traverse.verify = function (opts) {
|
||||
throw new Error(messages.get("traverseVerifyRootFunction"));
|
||||
}
|
||||
|
||||
if (!opts.enter) opts.enter = function () { };
|
||||
if (!opts.exit) opts.exit = function () { };
|
||||
if (!opts.shouldSkip) opts.shouldSkip = function () { return false; };
|
||||
|
||||
for (var key in opts) {
|
||||
// it's all good
|
||||
if (key === "blacklist") continue;
|
||||
|
||||
@@ -68,7 +68,12 @@ var blockVariableVisitor = {
|
||||
var renameVisitor = explode({
|
||||
Identifier(node, parent, scope, state) {
|
||||
if (this.isReferenced() && node.name === state.oldName) {
|
||||
node.name = state.newName;
|
||||
if (this.parentPath.isProperty() && this.key === "key" && parent.shorthand) {
|
||||
parent.shorthand = false;
|
||||
parent.value = t.identifier(state.newName);
|
||||
} else {
|
||||
node.name = state.newName;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user