Skip to content

Commit b1f90e6

Browse files
committed
change to use map instead of flag, value tuple.
1 parent 527f197 commit b1f90e6

1 file changed

Lines changed: 155 additions & 156 deletions

File tree

src/harness/harness.ts

Lines changed: 155 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -915,202 +915,202 @@ module Harness {
915915
includeBuiltFileNames?: string[];
916916
}
917917

918-
export function setCompilerOptionForSetting(setting: Harness.TestCaseParser.CompilerSetting, options: ts.CompilerOptions & HarnesOptions): void {
919-
let name = setting.flag.toLowerCase();
920-
let value = setting.value ? setting.value.toLowerCase() : setting.value;
921-
switch (name) {
922-
case "module":
923-
if (value === "amd") {
924-
options.module = ts.ModuleKind.AMD;
925-
} else if (value === "umd") {
926-
options.module = ts.ModuleKind.UMD;
927-
} else if (value === "commonjs") {
928-
options.module = ts.ModuleKind.CommonJS;
929-
} else if (value === "system") {
930-
options.module = ts.ModuleKind.System;
931-
} else if (value === "unspecified") {
932-
options.module = ts.ModuleKind.None;
933-
} else {
934-
throw new Error("Unknown module type " + value);
935-
}
936-
break;
937-
938-
case "target":
939-
if (value === "es3") {
940-
options.target = ts.ScriptTarget.ES3;
941-
} else if (value === "es5") {
942-
options.target = ts.ScriptTarget.ES5;
943-
} else if (value === "es6") {
944-
options.target = ts.ScriptTarget.ES6;
945-
} else {
946-
throw new Error("Unknown compile target " + value);
947-
}
948-
break;
918+
export function setCompilerOptionForSetting(settings: Harness.TestCaseParser.CompilerSettings, options: ts.CompilerOptions & HarnesOptions): void {
919+
for (let name in settings) {
920+
if (settings.hasOwnProperty(name)) {
921+
let value = settings[name] ? settings[name].toLowerCase() : settings[name];
922+
switch (name.toLowerCase()) {
923+
case "module":
924+
if (value === "amd") {
925+
options.module = ts.ModuleKind.AMD;
926+
} else if (value === "umd") {
927+
options.module = ts.ModuleKind.UMD;
928+
} else if (value === "commonjs") {
929+
options.module = ts.ModuleKind.CommonJS;
930+
} else if (value === "system") {
931+
options.module = ts.ModuleKind.System;
932+
} else if (value === "unspecified") {
933+
options.module = ts.ModuleKind.None;
934+
} else {
935+
throw new Error("Unknown module type " + value);
936+
}
937+
break;
938+
939+
case "target":
940+
if (value === "es3") {
941+
options.target = ts.ScriptTarget.ES3;
942+
} else if (value === "es5") {
943+
options.target = ts.ScriptTarget.ES5;
944+
} else if (value === "es6") {
945+
options.target = ts.ScriptTarget.ES6;
946+
} else {
947+
throw new Error("Unknown compile target " + value);
948+
}
949+
break;
949950

950-
case "experimentaldecorators":
951-
options.experimentalDecorators = value === "true";
952-
break;
951+
case "experimentaldecorators":
952+
options.experimentalDecorators = value === "true";
953+
break;
953954

954-
case "emitdecoratormetadata":
955-
options.emitDecoratorMetadata = value === "true";
956-
break;
955+
case "emitdecoratormetadata":
956+
options.emitDecoratorMetadata = value === "true";
957+
break;
957958

958-
case "experimentalasyncfunctions":
959-
options.experimentalAsyncFunctions = value === "true";
960-
break;
959+
case "experimentalasyncfunctions":
960+
options.experimentalAsyncFunctions = value === "true";
961+
break;
961962

962-
case "noemithelpers":
963-
options.noEmitHelpers = value === "true";
964-
break;
963+
case "noemithelpers":
964+
options.noEmitHelpers = value === "true";
965+
break;
965966

966-
case "noemitonerror":
967-
options.noEmitOnError = value === "true";
968-
break;
967+
case "noemitonerror":
968+
options.noEmitOnError = value === "true";
969+
break;
969970

970-
case "noresolve":
971-
options.noResolve = value === "true";
972-
break;
971+
case "noresolve":
972+
options.noResolve = value === "true";
973+
break;
973974

974-
case "noimplicitany":
975-
options.noImplicitAny = value === "true";
976-
break;
975+
case "noimplicitany":
976+
options.noImplicitAny = value === "true";
977+
break;
977978

978-
case "nolib":
979-
options.noLib = value === "true";
980-
break;
979+
case "nolib":
980+
options.noLib = value === "true";
981+
break;
981982

982-
case "out":
983-
options.out = value;
984-
break;
983+
case "out":
984+
options.out = settings[name];
985+
break;
985986

986-
case "outdir":
987-
options.outDir = value;
988-
break;
987+
case "outdir":
988+
options.outDir = settings[name];
989+
break;
989990

990-
case "skipdefaultlibcheck":
991-
options.skipDefaultLibCheck = value === "true";
992-
break;
991+
case "skipdefaultlibcheck":
992+
options.skipDefaultLibCheck = value === "true";
993+
break;
993994

994-
case "sourceroot":
995-
options.sourceRoot = value;
996-
break;
995+
case "sourceroot":
996+
options.sourceRoot = settings[name];
997+
break;
997998

998-
case "maproot":
999-
options.mapRoot = value;
1000-
break;
999+
case "maproot":
1000+
options.mapRoot = settings[name];
1001+
break;
10011002

1002-
case "sourcemap":
1003-
options.sourceMap = value === "true";
1004-
break;
1003+
case "sourcemap":
1004+
options.sourceMap = value === "true";
1005+
break;
10051006

1006-
case "declaration":
1007-
options.declaration = value === "true";
1008-
break;
1007+
case "declaration":
1008+
options.declaration = value === "true";
1009+
break;
10091010

1010-
case "newline":
1011-
if (value === "crlf") {
1012-
options.newLine = ts.NewLineKind.CarriageReturnLineFeed;
1013-
}
1014-
else if (value === "lf") {
1015-
options.newLine = ts.NewLineKind.LineFeed;
1016-
}
1017-
else {
1018-
throw new Error("Unknown option for newLine: " + value);
1019-
}
1020-
break;
1011+
case "newline":
1012+
if (value === "crlf") {
1013+
options.newLine = ts.NewLineKind.CarriageReturnLineFeed;
1014+
}
1015+
else if (value === "lf") {
1016+
options.newLine = ts.NewLineKind.LineFeed;
1017+
}
1018+
else {
1019+
throw new Error("Unknown option for newLine: " + value);
1020+
}
1021+
break;
10211022

1022-
case "comments":
1023-
options.removeComments = value === "false";
1024-
break;
1023+
case "comments":
1024+
options.removeComments = value === "false";
1025+
break;
10251026

1026-
case "stripinternal":
1027-
options.stripInternal = value === "true";
1027+
case "stripinternal":
1028+
options.stripInternal = value === "true";
1029+
break;
10281030

1029-
case "usecasesensitivefilenames":
1030-
options.useCaseSensitiveFileNames = value === "true";
1031-
break;
1031+
case "usecasesensitivefilenames":
1032+
options.useCaseSensitiveFileNames = value === "true";
1033+
break;
10321034

1033-
case "filename":
1034-
// Not supported yet
1035-
break;
1035+
case "filename":
1036+
// Not supported yet
1037+
break;
10361038

1037-
case "emitbom":
1038-
options.emitBOM = value === "true";
1039-
break;
1039+
case "emitbom":
1040+
options.emitBOM = value === "true";
1041+
break;
10401042

1041-
case "errortruncation":
1042-
options.noErrorTruncation = value === "false";
1043-
break;
1043+
case "errortruncation":
1044+
options.noErrorTruncation = value === "false";
1045+
break;
10441046

1045-
case "preserveconstenums":
1046-
options.preserveConstEnums = value === "true";
1047-
break;
1047+
case "preserveconstenums":
1048+
options.preserveConstEnums = value === "true";
1049+
break;
10481050

1049-
case "isolatedmodules":
1050-
options.isolatedModules = value === "true";
1051-
break;
1051+
case "isolatedmodules":
1052+
options.isolatedModules = value === "true";
1053+
break;
10521054

1053-
case "suppressimplicitanyindexerrors":
1054-
options.suppressImplicitAnyIndexErrors = value === "true";
1055-
break;
1055+
case "suppressimplicitanyindexerrors":
1056+
options.suppressImplicitAnyIndexErrors = value === "true";
1057+
break;
10561058

1057-
case "includebuiltfile":
1058-
if (!options.includeBuiltFileNames) {
1059-
options.includeBuiltFileNames = [];
1060-
}
1061-
options.includeBuiltFileNames.push(value);
1062-
break;
1059+
case "includebuiltfile":
1060+
if (!options.includeBuiltFileNames) {
1061+
options.includeBuiltFileNames = [];
1062+
}
1063+
options.includeBuiltFileNames.push(settings[name]);
1064+
break;
10631065

1064-
case "inlinesourcemap":
1065-
options.inlineSourceMap = value === "true";
1066-
break;
1066+
case "inlinesourcemap":
1067+
options.inlineSourceMap = value === "true";
1068+
break;
10671069

1068-
case "inlinesources":
1069-
options.inlineSources = value === "true";
1070-
break;
1070+
case "inlinesources":
1071+
options.inlineSources = value === "true";
1072+
break;
10711073

1072-
case "jsx":
1073-
if (value === "react") {
1074-
options.jsx = ts.JsxEmit.React;
1075-
}
1076-
else if (value === "preserve") {
1077-
options.jsx = ts.JsxEmit.Preserve;
1078-
}
1079-
else if (value === "none") {
1080-
options.jsx = ts.JsxEmit.None;
1081-
}
1082-
else {
1083-
throw new Error("Unknown option for jsx: " + value);
1084-
}
1085-
break;
1074+
case "jsx":
1075+
if (value === "react") {
1076+
options.jsx = ts.JsxEmit.React;
1077+
}
1078+
else if (value === "preserve") {
1079+
options.jsx = ts.JsxEmit.Preserve;
1080+
}
1081+
else if (value === "none") {
1082+
options.jsx = ts.JsxEmit.None;
1083+
}
1084+
else {
1085+
throw new Error("Unknown option for jsx: " + value);
1086+
}
1087+
break;
10861088

1087-
default:
1088-
throw new Error("Unsupported compiler setting " + setting.flag);
1089+
default:
1090+
throw new Error("Unsupported compiler setting " + value);
1091+
}
1092+
}
10891093
}
10901094
}
10911095

10921096
export class HarnessCompiler {
10931097
private inputFiles: { unitName: string; content: string }[] = [];
10941098
private compileOptions: ts.CompilerOptions;
1095-
private settings: Harness.TestCaseParser.CompilerSetting[] = [];
1099+
private settings: Harness.TestCaseParser.CompilerSettings = {};
10961100

10971101
private lastErrors: ts.Diagnostic[];
10981102

10991103
public reset() {
11001104
this.inputFiles = [];
1101-
this.settings = [];
1105+
this.settings = {};
11021106
this.lastErrors = [];
11031107
}
11041108

11051109
public reportCompilationErrors() {
11061110
return this.lastErrors;
11071111
}
11081112

1109-
public setCompilerSettingsFromOptions(tcSettings: ts.CompilerOptions) {
1110-
this.settings = Object.keys(tcSettings).map(k => ({ flag: k, value: (<any>tcSettings)[k] }));
1111-
}
1112-
1113-
public setCompilerSettings(tcSettings: Harness.TestCaseParser.CompilerSetting[]) {
1113+
public setCompilerSettings(tcSettings: Harness.TestCaseParser.CompilerSettings) {
11141114
this.settings = tcSettings;
11151115
}
11161116

@@ -1164,7 +1164,7 @@ module Harness {
11641164
options.skipDefaultLibCheck = true;
11651165

11661166
// Parse settings
1167-
this.settings.forEach(setting => setCompilerOptionForSetting(setting, options));
1167+
setCompilerOptionForSetting(this.settings, options);
11681168

11691169
// Files from built\local that are requested by test "@includeBuiltFiles" to be in the context.
11701170
// Treat them as library files, so include them in build, but not in baselines.
@@ -1514,9 +1514,8 @@ module Harness {
15141514

15151515
export module TestCaseParser {
15161516
/** all the necessary information to set the right compiler settings */
1517-
export interface CompilerSetting {
1518-
flag: string;
1519-
value: string;
1517+
export interface CompilerSettings {
1518+
[name: string]: string;
15201519
}
15211520

15221521
/** All the necessary information to turn a multi file test into useful units for later compilation */
@@ -1531,20 +1530,20 @@ module Harness {
15311530
// Regex for parsing options in the format "@Alpha: Value of any sort"
15321531
let optionRegex = /^[\/]{2}\s*@(\w+)\s*:\s*(\S*)/gm; // multiple matches on multiple lines
15331532

1534-
function extractCompilerSettings(content: string): CompilerSetting[] {
1533+
function extractCompilerSettings(content: string): CompilerSettings {
15351534

1536-
let opts: CompilerSetting[] = [];
1535+
let opts: CompilerSettings = {};
15371536

15381537
let match: RegExpExecArray;
15391538
while ((match = optionRegex.exec(content)) != null) {
1540-
opts.push({ flag: match[1], value: match[2] });
1539+
opts[match[1]] = match[2];
15411540
}
15421541

15431542
return opts;
15441543
}
15451544

15461545
/** Given a test file containing // @FileName directives, return an array of named units of code to be added to an existing compiler instance */
1547-
export function makeUnitsFromTest(code: string, fileName: string): { settings: CompilerSetting[]; testUnitData: TestUnitData[]; } {
1546+
export function makeUnitsFromTest(code: string, fileName: string): { settings: CompilerSettings; testUnitData: TestUnitData[]; } {
15481547
let settings = extractCompilerSettings(code);
15491548

15501549
// List of all the subfiles we've parsed out

0 commit comments

Comments
 (0)