@@ -227,14 +227,22 @@ namespace compiler {
227227 public readonly program : ts . Program | undefined ;
228228 public readonly result : ts . EmitResult | undefined ;
229229 public readonly options : ts . CompilerOptions ;
230- public readonly diagnostics : ts . Diagnostic [ ] ;
231- public readonly js : core . KeyedCollection < string , documents . TextDocument > ;
232- public readonly dts : core . KeyedCollection < string , documents . TextDocument > ;
233- public readonly maps : core . KeyedCollection < string , documents . TextDocument > ;
230+ public readonly diagnostics : ReadonlyArray < ts . Diagnostic > ;
231+ public readonly js : core . ReadonlyKeyedCollection < string , documents . TextDocument > ;
232+ public readonly dts : core . ReadonlyKeyedCollection < string , documents . TextDocument > ;
233+ public readonly maps : core . ReadonlyKeyedCollection < string , documents . TextDocument > ;
234234
235235 private _inputs : documents . TextDocument [ ] = [ ] ;
236236 private _inputsAndOutputs : core . KeyedCollection < string , CompilationOutput > ;
237237
238+ // from CompilerResult
239+ public readonly files : ReadonlyArray < Harness . Compiler . GeneratedFile > ;
240+ public readonly declFilesCode : ReadonlyArray < Harness . Compiler . GeneratedFile > ;
241+ public readonly sourceMaps : ReadonlyArray < Harness . Compiler . GeneratedFile > ;
242+ public readonly errors : ReadonlyArray < ts . Diagnostic > ;
243+ public readonly currentDirectoryForProgram : string ;
244+ public readonly traceResults : ReadonlyArray < string > ;
245+
238246 constructor ( host : CompilerHost , options : ts . CompilerOptions , program : ts . Program | undefined , result : ts . EmitResult | undefined , diagnostics : ts . Diagnostic [ ] ) {
239247 this . host = host ;
240248 this . program = program ;
@@ -243,18 +251,18 @@ namespace compiler {
243251 this . options = program ? program . getCompilerOptions ( ) : options ;
244252
245253 // collect outputs
246- this . js = new core . KeyedCollection < string , documents . TextDocument > ( this . vfs . pathComparer ) ;
247- this . dts = new core . KeyedCollection < string , documents . TextDocument > ( this . vfs . pathComparer ) ;
248- this . maps = new core . KeyedCollection < string , documents . TextDocument > ( this . vfs . pathComparer ) ;
254+ const js = this . js = new core . KeyedCollection < string , documents . TextDocument > ( this . vfs . pathComparer ) ;
255+ const dts = this . dts = new core . KeyedCollection < string , documents . TextDocument > ( this . vfs . pathComparer ) ;
256+ const maps = this . maps = new core . KeyedCollection < string , documents . TextDocument > ( this . vfs . pathComparer ) ;
249257 for ( const document of this . host . outputs ) {
250258 if ( vpath . isJavaScript ( document . file ) ) {
251- this . js . set ( document . file , document ) ;
259+ js . set ( document . file , document ) ;
252260 }
253261 else if ( vpath . isDeclaration ( document . file ) ) {
254- this . dts . set ( document . file , document ) ;
262+ dts . set ( document . file , document ) ;
255263 }
256264 else if ( vpath . isSourceMap ( document . file ) ) {
257- this . maps . set ( document . file , document ) ;
265+ maps . set ( document . file , document ) ;
258266 }
259267 }
260268
@@ -268,9 +276,9 @@ namespace compiler {
268276 if ( ! vpath . isDeclaration ( sourceFile . fileName ) ) {
269277 const outputs = {
270278 input,
271- js : this . js . get ( this . getOutputPath ( sourceFile . fileName , ts . getOutputExtension ( sourceFile , this . options ) ) ) ,
272- dts : this . dts . get ( this . getOutputPath ( sourceFile . fileName , ".d.ts" , this . options . declarationDir ) ) ,
273- map : this . maps . get ( this . getOutputPath ( sourceFile . fileName , ts . getOutputExtension ( sourceFile , this . options ) + ".map" ) )
279+ js : js . get ( this . getOutputPath ( sourceFile . fileName , ts . getOutputExtension ( sourceFile , this . options ) ) ) ,
280+ dts : dts . get ( this . getOutputPath ( sourceFile . fileName , ".d.ts" , this . options . declarationDir ) ) ,
281+ map : maps . get ( this . getOutputPath ( sourceFile . fileName , ts . getOutputExtension ( sourceFile , this . options ) + ".map" ) )
274282 } ;
275283
276284 this . _inputsAndOutputs . set ( sourceFile . fileName , outputs ) ;
@@ -281,9 +289,17 @@ namespace compiler {
281289 }
282290 }
283291 }
292+
293+ // from CompilerResult
294+ this . files = Array . from ( this . js . values ( ) , file => file . asGeneratedFile ( ) ) ;
295+ this . declFilesCode = Array . from ( this . dts . values ( ) , file => file . asGeneratedFile ( ) ) ;
296+ this . sourceMaps = Array . from ( this . maps . values ( ) , file => file . asGeneratedFile ( ) ) ;
297+ this . errors = diagnostics ;
298+ this . currentDirectoryForProgram = host . vfs . currentDirectory ;
299+ this . traceResults = host . traces ;
284300 }
285301
286- public get vfs ( ) {
302+ public get vfs ( ) : vfs . VirtualFileSystem {
287303 return this . host . vfs ;
288304 }
289305
@@ -326,6 +342,12 @@ namespace compiler {
326342 return outputs && outputs [ kind ] ;
327343 }
328344
345+ public getSourceMapRecord ( ) : string | undefined {
346+ if ( this . result . sourceMaps && this . result . sourceMaps . length > 0 ) {
347+ return Harness . SourceMapRecorder . getSourceMapRecord ( this . result . sourceMaps , this . program , this . files ) ;
348+ }
349+ }
350+
329351 public getSourceMap ( path : string ) : documents . SourceMap | undefined {
330352 if ( this . options . noEmit || vpath . isDeclaration ( path ) ) return undefined ;
331353 if ( this . options . inlineSourceMap ) {
@@ -338,7 +360,7 @@ namespace compiler {
338360 }
339361 }
340362
341- public getOutputPath ( path : string , ext : string , outDir : string | undefined = this . options . outDir ) {
363+ public getOutputPath ( path : string , ext : string , outDir : string | undefined = this . options . outDir ) : string {
342364 if ( outDir ) {
343365 path = vpath . resolve ( this . vfs . currentDirectory , path ) ;
344366 const common = this . commonSourceDirectory ;
@@ -352,8 +374,7 @@ namespace compiler {
352374 }
353375 }
354376
355- export function compileFiles ( host : CompilerHost , rootFiles : string [ ] | undefined , compilerOptions : ts . CompilerOptions ) {
356- // establish defaults (aligns with old harness)
377+ export function compileFiles ( host : CompilerHost , rootFiles : string [ ] | undefined , compilerOptions : ts . CompilerOptions ) : CompilationResult {
357378 if ( compilerOptions . project || ! rootFiles || rootFiles . length === 0 ) {
358379 const project = readProject ( host . parseConfigHost , compilerOptions . project , compilerOptions ) ;
359380 if ( project ) {
@@ -368,6 +389,7 @@ namespace compiler {
368389 delete compilerOptions . project ;
369390 }
370391
392+ // establish defaults (aligns with old harness)
371393 if ( compilerOptions . target === undefined ) compilerOptions . target = ts . ScriptTarget . ES3 ;
372394 if ( compilerOptions . newLine === undefined ) compilerOptions . newLine = ts . NewLineKind . CarriageReturnLineFeed ;
373395 if ( compilerOptions . skipDefaultLibCheck === undefined ) compilerOptions . skipDefaultLibCheck = true ;
0 commit comments