Respond to PR comments

This commit is contained in:
Andy Hanson 2016-06-06 13:31:37 -07:00
parent d9ec5125be
commit 1fe8a08085
2 changed files with 17 additions and 12 deletions

View File

@ -1920,11 +1920,15 @@ namespace ts {
sourceMapText?: string;
}
const commandLineOptions_stringToEnum = <CommandLineOptionOfCustomType[]>filter(optionDeclarations, o => {
return typeof o.type === "object" && !forEachValue(<Map<any>> 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 = <CommandLineOptionOfCustomType[]>filter(optionDeclarations, o => {
return typeof o.type === "object" && !forEachValue(<Map<any>> 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.

View File

@ -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: <ModuleKind><any>{} } },
expectedDiagnosticCodes: [6046]
expectedDiagnosticCodes: [6046],
expectedDiagnosticTexts: ["Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015'"]
});
});
});