From e317767966aa175d2e1f167ba1e5d3686eee1479 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Fri, 16 Jan 2015 19:46:32 -0800 Subject: [PATCH] Consolidate getSuperContainer --- src/compiler/checker.ts | 24 ++---------------------- src/compiler/utilities.ts | 12 ++++++++---- src/services/services.ts | 4 ++-- 3 files changed, 12 insertions(+), 28 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8c5b49014ad..98fcd90b623 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4870,26 +4870,6 @@ module ts { return anyType; } - function getSuperContainer(node: Node): Node { - while (true) { - node = node.parent; - if (!node) return node; - switch (node.kind) { - case SyntaxKind.FunctionDeclaration: - case SyntaxKind.FunctionExpression: - case SyntaxKind.ArrowFunction: - case SyntaxKind.PropertyDeclaration: - case SyntaxKind.PropertySignature: - case SyntaxKind.MethodDeclaration: - case SyntaxKind.MethodSignature: - case SyntaxKind.Constructor: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - return node; - } - } - } - function isInConstructorArgumentInitializer(node: Node, constructorDecl: Node): boolean { for (var n = node; n && n !== constructorDecl; n = n.parent) { if (n.kind === SyntaxKind.Parameter) { @@ -4913,7 +4893,7 @@ module ts { return unknownType; } - var container = getSuperContainer(node); + var container = getSuperContainer(node, /*includeFunctions*/ true); if (container) { var canUseSuperExpression = false; @@ -4931,7 +4911,7 @@ module ts { // super property access might appear in arrow functions with arbitrary deep nesting var needToCaptureLexicalThis = false; while (container && container.kind === SyntaxKind.ArrowFunction) { - container = getSuperContainer(container); + container = getSuperContainer(container, /*includeFunctions*/ true); needToCaptureLexicalThis = true; } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 6f3460244b3..d41b7ea6b24 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -429,13 +429,17 @@ module ts { } } - export function getSuperContainer(node: Node): Node { + export function getSuperContainer(node: Node, includeFunctions: boolean): Node { while (true) { node = node.parent; - if (!node) { - return undefined; - } + if (!node) return node; switch (node.kind) { + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.FunctionExpression: + case SyntaxKind.ArrowFunction: + if (!includeFunctions) { + continue; + } case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: case SyntaxKind.MethodDeclaration: diff --git a/src/services/services.ts b/src/services/services.ts index 8c6ebecf469..848c22b52a3 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4114,7 +4114,7 @@ module ts { } function getReferencesForSuperKeyword(superKeyword: Node): ReferenceEntry[] { - var searchSpaceNode = getSuperContainer(superKeyword); + var searchSpaceNode = getSuperContainer(superKeyword, /*includeFunctions*/ false); if (!searchSpaceNode) { return undefined; } @@ -4149,7 +4149,7 @@ module ts { return; } - var container = getSuperContainer(node); + var container = getSuperContainer(node, /*includeFunctions*/ false); // If we have a 'super' container, we must have an enclosing class. // Now make sure the owning class is the same as the search-space