Switch to isNodeDescendantOf
This commit is contained in:
parent
6aecd43d9a
commit
201266b97f
|
@ -4420,26 +4420,13 @@ namespace ts {
|
|||
let container = getThisContainer(node, /*includeArrowFunctions*/ false);
|
||||
let parent = container && container.parent;
|
||||
if (parent && (isClassLike(parent) || parent.kind === SyntaxKind.InterfaceDeclaration)) {
|
||||
if (!(container.flags & NodeFlags.Static) && !isConstructorParameter(node, container)) {
|
||||
if (!(container.flags & NodeFlags.Static) &&
|
||||
(container.kind !== SyntaxKind.Constructor || isNodeDescendentOf(node, (<ConstructorDeclaration>container).body))) {
|
||||
return getDeclaredTypeOfClassOrInterface(getSymbolOfNode(parent)).thisType;
|
||||
}
|
||||
}
|
||||
error(node, Diagnostics.A_this_type_is_available_only_in_a_non_static_member_of_a_class_or_interface);
|
||||
return unknownType;
|
||||
|
||||
function isConstructorParameter(node: Node, container: Node) {
|
||||
if (container.kind === SyntaxKind.Constructor) {
|
||||
let ctor = (<ConstructorDeclaration>container);
|
||||
while (node && node !== ctor) {
|
||||
if (node === ctor.body) {
|
||||
return false;
|
||||
}
|
||||
node = node.parent;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getTypeFromThisTypeNode(node: TypeNode): Type {
|
||||
|
|
|
@ -359,14 +359,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
|||
sourceMaps: sourceMapDataList
|
||||
};
|
||||
|
||||
function isNodeDescendentOf(node: Node, ancestor: Node): boolean {
|
||||
while (node) {
|
||||
if (node === ancestor) return true;
|
||||
node = node.parent;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function isUniqueLocalName(name: string, container: Node): boolean {
|
||||
for (let node = container; isNodeDescendentOf(node, container); node = node.nextContainer) {
|
||||
if (node.locals && hasProperty(node.locals, name)) {
|
||||
|
|
|
@ -1167,6 +1167,14 @@ namespace ts {
|
|||
return !!node && (node.kind === SyntaxKind.ArrayBindingPattern || node.kind === SyntaxKind.ObjectBindingPattern);
|
||||
}
|
||||
|
||||
export function isNodeDescendentOf(node: Node, ancestor: Node): boolean {
|
||||
while (node) {
|
||||
if (node === ancestor) return true;
|
||||
node = node.parent;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isInAmbientContext(node: Node): boolean {
|
||||
while (node) {
|
||||
if (node.flags & (NodeFlags.Ambient | NodeFlags.DeclarationFile)) {
|
||||
|
|
Loading…
Reference in a new issue