From 56d94d59f5d1730c571a1e21065950ad4c3cc6f6 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 27 Oct 2021 13:33:05 -0700 Subject: [PATCH 1/2] Add error on new module/moduleResolution modes when used in non-nightly TS --- src/compiler/diagnosticMessages.json | 5 +++++ src/compiler/program.ts | 19 +++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index e842f75a609ff..7d81677c4fab1 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3770,6 +3770,11 @@ "category": "Error", "code": 4123 }, + "Compiler option '{0}' of value '{1}' is unstable. Use nightly TypeScript to silence this error.": { + "category": "Error", + "code": 4124 + }, + "The current host does not support the '{0}' option.": { "category": "Error", "code": 5001 diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 0847e2dbfc3d7..180d6c2a7c4c9 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -3160,6 +3160,21 @@ namespace ts { } function verifyCompilerOptions() { + const isNightly = stringContains(version, "-dev"); + if (!isNightly) { + if (getEmitModuleKind(options) === ModuleKind.Node12) { + createOptionValueDiagnostic("module", Diagnostics.Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error, "module", "node12"); + } + else if (getEmitModuleKind(options) === ModuleKind.NodeNext) { + createOptionValueDiagnostic("module", Diagnostics.Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error, "module", "nodenext"); + } + else if (getEmitModuleResolutionKind(options) === ModuleResolutionKind.Node12) { + createOptionValueDiagnostic("moduleResolution", Diagnostics.Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error, "moduleResolution", "node12"); + } + else if (getEmitModuleResolutionKind(options) === ModuleResolutionKind.NodeNext) { + createOptionValueDiagnostic("moduleResolution", Diagnostics.Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error, "moduleResolution", "nodenext"); + } + } if (options.strictPropertyInitialization && !getStrictOptionValue(options, "strictNullChecks")) { createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "strictPropertyInitialization", "strictNullChecks"); } @@ -3696,8 +3711,8 @@ namespace ts { createDiagnosticForOption(/*onKey*/ true, option1, option2, message, option1, option2, option3); } - function createOptionValueDiagnostic(option1: string, message: DiagnosticMessage, arg0?: string) { - createDiagnosticForOption(/*onKey*/ false, option1, /*option2*/ undefined, message, arg0); + function createOptionValueDiagnostic(option1: string, message: DiagnosticMessage, arg0?: string, arg1?: string) { + createDiagnosticForOption(/*onKey*/ false, option1, /*option2*/ undefined, message, arg0, arg1); } function createDiagnosticForReference(sourceFile: JsonSourceFile | undefined, index: number, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number) { From 5e41c0e2e02e1c008d21da25bdae36ebee106a04 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 27 Oct 2021 13:58:51 -0700 Subject: [PATCH 2/2] Update diagnostic --- src/compiler/diagnosticMessages.json | 2 +- src/compiler/program.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 7d81677c4fab1..c3ca4877500c8 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3770,7 +3770,7 @@ "category": "Error", "code": 4123 }, - "Compiler option '{0}' of value '{1}' is unstable. Use nightly TypeScript to silence this error.": { + "Compiler option '{0}' of value '{1}' is unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'.": { "category": "Error", "code": 4124 }, diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 180d6c2a7c4c9..57fa55bfb494f 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -3163,16 +3163,16 @@ namespace ts { const isNightly = stringContains(version, "-dev"); if (!isNightly) { if (getEmitModuleKind(options) === ModuleKind.Node12) { - createOptionValueDiagnostic("module", Diagnostics.Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error, "module", "node12"); + createOptionValueDiagnostic("module", Diagnostics.Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next, "module", "node12"); } else if (getEmitModuleKind(options) === ModuleKind.NodeNext) { - createOptionValueDiagnostic("module", Diagnostics.Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error, "module", "nodenext"); + createOptionValueDiagnostic("module", Diagnostics.Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next, "module", "nodenext"); } else if (getEmitModuleResolutionKind(options) === ModuleResolutionKind.Node12) { - createOptionValueDiagnostic("moduleResolution", Diagnostics.Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error, "moduleResolution", "node12"); + createOptionValueDiagnostic("moduleResolution", Diagnostics.Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next, "moduleResolution", "node12"); } else if (getEmitModuleResolutionKind(options) === ModuleResolutionKind.NodeNext) { - createOptionValueDiagnostic("moduleResolution", Diagnostics.Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error, "moduleResolution", "nodenext"); + createOptionValueDiagnostic("moduleResolution", Diagnostics.Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next, "moduleResolution", "nodenext"); } } if (options.strictPropertyInitialization && !getStrictOptionValue(options, "strictNullChecks")) {