@@ -303,6 +303,7 @@ export namespace Compiler {
303
303
{ name : "noTypesAndSymbols" , type : "boolean" , defaultValueDescription : false } ,
304
304
// Emitted js baseline will print full paths for every output file
305
305
{ name : "fullEmitPaths" , type : "boolean" , defaultValueDescription : false } ,
306
+ { name : "noCheck" , type : "boolean" , defaultValueDescription : false } ,
306
307
{ name : "reportDiagnostics" , type : "boolean" , defaultValueDescription : false } , // used to enable error collection in `transpile` baselines
307
308
] ;
308
309
@@ -371,6 +372,8 @@ export namespace Compiler {
371
372
fileOptions ?: any ;
372
373
}
373
374
375
+ export type CompileFilesResult = compiler . CompilationResult & { repeat ( newOptions : TestCaseParser . CompilerSettings ) : CompileFilesResult ; } ;
376
+
374
377
export function compileFiles (
375
378
inputFiles : TestFile [ ] ,
376
379
otherFiles : TestFile [ ] ,
@@ -379,7 +382,8 @@ export namespace Compiler {
379
382
// Current directory is needed for rwcRunner to be able to use currentDirectory defined in json file
380
383
currentDirectory : string | undefined ,
381
384
symlinks ?: vfs . FileSet ,
382
- ) : compiler . CompilationResult {
385
+ ) : CompileFilesResult {
386
+ const originalCurrentDirectory = currentDirectory ;
383
387
const options : ts . CompilerOptions & HarnessOptions = compilerOptions ? ts . cloneCompilerOptions ( compilerOptions ) : { noResolve : false } ;
384
388
options . newLine = options . newLine || ts . NewLineKind . CarriageReturnLineFeed ;
385
389
options . noErrorTruncation = true ;
@@ -428,7 +432,8 @@ export namespace Compiler {
428
432
const host = new fakes . CompilerHost ( fs , options ) ;
429
433
const result = compiler . compileFiles ( host , programFileNames , options , typeScriptVersion ) ;
430
434
result . symlinks = symlinks ;
431
- return result ;
435
+ ( result as CompileFilesResult ) . repeat = newOptions => compileFiles ( inputFiles , otherFiles , { ...harnessSettings , ...newOptions } , compilerOptions , originalCurrentDirectory , symlinks ) ;
436
+ return result as CompileFilesResult ;
432
437
}
433
438
434
439
export interface DeclarationCompilationContext {
@@ -944,7 +949,7 @@ export namespace Compiler {
944
949
return "\n//// https://sokra.github.io/source-map-visualization" + hash + "\n" ;
945
950
}
946
951
947
- export function doJsEmitBaseline ( baselinePath : string , header : string , options : ts . CompilerOptions , result : compiler . CompilationResult , tsConfigFiles : readonly TestFile [ ] , toBeCompiled : readonly TestFile [ ] , otherFiles : readonly TestFile [ ] , harnessSettings : TestCaseParser . CompilerSettings ) {
952
+ export function doJsEmitBaseline ( baselinePath : string , header : string , options : ts . CompilerOptions , result : CompileFilesResult , tsConfigFiles : readonly TestFile [ ] , toBeCompiled : readonly TestFile [ ] , otherFiles : readonly TestFile [ ] , harnessSettings : TestCaseParser . CompilerSettings ) {
948
953
if ( ! options . noEmit && ! options . emitDeclarationOnly && result . js . size === 0 && result . diagnostics . length === 0 ) {
949
954
throw new Error ( "Expected at least one js file to be emitted or at least one error to be created." ) ;
950
955
}
@@ -996,9 +1001,33 @@ export namespace Compiler {
996
1001
jsCode += "\r\n\r\n" ;
997
1002
jsCode += getErrorBaseline ( tsConfigFiles . concat ( declFileCompilationResult . declInputFiles , declFileCompilationResult . declOtherFiles ) , declFileCompilationResult . declResult . diagnostics ) ;
998
1003
}
1004
+ else if ( ! options . noCheck && ! options . noEmit && ( options . composite || options . declaration || options . emitDeclarationOnly ) ) {
1005
+ const withoutChecking = result . repeat ( { noCheck : "true" , emitDeclarationOnly : "true" } ) ;
1006
+ compareResultFileSets ( withoutChecking . dts , result . dts ) ;
1007
+ }
999
1008
1000
1009
// eslint-disable-next-line no-restricted-syntax
1001
1010
Baseline . runBaseline ( baselinePath . replace ( / \. t s x ? / , ts . Extension . Js ) , jsCode . length > 0 ? tsCode + "\r\n\r\n" + jsCode : null ) ;
1011
+
1012
+ function compareResultFileSets ( a : ReadonlyMap < string , documents . TextDocument > , b : ReadonlyMap < string , documents . TextDocument > ) {
1013
+ a . forEach ( ( doc , key ) => {
1014
+ const original = b . get ( key ) ;
1015
+ if ( ! original ) {
1016
+ jsCode += `\r\n\r\n!!!! File ${ Utils . removeTestPathPrefixes ( doc . file ) } missing from original emit, but present in noCheck emit\r\n` ;
1017
+ jsCode += fileOutput ( doc , harnessSettings ) ;
1018
+ }
1019
+ else if ( original . text !== doc . text ) {
1020
+ jsCode += `\r\n\r\n!!!! File ${ Utils . removeTestPathPrefixes ( doc . file ) } differs from original emit in noCheck emit\r\n` ;
1021
+ const Diff = require ( "diff" ) ;
1022
+ const expected = original . text ;
1023
+ const actual = doc . text ;
1024
+ const patch = Diff . createTwoFilesPatch ( "Expected" , "Actual" , expected , actual , "The full check baseline" , "with noCheck set" ) ;
1025
+ const fileName = harnessSettings . fullEmitPaths ? Utils . removeTestPathPrefixes ( doc . file ) : ts . getBaseFileName ( doc . file ) ;
1026
+ jsCode += "//// [" + fileName + "]\r\n" ;
1027
+ jsCode += patch ;
1028
+ }
1029
+ } ) ;
1030
+ }
1002
1031
}
1003
1032
1004
1033
function fileOutput ( file : documents . TextDocument , harnessSettings : TestCaseParser . CompilerSettings ) : string {
0 commit comments