@@ -180,9 +180,10 @@ namespace ts {
180180 ] ;
181181 let jsDocCompletionEntries : CompletionEntry [ ] ;
182182
183- function createNode ( kind : SyntaxKind , pos : number , end : number , flags : NodeFlags , parent ?: Node ) : NodeObject {
184- const node = new NodeObject ( kind , pos , end ) ;
185- node . flags = flags ;
183+ function createNode ( kind : SyntaxKind , pos : number , end : number , parent ?: Node ) : NodeObject | TokenObject | IdentifierObject {
184+ const node = kind >= SyntaxKind . FirstNode ? new NodeObject ( kind , pos , end ) :
185+ kind === SyntaxKind . Identifier ? new IdentifierObject ( kind , pos , end ) :
186+ new TokenObject ( kind , pos , end ) ;
186187 node . parent = parent ;
187188 return node ;
188189 }
@@ -197,11 +198,11 @@ namespace ts {
197198 private _children : Node [ ] ;
198199
199200 constructor ( kind : SyntaxKind , pos : number , end : number ) {
200- this . kind = kind ;
201201 this . pos = pos ;
202202 this . end = end ;
203203 this . flags = NodeFlags . None ;
204204 this . parent = undefined ;
205+ this . kind = kind ;
205206 }
206207
207208 public getSourceFile ( ) : SourceFile {
@@ -246,15 +247,15 @@ namespace ts {
246247 const token = useJSDocScanner ? scanner . scanJSDocToken ( ) : scanner . scan ( ) ;
247248 const textPos = scanner . getTextPos ( ) ;
248249 if ( textPos <= end ) {
249- nodes . push ( createNode ( token , pos , textPos , 0 , this ) ) ;
250+ nodes . push ( createNode ( token , pos , textPos , this ) ) ;
250251 }
251252 pos = textPos ;
252253 }
253254 return pos ;
254255 }
255256
256257 private createSyntaxList ( nodes : NodeArray < Node > ) : Node {
257- const list = createNode ( SyntaxKind . SyntaxList , nodes . pos , nodes . end , 0 , this ) ;
258+ const list = < NodeObject > createNode ( SyntaxKind . SyntaxList , nodes . pos , nodes . end , this ) ;
258259 list . _children = [ ] ;
259260 let pos = nodes . pos ;
260261
@@ -345,6 +346,95 @@ namespace ts {
345346 }
346347 }
347348
349+ class TokenOrIdentifierObject implements Token {
350+ public kind : SyntaxKind ;
351+ public pos : number ;
352+ public end : number ;
353+ public flags : NodeFlags ;
354+ public parent : Node ;
355+ public jsDocComments : JSDocComment [ ] ;
356+ public __tokenTag : any ;
357+
358+ constructor ( pos : number , end : number ) {
359+ // Set properties in same order as NodeObject
360+ this . pos = pos ;
361+ this . end = end ;
362+ this . flags = NodeFlags . None ;
363+ this . parent = undefined ;
364+ }
365+
366+ public getSourceFile ( ) : SourceFile {
367+ return getSourceFileOfNode ( this ) ;
368+ }
369+
370+ public getStart ( sourceFile ?: SourceFile , includeJsDocComment ?: boolean ) : number {
371+ return getTokenPosOfNode ( this , sourceFile , includeJsDocComment ) ;
372+ }
373+
374+ public getFullStart ( ) : number {
375+ return this . pos ;
376+ }
377+
378+ public getEnd ( ) : number {
379+ return this . end ;
380+ }
381+
382+ public getWidth ( sourceFile ?: SourceFile ) : number {
383+ return this . getEnd ( ) - this . getStart ( sourceFile ) ;
384+ }
385+
386+ public getFullWidth ( ) : number {
387+ return this . end - this . pos ;
388+ }
389+
390+ public getLeadingTriviaWidth ( sourceFile ?: SourceFile ) : number {
391+ return this . getStart ( sourceFile ) - this . pos ;
392+ }
393+
394+ public getFullText ( sourceFile ?: SourceFile ) : string {
395+ return ( sourceFile || this . getSourceFile ( ) ) . text . substring ( this . pos , this . end ) ;
396+ }
397+
398+ public getText ( sourceFile ?: SourceFile ) : string {
399+ return ( sourceFile || this . getSourceFile ( ) ) . text . substring ( this . getStart ( ) , this . getEnd ( ) ) ;
400+ }
401+
402+ public getChildCount ( sourceFile ?: SourceFile ) : number {
403+ return 0 ;
404+ }
405+
406+ public getChildAt ( index : number , sourceFile ?: SourceFile ) : Node {
407+ return undefined ;
408+ }
409+
410+ public getChildren ( sourceFile ?: SourceFile ) : Node [ ] {
411+ return emptyArray ;
412+ }
413+
414+ public getFirstToken ( sourceFile ?: SourceFile ) : Node {
415+ return undefined ;
416+ }
417+
418+ public getLastToken ( sourceFile ?: SourceFile ) : Node {
419+ return undefined ;
420+ }
421+ }
422+
423+ class TokenObject extends TokenOrIdentifierObject {
424+ public kind : SyntaxKind ;
425+ constructor ( kind : SyntaxKind , pos : number , end : number ) {
426+ super ( pos , end ) ;
427+ this . kind = kind ;
428+ }
429+ }
430+
431+ class IdentifierObject extends TokenOrIdentifierObject {
432+ constructor ( kind : SyntaxKind , pos : number , end : number ) {
433+ super ( pos , end ) ;
434+ }
435+ }
436+ IdentifierObject . prototype . kind = SyntaxKind . Identifier ;
437+
348438 class SymbolObject implements Symbol {
349439 flags : SymbolFlags ;
350440 name : string ;
@@ -8694,6 +8784,8 @@ namespace ts {
86948784 function initializeServices ( ) {
86958785 objectAllocator = {
86968786 getNodeConstructor : ( ) => NodeObject ,
8787+ getTokenConstructor : ( ) => TokenObject ,
8788+ getIdentifierConstructor : ( ) => IdentifierObject ,
86978789 getSourceFileConstructor : ( ) => SourceFileObject ,
86988790 getSymbolConstructor : ( ) => SymbolObject ,
86998791 getTypeConstructor : ( ) => TypeObject ,
0 commit comments