Skip to content

Commit f4e07cc

Browse files
authored
fix: Do not throw exceptions when scope information is corrupted (#15303)
fix
1 parent a6e8fa3 commit f4e07cc

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

  • packages/babel-plugin-transform-block-scoping/src

packages/babel-plugin-transform-block-scoping/src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,13 @@ export default declare((api, opts: Options) => {
7575
for (const name of names) {
7676
if (bodyScope?.hasOwnBinding(name)) continue; // shadowed
7777

78+
let binding = headPath.scope.getOwnBinding(name);
79+
if (!binding) {
80+
headPath.scope.crawl();
81+
binding = headPath.scope.getOwnBinding(name);
82+
}
7883
const { usages, capturedInClosure, hasConstantViolations } =
79-
getUsageInBody(headPath.scope.getOwnBinding(name), path);
84+
getUsageInBody(binding, path);
8085

8186
if (capturedInClosure) {
8287
markNeedsBodyWrap();
@@ -169,7 +174,9 @@ function transformBlockScopedVariable(
169174

170175
const bindingNames = Object.keys(path.getBindingIdentifiers());
171176
for (const name of bindingNames) {
172-
path.scope.getOwnBinding(name).kind = "var";
177+
const binding = path.scope.getOwnBinding(name);
178+
if (!binding) continue;
179+
binding.kind = "var";
173180
}
174181

175182
if (

0 commit comments

Comments
 (0)