@@ -17698,18 +17698,20 @@ namespace ts {
17698
17698
if (usedInFunction) {
17699
17699
// mark iteration statement as containing block-scoped binding captured in some function
17700
17700
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
+ }
17713
17715
}
17714
17716
}
17715
17717
}
@@ -17720,10 +17722,11 @@ namespace ts {
17720
17722
17721
17723
// mark variables that are declared in loop initializer and reassigned inside the body of ForStatement.
17722
17724
// 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
+ }
17727
17730
}
17728
17731
17729
17732
// set 'declared inside loop' bit on the block-scoped binding
0 commit comments