fix: @babel/traverse can't use path.remove() with noScope (#11136)
This commit is contained in:
parent
4cfbd64f6c
commit
31b0506040
@ -7,7 +7,9 @@ export function remove() {
|
||||
this._assertUnremoved();
|
||||
|
||||
this.resync();
|
||||
if (!this.opts || !this.opts.noScope) {
|
||||
this._removeFromScope();
|
||||
}
|
||||
|
||||
if (this._callRemovalHooks()) {
|
||||
this._markRemoved();
|
||||
|
||||
@ -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("");
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user