@@ -803,6 +803,9 @@ namespace ts {
803
803
804
804
function isUsedInFunctionOrInstanceProperty(usage: Node, declaration: Node, container?: Node): boolean {
805
805
return !!findAncestor(usage, current => {
806
+ if (current === container) {
807
+ return "quit";
808
+ }
806
809
if (isFunctionLike(current)) {
807
810
return true;
808
811
}
@@ -824,7 +827,7 @@ namespace ts {
824
827
}
825
828
}
826
829
}
827
- }, n => n === container );
830
+ });
828
831
}
829
832
}
830
833
@@ -1246,7 +1249,7 @@ namespace ts {
1246
1249
* Return false if 'stopAt' node is reached or isFunctionLike(current) === true.
1247
1250
*/
1248
1251
function isSameScopeDescendentOf(initial: Node, parent: Node, stopAt: Node): boolean {
1249
- return parent && !!findAncestor(initial, n => n === parent, n => n === stopAt || isFunctionLike(n) );
1252
+ return parent && !!findAncestor(initial, n => n === stopAt || isFunctionLike(n) ? "quit" : n === parent );
1250
1253
}
1251
1254
1252
1255
function getAnyImportSyntax(node: Node): AnyImportSyntax {
@@ -7890,6 +7893,9 @@ namespace ts {
7890
7893
// the type parameters introduced by enclosing declarations. We just pick the first
7891
7894
// declaration since multiple declarations will all have the same parent anyway.
7892
7895
return !!findAncestor(symbol.declarations[0], node => {
7896
+ if (node.kind === SyntaxKind.ModuleDeclaration || node.kind === SyntaxKind.SourceFile) {
7897
+ return "quit";
7898
+ }
7893
7899
switch (node.kind) {
7894
7900
case SyntaxKind.FunctionType:
7895
7901
case SyntaxKind.ConstructorType:
@@ -7937,8 +7943,7 @@ namespace ts {
7937
7943
}
7938
7944
break;
7939
7945
}
7940
- },
7941
- node => node.kind === SyntaxKind.ModuleDeclaration || node.kind === SyntaxKind.SourceFile);
7946
+ });
7942
7947
}
7943
7948
7944
7949
function isTopLevelTypeAlias(symbol: Symbol) {
@@ -10384,8 +10389,7 @@ namespace ts {
10384
10389
// The expression is restricted to a single identifier or a sequence of identifiers separated by periods
10385
10390
return !!findAncestor(
10386
10391
node,
10387
- n => n.kind === SyntaxKind.TypeQuery,
10388
- n => n.kind !== SyntaxKind.TypeQuery && n.kind !== SyntaxKind.Identifier && n.kind !== SyntaxKind.QualifiedName);
10392
+ n => n.kind === SyntaxKind.TypeQuery ? true : n.kind === SyntaxKind.Identifier || n.kind === SyntaxKind.QualifiedName ? false : "quit");
10389
10393
}
10390
10394
10391
10395
// Return the flow cache key for a "dotted name" (i.e. a sequence of identifiers
@@ -11629,7 +11633,7 @@ namespace ts {
11629
11633
}
11630
11634
11631
11635
function hasParentWithAssignmentsMarked(node: Node) {
11632
- return !!findAncestor(node.parent, node => isFunctionLike(node) && getNodeLinks(node).flags & NodeCheckFlags.AssignmentsMarked);
11636
+ return !!findAncestor(node.parent, node => isFunctionLike(node) && !!( getNodeLinks(node).flags & NodeCheckFlags.AssignmentsMarked) );
11633
11637
}
11634
11638
11635
11639
function markParameterAssignments(node: Node) {
@@ -11801,7 +11805,7 @@ namespace ts {
11801
11805
}
11802
11806
11803
11807
function isInsideFunction(node: Node, threshold: Node): boolean {
11804
- return !!findAncestor(node, isFunctionLike, n => n === threshold);
11808
+ return !!findAncestor(node, n => n === threshold ? "quit" : isFunctionLike(n) );
11805
11809
}
11806
11810
11807
11811
function checkNestedBlockScopedBinding(node: Identifier, symbol: Symbol): void {
@@ -11875,7 +11879,7 @@ namespace ts {
11875
11879
11876
11880
// at this point we know that node is the target of assignment
11877
11881
// now check that modification happens inside the statement part of the ForStatement
11878
- return !!findAncestor(current, n => n === container.statement, n => n === container);
11882
+ return !!findAncestor(current, n => n === container ? "quit" : n === container.statement );
11879
11883
}
11880
11884
11881
11885
function captureLexicalThis(node: Node, container: Node): void {
@@ -12057,7 +12061,7 @@ namespace ts {
12057
12061
}
12058
12062
12059
12063
function isInConstructorArgumentInitializer(node: Node, constructorDecl: Node): boolean {
12060
- return !!findAncestor(node, n => n.kind === SyntaxKind.Parameter, n => n === constructorDecl );
12064
+ return !!findAncestor(node, n => n === constructorDecl ? "quit" : n.kind === SyntaxKind.Parameter );
12061
12065
}
12062
12066
12063
12067
function checkSuperExpression(node: Node): Type {
@@ -12083,7 +12087,7 @@ namespace ts {
12083
12087
// class B {
12084
12088
// [super.foo()]() {}
12085
12089
// }
12086
- const current = findAncestor(node, n => n.kind === SyntaxKind.ComputedPropertyName, n => n === container );
12090
+ const current = findAncestor(node, n => n === container ? "quit" : n.kind === SyntaxKind.ComputedPropertyName );
12087
12091
if (current && current.kind === SyntaxKind.ComputedPropertyName) {
12088
12092
error(node, Diagnostics.super_cannot_be_referenced_in_a_computed_property_name);
12089
12093
}
@@ -12687,7 +12691,7 @@ namespace ts {
12687
12691
}
12688
12692
12689
12693
function getContextualMapper(node: Node) {
12690
- node = findAncestor(node, n => n.contextualMapper);
12694
+ node = findAncestor(node, n => !! n.contextualMapper);
12691
12695
return node ? node.contextualMapper : identityMapper;
12692
12696
}
12693
12697
@@ -19138,14 +19142,17 @@ namespace ts {
19138
19142
// - parameter is wrapped in function-like entity
19139
19143
if (findAncestor(
19140
19144
n,
19141
- current =>
19142
- isFunctionLike(current.parent) ||
19143
- // computed property names/initializers in instance property declaration of class like entities
19144
- // are executed in constructor and thus deferred
19145
- (current.parent.kind === SyntaxKind.PropertyDeclaration &&
19146
- !(hasModifier(current.parent, ModifierFlags.Static)) &&
19147
- isClassLike(current.parent.parent)),
19148
- n => n === node.initializer)) {
19145
+ current => {
19146
+ if (current === node.initializer) {
19147
+ return "quit";
19148
+ }
19149
+ return isFunctionLike(current.parent) ||
19150
+ // computed property names/initializers in instance property declaration of class like entities
19151
+ // are executed in constructor and thus deferred
19152
+ (current.parent.kind === SyntaxKind.PropertyDeclaration &&
19153
+ !(hasModifier(current.parent, ModifierFlags.Static)) &&
19154
+ isClassLike(current.parent.parent));
19155
+ })) {
19149
19156
return;
19150
19157
}
19151
19158
// fall through to report error
@@ -19946,13 +19953,15 @@ namespace ts {
19946
19953
if (!checkGrammarStatementInAmbientContext(node)) {
19947
19954
findAncestor(node.parent,
19948
19955
current => {
19956
+ if (isFunctionLike(current)) {
19957
+ return "quit";
19958
+ }
19949
19959
if (current.kind === SyntaxKind.LabeledStatement && (<LabeledStatement>current).label.text === node.label.text) {
19950
19960
const sourceFile = getSourceFileOfNode(node);
19951
19961
grammarErrorOnNode(node.label, Diagnostics.Duplicate_label_0, getTextOfNodeFromSourceText(sourceFile.text, node.label));
19952
19962
return true;
19953
19963
}
19954
- },
19955
- isFunctionLike);
19964
+ });
19956
19965
}
19957
19966
19958
19967
// ensure that label is unique
0 commit comments