@@ -6742,14 +6742,6 @@ namespace ts {
6742
6742
javascriptText : string ,
6743
6743
declarationText : string
6744
6744
) : InputFiles ;
6745
- export function createInputFiles (
6746
- readFileText : ( path : string ) => string | undefined ,
6747
- javascriptPath : string ,
6748
- javascriptMapPath : string | undefined ,
6749
- declarationPath : string ,
6750
- declarationMapPath : string | undefined ,
6751
- buildInfoPath : string | undefined
6752
- ) : InputFiles ;
6753
6745
export function createInputFiles (
6754
6746
javascriptText : string ,
6755
6747
declarationText : string ,
@@ -6758,19 +6750,13 @@ namespace ts {
6758
6750
declarationMapPath : string | undefined ,
6759
6751
declarationMapText : string | undefined
6760
6752
) : InputFiles ;
6761
- /*@internal */
6762
6753
export function createInputFiles (
6763
- javascriptText : string ,
6764
- declarationText : string ,
6754
+ readFileText : ( path : string ) => string | undefined ,
6755
+ javascriptPath : string ,
6765
6756
javascriptMapPath : string | undefined ,
6766
- javascriptMapText : string | undefined ,
6757
+ declarationPath : string ,
6767
6758
declarationMapPath : string | undefined ,
6768
- declarationMapText : string | undefined ,
6769
- javascriptPath : string | undefined ,
6770
- declarationPath : string | undefined ,
6771
- buildInfoPath ?: string | undefined ,
6772
- buildInfo ?: BuildInfo ,
6773
- oldFileOfCurrentEmit ?: boolean
6759
+ buildInfoPath : string | undefined
6774
6760
) : InputFiles ;
6775
6761
export function createInputFiles (
6776
6762
javascriptTextOrReadFileText : string | ( ( path : string ) => string | undefined ) ,
@@ -6779,62 +6765,106 @@ namespace ts {
6779
6765
javascriptMapTextOrDeclarationPath ?: string ,
6780
6766
declarationMapPath ?: string ,
6781
6767
declarationMapTextOrBuildInfoPath ?: string ,
6782
- javascriptPath ?: string | undefined ,
6783
- declarationPath ?: string | undefined ,
6784
- buildInfoPath ?: string | undefined ,
6785
- buildInfo ?: BuildInfo ,
6786
- oldFileOfCurrentEmit ?: boolean
6768
+ ) : InputFiles {
6769
+ return ! isString ( javascriptTextOrReadFileText ) ?
6770
+ createInputFilesWithFilePaths (
6771
+ javascriptTextOrReadFileText ,
6772
+ declarationTextOrJavascriptPath ,
6773
+ javascriptMapPath ,
6774
+ javascriptMapTextOrDeclarationPath ! ,
6775
+ declarationMapPath ,
6776
+ declarationMapTextOrBuildInfoPath ,
6777
+ ) :
6778
+ createInputFilesWithFileTexts (
6779
+ /*javascriptPath*/ undefined ,
6780
+ javascriptTextOrReadFileText ,
6781
+ javascriptMapPath ,
6782
+ javascriptMapTextOrDeclarationPath ,
6783
+ /*declarationPath*/ undefined ,
6784
+ declarationTextOrJavascriptPath ,
6785
+ declarationMapPath ,
6786
+ declarationMapTextOrBuildInfoPath ,
6787
+ ) ;
6788
+ }
6789
+ /*@internal */
6790
+ export function createInputFilesWithFilePaths (
6791
+ readFileText : ( path : string ) => string | undefined ,
6792
+ javascriptPath : string ,
6793
+ javascriptMapPath : string | undefined ,
6794
+ declarationPath : string ,
6795
+ declarationMapPath : string | undefined ,
6796
+ buildInfoPath : string | undefined ,
6797
+ host ?: CompilerHost ,
6798
+ options ?: CompilerOptions ,
6787
6799
) : InputFiles {
6788
6800
const node = parseNodeFactory . createInputFiles ( ) ;
6789
- if ( ! isString ( javascriptTextOrReadFileText ) ) {
6790
- const cache = new Map < string , string | false > ( ) ;
6791
- const textGetter = ( path : string | undefined ) => {
6792
- if ( path === undefined ) return undefined ;
6793
- let value = cache . get ( path ) ;
6794
- if ( value === undefined ) {
6795
- value = javascriptTextOrReadFileText ( path ) ;
6796
- cache . set ( path , value !== undefined ? value : false ) ;
6801
+ node . javascriptPath = javascriptPath ;
6802
+ node . javascriptMapPath = javascriptMapPath ;
6803
+ node . declarationPath = declarationPath ;
6804
+ node . declarationMapPath = declarationMapPath ;
6805
+ node . buildInfoPath = buildInfoPath ;
6806
+ const cache = new Map < string , string | false > ( ) ;
6807
+ const textGetter = ( path : string | undefined ) => {
6808
+ if ( path === undefined ) return undefined ;
6809
+ let value = cache . get ( path ) ;
6810
+ if ( value === undefined ) {
6811
+ value = readFileText ( path ) ;
6812
+ cache . set ( path , value !== undefined ? value : false ) ;
6813
+ }
6814
+ return value !== false ? value as string : undefined ;
6815
+ } ;
6816
+ const definedTextGetter = ( path : string ) => {
6817
+ const result = textGetter ( path ) ;
6818
+ return result !== undefined ? result : `/* Input file ${ path } was missing */\r\n` ;
6819
+ } ;
6820
+ let buildInfo : BuildInfo | false ;
6821
+ const getAndCacheBuildInfo = ( ) => {
6822
+ if ( buildInfo === undefined && buildInfoPath ) {
6823
+ if ( host ?. getBuildInfo ) {
6824
+ buildInfo = host . getBuildInfo ( buildInfoPath , options ! . configFilePath ) ?? false ;
6797
6825
}
6798
- return value !== false ? value as string : undefined ;
6799
- } ;
6800
- const definedTextGetter = ( path : string ) => {
6801
- const result = textGetter ( path ) ;
6802
- return result !== undefined ? result : `/* Input file ${ path } was missing */\r\n` ;
6803
- } ;
6804
- let buildInfo : BuildInfo | false ;
6805
- const getAndCacheBuildInfo = ( getText : ( ) => string | undefined ) => {
6806
- if ( buildInfo === undefined ) {
6807
- const result = getText ( ) ;
6808
- buildInfo = result !== undefined ? getBuildInfo ( node . buildInfoPath ! , result ) ?? false : false ;
6826
+ else {
6827
+ const result = textGetter ( buildInfoPath ) ;
6828
+ buildInfo = result !== undefined ? getBuildInfo ( buildInfoPath , result ) ?? false : false ;
6809
6829
}
6810
- return buildInfo || undefined ;
6811
- } ;
6812
- node . javascriptPath = declarationTextOrJavascriptPath ;
6813
- node . javascriptMapPath = javascriptMapPath ;
6814
- node . declarationPath = Debug . checkDefined ( javascriptMapTextOrDeclarationPath ) ;
6815
- node . declarationMapPath = declarationMapPath ;
6816
- node . buildInfoPath = declarationMapTextOrBuildInfoPath ;
6817
- Object . defineProperties ( node , {
6818
- javascriptText : { get ( ) { return definedTextGetter ( declarationTextOrJavascriptPath ) ; } } ,
6819
- javascriptMapText : { get ( ) { return textGetter ( javascriptMapPath ) ; } } , // TODO:: if there is inline sourceMap in jsFile, use that
6820
- declarationText : { get ( ) { return definedTextGetter ( Debug . checkDefined ( javascriptMapTextOrDeclarationPath ) ) ; } } ,
6821
- declarationMapText : { get ( ) { return textGetter ( declarationMapPath ) ; } } , // TODO:: if there is inline sourceMap in dtsFile, use that
6822
- buildInfo : { get ( ) { return getAndCacheBuildInfo ( ( ) => textGetter ( declarationMapTextOrBuildInfoPath ) ) ; } }
6823
- } ) ;
6824
- }
6825
- else {
6826
- node . javascriptText = javascriptTextOrReadFileText ;
6827
- node . javascriptMapPath = javascriptMapPath ;
6828
- node . javascriptMapText = javascriptMapTextOrDeclarationPath ;
6829
- node . declarationText = declarationTextOrJavascriptPath ;
6830
- node . declarationMapPath = declarationMapPath ;
6831
- node . declarationMapText = declarationMapTextOrBuildInfoPath ;
6832
- node . javascriptPath = javascriptPath ;
6833
- node . declarationPath = declarationPath ;
6834
- node . buildInfoPath = buildInfoPath ;
6835
- node . buildInfo = buildInfo ;
6836
- node . oldFileOfCurrentEmit = oldFileOfCurrentEmit ;
6837
- }
6830
+ }
6831
+ return buildInfo || undefined ;
6832
+ } ;
6833
+ Object . defineProperties ( node , {
6834
+ javascriptText : { get : ( ) => definedTextGetter ( javascriptPath ) } ,
6835
+ javascriptMapText : { get : ( ) => textGetter ( javascriptMapPath ) } , // TODO:: if there is inline sourceMap in jsFile, use that
6836
+ declarationText : { get : ( ) => definedTextGetter ( Debug . checkDefined ( declarationPath ) ) } ,
6837
+ declarationMapText : { get : ( ) => textGetter ( declarationMapPath ) } , // TODO:: if there is inline sourceMap in dtsFile, use that
6838
+ buildInfo : { get : getAndCacheBuildInfo } ,
6839
+ } ) ;
6840
+ return node ;
6841
+ }
6842
+ /*@internal */
6843
+ export function createInputFilesWithFileTexts (
6844
+ javascriptPath : string | undefined ,
6845
+ javascriptText : string ,
6846
+ javascriptMapPath : string | undefined ,
6847
+ javascriptMapText : string | undefined ,
6848
+ declarationPath : string | undefined ,
6849
+ declarationText : string ,
6850
+ declarationMapPath : string | undefined ,
6851
+ declarationMapText : string | undefined ,
6852
+ buildInfoPath ?: string ,
6853
+ buildInfo ?: BuildInfo ,
6854
+ oldFileOfCurrentEmit ?: boolean ,
6855
+ ) : InputFiles {
6856
+ const node = parseNodeFactory . createInputFiles ( ) ;
6857
+ node . javascriptPath = javascriptPath ;
6858
+ node . javascriptText = javascriptText ;
6859
+ node . javascriptMapPath = javascriptMapPath ;
6860
+ node . javascriptMapText = javascriptMapText ;
6861
+ node . declarationPath = declarationPath ;
6862
+ node . declarationText = declarationText ;
6863
+ node . declarationMapPath = declarationMapPath ;
6864
+ node . declarationMapText = declarationMapText ;
6865
+ node . buildInfoPath = buildInfoPath ;
6866
+ node . buildInfo = buildInfo ;
6867
+ node . oldFileOfCurrentEmit = oldFileOfCurrentEmit ;
6838
6868
return node ;
6839
6869
}
6840
6870
0 commit comments