From 5d49f98d161a8ea8069fcf94e544ecf772957bea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Thu, 28 Dec 2023 23:57:13 +0100 Subject: [PATCH] Fixed `self-check` crash --- src/compiler/checker.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 934283801b27c..ac8fc8e275461 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2834,8 +2834,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return findAncestor(errorBindingElement, isBindingElement) !== findAncestor(declaration, isBindingElement) || declaration.pos < errorBindingElement.pos; } + const rootDeclaration = getRootDeclaration(declaration) as Declaration; + if (rootDeclaration.kind !== SyntaxKind.VariableDeclaration) { + return true; + } // or it might be illegal if usage happens before parent variable is declared (eg var [a] = a) - return isBlockScopedNameDeclaredBeforeUse(getAncestor(declaration, SyntaxKind.VariableDeclaration) as Declaration, usage); + return isBlockScopedNameDeclaredBeforeUse(rootDeclaration, usage); } else if (declaration.kind === SyntaxKind.VariableDeclaration) { // still might be illegal if usage is in the initializer of the variable declaration (eg var a = a)