Repository navigation
fix(traverse,transform-regenerator): resolve var binding scope on removal - #18617
Conversation
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/63549 |
|
commit: |
JLHwung
left a comment
There was a problem hiding this comment.
With suggested minimal changes, it should pass all the tests introduced in this PR.
| removeHoistedVarBindings(path, funPath.scope); | ||
| if (expr === null) { | ||
| path.remove(); | ||
| removeWithoutScopeBindingRemoval(path); |
There was a problem hiding this comment.
I think this issue should be fixed on path.remove(), specifically in
babel/packages/babel-traverse/src/path/removal.ts
Lines 23 to 26 in 4a79850
For a var declaration, we should find the scope from getFunctionParent() ?? getProgramParent(), rather than its nearest scope this.scope, which might be lexical like the catch clause.
| for (const name of Object.keys(path.getBindingIdentifiers())) { | ||
| // Remove the binding, to avoid "duplicate declaration" errors when it will | ||
| // be injected again. | ||
| path.scope.removeBinding(name); |
There was a problem hiding this comment.
Add here, we should use funcScope for var and path.scope for other lexical declarations, such as let and const.
|
Updated per your suggestions: fixed |
|
Backported to 7.x in #18748. |
When removing or hoisting a
vardeclaration inside a lexical scope such ascatch (x), removing the binding fromthis.scopedeleted the catch parameter binding instead of the hoisted function/program binding.Update
path.remove()in@babel/traverseto resolvevarbindings fromgetFunctionParent() ?? getProgramParent(), and usefunPath.scopeforvarbindings in@babel/plugin-transform-regenerator'shoist.