@@ -58,6 +58,7 @@ import {
5858 EditorOptions ,
5959 EditorSettings ,
6060 ElementAccessExpression ,
61+ EmitNode ,
6162 EmitTextWriter ,
6263 emptyArray ,
6364 emptyOptions ,
@@ -289,6 +290,7 @@ import {
289290 SymbolDisplayPart ,
290291 SymbolFlags ,
291292 symbolName ,
293+ SymbolTable ,
292294 SyntaxKind ,
293295 SyntaxList ,
294296 sys ,
@@ -333,7 +335,7 @@ import * as classifier2020 from "./classifier2020";
333335/** The version of the language service API */
334336export const servicesVersion = "0.8" ;
335337
336- function createNode < TKind extends SyntaxKind > ( kind : TKind , pos : number , end : number , parent : Node ) : NodeObject | TokenObject < TKind > | IdentifierObject | PrivateIdentifierObject {
338+ function createNode < TKind extends SyntaxKind > ( kind : TKind , pos : number , end : number , parent : Node ) : NodeObject < TKind > | TokenObject < TKind > | IdentifierObject | PrivateIdentifierObject {
337339 const node = isNodeKind ( kind ) ? new NodeObject ( kind , pos , end ) :
338340 kind === SyntaxKind . Identifier ? new IdentifierObject ( SyntaxKind . Identifier , pos , end ) :
339341 kind === SyntaxKind . PrivateIdentifier ? new PrivateIdentifierObject ( SyntaxKind . PrivateIdentifier , pos , end ) :
@@ -343,8 +345,8 @@ function createNode<TKind extends SyntaxKind>(kind: TKind, pos: number, end: num
343345 return node ;
344346}
345347
346- class NodeObject implements Node {
347- public kind : SyntaxKind ;
348+ class NodeObject < TKind extends SyntaxKind > implements Node {
349+ public kind : TKind ;
348350 public pos : number ;
349351 public end : number ;
350352 public flags : NodeFlags ;
@@ -355,15 +357,21 @@ class NodeObject implements Node {
355357 public jsDoc ?: JSDoc [ ] ;
356358 public original ?: Node ;
357359 private _children : Node [ ] | undefined ;
360+ public id ?: number ;
361+ public emitNode ?: EmitNode ;
358362
359- constructor ( kind : SyntaxKind , pos : number , end : number ) {
363+ constructor ( kind : TKind , pos : number , end : number ) {
364+ // Note: must match Node in src/compiler/utilities.ts
360365 this . pos = pos ;
361366 this . end = end ;
367+ this . kind = kind ;
368+ this . id = 0 ;
362369 this . flags = NodeFlags . None ;
363370 this . modifierFlagsCache = ModifierFlags . None ;
364371 this . transformFlags = TransformFlags . None ;
365372 this . parent = undefined ! ;
366- this . kind = kind ;
373+ this . original = undefined ;
374+ this . emitNode = undefined ;
367375 }
368376
369377 private assertHasRealPosition ( message ?: string ) {
@@ -534,25 +542,30 @@ function createSyntaxList(nodes: NodeArray<Node>, parent: Node): Node {
534542 return list ;
535543}
536544
537- class TokenOrIdentifierObject implements Node {
538- public kind ! : SyntaxKind ;
545+ class TokenOrIdentifierObject < TKind extends SyntaxKind > implements Node {
546+ public kind : TKind ;
539547 public pos : number ;
540548 public end : number ;
541549 public flags : NodeFlags ;
542- public modifierFlagsCache : ModifierFlags ;
550+ public modifierFlagsCache ! : ModifierFlags ;
543551 public transformFlags : TransformFlags ;
544552 public parent : Node ;
545553 public symbol ! : Symbol ;
546554 public jsDocComments ?: JSDoc [ ] ;
555+ public id ?: number ;
556+ public emitNode ?: EmitNode | undefined ;
547557
548- constructor ( pos : number , end : number ) {
558+ constructor ( kind : TKind , pos : number , end : number ) {
549559 // Set properties in same order as NodeObject
560+ // Note: must match Token and Identifier in src/compiler/utilities.ts
550561 this . pos = pos ;
551562 this . end = end ;
563+ this . kind = kind ;
564+ this . id = 0 ;
552565 this . flags = NodeFlags . None ;
553- this . modifierFlagsCache = ModifierFlags . None ;
554566 this . transformFlags = TransformFlags . None ;
555567 this . parent = undefined ! ;
568+ this . emitNode = undefined ;
556569 }
557570
558571 public getSourceFile ( ) : SourceFile {
@@ -622,11 +635,17 @@ class TokenOrIdentifierObject implements Node {
622635class SymbolObject implements Symbol {
623636 flags : SymbolFlags ;
624637 escapedName : __String ;
625- declarations ! : Declaration [ ] ;
626- valueDeclaration ! : Declaration ;
627- id = 0 ;
628- mergeId = 0 ;
638+ declarations ?: Declaration [ ] ;
639+ valueDeclaration ?: Declaration ;
640+ members ?: SymbolTable ;
641+ exports ?: SymbolTable ;
642+ id : number ;
643+ mergeId : number ;
644+ parent ?: Symbol ;
645+ exportSymbol ?: Symbol ;
629646 constEnumOnlyModule : boolean | undefined ;
647+ isReferenced ?: SymbolFlags ;
648+ lastAssignmentPos ?: number ;
630649
631650 // Undefined is used to indicate the value has not been computed. If, after computing, the
632651 // symbol has no doc comment, then the empty array will be returned.
@@ -640,8 +659,21 @@ class SymbolObject implements Symbol {
640659 contextualSetAccessorTags ?: JSDocTagInfo [ ] ;
641660
642661 constructor ( flags : SymbolFlags , name : __String ) {
662+ // Note: must match Symbol in src/compiler/types.ts
643663 this . flags = flags ;
644664 this . escapedName = name ;
665+ this . declarations = undefined ;
666+ this . valueDeclaration = undefined ;
667+ this . id = 0 ;
668+ this . mergeId = 0 ;
669+ this . parent = undefined ;
670+ this . members = undefined ;
671+ this . exports = undefined ;
672+ this . exportSymbol = undefined ;
673+ this . constEnumOnlyModule = undefined ;
674+ this . isReferenced = undefined ;
675+ this . lastAssignmentPos = undefined ;
676+ ( this as any ) . links = undefined ; // used by TransientSymbol
645677 }
646678
647679 getFlags ( ) : SymbolFlags {
@@ -732,17 +764,13 @@ class SymbolObject implements Symbol {
732764 }
733765}
734766
735- class TokenObject < TKind extends SyntaxKind > extends TokenOrIdentifierObject implements Token < TKind > {
736- public override kind : TKind ;
737-
767+ class TokenObject < TKind extends SyntaxKind > extends TokenOrIdentifierObject < TKind > implements Token < TKind > {
738768 constructor ( kind : TKind , pos : number , end : number ) {
739- super ( pos , end ) ;
740- this . kind = kind ;
769+ super ( kind , pos , end ) ;
741770 }
742771}
743772
744- class IdentifierObject extends TokenOrIdentifierObject implements Identifier {
745- public override kind : SyntaxKind . Identifier = SyntaxKind . Identifier ;
773+ class IdentifierObject extends TokenOrIdentifierObject < SyntaxKind . Identifier > implements Identifier {
746774 public escapedText ! : __String ;
747775 declare _primaryExpressionBrand : any ;
748776 declare _memberExpressionBrand : any ;
@@ -754,33 +782,31 @@ class IdentifierObject extends TokenOrIdentifierObject implements Identifier {
754782 declare _jsdocContainerBrand : any ;
755783 declare _flowContainerBrand : any ;
756784 /** @internal */ typeArguments ! : NodeArray < TypeNode > ;
757- constructor ( _kind : SyntaxKind . Identifier , pos : number , end : number ) {
758- super ( pos , end ) ;
785+ constructor ( kind : SyntaxKind . Identifier , pos : number , end : number ) {
786+ super ( kind , pos , end ) ;
759787 }
760788
761789 get text ( ) : string {
762790 return idText ( this ) ;
763791 }
764792}
765- IdentifierObject . prototype . kind = SyntaxKind . Identifier ;
766- class PrivateIdentifierObject extends TokenOrIdentifierObject implements PrivateIdentifier {
767- public override kind : SyntaxKind . PrivateIdentifier = SyntaxKind . PrivateIdentifier ;
793+
794+ class PrivateIdentifierObject extends TokenOrIdentifierObject < SyntaxKind . PrivateIdentifier > implements PrivateIdentifier {
768795 public escapedText ! : __String ;
769796 declare _primaryExpressionBrand : any ;
770797 declare _memberExpressionBrand : any ;
771798 declare _leftHandSideExpressionBrand : any ;
772799 declare _updateExpressionBrand : any ;
773800 declare _unaryExpressionBrand : any ;
774801 declare _expressionBrand : any ;
775- constructor ( _kind : SyntaxKind . PrivateIdentifier , pos : number , end : number ) {
776- super ( pos , end ) ;
802+ constructor ( kind : SyntaxKind . PrivateIdentifier , pos : number , end : number ) {
803+ super ( kind , pos , end ) ;
777804 }
778805
779806 get text ( ) : string {
780807 return idText ( this ) ;
781808 }
782809}
783- PrivateIdentifierObject . prototype . kind = SyntaxKind . PrivateIdentifier ;
784810
785811class TypeObject implements Type {
786812 checker : TypeChecker ;
@@ -789,8 +815,9 @@ class TypeObject implements Type {
789815 id ! : number ;
790816 symbol ! : Symbol ;
791817 constructor ( checker : TypeChecker , flags : TypeFlags ) {
792- this . checker = checker ;
818+ // Note: must match Type in src/compiler/types.ts
793819 this . flags = flags ;
820+ this . checker = checker ;
794821 }
795822 getFlags ( ) : TypeFlags {
796823 return this . flags ;
@@ -897,8 +924,9 @@ class SignatureObject implements Signature {
897924 jsDocTags ?: JSDocTagInfo [ ] ; // same
898925
899926 constructor ( checker : TypeChecker , flags : SignatureFlags ) {
900- this . checker = checker ;
927+ // Note: must match Signature in src/compiler/types.ts
901928 this . flags = flags ;
929+ this . checker = checker ;
902930 }
903931
904932 getDeclaration ( ) : SignatureDeclaration {
@@ -1002,8 +1030,7 @@ function findBaseOfDeclaration<T>(checker: TypeChecker, declaration: Declaration
10021030 } ) ;
10031031}
10041032
1005- class SourceFileObject extends NodeObject implements SourceFile {
1006- public override kind : SyntaxKind . SourceFile = SyntaxKind . SourceFile ;
1033+ class SourceFileObject extends NodeObject < SyntaxKind . SourceFile > implements SourceFile {
10071034 declare _declarationBrand : any ;
10081035 declare _localsContainerBrand : any ;
10091036 public fileName ! : string ;
@@ -1053,7 +1080,7 @@ class SourceFileObject extends NodeObject implements SourceFile {
10531080 public localJsxFactory : EntityName | undefined ;
10541081 public localJsxNamespace : __String | undefined ;
10551082
1056- constructor ( kind : SyntaxKind , pos : number , end : number ) {
1083+ constructor ( kind : SyntaxKind . SourceFile , pos : number , end : number ) {
10571084 super ( kind , pos , end ) ;
10581085 }
10591086
@@ -1248,8 +1275,17 @@ class SourceFileObject extends NodeObject implements SourceFile {
12481275}
12491276
12501277class SourceMapSourceObject implements SourceMapSource {
1278+ fileName : string ;
1279+ text : string ;
1280+ skipTrivia ?: ( ( pos : number ) => number ) | undefined ;
12511281 lineMap ! : number [ ] ;
1252- constructor ( public fileName : string , public text : string , public skipTrivia ?: ( pos : number ) => number ) { }
1282+
1283+ constructor ( fileName : string , text : string , skipTrivia ?: ( pos : number ) => number ) {
1284+ // Note: must match SourceMapSource in src/compiler/types.ts
1285+ this . fileName = fileName ;
1286+ this . text = text ;
1287+ this . skipTrivia = skipTrivia || ( pos => pos ) ;
1288+ }
12531289
12541290 public getLineAndCharacterOfPosition ( pos : number ) : LineAndCharacter {
12551291 return getLineAndCharacterOfPosition ( this , pos ) ;
0 commit comments