diff --git a/src/services/services.ts b/src/services/services.ts index 2664c430912..c64610c7509 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1920,11 +1920,15 @@ namespace ts { sourceMapText?: string; } + const commandLineOptions_stringToEnum = filter(optionDeclarations, o => { + return typeof o.type === "object" && !forEachValue(> o.type, v => typeof v !== "number"); + }); + /** JS users may pass in string values for enum compiler options (such as ModuleKind), so convert. */ function fixupCompilerOptions(options: CompilerOptions, diagnostics: Diagnostic[]) { options = clone(options); - for (const opt of stringValuedEnums) { + for (const opt of commandLineOptions_stringToEnum) { if (!hasProperty(options, opt.name)) { continue; } @@ -1946,10 +1950,6 @@ namespace ts { return options; } - const stringValuedEnums = filter(optionDeclarations, o => { - return typeof o.type === "object" && !forEachValue(> o.type, v => typeof v !== "number"); - }); - /* * This function will compile source text from 'input' argument using specified compiler options. * If not options are provided - it will use a set of default compiler options. diff --git a/tests/cases/unittests/transpile.ts b/tests/cases/unittests/transpile.ts index ca2c5939f35..e694f943e1a 100644 --- a/tests/cases/unittests/transpile.ts +++ b/tests/cases/unittests/transpile.ts @@ -7,13 +7,17 @@ namespace ts { options?: TranspileOptions; expectedOutput?: string; expectedDiagnosticCodes?: number[]; + expectedDiagnosticTexts?: string[]; } - function checkDiagnostics(diagnostics: Diagnostic[], expectedDiagnosticCodes: number[] = []) { - for (let i = 0; i < expectedDiagnosticCodes.length; i++) { - assert.equal(expectedDiagnosticCodes[i], diagnostics[i] && diagnostics[i].code, `Could not find expeced diagnostic.`); + function checkDiagnostics(diagnostics: Diagnostic[], expectedDiagnosticCodes: number[] = [], expectedDiagnosticTexts: string[] = []) { + const n = expectedDiagnosticCodes.length; + assert.equal(n, expectedDiagnosticTexts.length); + for (let i = 0; i < n; i++) { + assert.equal(expectedDiagnosticCodes[i], diagnostics[i] && diagnostics[i].code, `Could not find expected diagnostic.`); + assert.equal(expectedDiagnosticTexts[i], diagnostics[i] && diagnostics[i].messageText); } - assert.equal(diagnostics.length, expectedDiagnosticCodes.length, "Resuting diagnostics count does not match expected"); + assert.equal(diagnostics.length, n, "Resuting diagnostics count does not match expected"); } function test(input: string, testSettings: TranspileTestSettings): void { @@ -32,7 +36,7 @@ namespace ts { transpileOptions.reportDiagnostics = true; const transpileModuleResult = transpileModule(input, transpileOptions); - checkDiagnostics(transpileModuleResult.diagnostics, testSettings.expectedDiagnosticCodes); + checkDiagnostics(transpileModuleResult.diagnostics, testSettings.expectedDiagnosticCodes, testSettings.expectedDiagnosticTexts); if (testSettings.expectedOutput !== undefined) { assert.equal(transpileModuleResult.outputText, testSettings.expectedOutput); @@ -41,7 +45,7 @@ namespace ts { if (canUseOldTranspile) { const diagnostics: Diagnostic[] = []; const transpileResult = transpile(input, transpileOptions.compilerOptions, transpileOptions.fileName, diagnostics, transpileOptions.moduleName); - checkDiagnostics(diagnostics, testSettings.expectedDiagnosticCodes); + checkDiagnostics(diagnostics, testSettings.expectedDiagnosticCodes, testSettings.expectedDiagnosticTexts); if (testSettings.expectedOutput) { assert.equal(transpileResult, testSettings.expectedOutput); } @@ -313,7 +317,8 @@ var x = 0;`, it("Fails on bad value", () => { test(``, { options: { compilerOptions: { module: {} } }, - expectedDiagnosticCodes: [6046] + expectedDiagnosticCodes: [6046], + expectedDiagnosticTexts: ["Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015'"] }); }); });