@@ -227,14 +227,22 @@ namespace compiler {
227
227
public readonly program : ts . Program | undefined ;
228
228
public readonly result : ts . EmitResult | undefined ;
229
229
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 > ;
234
234
235
235
private _inputs : documents . TextDocument [ ] = [ ] ;
236
236
private _inputsAndOutputs : core . KeyedCollection < string , CompilationOutput > ;
237
237
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
+
238
246
constructor ( host : CompilerHost , options : ts . CompilerOptions , program : ts . Program | undefined , result : ts . EmitResult | undefined , diagnostics : ts . Diagnostic [ ] ) {
239
247
this . host = host ;
240
248
this . program = program ;
@@ -243,18 +251,18 @@ namespace compiler {
243
251
this . options = program ? program . getCompilerOptions ( ) : options ;
244
252
245
253
// 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 ) ;
249
257
for ( const document of this . host . outputs ) {
250
258
if ( vpath . isJavaScript ( document . file ) ) {
251
- this . js . set ( document . file , document ) ;
259
+ js . set ( document . file , document ) ;
252
260
}
253
261
else if ( vpath . isDeclaration ( document . file ) ) {
254
- this . dts . set ( document . file , document ) ;
262
+ dts . set ( document . file , document ) ;
255
263
}
256
264
else if ( vpath . isSourceMap ( document . file ) ) {
257
- this . maps . set ( document . file , document ) ;
265
+ maps . set ( document . file , document ) ;
258
266
}
259
267
}
260
268
@@ -268,9 +276,9 @@ namespace compiler {
268
276
if ( ! vpath . isDeclaration ( sourceFile . fileName ) ) {
269
277
const outputs = {
270
278
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" ) )
274
282
} ;
275
283
276
284
this . _inputsAndOutputs . set ( sourceFile . fileName , outputs ) ;
@@ -281,9 +289,17 @@ namespace compiler {
281
289
}
282
290
}
283
291
}
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 ;
284
300
}
285
301
286
- public get vfs ( ) {
302
+ public get vfs ( ) : vfs . VirtualFileSystem {
287
303
return this . host . vfs ;
288
304
}
289
305
@@ -326,6 +342,12 @@ namespace compiler {
326
342
return outputs && outputs [ kind ] ;
327
343
}
328
344
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
+
329
351
public getSourceMap ( path : string ) : documents . SourceMap | undefined {
330
352
if ( this . options . noEmit || vpath . isDeclaration ( path ) ) return undefined ;
331
353
if ( this . options . inlineSourceMap ) {
@@ -338,7 +360,7 @@ namespace compiler {
338
360
}
339
361
}
340
362
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 {
342
364
if ( outDir ) {
343
365
path = vpath . resolve ( this . vfs . currentDirectory , path ) ;
344
366
const common = this . commonSourceDirectory ;
@@ -352,8 +374,7 @@ namespace compiler {
352
374
}
353
375
}
354
376
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 {
357
378
if ( compilerOptions . project || ! rootFiles || rootFiles . length === 0 ) {
358
379
const project = readProject ( host . parseConfigHost , compilerOptions . project , compilerOptions ) ;
359
380
if ( project ) {
@@ -368,6 +389,7 @@ namespace compiler {
368
389
delete compilerOptions . project ;
369
390
}
370
391
392
+ // establish defaults (aligns with old harness)
371
393
if ( compilerOptions . target === undefined ) compilerOptions . target = ts . ScriptTarget . ES3 ;
372
394
if ( compilerOptions . newLine === undefined ) compilerOptions . newLine = ts . NewLineKind . CarriageReturnLineFeed ;
373
395
if ( compilerOptions . skipDefaultLibCheck === undefined ) compilerOptions . skipDefaultLibCheck = true ;
0 commit comments