@@ -1194,13 +1194,21 @@ namespace Harness {
1194
1194
return { result, options } ;
1195
1195
}
1196
1196
1197
- export function compileDeclarationFiles ( inputFiles : TestFile [ ] ,
1197
+ export interface DeclarationCompilationContext {
1198
+ declInputFiles : TestFile [ ] ;
1199
+ declOtherFiles : TestFile [ ] ;
1200
+ harnessSettings : TestCaseParser . CompilerSettings & HarnessOptions ;
1201
+ options : ts . CompilerOptions ;
1202
+ currentDirectory : string ;
1203
+ }
1204
+
1205
+ export function prepareDeclarationCompilationContext ( inputFiles : TestFile [ ] ,
1198
1206
otherFiles : TestFile [ ] ,
1199
1207
result : CompilerResult ,
1200
1208
harnessSettings : TestCaseParser . CompilerSettings & HarnessOptions ,
1201
1209
options : ts . CompilerOptions ,
1202
1210
// Current directory is needed for rwcRunner to be able to use currentDirectory defined in json file
1203
- currentDirectory : string ) {
1211
+ currentDirectory : string ) : DeclarationCompilationContext | undefined {
1204
1212
if ( options . declaration && result . errors . length === 0 && result . declFilesCode . length !== result . files . length ) {
1205
1213
throw new Error ( "There were no errors and declFiles generated did not match number of js files generated" ) ;
1206
1214
}
@@ -1212,8 +1220,7 @@ namespace Harness {
1212
1220
if ( options . declaration && result . errors . length === 0 && result . declFilesCode . length > 0 ) {
1213
1221
ts . forEach ( inputFiles , file => addDtsFile ( file , declInputFiles ) ) ;
1214
1222
ts . forEach ( otherFiles , file => addDtsFile ( file , declOtherFiles ) ) ;
1215
- const output = compileFiles ( declInputFiles , declOtherFiles , harnessSettings , options , currentDirectory || harnessSettings [ "currentDirectory" ] ) ;
1216
- return { declInputFiles, declOtherFiles, declResult : output . result } ;
1223
+ return { declInputFiles, declOtherFiles, harnessSettings, options, currentDirectory : currentDirectory || harnessSettings [ "currentDirectory" ] } ;
1217
1224
}
1218
1225
1219
1226
function addDtsFile ( file : TestFile , dtsFiles : TestFile [ ] ) {
@@ -1259,6 +1266,15 @@ namespace Harness {
1259
1266
}
1260
1267
}
1261
1268
1269
+ export function compileDeclarationFiles ( context : DeclarationCompilationContext | undefined ) {
1270
+ if ( ! context ) {
1271
+ return ;
1272
+ }
1273
+ const { declInputFiles, declOtherFiles, harnessSettings, options, currentDirectory } = context ;
1274
+ const output = compileFiles ( declInputFiles , declOtherFiles , harnessSettings , options , currentDirectory ) ;
1275
+ return { declInputFiles, declOtherFiles, declResult : output . result } ;
1276
+ }
1277
+
1262
1278
function normalizeLineEndings ( text : string , lineEnding : string ) : string {
1263
1279
let normalized = text . replace ( / \r \n ? / g, "\n" ) ;
1264
1280
if ( lineEnding !== "\n" ) {
@@ -1273,10 +1289,19 @@ namespace Harness {
1273
1289
1274
1290
export function getErrorBaseline ( inputFiles : TestFile [ ] , diagnostics : ts . Diagnostic [ ] ) {
1275
1291
diagnostics . sort ( ts . compareDiagnostics ) ;
1276
- const outputLines : string [ ] = [ ] ;
1292
+ let outputLines = "" ;
1277
1293
// Count up all errors that were found in files other than lib.d.ts so we don't miss any
1278
1294
let totalErrorsReportedInNonLibraryFiles = 0 ;
1279
1295
1296
+ let firstLine = true ;
1297
+ function newLine ( ) {
1298
+ if ( firstLine ) {
1299
+ firstLine = false ;
1300
+ return "" ;
1301
+ }
1302
+ return "\r\n" ;
1303
+ }
1304
+
1280
1305
function outputErrorText ( error : ts . Diagnostic ) {
1281
1306
const message = ts . flattenDiagnosticMessageText ( error . messageText , Harness . IO . newLine ( ) ) ;
1282
1307
@@ -1285,7 +1310,7 @@ namespace Harness {
1285
1310
. map ( s => s . length > 0 && s . charAt ( s . length - 1 ) === "\r" ? s . substr ( 0 , s . length - 1 ) : s )
1286
1311
. filter ( s => s . length > 0 )
1287
1312
. map ( s => "!!! " + ts . DiagnosticCategory [ error . category ] . toLowerCase ( ) + " TS" + error . code + ": " + s ) ;
1288
- errLines . forEach ( e => outputLines . push ( e ) ) ;
1313
+ errLines . forEach ( e => outputLines += ( newLine ( ) + e ) ) ;
1289
1314
1290
1315
// do not count errors from lib.d.ts here, they are computed separately as numLibraryDiagnostics
1291
1316
// if lib.d.ts is explicitly included in input files and there are some errors in it (i.e. because of duplicate identifiers)
@@ -1311,7 +1336,7 @@ namespace Harness {
1311
1336
1312
1337
1313
1338
// Header
1314
- outputLines . push ( "==== " + inputFile . unitName + " (" + fileErrors . length + " errors) ====" ) ;
1339
+ outputLines += ( newLine ( ) + "==== " + inputFile . unitName + " (" + fileErrors . length + " errors) ====" ) ;
1315
1340
1316
1341
// Make sure we emit something for every error
1317
1342
let markedErrorCount = 0 ;
@@ -1340,7 +1365,7 @@ namespace Harness {
1340
1365
nextLineStart = lineStarts [ lineIndex + 1 ] ;
1341
1366
}
1342
1367
// Emit this line from the original file
1343
- outputLines . push ( " " + line ) ;
1368
+ outputLines += ( newLine ( ) + " " + line ) ;
1344
1369
fileErrors . forEach ( err => {
1345
1370
// Does any error start or continue on to this line? Emit squiggles
1346
1371
const end = ts . textSpanEnd ( err ) ;
@@ -1352,7 +1377,7 @@ namespace Harness {
1352
1377
// Calculate the start of the squiggle
1353
1378
const squiggleStart = Math . max ( 0 , relativeOffset ) ;
1354
1379
// TODO/REVIEW: this doesn't work quite right in the browser if a multi file test has files whose names are just the right length relative to one another
1355
- outputLines . push ( " " + line . substr ( 0 , squiggleStart ) . replace ( / [ ^ \s ] / g, " " ) + new Array ( Math . min ( length , line . length - squiggleStart ) + 1 ) . join ( "~" ) ) ;
1380
+ outputLines += ( newLine ( ) + " " + line . substr ( 0 , squiggleStart ) . replace ( / [ ^ \s ] / g, " " ) + new Array ( Math . min ( length , line . length - squiggleStart ) + 1 ) . join ( "~" ) ) ;
1356
1381
1357
1382
// If the error ended here, or we're at the end of the file, emit its message
1358
1383
if ( ( lineIndex === lines . length - 1 ) || nextLineStart > end ) {
@@ -1383,7 +1408,7 @@ namespace Harness {
1383
1408
assert . equal ( totalErrorsReportedInNonLibraryFiles + numLibraryDiagnostics + numTest262HarnessDiagnostics , diagnostics . length , "total number of errors" ) ;
1384
1409
1385
1410
return minimalDiagnosticsToString ( diagnostics ) +
1386
- Harness . IO . newLine ( ) + Harness . IO . newLine ( ) + outputLines . join ( "\r\n" ) ;
1411
+ Harness . IO . newLine ( ) + Harness . IO . newLine ( ) + outputLines ;
1387
1412
}
1388
1413
1389
1414
export function doErrorBaseline ( baselinePath : string , inputFiles : TestFile [ ] , errors : ts . Diagnostic [ ] ) {
@@ -1586,9 +1611,10 @@ namespace Harness {
1586
1611
}
1587
1612
}
1588
1613
1589
- const declFileCompilationResult =
1590
- Harness . Compiler . compileDeclarationFiles (
1591
- toBeCompiled , otherFiles , result , harnessSettings , options , /*currentDirectory*/ undefined ) ;
1614
+ const declFileContext = Harness . Compiler . prepareDeclarationCompilationContext (
1615
+ toBeCompiled , otherFiles , result , harnessSettings , options , /*currentDirectory*/ undefined
1616
+ ) ;
1617
+ const declFileCompilationResult = Harness . Compiler . compileDeclarationFiles ( declFileContext ) ;
1592
1618
1593
1619
if ( declFileCompilationResult && declFileCompilationResult . declResult . errors . length ) {
1594
1620
jsCode += "\r\n\r\n//// [DtsFileErrors]\r\n" ;
0 commit comments