@@ -534,7 +534,7 @@ module Harness {
534534 export var libText = IO . readFile ( libFolder + "lib.d.ts" ) ;
535535 export var libTextMinimal = IO . readFile ( 'bin/lib.core.d.ts' ) ;
536536
537- export function createCompilerHost ( filemap : { [ filename : string ] : ts . SourceFile ; } , writeFile : ( fn : string , contents : string ) => void ) : ts . CompilerHost {
537+ export function createCompilerHost ( filemap : { [ filename : string ] : ts . SourceFile ; } , writeFile : ( fn : string , contents : string , writeByteOrderMark : boolean ) => void ) : ts . CompilerHost {
538538 return {
539539 getCurrentDirectory : sys . getCurrentDirectory ,
540540 getCancellationToken : ( ) : any => undefined ,
@@ -544,7 +544,7 @@ module Harness {
544544 } else {
545545 var lib = 'lib.d.ts' ;
546546 if ( fn . substr ( fn . length - lib . length ) === lib ) {
547- return filemap [ fn ] = ts . createSourceFile ( 'lib.d.ts' , libTextMinimal , languageVersion , ts . ByteOrderMark . None ) ;
547+ return filemap [ fn ] = ts . createSourceFile ( 'lib.d.ts' , libTextMinimal , languageVersion ) ;
548548 }
549549 // Don't throw here -- the compiler might be looking for a test that actually doesn't exist as part of the TC
550550 return null ;
@@ -712,6 +712,10 @@ module Harness {
712712 // Not supported yet
713713 break ;
714714
715+ case 'emitbom' :
716+ options . emitBOM = ! ! setting . value ;
717+ break ;
718+
715719 default :
716720 throw new Error ( 'Unsupported compiler setting ' + setting . flag ) ;
717721 }
@@ -720,18 +724,15 @@ module Harness {
720724 var filemap : { [ name : string ] : ts . SourceFile ; } = { } ;
721725 var register = ( file : { unitName : string ; content : string ; } ) => {
722726 var filename = Path . switchToForwardSlashes ( file . unitName ) ;
723- filemap [ filename ] = ts . createSourceFile ( filename , file . content , options . target , ts . ByteOrderMark . None ) ;
727+ filemap [ filename ] = ts . createSourceFile ( filename , file . content , options . target ) ;
724728 } ;
725729 inputFiles . forEach ( register ) ;
726730 otherFiles . forEach ( register ) ;
727731
728- var fileOutputs : {
729- fileName : string ;
730- file : string ;
731- } [ ] = [ ] ;
732+ var fileOutputs : GeneratedFile [ ] = [ ] ;
732733
733734 var programFiles = inputFiles . map ( file => file . unitName ) ;
734- var program = ts . createProgram ( programFiles , options , createCompilerHost ( filemap , ( fn , contents ) => fileOutputs . push ( { fileName : fn , file : contents } ) ) ) ;
735+ var program = ts . createProgram ( programFiles , options , createCompilerHost ( filemap , ( fn , contents , writeByteOrderMark ) => fileOutputs . push ( { fileName : fn , code : contents , writeByteOrderMark : writeByteOrderMark } ) ) ) ;
735736
736737 var hadParseErrors = program . getDiagnostics ( ) . length > 0 ;
737738
@@ -810,6 +811,7 @@ module Harness {
810811 export interface GeneratedFile {
811812 fileName : string ;
812813 code : string ;
814+ writeByteOrderMark : boolean ;
813815 }
814816
815817 function stringEndsWith ( str : string , end : string ) {
@@ -837,19 +839,18 @@ module Harness {
837839 public sourceMapRecord : string ;
838840
839841 /** @param fileResults an array of strings for the fileName and an ITextWriter with its code */
840- constructor ( fileResults : { fileName : string ; file : string ; } [ ] , errors : MinimalDiagnostic [ ] , sourceMapRecordLines : string [ ] ) {
842+ constructor ( fileResults : GeneratedFile [ ] , errors : MinimalDiagnostic [ ] , sourceMapRecordLines : string [ ] ) {
841843 var lines : string [ ] = [ ] ;
842844
843845 fileResults . forEach ( emittedFile => {
844- var fileObj = { fileName : emittedFile . fileName , code : emittedFile . file } ;
845846 if ( isDTS ( emittedFile . fileName ) ) {
846847 // .d.ts file, add to declFiles emit
847- this . declFilesCode . push ( fileObj ) ;
848+ this . declFilesCode . push ( emittedFile ) ;
848849 } else if ( isJS ( emittedFile . fileName ) ) {
849850 // .js file, add to files
850- this . files . push ( fileObj ) ;
851+ this . files . push ( emittedFile ) ;
851852 } else if ( isJSMap ( emittedFile . fileName ) ) {
852- this . sourceMaps . push ( fileObj ) ;
853+ this . sourceMaps . push ( emittedFile ) ;
853854 } else {
854855 throw new Error ( 'Unrecognized file extension for file ' + emittedFile . fileName ) ;
855856 }
@@ -896,7 +897,7 @@ module Harness {
896897 var optionRegex = / ^ [ \/ ] { 2 } \s * @ ( \w + ) \s * : \s * ( \S * ) / gm; // multiple matches on multiple lines
897898
898899 // List of allowed metadata names
899- var fileMetadataNames = [ "filename" , "comments" , "declaration" , "module" , "nolib" , "sourcemap" , "target" , "out" , "outDir" , "noimplicitany" , "noresolve" , "newline" , "newlines" ] ;
900+ var fileMetadataNames = [ "filename" , "comments" , "declaration" , "module" , "nolib" , "sourcemap" , "target" , "out" , "outDir" , "noimplicitany" , "noresolve" , "newline" , "newlines" , "emitbom" ] ;
900901
901902 function extractCompilerSettings ( content : string ) : CompilerSetting [ ] {
902903
0 commit comments