27
27
module ts {
28
28
export interface Node {
29
29
getSourceFile ( ) : SourceFile ;
30
- getChildCount ( ) : number ;
31
- getChildAt ( index : number ) : Node ;
32
- getChildren ( ) : Node [ ] ;
33
- getStart ( ) : number ;
30
+ getChildCount ( sourceFile ?: SourceFile ) : number ;
31
+ getChildAt ( index : number , sourceFile ?: SourceFile ) : Node ;
32
+ getChildren ( sourceFile ?: SourceFile ) : Node [ ] ;
33
+ getStart ( sourceFile ?: SourceFile ) : number ;
34
34
getFullStart ( ) : number ;
35
35
getEnd ( ) : number ;
36
- getWidth ( ) : number ;
36
+ getWidth ( sourceFile ?: SourceFile ) : number ;
37
37
getFullWidth ( ) : number ;
38
- getLeadingTriviaWidth ( ) : number ;
39
- getFullText ( ) : string ;
40
- getFirstToken ( ) : Node ;
41
- getLastToken ( ) : Node ;
38
+ getLeadingTriviaWidth ( sourceFile ?: SourceFile ) : number ;
39
+ getFullText ( sourceFile ?: SourceFile ) : string ;
40
+ getFirstToken ( sourceFile ?: SourceFile ) : Node ;
41
+ getLastToken ( sourceFile ?: SourceFile ) : Node ;
42
42
}
43
43
44
44
export interface Symbol {
@@ -100,8 +100,8 @@ module ts {
100
100
return < SourceFile > node ;
101
101
}
102
102
103
- public getStart ( ) : number {
104
- return getTokenPosOfNode ( this ) ;
103
+ public getStart ( sourceFile ?: SourceFile ) : number {
104
+ return getTokenPosOfNode ( this , sourceFile ) ;
105
105
}
106
106
107
107
public getFullStart ( ) : number {
@@ -112,20 +112,20 @@ module ts {
112
112
return this . end ;
113
113
}
114
114
115
- public getWidth ( ) : number {
116
- return this . getEnd ( ) - this . getStart ( ) ;
115
+ public getWidth ( sourceFile ?: SourceFile ) : number {
116
+ return this . getEnd ( ) - this . getStart ( sourceFile ) ;
117
117
}
118
118
119
119
public getFullWidth ( ) : number {
120
120
return this . end - this . getFullStart ( ) ;
121
121
}
122
122
123
- public getLeadingTriviaWidth ( ) : number {
124
- return this . getStart ( ) - this . pos ;
123
+ public getLeadingTriviaWidth ( sourceFile ?: SourceFile ) : number {
124
+ return this . getStart ( sourceFile ) - this . pos ;
125
125
}
126
126
127
- public getFullText ( ) : string {
128
- return this . getSourceFile ( ) . text . substring ( this . pos , this . end ) ;
127
+ public getFullText ( sourceFile ?: SourceFile ) : string {
128
+ return ( sourceFile || this . getSourceFile ( ) ) . text . substring ( this . pos , this . end ) ;
129
129
}
130
130
131
131
private addSyntheticNodes ( nodes : Node [ ] , pos : number , end : number ) : number {
@@ -157,9 +157,9 @@ module ts {
157
157
return list ;
158
158
}
159
159
160
- private createChildren ( ) {
160
+ private createChildren ( sourceFile ?: SourceFile ) {
161
161
if ( this . kind > SyntaxKind . Missing ) {
162
- scanner . setText ( this . getSourceFile ( ) . text ) ;
162
+ scanner . setText ( ( sourceFile || this . getSourceFile ( ) ) . text ) ;
163
163
var children : Node [ ] = [ ] ;
164
164
var pos = this . pos ;
165
165
var processNode = ( node : Node ) => {
@@ -185,36 +185,36 @@ module ts {
185
185
this . _children = children || emptyArray ;
186
186
}
187
187
188
- public getChildCount ( ) : number {
189
- if ( ! this . _children ) this . createChildren ( ) ;
188
+ public getChildCount ( sourceFile ?: SourceFile ) : number {
189
+ if ( ! this . _children ) this . createChildren ( sourceFile ) ;
190
190
return this . _children . length ;
191
191
}
192
192
193
- public getChildAt ( index : number ) : Node {
194
- if ( ! this . _children ) this . createChildren ( ) ;
193
+ public getChildAt ( index : number , sourceFile ?: SourceFile ) : Node {
194
+ if ( ! this . _children ) this . createChildren ( sourceFile ) ;
195
195
return this . _children [ index ] ;
196
196
}
197
197
198
- public getChildren ( ) : Node [ ] {
199
- if ( ! this . _children ) this . createChildren ( ) ;
198
+ public getChildren ( sourceFile ?: SourceFile ) : Node [ ] {
199
+ if ( ! this . _children ) this . createChildren ( sourceFile ) ;
200
200
return this . _children ;
201
201
}
202
202
203
- public getFirstToken ( ) : Node {
204
- var children = this . getChildren ( ) ;
203
+ public getFirstToken ( sourceFile ?: SourceFile ) : Node {
204
+ var children = this . getChildren ( sourceFile ) ;
205
205
for ( var i = 0 ; i < children . length ; i ++ ) {
206
206
var child = children [ i ] ;
207
207
if ( child . kind < SyntaxKind . Missing ) return child ;
208
- if ( child . kind > SyntaxKind . Missing ) return child . getFirstToken ( ) ;
208
+ if ( child . kind > SyntaxKind . Missing ) return child . getFirstToken ( sourceFile ) ;
209
209
}
210
210
}
211
211
212
- public getLastToken ( ) : Node {
213
- var children = this . getChildren ( ) ;
212
+ public getLastToken ( sourceFile ?: SourceFile ) : Node {
213
+ var children = this . getChildren ( sourceFile ) ;
214
214
for ( var i = children . length - 1 ; i >= 0 ; i -- ) {
215
215
var child = children [ i ] ;
216
216
if ( child . kind < SyntaxKind . Missing ) return child ;
217
- if ( child . kind > SyntaxKind . Missing ) return child . getLastToken ( ) ;
217
+ if ( child . kind > SyntaxKind . Missing ) return child . getLastToken ( sourceFile ) ;
218
218
}
219
219
}
220
220
}
0 commit comments