mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-14 10:55:15 -06:00
Consolidate getSuperContainer
This commit is contained in:
parent
4cc2722700
commit
e317767966
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user