Skip to content

Commit 1fe8a08

Browse files
author
Andy Hanson
committed
Respond to PR comments
1 parent d9ec512 commit 1fe8a08

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

src/services/services.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,11 +1920,15 @@ namespace ts {
19201920
sourceMapText?: string;
19211921
}
19221922

1923+
const commandLineOptions_stringToEnum = <CommandLineOptionOfCustomType[]>filter(optionDeclarations, o => {
1924+
return typeof o.type === "object" && !forEachValue(<Map<any>> o.type, v => typeof v !== "number");
1925+
});
1926+
19231927
/** JS users may pass in string values for enum compiler options (such as ModuleKind), so convert. */
19241928
function fixupCompilerOptions(options: CompilerOptions, diagnostics: Diagnostic[]) {
19251929
options = clone(options);
19261930

1927-
for (const opt of stringValuedEnums) {
1931+
for (const opt of commandLineOptions_stringToEnum) {
19281932
if (!hasProperty(options, opt.name)) {
19291933
continue;
19301934
}
@@ -1946,10 +1950,6 @@ namespace ts {
19461950
return options;
19471951
}
19481952

1949-
const stringValuedEnums = <CommandLineOptionOfCustomType[]>filter(optionDeclarations, o => {
1950-
return typeof o.type === "object" && !forEachValue(<Map<any>> o.type, v => typeof v !== "number");
1951-
});
1952-
19531953
/*
19541954
* This function will compile source text from 'input' argument using specified compiler options.
19551955
* If not options are provided - it will use a set of default compiler options.

tests/cases/unittests/transpile.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ namespace ts {
77
options?: TranspileOptions;
88
expectedOutput?: string;
99
expectedDiagnosticCodes?: number[];
10+
expectedDiagnosticTexts?: string[];
1011
}
1112

12-
function checkDiagnostics(diagnostics: Diagnostic[], expectedDiagnosticCodes: number[] = []) {
13-
for (let i = 0; i < expectedDiagnosticCodes.length; i++) {
14-
assert.equal(expectedDiagnosticCodes[i], diagnostics[i] && diagnostics[i].code, `Could not find expeced diagnostic.`);
13+
function checkDiagnostics(diagnostics: Diagnostic[], expectedDiagnosticCodes: number[] = [], expectedDiagnosticTexts: string[] = []) {
14+
const n = expectedDiagnosticCodes.length;
15+
assert.equal(n, expectedDiagnosticTexts.length);
16+
for (let i = 0; i < n; i++) {
17+
assert.equal(expectedDiagnosticCodes[i], diagnostics[i] && diagnostics[i].code, `Could not find expected diagnostic.`);
18+
assert.equal(expectedDiagnosticTexts[i], diagnostics[i] && diagnostics[i].messageText);
1519
}
16-
assert.equal(diagnostics.length, expectedDiagnosticCodes.length, "Resuting diagnostics count does not match expected");
20+
assert.equal(diagnostics.length, n, "Resuting diagnostics count does not match expected");
1721
}
1822

1923
function test(input: string, testSettings: TranspileTestSettings): void {
@@ -32,7 +36,7 @@ namespace ts {
3236
transpileOptions.reportDiagnostics = true;
3337
const transpileModuleResult = transpileModule(input, transpileOptions);
3438

35-
checkDiagnostics(transpileModuleResult.diagnostics, testSettings.expectedDiagnosticCodes);
39+
checkDiagnostics(transpileModuleResult.diagnostics, testSettings.expectedDiagnosticCodes, testSettings.expectedDiagnosticTexts);
3640

3741
if (testSettings.expectedOutput !== undefined) {
3842
assert.equal(transpileModuleResult.outputText, testSettings.expectedOutput);
@@ -41,7 +45,7 @@ namespace ts {
4145
if (canUseOldTranspile) {
4246
const diagnostics: Diagnostic[] = [];
4347
const transpileResult = transpile(input, transpileOptions.compilerOptions, transpileOptions.fileName, diagnostics, transpileOptions.moduleName);
44-
checkDiagnostics(diagnostics, testSettings.expectedDiagnosticCodes);
48+
checkDiagnostics(diagnostics, testSettings.expectedDiagnosticCodes, testSettings.expectedDiagnosticTexts);
4549
if (testSettings.expectedOutput) {
4650
assert.equal(transpileResult, testSettings.expectedOutput);
4751
}
@@ -313,7 +317,8 @@ var x = 0;`,
313317
it("Fails on bad value", () => {
314318
test(``, {
315319
options: { compilerOptions: { module: <ModuleKind><any>{} } },
316-
expectedDiagnosticCodes: [6046]
320+
expectedDiagnosticCodes: [6046],
321+
expectedDiagnosticTexts: ["Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015'"]
317322
});
318323
});
319324
});

0 commit comments

Comments
 (0)