Encode the conditional presence of 'error' in the type system.

This commit is contained in:
Daniel Rosenwasser 2015-09-10 14:23:56 -07:00
parent 4b15c5f628
commit 535efd1b5d
2 changed files with 17 additions and 7 deletions

View File

@ -327,11 +327,8 @@ namespace ts {
if (hasProperty(map, key)) {
options[opt.name] = map[key];
}
else if (opt.error) {
errors.push(createCompilerDiagnostic(opt.error));
}
else {
Debug.fail(`Command line option for '${opt.name}' doesn't account for invalid options.`);
errors.push(createCompilerDiagnostic((<CommandLineOptionOfCustomType>opt).error));
}
}
}
@ -444,7 +441,7 @@ namespace ts {
value = optType[key];
}
else {
errors.push(createCompilerDiagnostic(opt.error));
errors.push(createCompilerDiagnostic((<CommandLineOptionOfCustomType>opt).error));
value = 0;
}
}

View File

@ -2112,17 +2112,30 @@ namespace ts {
}
/* @internal */
export interface CommandLineOption {
interface CommandLineOptionBase {
name: string;
type: string | Map<number>; // "string", "number", "boolean", or an object literal mapping named values to actual values
isFilePath?: boolean; // True if option value is a path or fileName
shortName?: string; // A short mnemonic for convenience - for instance, 'h' can be used in place of 'help'
description?: DiagnosticMessage; // The message describing what the command line switch does
paramType?: DiagnosticMessage; // The name to be used for a non-boolean option's parameter
error?: DiagnosticMessage; // The error given when the argument does not fit a customized 'type'
experimental?: boolean;
}
/* @internal */
export interface CommandLineOptionOfPrimitiveType extends CommandLineOptionBase {
type: string; // "string" | "number" | "boolean"
}
/* @internal */
export interface CommandLineOptionOfCustomType extends CommandLineOptionBase {
type: Map<number>; // an object literal mapping named values to actual values
error: DiagnosticMessage; // The error given when the argument does not fit a customized 'type'
}
/* @internal */
export type CommandLineOption = CommandLineOptionOfCustomType | CommandLineOptionOfPrimitiveType;
/* @internal */
export const enum CharacterCodes {
nullCharacter = 0,