Skip to content

Commit 1608291

Browse files
author
Joey Watts
committed
Fix checker crash with new block scoped bindings
Signed-off-by: Joey Watts <[email protected]>
1 parent c24df57 commit 1608291

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

src/compiler/checker.ts

+19-16
Original file line numberDiff line numberDiff line change
@@ -17698,18 +17698,20 @@ namespace ts {
1769817698
if (usedInFunction) {
1769917699
// mark iteration statement as containing block-scoped binding captured in some function
1770017700
let capturesBlockScopeBindingInLoopBody = true;
17701-
if (isForStatement(container) &&
17702-
getAncestor(symbol.valueDeclaration, SyntaxKind.VariableDeclarationList)!.parent === container) {
17703-
const part = getPartOfForStatementContainingNode(node.parent, container);
17704-
if (part) {
17705-
const links = getNodeLinks(part);
17706-
links.flags |= NodeCheckFlags.ContainsCapturedBlockScopeBinding;
17707-
17708-
const capturedBindings = links.capturedBlockScopeBindings || (links.capturedBlockScopeBindings = []);
17709-
pushIfUnique(capturedBindings, symbol);
17710-
17711-
if (part === container.initializer) {
17712-
capturesBlockScopeBindingInLoopBody = false; // Initializer is outside of loop body
17701+
if (isForStatement(container)) {
17702+
const varDeclList = getAncestor(symbol.valueDeclaration, SyntaxKind.VariableDeclarationList);
17703+
if (varDeclList && varDeclList.parent === container) {
17704+
const part = getPartOfForStatementContainingNode(node.parent, container);
17705+
if (part) {
17706+
const links = getNodeLinks(part);
17707+
links.flags |= NodeCheckFlags.ContainsCapturedBlockScopeBinding;
17708+
17709+
const capturedBindings = links.capturedBlockScopeBindings || (links.capturedBlockScopeBindings = []);
17710+
pushIfUnique(capturedBindings, symbol);
17711+
17712+
if (part === container.initializer) {
17713+
capturesBlockScopeBindingInLoopBody = false; // Initializer is outside of loop body
17714+
}
1771317715
}
1771417716
}
1771517717
}
@@ -17720,10 +17722,11 @@ namespace ts {
1772017722

1772117723
// mark variables that are declared in loop initializer and reassigned inside the body of ForStatement.
1772217724
// if body of ForStatement will be converted to function then we'll need a extra machinery to propagate reassigned values back.
17723-
if (container.kind === SyntaxKind.ForStatement &&
17724-
getAncestor(symbol.valueDeclaration, SyntaxKind.VariableDeclarationList)!.parent === container &&
17725-
isAssignedInBodyOfForStatement(node, <ForStatement>container)) {
17726-
getNodeLinks(symbol.valueDeclaration).flags |= NodeCheckFlags.NeedsLoopOutParameter;
17725+
if (isForStatement(container)) {
17726+
const varDeclList = getAncestor(symbol.valueDeclaration, SyntaxKind.VariableDeclarationList);
17727+
if (varDeclList && varDeclList.parent === container && isAssignedInBodyOfForStatement(node, container)) {
17728+
getNodeLinks(symbol.valueDeclaration).flags |= NodeCheckFlags.NeedsLoopOutParameter;
17729+
}
1772717730
}
1772817731

1772917732
// set 'declared inside loop' bit on the block-scoped binding

0 commit comments

Comments
 (0)