Skip to content

Commit

Permalink
fix: @babel/traverse can't use path.remove() with noScope (#11136)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Feb 14, 2020
1 parent 4cfbd64 commit 31b0506
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/babel-traverse/src/path/removal.js
Expand Up @@ -7,7 +7,9 @@ export function remove() {
this._assertUnremoved();

this.resync();
this._removeFromScope();
if (!this.opts || !this.opts.noScope) {
this._removeFromScope();
}

if (this._callRemovalHooks()) {
this._markRemoved();
Expand Down
12 changes: 12 additions & 0 deletions packages/babel-traverse/test/removal.js
Expand Up @@ -33,4 +33,16 @@ describe("removal", function() {
expect(generateCode(rootPath)).toBe("x = () => {};");
});
});

it("remove with noScope", function() {
const ast = parse("a=1");
traverse(ast, {
AssignmentExpression: function(path) {
path.remove();
},
noScope: true,
});

expect(generate(ast).code).toBe("");
});
});

0 comments on commit 31b0506

Please sign in to comment.