@@ -900,7 +900,7 @@ module Harness {
900900 private compileOptions : ts . CompilerOptions ;
901901 private settings : Harness . TestCaseParser . CompilerSetting [ ] = [ ] ;
902902
903- private lastErrors : HarnessDiagnostic [ ] ;
903+ private lastErrors : ts . Diagnostic [ ] ;
904904
905905 public reset ( ) {
906906 this . inputFiles = [ ] ;
@@ -985,19 +985,13 @@ module Harness {
985985 // always push the default lib in *last* to normalize the type/symbol baselines.
986986 programFiles . push ( defaultLibFileName ) ;
987987 }
988-
989- var program = ts . createProgram ( programFiles , options ,
990- createCompilerHost ( inputFiles . concat ( includeBuiltFiles ) . concat ( otherFiles ) ,
988+ var program = ts . createProgram ( programFiles , options , createCompilerHost ( inputFiles . concat ( includeBuiltFiles ) . concat ( otherFiles ) ,
991989 ( fn , contents , writeByteOrderMark ) => fileOutputs . push ( { fileName : fn , code : contents , writeByteOrderMark : writeByteOrderMark } ) ,
992990 options . target , useCaseSensitiveFileNames , currentDirectory , options . newLine ) ) ;
993991
994992 var emitResult = program . emit ( ) ;
995993
996- var errors : HarnessDiagnostic [ ] = [ ] ;
997- ts . getPreEmitDiagnostics ( program ) . concat ( emitResult . diagnostics ) . forEach ( err => {
998- // TODO: new compiler formats errors after this point to add . and newlines so we'll just do it manually for now
999- errors . push ( getMinimalDiagnostic ( err ) ) ;
1000- } ) ;
994+ var errors = ts . getPreEmitDiagnostics ( program ) . concat ( emitResult . diagnostics ) ;
1001995 this . lastErrors = errors ;
1002996
1003997 var result = new CompilerResult ( fileOutputs , errors , program , ts . sys . getCurrentDirectory ( ) , emitResult . sourceMaps ) ;
@@ -1114,10 +1108,6 @@ module Harness {
11141108 }
11151109 break ;
11161110
1117- case 'normalizenewline' :
1118- newLine = setting . value ;
1119- break ;
1120-
11211111 case 'comments' :
11221112 options . removeComments = setting . value === 'false' ;
11231113 break ;
@@ -1248,70 +1238,50 @@ module Harness {
12481238 return normalized ;
12491239 }
12501240
1251- export function getMinimalDiagnostic ( err : ts . Diagnostic ) : HarnessDiagnostic {
1252- var errorLineInfo = err . file ? err . file . getLineAndCharacterOfPosition ( err . start ) : { line : - 1 , character : - 1 } ;
1253- return {
1254- fileName : err . file && err . file . fileName ,
1255- start : err . start ,
1256- end : err . start + err . length ,
1257- line : errorLineInfo . line + 1 ,
1258- character : errorLineInfo . character + 1 ,
1259- message : ts . flattenDiagnosticMessageText ( err . messageText , ts . sys . newLine ) ,
1260- category : ts . DiagnosticCategory [ err . category ] . toLowerCase ( ) ,
1261- code : err . code
1262- } ;
1263- }
1264-
1265- export function minimalDiagnosticsToString ( diagnostics : HarnessDiagnostic [ ] ) {
1241+ export function minimalDiagnosticsToString ( diagnostics : ts . Diagnostic [ ] ) {
12661242 // This is basically copied from tsc.ts's reportError to replicate what tsc does
12671243 var errorOutput = "" ;
1268- ts . forEach ( diagnostics , diagnotic => {
1269- if ( diagnotic . fileName ) {
1270- errorOutput += diagnotic . fileName + "(" + diagnotic . line + "," + diagnotic . character + "): " ;
1244+ ts . forEach ( diagnostics , diagnostic => {
1245+ if ( diagnostic . file ) {
1246+ var lineAndCharacter = diagnostic . file . getLineAndCharacterOfPosition ( diagnostic . start ) ;
1247+ errorOutput += diagnostic . file . fileName + "(" + ( lineAndCharacter . line + 1 ) + "," + ( lineAndCharacter . character + 1 ) + "): " ;
12711248 }
12721249
1273- errorOutput += diagnotic . category + " TS" + diagnotic . code + ": " + diagnotic . message + ts . sys . newLine ;
1250+ errorOutput += ts . DiagnosticCategory [ diagnostic . category ] . toLowerCase ( ) + " TS" + diagnostic . code + ": " + ts . flattenDiagnosticMessageText ( diagnostic . messageText , ts . sys . newLine ) + ts . sys . newLine ;
12741251 } ) ;
12751252
12761253 return errorOutput ;
12771254 }
12781255
1279- function compareDiagnostics ( d1 : HarnessDiagnostic , d2 : HarnessDiagnostic ) {
1280- return ts . compareValues ( d1 . fileName , d2 . fileName ) ||
1281- ts . compareValues ( d1 . start , d2 . start ) ||
1282- ts . compareValues ( d1 . end , d2 . end ) ||
1283- ts . compareValues ( d1 . code , d2 . code ) ||
1284- ts . compareValues ( d1 . message , d2 . message ) ||
1285- 0 ;
1286- }
1287-
1288- export function getErrorBaseline ( inputFiles : { unitName : string ; content : string } [ ] , diagnostics : HarnessDiagnostic [ ] ) {
1289- diagnostics . sort ( compareDiagnostics ) ;
1256+ export function getErrorBaseline ( inputFiles : { unitName : string ; content : string } [ ] , diagnostics : ts . Diagnostic [ ] ) {
1257+ diagnostics . sort ( ts . compareDiagnostics ) ;
12901258 var outputLines : string [ ] = [ ] ;
12911259 // Count up all the errors we find so we don't miss any
12921260 var totalErrorsReported = 0 ;
12931261
1294- function outputErrorText ( error : Harness . Compiler . HarnessDiagnostic ) {
1295- var errLines = RunnerBase . removeFullPaths ( error . message )
1262+ function outputErrorText ( error : ts . Diagnostic ) {
1263+ var message = ts . flattenDiagnosticMessageText ( error . messageText , ts . sys . newLine ) ;
1264+
1265+ var errLines = RunnerBase . removeFullPaths ( message )
12961266 . split ( '\n' )
12971267 . map ( s => s . length > 0 && s . charAt ( s . length - 1 ) === '\r' ? s . substr ( 0 , s . length - 1 ) : s )
12981268 . filter ( s => s . length > 0 )
1299- . map ( s => '!!! ' + error . category + " TS" + error . code + ": " + s ) ;
1269+ . map ( s => '!!! ' + ts . DiagnosticCategory [ error . category ] . toLowerCase ( ) + " TS" + error . code + ": " + s ) ;
13001270 errLines . forEach ( e => outputLines . push ( e ) ) ;
13011271
13021272 totalErrorsReported ++ ;
13031273 }
13041274
13051275 // Report global errors
1306- var globalErrors = diagnostics . filter ( err => ! err . fileName ) ;
1276+ var globalErrors = diagnostics . filter ( err => ! err . file ) ;
13071277 globalErrors . forEach ( outputErrorText ) ;
13081278
13091279 // 'merge' the lines of each input file with any errors associated with it
13101280 inputFiles . filter ( f => f . content !== undefined ) . forEach ( inputFile => {
13111281 // Filter down to the errors in the file
13121282 var fileErrors = diagnostics . filter ( e => {
1313- var errFn = e . fileName ;
1314- return errFn && errFn === inputFile . unitName ;
1283+ var errFn = e . file ;
1284+ return errFn && errFn . fileName === inputFile . unitName ;
13151285 } ) ;
13161286
13171287
@@ -1347,18 +1317,19 @@ module Harness {
13471317 outputLines . push ( ' ' + line ) ;
13481318 fileErrors . forEach ( err => {
13491319 // Does any error start or continue on to this line? Emit squiggles
1350- if ( ( err . end >= thisLineStart ) && ( ( err . start < nextLineStart ) || ( lineIndex === lines . length - 1 ) ) ) {
1320+ let end = ts . textSpanEnd ( err ) ;
1321+ if ( ( end >= thisLineStart ) && ( ( err . start < nextLineStart ) || ( lineIndex === lines . length - 1 ) ) ) {
13511322 // How many characters from the start of this line the error starts at (could be positive or negative)
13521323 var relativeOffset = err . start - thisLineStart ;
13531324 // How many characters of the error are on this line (might be longer than this line in reality)
1354- var length = ( err . end - err . start ) - Math . max ( 0 , thisLineStart - err . start ) ;
1325+ var length = ( end - err . start ) - Math . max ( 0 , thisLineStart - err . start ) ;
13551326 // Calculate the start of the squiggle
13561327 var squiggleStart = Math . max ( 0 , relativeOffset ) ;
13571328 // 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
13581329 outputLines . push ( ' ' + line . substr ( 0 , squiggleStart ) . replace ( / [ ^ \s ] / g, ' ' ) + new Array ( Math . min ( length , line . length - squiggleStart ) + 1 ) . join ( '~' ) ) ;
13591330
13601331 // If the error ended here, or we're at the end of the file, emit its message
1361- if ( ( lineIndex === lines . length - 1 ) || nextLineStart > err . end ) {
1332+ if ( ( lineIndex === lines . length - 1 ) || nextLineStart > end ) {
13621333 // Just like above, we need to do a split on a string instead of on a regex
13631334 // because the JS engine does regexes wrong
13641335
@@ -1374,12 +1345,12 @@ module Harness {
13741345 } ) ;
13751346
13761347 var numLibraryDiagnostics = ts . countWhere ( diagnostics , diagnostic => {
1377- return diagnostic . fileName && ( isLibraryFile ( diagnostic . fileName ) || isBuiltFile ( diagnostic . fileName ) ) ;
1348+ return diagnostic . file && ( isLibraryFile ( diagnostic . file . fileName ) || isBuiltFile ( diagnostic . file . fileName ) ) ;
13781349 } ) ;
13791350
13801351 var numTest262HarnessDiagnostics = ts . countWhere ( diagnostics , diagnostic => {
13811352 // Count an error generated from tests262-harness folder.This should only apply for test262
1382- return diagnostic . fileName && diagnostic . fileName . indexOf ( "test262-harness" ) >= 0 ;
1353+ return diagnostic . file && diagnostic . file . fileName . indexOf ( "test262-harness" ) >= 0 ;
13831354 } ) ;
13841355
13851356 // Verify we didn't miss any errors in total
@@ -1433,17 +1404,6 @@ module Harness {
14331404 //harnessCompiler.compileString(code, unitName, callback);
14341405 }
14351406
1436- export interface HarnessDiagnostic {
1437- fileName : string ;
1438- start : number ;
1439- end : number ;
1440- line : number ;
1441- character : number ;
1442- message : string ;
1443- category : string ;
1444- code : number ;
1445- }
1446-
14471407 export interface GeneratedFile {
14481408 fileName : string ;
14491409 code : string ;
@@ -1473,12 +1433,12 @@ module Harness {
14731433 /** Contains the code and errors of a compilation and some helper methods to check its status. */
14741434 export class CompilerResult {
14751435 public files : GeneratedFile [ ] = [ ] ;
1476- public errors : HarnessDiagnostic [ ] = [ ] ;
1436+ public errors : ts . Diagnostic [ ] = [ ] ;
14771437 public declFilesCode : GeneratedFile [ ] = [ ] ;
14781438 public sourceMaps : GeneratedFile [ ] = [ ] ;
14791439
14801440 /** @param fileResults an array of strings for the fileName and an ITextWriter with its code */
1481- constructor ( fileResults : GeneratedFile [ ] , errors : HarnessDiagnostic [ ] , public program : ts . Program ,
1441+ constructor ( fileResults : GeneratedFile [ ] , errors : ts . Diagnostic [ ] , public program : ts . Program ,
14821442 public currentDirectoryForProgram : string , private sourceMapData : ts . SourceMapData [ ] ) {
14831443
14841444 fileResults . forEach ( emittedFile => {
@@ -1503,15 +1463,6 @@ module Harness {
15031463 return Harness . SourceMapRecoder . getSourceMapRecord ( this . sourceMapData , this . program , this . files ) ;
15041464 }
15051465 }
1506-
1507- public isErrorAt ( line : number , column : number , message : string ) {
1508- for ( var i = 0 ; i < this . errors . length ; i ++ ) {
1509- if ( ( this . errors [ i ] . line + 1 ) === line && ( this . errors [ i ] . character + 1 ) === column && this . errors [ i ] . message === message )
1510- return true ;
1511- }
1512-
1513- return false ;
1514- }
15151466 }
15161467 }
15171468
0 commit comments