Skip to content

Commit

Permalink
fix: remove parent cache when replacing node
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Nov 4, 2020
1 parent af2a53e commit 3a365bf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/babel-traverse/src/path/removal.js
@@ -1,6 +1,7 @@
// This file contains methods responsible for removing a node.

import { hooks } from "./lib/removal-hooks";
import { path as pathCache } from "../cache";
import { REMOVED, SHOULD_SKIP } from "./index";

export function remove() {
Expand Down Expand Up @@ -44,6 +45,7 @@ export function _remove() {
export function _markRemoved() {
// this.shouldSkip = true; this.removed = true;
this._traverseFlags |= SHOULD_SKIP | REMOVED;
if (this.parent) pathCache.get(this.parent).delete(this.node);
this.node = null;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/babel-traverse/src/path/replacement.js
Expand Up @@ -3,6 +3,7 @@
import { codeFrameColumns } from "@babel/code-frame";
import traverse from "../index";
import NodePath from "./index";
import { path as pathCache } from "../cache";
import { parse } from "@babel/parser";
import * as t from "@babel/types";

Expand Down Expand Up @@ -49,6 +50,7 @@ export function replaceWithMultiple(nodes: Array<Object>) {
nodes = this._verifyNodeList(nodes);
t.inheritLeadingComments(nodes[0], this.node);
t.inheritTrailingComments(nodes[nodes.length - 1], this.node);
pathCache.get(this.parent).delete(this.node);
this.node = this.container[this.key] = null;
const paths = this.insertAfter(nodes);

Expand Down

0 comments on commit 3a365bf

Please sign in to comment.