@@ -58,6 +58,7 @@ import {
58
58
EditorOptions ,
59
59
EditorSettings ,
60
60
ElementAccessExpression ,
61
+ EmitNode ,
61
62
EmitTextWriter ,
62
63
emptyArray ,
63
64
emptyOptions ,
@@ -289,6 +290,7 @@ import {
289
290
SymbolDisplayPart ,
290
291
SymbolFlags ,
291
292
symbolName ,
293
+ SymbolTable ,
292
294
SyntaxKind ,
293
295
SyntaxList ,
294
296
sys ,
@@ -333,7 +335,7 @@ import * as classifier2020 from "./classifier2020";
333
335
/** The version of the language service API */
334
336
export const servicesVersion = "0.8" ;
335
337
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 {
337
339
const node = isNodeKind ( kind ) ? new NodeObject ( kind , pos , end ) :
338
340
kind === SyntaxKind . Identifier ? new IdentifierObject ( SyntaxKind . Identifier , pos , end ) :
339
341
kind === SyntaxKind . PrivateIdentifier ? new PrivateIdentifierObject ( SyntaxKind . PrivateIdentifier , pos , end ) :
@@ -343,8 +345,8 @@ function createNode<TKind extends SyntaxKind>(kind: TKind, pos: number, end: num
343
345
return node ;
344
346
}
345
347
346
- class NodeObject implements Node {
347
- public kind : SyntaxKind ;
348
+ class NodeObject < TKind extends SyntaxKind > implements Node {
349
+ public kind : TKind ;
348
350
public pos : number ;
349
351
public end : number ;
350
352
public flags : NodeFlags ;
@@ -355,15 +357,21 @@ class NodeObject implements Node {
355
357
public jsDoc ?: JSDoc [ ] ;
356
358
public original ?: Node ;
357
359
private _children : Node [ ] | undefined ;
360
+ public id ?: number ;
361
+ public emitNode ?: EmitNode ;
358
362
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
360
365
this . pos = pos ;
361
366
this . end = end ;
367
+ this . kind = kind ;
368
+ this . id = 0 ;
362
369
this . flags = NodeFlags . None ;
363
370
this . modifierFlagsCache = ModifierFlags . None ;
364
371
this . transformFlags = TransformFlags . None ;
365
372
this . parent = undefined ! ;
366
- this . kind = kind ;
373
+ this . original = undefined ;
374
+ this . emitNode = undefined ;
367
375
}
368
376
369
377
private assertHasRealPosition ( message ?: string ) {
@@ -534,25 +542,30 @@ function createSyntaxList(nodes: NodeArray<Node>, parent: Node): Node {
534
542
return list ;
535
543
}
536
544
537
- class TokenOrIdentifierObject implements Node {
538
- public kind ! : SyntaxKind ;
545
+ class TokenOrIdentifierObject < TKind extends SyntaxKind > implements Node {
546
+ public kind : TKind ;
539
547
public pos : number ;
540
548
public end : number ;
541
549
public flags : NodeFlags ;
542
- public modifierFlagsCache : ModifierFlags ;
550
+ public modifierFlagsCache ! : ModifierFlags ;
543
551
public transformFlags : TransformFlags ;
544
552
public parent : Node ;
545
553
public symbol ! : Symbol ;
546
554
public jsDocComments ?: JSDoc [ ] ;
555
+ public id ?: number ;
556
+ public emitNode ?: EmitNode | undefined ;
547
557
548
- constructor ( pos : number , end : number ) {
558
+ constructor ( kind : TKind , pos : number , end : number ) {
549
559
// Set properties in same order as NodeObject
560
+ // Note: must match Token and Identifier in src/compiler/utilities.ts
550
561
this . pos = pos ;
551
562
this . end = end ;
563
+ this . kind = kind ;
564
+ this . id = 0 ;
552
565
this . flags = NodeFlags . None ;
553
- this . modifierFlagsCache = ModifierFlags . None ;
554
566
this . transformFlags = TransformFlags . None ;
555
567
this . parent = undefined ! ;
568
+ this . emitNode = undefined ;
556
569
}
557
570
558
571
public getSourceFile ( ) : SourceFile {
@@ -622,11 +635,17 @@ class TokenOrIdentifierObject implements Node {
622
635
class SymbolObject implements Symbol {
623
636
flags : SymbolFlags ;
624
637
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 ;
629
646
constEnumOnlyModule : boolean | undefined ;
647
+ isReferenced ?: SymbolFlags ;
648
+ lastAssignmentPos ?: number ;
630
649
631
650
// Undefined is used to indicate the value has not been computed. If, after computing, the
632
651
// symbol has no doc comment, then the empty array will be returned.
@@ -640,8 +659,21 @@ class SymbolObject implements Symbol {
640
659
contextualSetAccessorTags ?: JSDocTagInfo [ ] ;
641
660
642
661
constructor ( flags : SymbolFlags , name : __String ) {
662
+ // Note: must match Symbol in src/compiler/types.ts
643
663
this . flags = flags ;
644
664
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
645
677
}
646
678
647
679
getFlags ( ) : SymbolFlags {
@@ -732,17 +764,13 @@ class SymbolObject implements Symbol {
732
764
}
733
765
}
734
766
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 > {
738
768
constructor ( kind : TKind , pos : number , end : number ) {
739
- super ( pos , end ) ;
740
- this . kind = kind ;
769
+ super ( kind , pos , end ) ;
741
770
}
742
771
}
743
772
744
- class IdentifierObject extends TokenOrIdentifierObject implements Identifier {
745
- public override kind : SyntaxKind . Identifier = SyntaxKind . Identifier ;
773
+ class IdentifierObject extends TokenOrIdentifierObject < SyntaxKind . Identifier > implements Identifier {
746
774
public escapedText ! : __String ;
747
775
declare _primaryExpressionBrand : any ;
748
776
declare _memberExpressionBrand : any ;
@@ -754,33 +782,31 @@ class IdentifierObject extends TokenOrIdentifierObject implements Identifier {
754
782
declare _jsdocContainerBrand : any ;
755
783
declare _flowContainerBrand : any ;
756
784
/** @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 ) ;
759
787
}
760
788
761
789
get text ( ) : string {
762
790
return idText ( this ) ;
763
791
}
764
792
}
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 {
768
795
public escapedText ! : __String ;
769
796
declare _primaryExpressionBrand : any ;
770
797
declare _memberExpressionBrand : any ;
771
798
declare _leftHandSideExpressionBrand : any ;
772
799
declare _updateExpressionBrand : any ;
773
800
declare _unaryExpressionBrand : any ;
774
801
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 ) ;
777
804
}
778
805
779
806
get text ( ) : string {
780
807
return idText ( this ) ;
781
808
}
782
809
}
783
- PrivateIdentifierObject . prototype . kind = SyntaxKind . PrivateIdentifier ;
784
810
785
811
class TypeObject implements Type {
786
812
checker : TypeChecker ;
@@ -789,8 +815,9 @@ class TypeObject implements Type {
789
815
id ! : number ;
790
816
symbol ! : Symbol ;
791
817
constructor ( checker : TypeChecker , flags : TypeFlags ) {
792
- this . checker = checker ;
818
+ // Note: must match Type in src/compiler/types.ts
793
819
this . flags = flags ;
820
+ this . checker = checker ;
794
821
}
795
822
getFlags ( ) : TypeFlags {
796
823
return this . flags ;
@@ -897,8 +924,9 @@ class SignatureObject implements Signature {
897
924
jsDocTags ?: JSDocTagInfo [ ] ; // same
898
925
899
926
constructor ( checker : TypeChecker , flags : SignatureFlags ) {
900
- this . checker = checker ;
927
+ // Note: must match Signature in src/compiler/types.ts
901
928
this . flags = flags ;
929
+ this . checker = checker ;
902
930
}
903
931
904
932
getDeclaration ( ) : SignatureDeclaration {
@@ -1002,8 +1030,7 @@ function findBaseOfDeclaration<T>(checker: TypeChecker, declaration: Declaration
1002
1030
} ) ;
1003
1031
}
1004
1032
1005
- class SourceFileObject extends NodeObject implements SourceFile {
1006
- public override kind : SyntaxKind . SourceFile = SyntaxKind . SourceFile ;
1033
+ class SourceFileObject extends NodeObject < SyntaxKind . SourceFile > implements SourceFile {
1007
1034
declare _declarationBrand : any ;
1008
1035
declare _localsContainerBrand : any ;
1009
1036
public fileName ! : string ;
@@ -1053,7 +1080,7 @@ class SourceFileObject extends NodeObject implements SourceFile {
1053
1080
public localJsxFactory : EntityName | undefined ;
1054
1081
public localJsxNamespace : __String | undefined ;
1055
1082
1056
- constructor ( kind : SyntaxKind , pos : number , end : number ) {
1083
+ constructor ( kind : SyntaxKind . SourceFile , pos : number , end : number ) {
1057
1084
super ( kind , pos , end ) ;
1058
1085
}
1059
1086
@@ -1248,8 +1275,17 @@ class SourceFileObject extends NodeObject implements SourceFile {
1248
1275
}
1249
1276
1250
1277
class SourceMapSourceObject implements SourceMapSource {
1278
+ fileName : string ;
1279
+ text : string ;
1280
+ skipTrivia ?: ( ( pos : number ) => number ) | undefined ;
1251
1281
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
+ }
1253
1289
1254
1290
public getLineAndCharacterOfPosition ( pos : number ) : LineAndCharacter {
1255
1291
return getLineAndCharacterOfPosition ( this , pos ) ;
0 commit comments