8000 Switch to `isNodeDescendantOf` · jango2015/TypeScript@201266b · GitHub
[go: up one dir, main page]

Skip to content

Commit 201266b

Browse files
committed
Switch to isNodeDescendantOf
1 parent 6aecd43 commit 201266b

File tree

3 files changed

+10
-23
lines changed

3 files changed

+10
-23
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4420,26 +4420,13 @@ namespace ts {
44204420
let container = getThisContainer(node, /*includeArrowFunctions*/ false);
44214421
let parent = container && container.parent;
44224422
if (parent && (isClassLike(parent) || parent.kind === SyntaxKind.InterfaceDeclaration)) {
4423-
if (!(container.flags & NodeFlags.Static) && !isConstructorParameter(node, container)) {
4423+
if (!(container.flags & NodeFlags.Static) &&
4424+
(container.kind !== SyntaxKind.Constructor || isNodeDescendentOf(node, (<ConstructorDeclaration>container).body))) {
44244425
return getDeclaredTypeOfClassOrInterface(getSymbolOfNode(parent)).thisType;
44254426
}
44264427
}
44274428
error(node, Diagnostics.A_this_type_is_available_only_in_a_non_static_member_of_a_class_or_interface);
44284429
return unknownType;
4429-
4430-
function isConstructorParameter(node: Node, container: Node) {
4431-
if (container.kind === SyntaxKind.Constructor) {
4432-
let ctor = (<ConstructorDeclaration>container);
4433-
while (node && node !== ctor) {
4434-
if (node === ctor.body) {
4435-
return false;
4436-
}
4437-
node = node.parent;
4438-
}
4439-
4440-
return true;
4441-
}
4442-
}
44434430
}
44444431

44454432
function getTypeFromThisTypeNode(node: TypeNode): Type {

src/compiler/emitter.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
359359
sourceMaps: sourceMapDataList
360360
};
361361

362-
function isNodeDescendentOf(node: Node, ancestor: Node): boolean {
363-
while (node) {
364-
if (node === ancestor) return true;
365-
node = node.parent;
366-
}
367-
return false;
368-
}
369-
370362
function isUniqueLocalName(name: string, container: Node): boolean {
371363
for (let node = container; isNodeDescendentOf(node, container); node = node.nextContainer) {
372364
if (node.locals && hasProperty(node.locals, name)) {

src/compiler/utilities.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,14 @@ namespace ts {
11671167
return !!node && (node.kind === SyntaxKind.ArrayBindingPattern || node.kind === SyntaxKind.ObjectBindingPattern);
11681168
}
11691169

1170+
export function isNodeDescendentOf(node: Node, ancestor: Node): boolean {
1171+
while (node) {
1172+
if (node === ancestor) return true;
1173+
node = node.parent;
1174+
}
1175+
return false;
1176+
}
1177+
11701178
export function isInAmbientContext(node: Node): boolean {
11711179
while (node) {
11721180
if (node.flags & (NodeFlags.Ambient | NodeFlags.DeclarationFile)) {

0 commit comments

Comments
 (0)
0