Skip to content

Commit 4475d81

Browse files
committed
Add flags on commandLineOption to indicate strictFlag or option affecting semanticDiagnostics
1 parent d419968 commit 4475d81

File tree

3 files changed

+22
-33
lines changed

3 files changed

+22
-33
lines changed

src/compiler/commandLineParser.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,41 +319,47 @@ namespace ts {
319319
{
320320
name: "noImplicitAny",
321321
type: "boolean",
322+
strictFlag: true,
322323
showInSimplifiedHelpView: true,
323324
category: Diagnostics.Strict_Type_Checking_Options,
324-
description: Diagnostics.Raise_error_on_expressions_and_declarations_with_an_implied_any_type,
325+
description: Diagnostics.Raise_error_on_expressions_and_declarations_with_an_implied_any_type
325326
},
326327
{
327328
name: "strictNullChecks",
328329
type: "boolean",
330+
strictFlag: true,
329331
showInSimplifiedHelpView: true,
330332
category: Diagnostics.Strict_Type_Checking_Options,
331333
description: Diagnostics.Enable_strict_null_checks
332334
},
333335
{
334336
name: "strictFunctionTypes",
335337
type: "boolean",
338+
strictFlag: true,
336339
showInSimplifiedHelpView: true,
337340
category: Diagnostics.Strict_Type_Checking_Options,
338341
description: Diagnostics.Enable_strict_checking_of_function_types
339342
},
340343
{
341344
name: "strictPropertyInitialization",
342345
type: "boolean",
346+
strictFlag: true,
343347
showInSimplifiedHelpView: true,
344348
category: Diagnostics.Strict_Type_Checking_Options,
345349
description: Diagnostics.Enable_strict_checking_of_property_initialization_in_classes
346350
},
347351
{
348352
name: "noImplicitThis",
349353
type: "boolean",
354+
strictFlag: true,
350355
showInSimplifiedHelpView: true,
351356
category: Diagnostics.Strict_Type_Checking_Options,
352357
description: Diagnostics.Raise_error_on_this_expressions_with_an_implied_any_type,
353358
},
354359
{
355360
name: "alwaysStrict",
356361
type: "boolean",
362+
strictFlag: true,
357363
showInSimplifiedHelpView: true,
358364
category: Diagnostics.Strict_Type_Checking_Options,
359365
description: Diagnostics.Parse_in_strict_mode_and_emit_use_strict_for_each_source_file
@@ -363,27 +369,31 @@ namespace ts {
363369
{
364370
name: "noUnusedLocals",
365371
type: "boolean",
372+
affectsSemanticDiagnostics: true,
366373
showInSimplifiedHelpView: true,
367374
category: Diagnostics.Additional_Checks,
368375
description: Diagnostics.Report_errors_on_unused_locals,
369376
},
370377
{
371378
name: "noUnusedParameters",
372379
type: "boolean",
380+
affectsSemanticDiagnostics: true,
373381
showInSimplifiedHelpView: true,
374382
category: Diagnostics.Additional_Checks,
375383
description: Diagnostics.Report_errors_on_unused_parameters,
376384
},
377385
{
378386
name: "noImplicitReturns",
379387
type: "boolean",
388+
affectsSemanticDiagnostics: true,
380389
showInSimplifiedHelpView: true,
381390
category: Diagnostics.Additional_Checks,
382391
description: Diagnostics.Report_error_when_not_all_code_paths_in_function_return_a_value
383392
},
384393
{
385394
name: "noFallthroughCasesInSwitch",
386395
type: "boolean",
396+
affectsSemanticDiagnostics: true,
387397
showInSimplifiedHelpView: true,
388398
category: Diagnostics.Additional_Checks,
389399
description: Diagnostics.Report_errors_for_fallthrough_cases_in_switch_statement
@@ -640,6 +650,7 @@ namespace ts {
640650
{
641651
name: "noImplicitUseStrict",
642652
type: "boolean",
653+
affectsSemanticDiagnostics: true,
643654
category: Diagnostics.Advanced_Options,
644655
description: Diagnostics.Do_not_emit_use_strict_directives_in_module_output
645656
},
@@ -678,24 +689,28 @@ namespace ts {
678689
{
679690
name: "allowUnusedLabels",
680691
type: "boolean",
692+
affectsSemanticDiagnostics: true,
681693
category: Diagnostics.Advanced_Options,
682694
description: Diagnostics.Do_not_report_errors_on_unused_labels
683695
},
684696
{
685697
name: "allowUnreachableCode",
686698
type: "boolean",
699+
affectsSemanticDiagnostics: true,
687700
category: Diagnostics.Advanced_Options,
688701
description: Diagnostics.Do_not_report_errors_on_unreachable_code
689702
},
690703
{
691704
name: "suppressExcessPropertyErrors",
692705
type: "boolean",
706+
affectsSemanticDiagnostics: true,
693707
category: Diagnostics.Advanced_Options,
694708
description: Diagnostics.Suppress_excess_property_checks_for_object_literals,
695709
},
696710
{
697711
name: "suppressImplicitAnyIndexErrors",
698712
type: "boolean",
713+
affectsSemanticDiagnostics: true,
699714
category: Diagnostics.Advanced_Options,
700715
description: Diagnostics.Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures,
701716
},
@@ -714,6 +729,7 @@ namespace ts {
714729
{
715730
name: "noStrictGenericChecks",
716731
type: "boolean",
732+
affectsSemanticDiagnostics: true,
717733
category: Diagnostics.Advanced_Options,
718734
description: Diagnostics.Disable_strict_checking_of_generic_signatures_in_function_types,
719735
},

src/compiler/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4540,6 +4540,8 @@ namespace ts {
45404540
isCommandLineOnly?: boolean;
45414541
showInSimplifiedHelpView?: boolean;
45424542
category?: DiagnosticMessage;
4543+
strictFlag?: true; // true if the option is one of the flag under strict
4544+
affectsSemanticDiagnostics?: true; // true if option affects semantic diagnostics
45434545
}
45444546

45454547
/* @internal */

src/compiler/utilities.ts

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6972,38 +6972,9 @@ namespace ts {
69726972
return false;
69736973
}
69746974

6975-
return changedCompileOptionValueOf(newOptions, oldOptions, [
6976-
"noImplicitReturns",
6977-
"strict",
6978-
"suppressExcessPropertyErrors",
6979-
"suppressImplicitAnyIndexErrors",
6980-
"noFallthroughCasesInSwitch",
6981-
"noStrictGenericChecks",
6982-
"noUnusedLocals",
6983-
"noUnusedParameters",
6984-
"noImplicitUseStrict"
6985-
]) || changedStrictOptionValueOf(newOptions, oldOptions, [
6986-
"noImplicitAny",
6987-
"noImplicitThis",
6988-
"strictNullChecks",
6989-
"strictFunctionTypes",
6990-
"strictPropertyInitialization",
6991-
"alwaysStrict"
6992-
]);
6993-
}
6994-
6995-
function changedStrictOptionValueOf(newOptions: CompilerOptions, oldOptions: CompilerOptions, flags: StrictOptionName[]) {
6996-
for (const flag of flags) {
6997-
if (getStrictOptionValue(newOptions, flag) !== getStrictOptionValue(oldOptions, flag)) {
6998-
return true;
6999-
}
7000-
}
7001-
return false;
7002-
}
7003-
7004-
function changedCompileOptionValueOf(newOptions: CompilerOptions, oldOptions: CompilerOptions, optionKeys: (keyof CompilerOptions)[]) {
7005-
for (const optionKey of optionKeys) {
7006-
if (newOptions[optionKey] !== oldOptions[optionKey]) {
6975+
for (const option of optionDeclarations) {
6976+
if ((option.strictFlag && getStrictOptionValue(newOptions, option.name as StrictOptionName) !== getStrictOptionValue(oldOptions, option.name as StrictOptionName)) ||
6977+
(option.affectsSemanticDiagnostics && !newOptions[option.name] !== !oldOptions[option.name])) {
70076978
return true;
70086979
}
70096980
}

0 commit comments

Comments
 (0)