Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Do not throw exceptions when scope information is corrupted #15303

Merged
merged 1 commit into from Dec 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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