Skip to content

Commit 4ff22a0

Browse files
committed
added SyntaxKind.ModuleDeclaration to list of block scope containers
1 parent b183f8d commit 4ff22a0

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5086,10 +5086,6 @@ module ts {
50865086
return getNarrowedTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol), node);
50875087
}
50885088

5089-
function isNameScopeBoundary(n: Node): boolean {
5090-
return isAnyFunction(n) || n.kind === SyntaxKind.ModuleDeclaration || n.kind === SyntaxKind.SourceFile;
5091-
}
5092-
50935089
function checkBlockScopedBindingCapturedInLoop(node: Identifier, symbol: Symbol): void {
50945090
if (languageVersion >= ScriptTarget.ES6 || (symbol.flags & SymbolFlags.BlockScopedVariable) === 0) {
50955091
return;
@@ -5116,7 +5112,7 @@ module ts {
51165112
}
51175113

51185114
var current: Node = container;
5119-
while (current && !isNameScopeBoundary(current)) {
5115+
while (current && !nodeStartsNewLexicalEnvironment(current)) {
51205116
if (isIterationStatement(current, /*lookInLabeledStatements*/ false)) {
51215117
if (inFunction) {
51225118
grammarErrorOnFirstToken(current, Diagnostics.Code_in_the_loop_captures_block_scoped_variable_0_in_closure_This_is_natively_supported_in_ECMAScript_6_or_higher, declarationNameToString(node));

src/compiler/emitter.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3832,21 +3832,20 @@ module ts {
38323832
return current;
38333833
}
38343834
switch (current.kind) {
3835+
case SyntaxKind.SourceFile:
3836+
case SyntaxKind.SwitchKeyword:
38353837
case SyntaxKind.CatchClause:
3838+
case SyntaxKind.ModuleDeclaration:
38363839
case SyntaxKind.ForStatement:
38373840
case SyntaxKind.ForInStatement:
38383841
case SyntaxKind.ForOfStatement:
3839-
case SyntaxKind.SwitchKeyword:
38403842
return current;
38413843
case SyntaxKind.Block:
3842-
if (isAnyFunction(current.parent)) {
3843-
return current.parent;
3844-
}
3845-
else {
3844+
// function block is not considered block-scope container
3845+
// see comment in binder.ts: bind(...), case for SyntaxKind.Block
3846+
if (!isAnyFunction(current.parent)) {
38463847
return current;
38473848
}
3848-
case SyntaxKind.SourceFile:
3849-
return current;
38503849
}
38513850

38523851
current = current.parent;

src/compiler/utilities.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,11 @@ module ts {
11171117
return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), /*newLength: */newEndN - oldStartN);
11181118
}
11191119

1120+
// @internal
1121+
export function nodeStartsNewLexicalEnvironment(n: Node): boolean {
1122+
return isAnyFunction(n) || n.kind === SyntaxKind.ModuleDeclaration || n.kind === SyntaxKind.SourceFile;
1123+
}
1124+
11201125
// @internal
11211126
export function nodeIsSynthesized(node: Node): boolean {
11221127
return node.pos === -1 && node.end === -1;

0 commit comments

Comments
 (0)