Skip to content

Commit

Permalink
fix: Do not throw exceptions when scope information is corrupted (#15303
Browse files Browse the repository at this point in the history
)

fix
  • Loading branch information
liuxingbaoyu committed Dec 23, 2022
1 parent a6e8fa3 commit f4e07cc
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/babel-plugin-transform-block-scoping/src/index.ts
Expand Up @@ -75,8 +75,13 @@ export default declare((api, opts: Options) => {
for (const name of names) {
if (bodyScope?.hasOwnBinding(name)) continue; // shadowed

let binding = headPath.scope.getOwnBinding(name);
if (!binding) {
headPath.scope.crawl();
binding = headPath.scope.getOwnBinding(name);
}
const { usages, capturedInClosure, hasConstantViolations } =
getUsageInBody(headPath.scope.getOwnBinding(name), path);
getUsageInBody(binding, path);

if (capturedInClosure) {
markNeedsBodyWrap();
Expand Down Expand Up @@ -169,7 +174,9 @@ function transformBlockScopedVariable(

const bindingNames = Object.keys(path.getBindingIdentifiers());
for (const name of bindingNames) {
path.scope.getOwnBinding(name).kind = "var";
const binding = path.scope.getOwnBinding(name);
if (!binding) continue;
binding.kind = "var";
}

if (
Expand Down

0 comments on commit f4e07cc

Please sign in to comment.