@@ -16,10 +16,15 @@ namespace ts.FindAllReferences {
16
16
export const enum EntryKind { Span , Node , StringLiteral , SearchedLocalFoundProperty , SearchedPropertyFoundLocal }
17
17
export type NodeEntryKind = EntryKind . Node | EntryKind . StringLiteral | EntryKind . SearchedLocalFoundProperty | EntryKind . SearchedPropertyFoundLocal ;
18
18
export type Entry = NodeEntry | SpanEntry ;
19
+ export interface DeclarationNodeWithStartAndEnd {
20
+ start : Node ;
21
+ end : Node ;
22
+ }
23
+ export type DeclarationNode = Node | DeclarationNodeWithStartAndEnd ;
19
24
export interface NodeEntry {
20
25
readonly kind : NodeEntryKind ;
21
26
readonly node : Node ;
22
- readonly declaration ?: Node ;
27
+ readonly declaration ?: DeclarationNode ;
23
28
}
24
29
export interface SpanEntry {
25
30
readonly kind : EntryKind . Span ;
@@ -34,7 +39,11 @@ namespace ts.FindAllReferences {
34
39
} ;
35
40
}
36
41
37
- function getDeclarationForDeclarationSpanForNode ( node : Node ) : Node | undefined {
42
+ export function isDeclarationNodeWithStartAndEnd ( node : DeclarationNode ) : node is DeclarationNodeWithStartAndEnd {
43
+ return node && ( node as Node ) . kind === undefined ;
44
+ }
45
+
46
+ function getDeclarationForDeclarationSpanForNode ( node : Node ) : DeclarationNode | undefined {
38
47
if ( isDeclaration ( node ) ) {
39
48
return getDeclarationForDeclarationSpan ( node ) ;
40
49
}
@@ -72,14 +81,16 @@ namespace ts.FindAllReferences {
72
81
return undefined ;
73
82
}
74
83
75
- export function getDeclarationForDeclarationSpan ( node : NamedDeclaration | BinaryExpression | undefined ) : Node | undefined {
84
+ export function getDeclarationForDeclarationSpan ( node : NamedDeclaration | BinaryExpression | undefined ) : DeclarationNode | undefined {
76
85
if ( ! node ) return undefined ;
77
86
switch ( node . kind ) {
78
87
case SyntaxKind . VariableDeclaration :
79
88
return ! isVariableDeclarationList ( node . parent ) || node . parent . declarations . length !== 1 ?
80
89
node :
81
90
isVariableStatement ( node . parent . parent ) ?
82
91
node . parent . parent :
92
+ isForInOrOfStatement ( node . parent . parent ) ?
93
+ { start : node . parent . parent . initializer , end : node . parent . parent . expression } :
83
94
node . parent ;
84
95
85
96
case SyntaxKind . BindingElement :
@@ -257,7 +268,9 @@ namespace ts.FindAllReferences {
257
268
displayParts
258
269
} ;
259
270
if ( declaration ) {
260
- result . declarationSpan = getTextSpan ( declaration , sourceFile ) ;
271
+ result . declarationSpan = isDeclarationNodeWithStartAndEnd ( declaration ) ?
272
+ getTextSpan ( declaration . start , sourceFile , declaration . end ) :
273
+ getTextSpan ( declaration , sourceFile ) ;
261
274
}
262
275
return result ;
263
276
}
@@ -298,7 +311,9 @@ namespace ts.FindAllReferences {
298
311
const sourceFile = entry . node . getSourceFile ( ) ;
299
312
const result : DocumentSpan = { textSpan : getTextSpan ( entry . node , sourceFile ) , fileName : sourceFile . fileName } ;
300
313
if ( entry . declaration ) {
301
- result . declarationSpan = getTextSpan ( entry . declaration , sourceFile ) ;
314
+ result . declarationSpan = isDeclarationNodeWithStartAndEnd ( entry . declaration ) ?
315
+ getTextSpan ( entry . declaration . start , sourceFile , entry . declaration . end ) :
316
+ getTextSpan ( entry . declaration , sourceFile ) ;
302
317
}
303
318
return result ;
304
319
}
@@ -392,10 +407,11 @@ namespace ts.FindAllReferences {
392
407
return { fileName : documentSpan . fileName , span } ;
393
408
}
394
409
395
- function getTextSpan ( node : Node , sourceFile : SourceFile ) : TextSpan {
410
+ function getTextSpan ( node : Node , sourceFile : SourceFile , endNode ?: Node ) : TextSpan {
396
411
let start = node . getStart ( sourceFile ) ;
397
- let end = node . getEnd ( ) ;
412
+ let end = ( endNode || node ) . getEnd ( ) ;
398
413
if ( node . kind === SyntaxKind . StringLiteral ) {
414
+ Debug . assert ( endNode === undefined ) ;
399
415
start += 1 ;
400
416
end -= 1 ;
401
417
}
0 commit comments