From 4475d81b9c7f5dfcbe7efaee8abb6eefe9254bb9 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 6 Aug 2018 14:54:57 -0700 Subject: [PATCH] Add flags on commandLineOption to indicate strictFlag or option affecting semanticDiagnostics --- src/compiler/commandLineParser.ts | 18 +++++++++++++++- src/compiler/types.ts | 2 ++ src/compiler/utilities.ts | 35 +++---------------------------- 3 files changed, 22 insertions(+), 33 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 55f224caec..9845ec76fd 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -319,13 +319,15 @@ namespace ts { { name: "noImplicitAny", type: "boolean", + strictFlag: true, showInSimplifiedHelpView: true, category: Diagnostics.Strict_Type_Checking_Options, - description: Diagnostics.Raise_error_on_expressions_and_declarations_with_an_implied_any_type, + description: Diagnostics.Raise_error_on_expressions_and_declarations_with_an_implied_any_type }, { name: "strictNullChecks", type: "boolean", + strictFlag: true, showInSimplifiedHelpView: true, category: Diagnostics.Strict_Type_Checking_Options, description: Diagnostics.Enable_strict_null_checks @@ -333,6 +335,7 @@ namespace ts { { name: "strictFunctionTypes", type: "boolean", + strictFlag: true, showInSimplifiedHelpView: true, category: Diagnostics.Strict_Type_Checking_Options, description: Diagnostics.Enable_strict_checking_of_function_types @@ -340,6 +343,7 @@ namespace ts { { name: "strictPropertyInitialization", type: "boolean", + strictFlag: true, showInSimplifiedHelpView: true, category: Diagnostics.Strict_Type_Checking_Options, description: Diagnostics.Enable_strict_checking_of_property_initialization_in_classes @@ -347,6 +351,7 @@ namespace ts { { name: "noImplicitThis", type: "boolean", + strictFlag: true, showInSimplifiedHelpView: true, category: Diagnostics.Strict_Type_Checking_Options, description: Diagnostics.Raise_error_on_this_expressions_with_an_implied_any_type, @@ -354,6 +359,7 @@ namespace ts { { name: "alwaysStrict", type: "boolean", + strictFlag: true, showInSimplifiedHelpView: true, category: Diagnostics.Strict_Type_Checking_Options, description: Diagnostics.Parse_in_strict_mode_and_emit_use_strict_for_each_source_file @@ -363,6 +369,7 @@ namespace ts { { name: "noUnusedLocals", type: "boolean", + affectsSemanticDiagnostics: true, showInSimplifiedHelpView: true, category: Diagnostics.Additional_Checks, description: Diagnostics.Report_errors_on_unused_locals, @@ -370,6 +377,7 @@ namespace ts { { name: "noUnusedParameters", type: "boolean", + affectsSemanticDiagnostics: true, showInSimplifiedHelpView: true, category: Diagnostics.Additional_Checks, description: Diagnostics.Report_errors_on_unused_parameters, @@ -377,6 +385,7 @@ namespace ts { { name: "noImplicitReturns", type: "boolean", + affectsSemanticDiagnostics: true, showInSimplifiedHelpView: true, category: Diagnostics.Additional_Checks, description: Diagnostics.Report_error_when_not_all_code_paths_in_function_return_a_value @@ -384,6 +393,7 @@ namespace ts { { name: "noFallthroughCasesInSwitch", type: "boolean", + affectsSemanticDiagnostics: true, showInSimplifiedHelpView: true, category: Diagnostics.Additional_Checks, description: Diagnostics.Report_errors_for_fallthrough_cases_in_switch_statement @@ -640,6 +650,7 @@ namespace ts { { name: "noImplicitUseStrict", type: "boolean", + affectsSemanticDiagnostics: true, category: Diagnostics.Advanced_Options, description: Diagnostics.Do_not_emit_use_strict_directives_in_module_output }, @@ -678,24 +689,28 @@ namespace ts { { name: "allowUnusedLabels", type: "boolean", + affectsSemanticDiagnostics: true, category: Diagnostics.Advanced_Options, description: Diagnostics.Do_not_report_errors_on_unused_labels }, { name: "allowUnreachableCode", type: "boolean", + affectsSemanticDiagnostics: true, category: Diagnostics.Advanced_Options, description: Diagnostics.Do_not_report_errors_on_unreachable_code }, { name: "suppressExcessPropertyErrors", type: "boolean", + affectsSemanticDiagnostics: true, category: Diagnostics.Advanced_Options, description: Diagnostics.Suppress_excess_property_checks_for_object_literals, }, { name: "suppressImplicitAnyIndexErrors", type: "boolean", + affectsSemanticDiagnostics: true, category: Diagnostics.Advanced_Options, description: Diagnostics.Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures, }, @@ -714,6 +729,7 @@ namespace ts { { name: "noStrictGenericChecks", type: "boolean", + affectsSemanticDiagnostics: true, category: Diagnostics.Advanced_Options, description: Diagnostics.Disable_strict_checking_of_generic_signatures_in_function_types, }, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index f66c0c02e3..2fb504fef2 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4540,6 +4540,8 @@ namespace ts { isCommandLineOnly?: boolean; showInSimplifiedHelpView?: boolean; category?: DiagnosticMessage; + strictFlag?: true; // true if the option is one of the flag under strict + affectsSemanticDiagnostics?: true; // true if option affects semantic diagnostics } /* @internal */ diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index dcc4f968f2..77db371f70 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -6972,38 +6972,9 @@ namespace ts { return false; } - return changedCompileOptionValueOf(newOptions, oldOptions, [ - "noImplicitReturns", - "strict", - "suppressExcessPropertyErrors", - "suppressImplicitAnyIndexErrors", - "noFallthroughCasesInSwitch", - "noStrictGenericChecks", - "noUnusedLocals", - "noUnusedParameters", - "noImplicitUseStrict" - ]) || changedStrictOptionValueOf(newOptions, oldOptions, [ - "noImplicitAny", - "noImplicitThis", - "strictNullChecks", - "strictFunctionTypes", - "strictPropertyInitialization", - "alwaysStrict" - ]); - } - - function changedStrictOptionValueOf(newOptions: CompilerOptions, oldOptions: CompilerOptions, flags: StrictOptionName[]) { - for (const flag of flags) { - if (getStrictOptionValue(newOptions, flag) !== getStrictOptionValue(oldOptions, flag)) { - return true; - } - } - return false; - } - - function changedCompileOptionValueOf(newOptions: CompilerOptions, oldOptions: CompilerOptions, optionKeys: (keyof CompilerOptions)[]) { - for (const optionKey of optionKeys) { - if (newOptions[optionKey] !== oldOptions[optionKey]) { + for (const option of optionDeclarations) { + if ((option.strictFlag && getStrictOptionValue(newOptions, option.name as StrictOptionName) !== getStrictOptionValue(oldOptions, option.name as StrictOptionName)) || + (option.affectsSemanticDiagnostics && !newOptions[option.name] !== !oldOptions[option.name])) { return true; } }