diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c538134e6d8..67bd747a4ae 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8091,13 +8091,22 @@ namespace ts { return expression; } + function getControlFlowContainer(node: Node): Node { + while (true) { + node = node.parent; + if (isFunctionLike(node) || node.kind === SyntaxKind.ModuleBlock || node.kind === SyntaxKind.SourceFile || node.kind === SyntaxKind.PropertyDeclaration) { + return node; + } + } + } + function isDeclarationIncludedInFlow(reference: Node, declaration: Declaration, includeOuterFunctions: boolean) { - const declarationContainer = getContainingFunctionOrModule(declaration); - let container = getContainingFunctionOrModule(reference); + const declarationContainer = getControlFlowContainer(declaration); + let container = getControlFlowContainer(reference); while (container !== declarationContainer && (container.kind === SyntaxKind.FunctionExpression || container.kind === SyntaxKind.ArrowFunction) && (includeOuterFunctions || getImmediatelyInvokedFunctionExpression(container))) { - container = getContainingFunctionOrModule(container); + container = getControlFlowContainer(container); } return container === declarationContainer; } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 74ea3459b23..e2fa4662c1f 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -880,15 +880,6 @@ namespace ts { } } - export function getContainingFunctionOrModule(node: Node): Node { - while (true) { - node = node.parent; - if (isFunctionLike(node) || node.kind === SyntaxKind.ModuleDeclaration || node.kind === SyntaxKind.SourceFile) { - return node; - } - } - } - export function getContainingClass(node: Node): ClassLikeDeclaration { while (true) { node = node.parent;