fix weird path context state by clearing the context before we visit it

This commit is contained in:
Sebastian McKenzie
2015-04-30 17:19:27 +01:00
parent 062175586c
commit 1066a42fb2
6 changed files with 19 additions and 20 deletions

View File

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

View File

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

View File

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

View File

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