Skip to content

Commit 68decd2

Browse files
committed
refactor: apply suggested changes
simplify logic and add comments
1 parent 5c366b3 commit 68decd2

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

  • packages/babel-helper-create-class-features-plugin/src

packages/babel-helper-create-class-features-plugin/src/fields.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,15 @@ function unshadow(
195195
scope: Scope,
196196
innerBinding: t.Identifier | undefined,
197197
) {
198-
const binding = scope.getBinding(name);
199-
if (innerBinding && binding && innerBinding !== binding.identifier) {
200-
// the classRef has been shadowed, rename the local variable
201-
while (!scope.bindingIdentifierEquals(name, innerBinding)) {
202-
scope.rename(name);
203-
scope = scope.parent;
204-
}
198+
// in some cases, scope.getBinding(name) === undefined
199+
// so we check hasBinding to avoid keeping looping
200+
// see: https://github.com/babel/babel/pull/13656#discussion_r686030715
201+
while (
202+
scope?.hasBinding(name) &&
203+
!scope.bindingIdentifierEquals(name, innerBinding)
204+
) {
205+
scope.rename(name);
206+
scope = scope.parent;
205207
}
206208
}
207209

0 commit comments

Comments
 (0)