fix: @babel/traverse can't use path.remove() with noScope (#11136)

This commit is contained in:
liuxingbaoyu 2020-02-15 01:19:32 +08:00 committed by GitHub
parent 4cfbd64f6c
commit 31b0506040
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -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();

View File

@ -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("");
});
});