Skip to content

Commit

Permalink
fix @babel/traverse can't use path.remove() with noScope
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Feb 13, 2020
1 parent 3c6a8ae commit e822c8a
Show file tree
Hide file tree
Showing 2 changed files with 14 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
11 changes: 11 additions & 0 deletions packages/babel-traverse/test/removal.js
Expand Up @@ -33,4 +33,15 @@ 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();
},
});

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

0 comments on commit e822c8a

Please sign in to comment.