@@ -838,9 +838,9 @@ module Harness {
838
838
}
839
839
840
840
export function createSourceFileAndAssertInvariants (
841
- fileName : string ,
842
- sourceText : string ,
843
- languageVersion : ts . ScriptTarget ) {
841
+ fileName : string ,
842
+ sourceText : string ,
843
+ languageVersion : ts . ScriptTarget ) {
844
844
// We'll only assert inletiants outside of light mode.
845
845
const shouldAssertInvariants = ! Harness . lightMode ;
846
846
@@ -870,13 +870,13 @@ module Harness {
870
870
}
871
871
872
872
export function createCompilerHost (
873
- inputFiles : { unitName : string ; content : string ; } [ ] ,
874
- writeFile : ( fn : string , contents : string , writeByteOrderMark : boolean ) => void ,
875
- scriptTarget : ts . ScriptTarget ,
876
- useCaseSensitiveFileNames : boolean ,
877
- // the currentDirectory is needed for rwcRunner to passed in specified current directory to compiler host
878
- currentDirectory ?: string ,
879
- newLineKind ?: ts . NewLineKind ) : ts . CompilerHost {
873
+ inputFiles : { unitName : string ; content : string ; } [ ] ,
874
+ writeFile : ( fn : string , contents : string , writeByteOrderMark : boolean ) => void ,
875
+ scriptTarget : ts . ScriptTarget ,
876
+ useCaseSensitiveFileNames : boolean ,
877
+ // the currentDirectory is needed for rwcRunner to passed in specified current directory to compiler host
878
+ currentDirectory ?: string ,
879
+ newLineKind ?: ts . NewLineKind ) : ts . CompilerHost {
880
880
881
881
// Local get canonical file name function, that depends on passed in parameter for useCaseSensitiveFileNames
882
882
function getCanonicalFileName ( fileName : string ) : string {
@@ -894,7 +894,7 @@ module Harness {
894
894
}
895
895
} ;
896
896
inputFiles . forEach ( register ) ;
897
-
897
+
898
898
function getSourceFile ( fn : string , languageVersion : ts . ScriptTarget ) {
899
899
fn = ts . normalizePath ( fn ) ;
900
900
if ( Object . prototype . hasOwnProperty . call ( filemap , getCanonicalFileName ( fn ) ) ) {
@@ -938,200 +938,64 @@ module Harness {
938
938
939
939
interface HarnesOptions {
940
940
useCaseSensitiveFileNames ?: boolean ;
941
- includeBuiltFileNames ?: string [ ] ;
941
+ includeBuiltFile ?: string ;
942
942
baselineFile ?: string ;
943
943
}
944
944
945
+ // Additional options not already in ts.optionDeclarations
946
+ const harnessOptionDeclarations : ts . CommandLineOption [ ] = [
947
+ { name : "allowNonTsExtensions" , type : "boolean" } ,
948
+ { name : "useCaseSensitiveFileNames" , type : "boolean" } ,
949
+ { name : "baselineFile" , type : "string" } ,
950
+ { name : "includeBuiltFile" , type : "string" } ,
951
+ { name : "fileName" , type : "string" } ,
952
+ { name : "noErrorTruncation" , type : "boolean" }
953
+ ] ;
954
+
955
+ let optionsIndex : ts . Map < ts . CommandLineOption > ;
956
+ function getCommandLineOption ( name : string ) : ts . CommandLineOption {
957
+ if ( ! optionsIndex ) {
958
+ optionsIndex = { } ;
959
+ let optionDeclarations = harnessOptionDeclarations . concat ( ts . optionDeclarations ) ;
960
+ for ( let option of optionDeclarations ) {
961
+ optionsIndex [ option . name . toLowerCase ( ) ] = option ;
962
+ }
963
+ }
964
+ return ts . lookUp ( optionsIndex , name . toLowerCase ( ) ) ;
965
+ }
966
+
945
967
export function setCompilerOptionsFromHarnessSetting ( settings : Harness . TestCaseParser . CompilerSettings , options : ts . CompilerOptions & HarnesOptions ) : void {
946
968
for ( let name in settings ) {
947
969
if ( settings . hasOwnProperty ( name ) ) {
948
- let value = settings [ name ] ? settings [ name ] . toLowerCase ( ) : settings [ name ] ;
949
- switch ( name . toLowerCase ( ) ) {
950
- case "module" :
951
- if ( value === "amd" ) {
952
- options . module = ts . ModuleKind . AMD ;
953
- } else if ( value === "umd" ) {
954
- options . module = ts . ModuleKind . UMD ;
955
- } else if ( value === "commonjs" ) {
956
- options . module = ts . ModuleKind . CommonJS ;
957
- } else if ( value === "system" ) {
958
- options . module = ts . ModuleKind . System ;
959
- } else if ( value === "unspecified" ) {
960
- options . module = ts . ModuleKind . None ;
961
- } else {
962
- throw new Error ( "Unknown module type " + value ) ;
963
- }
964
- break ;
965
-
966
- case "target" :
967
- if ( value === "es3" ) {
968
- options . target = ts . ScriptTarget . ES3 ;
969
- } else if ( value === "es5" ) {
970
- options . target = ts . ScriptTarget . ES5 ;
971
- } else if ( value === "es6" ) {
972
- options . target = ts . ScriptTarget . ES6 ;
973
- } else {
974
- throw new Error ( "Unknown compile target " + value ) ;
975
- }
976
- break ;
977
-
978
- case "experimentaldecorators" :
979
- options . experimentalDecorators = value === "true" ;
980
- break ;
981
-
982
- case "emitdecoratormetadata" :
983
- options . emitDecoratorMetadata = value === "true" ;
984
- break ;
985
-
986
- case "experimentalasyncfunctions" :
987
- options . experimentalAsyncFunctions = value === "true" ;
988
- break ;
989
-
990
- case "noemithelpers" :
991
- options . noEmitHelpers = value === "true" ;
992
- break ;
993
-
994
- case "noemitonerror" :
995
- options . noEmitOnError = value === "true" ;
996
- break ;
997
-
998
- case "noresolve" :
999
- options . noResolve = value === "true" ;
1000
- break ;
1001
-
1002
- case "noimplicitany" :
1003
- options . noImplicitAny = value === "true" ;
1004
- break ;
1005
-
1006
- case "nolib" :
1007
- options . noLib = value === "true" ;
1008
- break ;
1009
-
1010
- case "out" :
1011
- options . out = settings [ name ] ;
1012
- break ;
1013
-
1014
- case "outfile" :
1015
- options . outFile = settings [ name ] ;
1016
- break ;
1017
-
1018
- case "outdir" :
1019
- options . outDir = settings [ name ] ;
1020
- break ;
1021
-
1022
- case "skipdefaultlibcheck" :
1023
- options . skipDefaultLibCheck = value === "true" ;
1024
- break ;
1025
-
1026
- case "sourceroot" :
1027
- options . sourceRoot = settings [ name ] ;
1028
- break ;
1029
-
1030
- case "maproot" :
1031
- options . mapRoot = settings [ name ] ;
1032
- break ;
1033
-
1034
- case "sourcemap" :
1035
- options . sourceMap = value === "true" ;
1036
- break ;
1037
-
1038
- case "declaration" :
1039
- options . declaration = value === "true" ;
1040
- break ;
1041
-
1042
- case "newline" :
1043
- if ( value === "crlf" ) {
1044
- options . newLine = ts . NewLineKind . CarriageReturnLineFeed ;
1045
- }
1046
- else if ( value === "lf" ) {
1047
- options . newLine = ts . NewLineKind . LineFeed ;
1048
- }
1049
- else {
1050
- throw new Error ( "Unknown option for newLine: " + value ) ;
1051
- }
1052
- break ;
1053
-
1054
- case "comments" :
1055
- options . removeComments = value === "false" ;
1056
- break ;
1057
-
1058
- case "stripinternal" :
1059
- options . stripInternal = value === "true" ;
1060
- break ;
1061
-
1062
- case "usecasesensitivefilenames" :
1063
- options . useCaseSensitiveFileNames = value === "true" ;
1064
- break ;
1065
-
1066
- case "filename" :
1067
- // Not supported yet
1068
- break ;
1069
-
1070
- case "emitbom" :
1071
- options . emitBOM = value === "true" ;
1072
- break ;
1073
-
1074
- case "errortruncation" :
1075
- options . noErrorTruncation = value === "false" ;
1076
- break ;
1077
-
1078
- case "preserveconstenums" :
1079
- options . preserveConstEnums = value === "true" ;
1080
- break ;
1081
-
1082
- case "isolatedmodules" :
1083
- options . isolatedModules = value === "true" ;
1084
- break ;
1085
-
1086
- case "suppressimplicitanyindexerrors" :
1087
- options . suppressImplicitAnyIndexErrors = value === "true" ;
1088
- break ;
1089
-
1090
- case "includebuiltfile" :
1091
- if ( ! options . includeBuiltFileNames ) {
1092
- options . includeBuiltFileNames = [ ] ;
1093
- }
1094
- options . includeBuiltFileNames . push ( settings [ name ] ) ;
1095
- break ;
1096
-
1097
- case "inlinesourcemap" :
1098
- options . inlineSourceMap = value === "true" ;
1099
- break ;
1100
-
1101
- case "inlinesources" :
1102
- options . inlineSources = value === "true" ;
1103
- break ;
1104
-
1105
- case "jsx" :
1106
- if ( value === "react" ) {
1107
- options . jsx = ts . JsxEmit . React ;
1108
- }
1109
- else if ( value === "preserve" ) {
1110
- options . jsx = ts . JsxEmit . Preserve ;
1111
- }
1112
- else if ( value === "none" ) {
1113
- options . jsx = ts . JsxEmit . None ;
1114
- }
1115
- else {
1116
- throw new Error ( "Unknown option for jsx: " + value ) ;
1117
- }
1118
- break ;
1119
-
1120
- case "allownontsextensions" :
1121
- options . allowNonTsExtensions = value === "true" ;
1122
- break ;
1123
-
1124
- case "baselinefile" :
1125
- options . baselineFile = settings [ name ] ;
1126
- break ;
1127
-
1128
- default :
1129
- throw new Error ( "Unsupported compiler setting " + value ) ;
970
+ let value = settings [ name ] ;
971
+ let option = getCommandLineOption ( name ) ;
972
+ if ( option ) {
973
+ switch ( option . type ) {
974
+ case "boolean" :
975
+ options [ option . name ] = value . toLowerCase ( ) === "true" ;
976
+ break ;
977
+ case "string" :
978
+ options [ option . name ] = value ;
979
+ break ;
980
+ // If not a primitive, the possible types are specified in what is effectively a map of options.
981
+ default :
982
+ let map = < ts . Map < number > > option . type ;
983
+ let key = ( value ) . toLowerCase ( ) ;
984
+ if ( ts . hasProperty ( map , key ) ) {
985
+ options [ option . name ] = map [ key ] ;
986
+ }
987
+ else {
988
+ throw new Error ( `Unkown value '${ value } ' for compiler option '${ name } '.` ) ;
989
+ }
990
+ }
991
+ }
992
+ else {
993
+ throw new Error ( `Unkown compiler option '${ name } '.` ) ;
1130
994
}
1131
995
}
1132
996
}
1133
997
}
1134
-
998
+
1135
999
export class HarnessCompiler {
1136
1000
private inputFiles : { unitName : string ; content : string } [ ] = [ ] ;
1137
1001
private compileOptions : ts . CompilerOptions ;
@@ -1194,24 +1058,24 @@ module Harness {
1194
1058
options . module = options . module || ts . ModuleKind . None ;
1195
1059
options . newLine = options . newLine || ts . NewLineKind . CarriageReturnLineFeed ;
1196
1060
options . noErrorTruncation = true ;
1061
+ options . skipDefaultLibCheck = true ;
1197
1062
1198
1063
if ( settingsCallback ) {
1199
1064
settingsCallback ( null ) ;
1200
1065
}
1201
1066
1202
1067
let newLine = "\r\n" ;
1203
- options . skipDefaultLibCheck = true ;
1204
1068
1205
1069
// Parse settings
1206
1070
setCompilerOptionsFromHarnessSetting ( this . settings , options ) ;
1207
1071
1208
1072
// Files from built\local that are requested by test "@includeBuiltFiles" to be in the context.
1209
1073
// Treat them as library files, so include them in build, but not in baselines.
1210
1074
let includeBuiltFiles : { unitName : string ; content : string } [ ] = [ ] ;
1211
- ts . forEach ( options . includeBuiltFileNames , fileName => {
1212
- let builtFileName = libFolder + fileName ;
1075
+ if ( options . includeBuiltFile ) {
1076
+ let builtFileName = libFolder + options . includeBuiltFile ;
1213
1077
includeBuiltFiles . push ( { unitName : builtFileName , content : normalizeLineEndings ( IO . readFile ( builtFileName ) , newLine ) } ) ;
1214
- } ) ;
1078
+ }
1215
1079
1216
1080
let useCaseSensitiveFileNames = options . useCaseSensitiveFileNames !== undefined ? options . useCaseSensitiveFileNames : Harness . IO . useCaseSensitiveFileNames ( ) ;
1217
1081
0 commit comments