From 535efd1b5de9cf86a6bf04a4a003f01c5c0d215b Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 10 Sep 2015 14:23:56 -0700 Subject: [PATCH] Encode the conditional presence of 'error' in the type system. --- src/compiler/commandLineParser.ts | 7 ++----- src/compiler/types.ts | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 93153e5fddb..9b7558f315a 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -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((opt).error)); } } } @@ -444,7 +441,7 @@ namespace ts { value = optType[key]; } else { - errors.push(createCompilerDiagnostic(opt.error)); + errors.push(createCompilerDiagnostic((opt).error)); value = 0; } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 47182e39527..f9d1b506274 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2112,17 +2112,30 @@ namespace ts { } /* @internal */ - export interface CommandLineOption { + interface CommandLineOptionBase { name: string; type: string | Map; // "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; // 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,