@@ -62,39 +62,52 @@ namespace ts {
62
62
this . kind = kind ;
63
63
}
64
64
65
+ private assertHasRealPosition ( message ?: string ) {
66
+ // tslint:disable-next-line:debug-assert
67
+ Debug . assert ( ! positionIsSynthesized ( this . pos ) && ! positionIsSynthesized ( this . end ) , message || "Node must have a real position for this operation" ) ;
68
+ }
69
+
65
70
public getSourceFile ( ) : SourceFile {
66
71
return getSourceFileOfNode ( this ) ;
67
72
}
68
73
69
74
public getStart ( sourceFile ?: SourceFileLike , includeJsDocComment ?: boolean ) : number {
75
+ this . assertHasRealPosition ( ) ;
70
76
return getTokenPosOfNode ( this , sourceFile , includeJsDocComment ) ;
71
77
}
72
78
73
79
public getFullStart ( ) : number {
80
+ this . assertHasRealPosition ( ) ;
74
81
return this . pos ;
75
82
}
76
83
77
84
public getEnd ( ) : number {
85
+ this . assertHasRealPosition ( ) ;
78
86
return this . end ;
79
87
}
80
88
81
89
public getWidth ( sourceFile ?: SourceFile ) : number {
90
+ this . assertHasRealPosition ( ) ;
82
91
return this . getEnd ( ) - this . getStart ( sourceFile ) ;
83
92
}
84
93
85
94
public getFullWidth ( ) : number {
95
+ this . assertHasRealPosition ( ) ;
86
96
return this . end - this . pos ;
87
97
}
88
98
89
99
public getLeadingTriviaWidth ( sourceFile ?: SourceFile ) : number {
100
+ this . assertHasRealPosition ( ) ;
90
101
return this . getStart ( sourceFile ) - this . pos ;
91
102
}
92
103
93
104
public getFullText ( sourceFile ?: SourceFile ) : string {
105
+ this . assertHasRealPosition ( ) ;
94
106
return ( sourceFile || this . getSourceFile ( ) ) . text . substring ( this . pos , this . end ) ;
95
107
}
96
108
97
109
public getText ( sourceFile ?: SourceFile ) : string {
110
+ this . assertHasRealPosition ( ) ;
98
111
if ( ! sourceFile ) {
99
112
sourceFile = this . getSourceFile ( ) ;
100
113
}
@@ -183,21 +196,25 @@ namespace ts {
183
196
}
184
197
185
198
public getChildCount ( sourceFile ?: SourceFile ) : number {
199
+ this . assertHasRealPosition ( ) ;
186
200
if ( ! this . _children ) this . createChildren ( sourceFile ) ;
187
201
return this . _children . length ;
188
202
}
189
203
190
204
public getChildAt ( index : number , sourceFile ?: SourceFile ) : Node {
205
+ this . assertHasRealPosition ( ) ;
191
206
if ( ! this . _children ) this . createChildren ( sourceFile ) ;
192
207
return this . _children [ index ] ;
193
208
}
194
209
195
210
public getChildren ( sourceFile ?: SourceFileLike ) : Node [ ] {
211
+ this . assertHasRealPosition ( "Node without a real position cannot be scanned and thus has no token nodes - use forEachChild and collect the result if that's fine" ) ;
196
212
if ( ! this . _children ) this . createChildren ( sourceFile ) ;
197
213
return this . _children ;
198
214
}
199
215
200
216
public getFirstToken ( sourceFile ?: SourceFile ) : Node {
217
+ this . assertHasRealPosition ( ) ;
201
218
const children = this . getChildren ( sourceFile ) ;
202
219
if ( ! children . length ) {
203
220
return undefined ;
@@ -210,6 +227,7 @@ namespace ts {
210
227
}
211
228
212
229
public getLastToken ( sourceFile ?: SourceFile ) : Node {
230
+ this . assertHasRealPosition ( ) ;
213
231
const children = this . getChildren ( sourceFile ) ;
214
232
215
233
const child = lastOrUndefined ( children ) ;
0 commit comments