Make sure we update the cache in all the right places

This commit is contained in:
Amjad Masad 2016-03-02 17:38:26 -08:00
parent 29ef158204
commit 5367d5d151
2 changed files with 13 additions and 1 deletions

View File

@ -39,7 +39,8 @@ traverse.explode = visitors.explode;
traverse.NodePath = require("./path");
traverse.Scope = require("./scope");
traverse.Hub = require("./hub");
traverse.Hub = require("./hub")
traverse.cache = require("./path/cache");
traverse.cheap = function (node, enter) {
if (!node) return;
@ -88,6 +89,8 @@ traverse.clearNode = function (node) {
if (key[0] === "_" && node[key] != null) node[key] = undefined;
}
traverse.cache.delete(node);
let syms: Array<Symbol> = Object.getOwnPropertySymbols(node);
for (let sym of syms) {
node[sym] = null;

View File

@ -373,6 +373,12 @@ function _inheritComments(key, child, parent) {
}
}
// Can't use import because of cyclic dependency between babel-traverse
// and this module (babel-types). This require needs to appear after
// we export the TYPES constant.
const traverse = require("babel-traverse").default;
/**
* Inherit all contextual properties from `parent` node to `child` node.
*/
@ -399,6 +405,9 @@ export function inherits(child, parent) {
t.inheritsComments(child, parent);
if (traverse.cache.has(parent)) {
traverse.cache.set(child, traverse.cache.get(parent));
}
return child;
}