@@ -2630,41 +2630,88 @@ namespace ts {
26302630 }
26312631
26322632 export function createUnparsedSourceFile ( text : string ) : UnparsedSource ;
2633+ export function createUnparsedSourceFile ( inputFile : InputFiles , type : "js" | "dts" ) : UnparsedSource ;
26332634 export function createUnparsedSourceFile ( text : string , mapPath : string | undefined , map : string | undefined ) : UnparsedSource ;
2634- export function createUnparsedSourceFile ( text : string , mapPath ?: string , map ?: string ) : UnparsedSource {
2635+ export function createUnparsedSourceFile ( textOrInputFiles : string | InputFiles , mapPathOrType ?: string , map ?: string ) : UnparsedSource {
26352636 const node = < UnparsedSource > createNode ( SyntaxKind . UnparsedSource ) ;
2636- node . text = text ;
2637- node . sourceMapPath = mapPath ;
2638- node . sourceMapText = map ;
2637+ if ( ! isString ( textOrInputFiles ) ) {
2638+ Debug . assert ( mapPathOrType === "js" || mapPathOrType === "dts" ) ;
2639+ node . fileName = mapPathOrType === "js" ? textOrInputFiles . javascriptPath : textOrInputFiles . declarationPath ;
2640+ node . sourceMapPath = mapPathOrType === "js" ? textOrInputFiles . javascriptMapPath : textOrInputFiles . declarationMapPath ;
2641+ Object . defineProperties ( node , {
2642+ text : { get ( ) { return mapPathOrType === "js" ? textOrInputFiles . javascriptText : textOrInputFiles . declarationText ; } } ,
2643+ sourceMapText : { get ( ) { return mapPathOrType === "js" ? textOrInputFiles . javascriptMapText : textOrInputFiles . declarationMapText ; } } ,
2644+ } ) ;
2645+ }
2646+ else {
2647+ node . text = textOrInputFiles ;
2648+ node . sourceMapPath = mapPathOrType ;
2649+ node . sourceMapText = map ;
2650+ }
26392651 return node ;
26402652 }
26412653 export function createInputFiles (
2642- javascript : string ,
2643- declaration : string
2654+ javascriptText : string ,
2655+ declarationText : string
2656+ ) : InputFiles ;
2657+ export function createInputFiles (
2658+ readFileText : ( path : string ) => string | undefined ,
2659+ javascriptPath : string ,
2660+ javascriptMapPath : string | undefined ,
2661+ declarationPath : string ,
2662+ declarationMapPath : string | undefined ,
26442663 ) : InputFiles ;
26452664 export function createInputFiles (
2646- javascript : string ,
2647- declaration : string ,
2665+ javascriptText : string ,
2666+ declarationText : string ,
26482667 javascriptMapPath : string | undefined ,
26492668 javascriptMapText : string | undefined ,
26502669 declarationMapPath : string | undefined ,
26512670 declarationMapText : string | undefined
26522671 ) : InputFiles ;
26532672 export function createInputFiles (
2654- javascript : string ,
2655- declaration : string ,
2673+ javascriptTextOrReadFileText : string | ( ( path : string ) => string | undefined ) ,
2674+ declarationTextOrJavascriptPath : string ,
26562675 javascriptMapPath ?: string ,
2657- javascriptMapText ?: string ,
2676+ javascriptMapTextOrDeclarationPath ?: string ,
26582677 declarationMapPath ?: string ,
26592678 declarationMapText ?: string
26602679 ) : InputFiles {
26612680 const node = < InputFiles > createNode ( SyntaxKind . InputFiles ) ;
2662- node . javascriptText = javascript ;
2663- node . javascriptMapPath = javascriptMapPath ;
2664- node . javascriptMapText = javascriptMapText ;
2665- node . declarationText = declaration ;
2666- node . declarationMapPath = declarationMapPath ;
2667- node . declarationMapText = declarationMapText ;
2681+ if ( ! isString ( javascriptTextOrReadFileText ) ) {
2682+ const cache = createMap < string | false > ( ) ;
2683+ const textGetter = ( path : string | undefined ) => {
2684+ if ( path === undefined ) return undefined ;
2685+ let value = cache . get ( path ) ;
2686+ if ( value === undefined ) {
2687+ value = javascriptTextOrReadFileText ( path ) ;
2688+ cache . set ( path , value !== undefined ? value : false ) ;
2689+ }
2690+ return value !== false ? value as string : undefined ;
2691+ } ;
2692+ const definedTextGetter = ( path : string ) => {
2693+ const result = textGetter ( path ) ;
2694+ return result !== undefined ? result : `/* Input file ${ path } was missing */\r\n` ;
2695+ } ;
2696+ node . javascriptPath = declarationTextOrJavascriptPath ;
2697+ node . javascriptMapPath = javascriptMapPath ;
2698+ node . declarationPath = Debug . assertDefined ( javascriptMapTextOrDeclarationPath ) ;
2699+ node . declarationMapPath = declarationMapPath ;
2700+ Object . defineProperties ( node , {
2701+ javascriptText : { get ( ) { return definedTextGetter ( declarationTextOrJavascriptPath ) ; } } ,
2702+ javascriptMapText : { get ( ) { return textGetter ( javascriptMapPath ) ; } } , // TODO:: if there is inline sourceMap in jsFile, use that
2703+ declarationText : { get ( ) { return definedTextGetter ( Debug . assertDefined ( javascriptMapTextOrDeclarationPath ) ) ; } } ,
2704+ declarationMapText : { get ( ) { return textGetter ( declarationMapPath ) ; } } // TODO:: if there is inline sourceMap in dtsFile, use that
2705+ } ) ;
2706+ }
2707+ else {
2708+ node . javascriptText = javascriptTextOrReadFileText ;
2709+ node . javascriptMapPath = javascriptMapPath ;
2710+ node . javascriptMapText = javascriptMapTextOrDeclarationPath ;
2711+ node . declarationText = declarationTextOrJavascriptPath ;
2712+ node . declarationMapPath = declarationMapPath ;
2713+ node . declarationMapText = declarationMapText ;
2714+ }
26682715 return node ;
26692716 }
26702717
0 commit comments