1
- /*@internal */
2
- namespace ts {
1
+ import * as ts from "./_namespaces/ts" ;
2
+
3
+ /** @internal */
3
4
export interface ReusableDiagnostic extends ReusableDiagnosticRelatedInformation {
4
5
/** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */
5
6
reportsUnnecessary ?: { } ;
@@ -9,6 +10,7 @@ export interface ReusableDiagnostic extends ReusableDiagnosticRelatedInformation
9
10
skippedOn ?: keyof ts . CompilerOptions ;
10
11
}
11
12
13
+ /** @internal */
12
14
export interface ReusableDiagnosticRelatedInformation {
13
15
category : ts . DiagnosticCategory ;
14
16
code : number ;
@@ -18,11 +20,14 @@ export interface ReusableDiagnosticRelatedInformation {
18
20
messageText : string | ReusableDiagnosticMessageChain ;
19
21
}
20
22
23
+ /** @internal */
21
24
export type ReusableDiagnosticMessageChain = ts . DiagnosticMessageChain ;
22
25
26
+ /** @internal */
23
27
/** Signature (Hash of d.ts emitted), is string if it was emitted using same d.ts.map option as what compilerOptions indicate, otherwise tuple of string */
24
28
export type EmitSignature = string | [ signature : string ] ;
25
29
30
+ /** @internal */
26
31
export interface ReusableBuilderProgramState extends ts . BuilderState {
27
32
/**
28
33
* Cache of bind and check diagnostics for files with their Path being the key
@@ -70,6 +75,7 @@ export interface ReusableBuilderProgramState extends ts.BuilderState {
70
75
bundle ?: ts . BundleBuildInfo ;
71
76
}
72
77
78
+ /** @internal */
73
79
export const enum BuilderFileEmit {
74
80
None = 0 ,
75
81
Js = 1 << 0 , // emit js file
@@ -83,6 +89,7 @@ export const enum BuilderFileEmit {
83
89
All = AllJs | AllDts ,
84
90
}
85
91
92
+ /** @internal */
86
93
/**
87
94
* State to store the changed files, affected files and cache semantic diagnostics
88
95
*/
@@ -140,6 +147,7 @@ export interface BuilderProgramState extends ts.BuilderState, ReusableBuilderPro
140
147
filesChangingSignature ?: ts . Set < ts . Path > ;
141
148
}
142
149
150
+ /** @internal */
143
151
export type SavedBuildProgramEmitState = Pick < BuilderProgramState ,
144
152
"affectedFilesPendingEmit" |
145
153
"seenEmittedFiles" |
@@ -150,6 +158,7 @@ export type SavedBuildProgramEmitState = Pick<BuilderProgramState,
150
158
"hasChangedEmitSignature"
151
159
> & { changedFilesSet : BuilderProgramState [ "changedFilesSet" ] | undefined } ;
152
160
161
+ /** @internal */
153
162
/** Get flags determining what all needs to be emitted */
154
163
export function getBuilderFileEmit ( options : ts . CompilerOptions ) {
155
164
let result = BuilderFileEmit . Js ;
@@ -161,6 +170,7 @@ export function getBuilderFileEmit(options: ts.CompilerOptions) {
161
170
return result ;
162
171
}
163
172
173
+ /** @internal */
164
174
/** Determing what all is pending to be emitted based on previous options or previous file emit flags */
165
175
export function getPendingEmitKind ( optionsOrEmitKind : ts . CompilerOptions | BuilderFileEmit , oldOptionsOrEmitKind : ts . CompilerOptions | BuilderFileEmit | undefined ) : BuilderFileEmit {
166
176
const oldEmitKind = oldOptionsOrEmitKind && ( ts . isNumber ( oldOptionsOrEmitKind ) ? oldOptionsOrEmitKind : getBuilderFileEmit ( oldOptionsOrEmitKind ) ) ;
@@ -789,16 +799,22 @@ function getBinderAndCheckerDiagnosticsOfFile(state: BuilderProgramState, source
789
799
return ts . filterSemanticDiagnostics ( diagnostics , state . compilerOptions ) ;
790
800
}
791
801
802
+ /** @internal */
792
803
export type ProgramBuildInfoFileId = number & { __programBuildInfoFileIdBrand : any } ;
804
+ /** @internal */
793
805
export type ProgramBuildInfoFileIdListId = number & { __programBuildInfoFileIdListIdBrand : any } ;
806
+ /** @internal */
794
807
export type ProgramBuildInfoDiagnostic = ProgramBuildInfoFileId | [ fileId : ProgramBuildInfoFileId , diagnostics : readonly ReusableDiagnostic [ ] ] ;
808
+ /** @internal */
795
809
/**
796
810
* fileId if pending emit is same as what compilerOptions suggest
797
811
* [fileId] if pending emit is only dts file emit
798
812
* [fileId, emitKind] if any other type emit is pending
799
813
*/
800
814
export type ProgramBuilderInfoFilePendingEmit = ProgramBuildInfoFileId | [ fileId : ProgramBuildInfoFileId ] | [ fileId : ProgramBuildInfoFileId , emitKind : BuilderFileEmit ] ;
815
+ /** @internal */
801
816
export type ProgramBuildInfoReferencedMap = [ fileId : ProgramBuildInfoFileId , fileIdListId : ProgramBuildInfoFileIdListId ] [ ] ;
817
+ /** @internal */
802
818
export type ProgramMultiFileEmitBuildInfoBuilderStateFileInfo = Omit < ts . BuilderState . FileInfo , "signature" > & {
803
819
/**
804
820
* Signature is
@@ -808,15 +824,18 @@ export type ProgramMultiFileEmitBuildInfoBuilderStateFileInfo = Omit<ts.BuilderS
808
824
*/
809
825
signature : string | false | undefined ;
810
826
} ;
827
+ /** @internal */
811
828
/**
812
829
* [fileId, signature] if different from file's signature
813
830
* fileId if file wasnt emitted
814
831
*/
815
832
export type ProgramBuildInfoEmitSignature = ProgramBuildInfoFileId | [ fileId : ProgramBuildInfoFileId , signature : EmitSignature | [ ] ] ;
833
+ /** @internal */
816
834
/**
817
835
* ProgramMultiFileEmitBuildInfoFileInfo is string if FileInfo.version === FileInfo.signature && !FileInfo.affectsGlobalScope otherwise encoded FileInfo
818
836
*/
819
837
export type ProgramMultiFileEmitBuildInfoFileInfo = string | ProgramMultiFileEmitBuildInfoBuilderStateFileInfo ;
838
+ /** @internal */
820
839
export interface ProgramMultiFileEmitBuildInfo {
821
840
fileNames : readonly string [ ] ;
822
841
fileInfos : readonly ProgramMultiFileEmitBuildInfoFileInfo [ ] ;
@@ -831,15 +850,18 @@ export interface ProgramMultiFileEmitBuildInfo {
831
850
// Because this is only output file in the program, we dont need fileId to deduplicate name
832
851
latestChangedDtsFile ?: string | undefined ;
833
852
}
853
+ /** @internal */
834
854
/**
835
855
* ProgramBundleEmitBuildInfoFileInfo is string if !FileInfo.impliedFormat otherwise encoded FileInfo
836
856
*/
837
857
export type ProgramBundleEmitBuildInfoFileInfo = string | ts . BuilderState . FileInfo ;
858
+ /** @internal */
838
859
/**
839
860
* false if it is the emit corresponding to compilerOptions
840
861
* value otherwise
841
862
*/
842
863
export type ProgramBuildInfoBundlePendingEmit = BuilderFileEmit | false ;
864
+ /** @internal */
843
865
export interface ProgramBundleEmitBuildInfo {
844
866
fileNames : readonly string [ ] ;
845
867
fileInfos : readonly ProgramBundleEmitBuildInfoFileInfo [ ] ;
@@ -849,8 +871,10 @@ export interface ProgramBundleEmitBuildInfo {
849
871
pendingEmit : ProgramBuildInfoBundlePendingEmit | undefined ;
850
872
}
851
873
874
+ /** @internal */
852
875
export type ProgramBuildInfo = ProgramMultiFileEmitBuildInfo | ProgramBundleEmitBuildInfo ;
853
876
877
+ /** @internal */
854
878
export function isProgramBundleEmitBuildInfo ( info : ProgramBuildInfo ) : info is ProgramBundleEmitBuildInfo {
855
879
return ! ! ts . outFile ( info . options || { } ) ;
856
880
}
@@ -1100,18 +1124,21 @@ function convertToReusableDiagnosticRelatedInformation(diagnostic: ts.Diagnostic
1100
1124
} ;
1101
1125
}
1102
1126
1127
+ /** @internal */
1103
1128
export enum BuilderProgramKind {
1104
1129
SemanticDiagnosticsBuilderProgram ,
1105
1130
EmitAndSemanticDiagnosticsBuilderProgram
1106
1131
}
1107
1132
1133
+ /** @internal */
1108
1134
export interface BuilderCreationParameters {
1109
1135
newProgram : ts . Program ;
1110
1136
host : ts . BuilderProgramHost ;
1111
1137
oldProgram : ts . BuilderProgram | undefined ;
1112
1138
configFileParsingDiagnostics : readonly ts . Diagnostic [ ] ;
1113
1139
}
1114
1140
1141
+ /** @internal */
1115
1142
export function getBuilderCreationParameters ( newProgramOrRootNames : ts . Program | readonly string [ ] | undefined , hostOrOptions : ts . BuilderProgramHost | ts . CompilerOptions | undefined , oldProgramOrHost ?: ts . BuilderProgram | ts . CompilerHost , configFileParsingDiagnosticsOrOldProgram ?: readonly ts . Diagnostic [ ] | ts . BuilderProgram , configFileParsingDiagnostics ?: readonly ts . Diagnostic [ ] , projectReferences ?: readonly ts . ProjectReference [ ] ) : BuilderCreationParameters {
1116
1143
let host : ts . BuilderProgramHost ;
1117
1144
let newProgram : ts . Program ;
@@ -1148,6 +1175,7 @@ function getTextHandlingSourceMapForSignature(text: string, data: ts.WriteFileCa
1148
1175
return data ?. sourceMapUrlPos !== undefined ? text . substring ( 0 , data . sourceMapUrlPos ) : text ;
1149
1176
}
1150
1177
1178
+ /** @internal */
1151
1179
export function computeSignatureWithDiagnostics (
1152
1180
sourceFile : ts . SourceFile ,
1153
1181
text : string ,
@@ -1181,12 +1209,16 @@ export function computeSignatureWithDiagnostics(
1181
1209
}
1182
1210
}
1183
1211
1212
+ /** @internal */
1184
1213
export function computeSignature ( text : string , computeHash : ts . BuilderState . ComputeHash | undefined , data ?: ts . WriteFileCallbackData ) {
1185
1214
return ( computeHash ?? ts . generateDjb2Hash ) ( getTextHandlingSourceMapForSignature ( text , data ) ) ;
1186
1215
}
1187
1216
1217
+ /** @internal */
1188
1218
export function createBuilderProgram ( kind : BuilderProgramKind . SemanticDiagnosticsBuilderProgram , builderCreationParameters : BuilderCreationParameters ) : ts . SemanticDiagnosticsBuilderProgram ;
1219
+ /** @internal */
1189
1220
export function createBuilderProgram ( kind : BuilderProgramKind . EmitAndSemanticDiagnosticsBuilderProgram , builderCreationParameters : BuilderCreationParameters ) : ts . EmitAndSemanticDiagnosticsBuilderProgram ;
1221
+ /** @internal */
1190
1222
export function createBuilderProgram ( kind : BuilderProgramKind , { newProgram, host, oldProgram, configFileParsingDiagnostics } : BuilderCreationParameters ) {
1191
1223
// Return same program if underlying program doesnt change
1192
1224
let oldState = oldProgram && oldProgram . getState ( ) ;
@@ -1530,6 +1562,7 @@ function addToAffectedFilesPendingEmit(state: BuilderProgramState, affectedFileP
1530
1562
( state . affectedFilesPendingEmit ??= new ts . Map ( ) ) . set ( affectedFilePendingEmit , existingKind | kind ) ;
1531
1563
}
1532
1564
1565
+ /** @internal */
1533
1566
export function toBuilderStateFileInfoForMultiEmit ( fileInfo : ProgramMultiFileEmitBuildInfoFileInfo ) : ts . BuilderState . FileInfo {
1534
1567
return ts . isString ( fileInfo ) ?
1535
1568
{ version : fileInfo , signature : fileInfo , affectsGlobalScope : undefined , impliedFormat : undefined } :
@@ -1538,14 +1571,17 @@ export function toBuilderStateFileInfoForMultiEmit(fileInfo: ProgramMultiFileEmi
1538
1571
{ version : fileInfo . version , signature : fileInfo . signature === false ? undefined : fileInfo . version , affectsGlobalScope : fileInfo . affectsGlobalScope , impliedFormat : fileInfo . impliedFormat } ;
1539
1572
}
1540
1573
1574
+ /** @internal */
1541
1575
export function toBuilderFileEmit ( value : ProgramBuilderInfoFilePendingEmit , fullEmitForOptions : BuilderFileEmit ) : BuilderFileEmit {
1542
1576
return ts . isNumber ( value ) ? fullEmitForOptions : value [ 1 ] || BuilderFileEmit . Dts ;
1543
1577
}
1544
1578
1579
+ /** @internal */
1545
1580
export function toProgramEmitPending ( value : ProgramBuildInfoBundlePendingEmit , options : ts . CompilerOptions | undefined ) : BuilderFileEmit | undefined {
1546
1581
return ! value ? getBuilderFileEmit ( options || { } ) : value ;
1547
1582
}
1548
1583
1584
+ /** @internal */
1549
1585
export function createBuilderProgramUsingProgramBuildInfo ( buildInfo : ts . BuildInfo , buildInfoPath : string , host : ts . ReadBuildProgramHost ) : ts . EmitAndSemanticDiagnosticsBuilderProgram {
1550
1586
const program = buildInfo . program ! ;
1551
1587
const buildInfoDirectory = ts . getDirectoryPath ( ts . getNormalizedAbsolutePath ( buildInfoPath , host . getCurrentDirectory ( ) ) ) ;
@@ -1661,6 +1697,7 @@ export function createBuilderProgramUsingProgramBuildInfo(buildInfo: ts.BuildInf
1661
1697
}
1662
1698
}
1663
1699
1700
+ /** @internal */
1664
1701
export function getBuildInfoFileVersionMap (
1665
1702
program : ProgramBuildInfo ,
1666
1703
buildInfoPath : string ,
@@ -1677,6 +1714,7 @@ export function getBuildInfoFileVersionMap(
1677
1714
return fileInfos ;
1678
1715
}
1679
1716
1717
+ /** @internal */
1680
1718
export function createRedirectedBuilderProgram ( getState : ( ) => { program ?: ts . Program | undefined ; compilerOptions : ts . CompilerOptions ; } , configFileParsingDiagnostics : readonly ts . Diagnostic [ ] ) : ts . BuilderProgram {
1681
1719
return {
1682
1720
getState : ts . notImplemented ,
@@ -1705,4 +1743,3 @@ export function createRedirectedBuilderProgram(getState: () => { program?: ts.Pr
1705
1743
return ts . Debug . checkDefined ( getState ( ) . program ) ;
1706
1744
}
1707
1745
}
1708
- }
0 commit comments