From 769d54213d74336488a4d759562f61b2750e14a7 Mon Sep 17 00:00:00 2001 From: KlyneChrysler Date: Thu, 16 Jul 2026 14:14:21 +0800 Subject: [PATCH] Error with a suggestion of '.' for empty project reference paths An empty reference path previously reported the generic TS18051 empty string message. Use a dedicated diagnostic that suggests '.' as discussed in #4484. Fixes #4484 --- internal/diagnostics/diagnostics_generated.go | 4 +++ .../diagnostics/extraDiagnosticMessages.json | 4 +++ internal/tsoptions/tsconfigparsing.go | 2 +- internal/tsoptions/tsconfigparsing_test.go | 13 +++++++++ ... for empty reference path with json api.js | 24 ++++++++++++++++ ... reference path with jsonSourceFile api.js | 28 +++++++++++++++++++ ...eports-invalid-project-reference-fields.js | 2 +- 7 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 testdata/baselines/reference/config/tsconfigParsing/generates errors for empty reference path with json api.js create mode 100644 testdata/baselines/reference/config/tsconfigParsing/generates errors for empty reference path with jsonSourceFile api.js diff --git a/internal/diagnostics/diagnostics_generated.go b/internal/diagnostics/diagnostics_generated.go index 86ffdcea417..62c91e1f962 100644 --- a/internal/diagnostics/diagnostics_generated.go +++ b/internal/diagnostics/diagnostics_generated.go @@ -3738,6 +3738,8 @@ var The_value_0_cannot_be_used_here = &Message{code: 18050, category: CategoryEr var Compiler_option_0_cannot_be_given_an_empty_string = &Message{code: 18051, category: CategoryError, key: "Compiler_option_0_cannot_be_given_an_empty_string_18051", text: "Compiler option '{0}' cannot be given an empty string."} +var A_project_reference_path_cannot_be_an_empty_string_Did_you_mean = &Message{code: 18052, category: CategoryError, key: "A_project_reference_path_cannot_be_an_empty_string_Did_you_mean_18052", text: "A project reference path cannot be an empty string. Did you mean '.'?"} + var Its_type_0_is_not_a_valid_JSX_element_type = &Message{code: 18053, category: CategoryError, key: "Its_type_0_is_not_a_valid_JSX_element_type_18053", text: "Its type '{0}' is not a valid JSX element type."} var X_await_using_statements_cannot_be_used_inside_a_class_static_block = &Message{code: 18054, category: CategoryError, key: "await_using_statements_cannot_be_used_inside_a_class_static_block_18054", text: "'await using' statements cannot be used inside a class static block."} @@ -8048,6 +8050,8 @@ func keyToMessage(key Key) *Message { return The_value_0_cannot_be_used_here case "Compiler_option_0_cannot_be_given_an_empty_string_18051": return Compiler_option_0_cannot_be_given_an_empty_string + case "A_project_reference_path_cannot_be_an_empty_string_Did_you_mean_18052": + return A_project_reference_path_cannot_be_an_empty_string_Did_you_mean case "Its_type_0_is_not_a_valid_JSX_element_type_18053": return Its_type_0_is_not_a_valid_JSX_element_type case "await_using_statements_cannot_be_used_inside_a_class_static_block_18054": diff --git a/internal/diagnostics/extraDiagnosticMessages.json b/internal/diagnostics/extraDiagnosticMessages.json index 10ea4408af6..71cddd11b86 100644 --- a/internal/diagnostics/extraDiagnosticMessages.json +++ b/internal/diagnostics/extraDiagnosticMessages.json @@ -43,6 +43,10 @@ "category": "Error", "code": 5090 }, + "A project reference path cannot be an empty string. Did you mean '.'?": { + "category": "Error", + "code": 18052 + }, "A JSDoc '@type' tag on a function must have a signature with the correct number of arguments.": { "category": "Error", "code": 8030 diff --git a/internal/tsoptions/tsconfigparsing.go b/internal/tsoptions/tsconfigparsing.go index b1e1955b1f9..ef7161aab3d 100644 --- a/internal/tsoptions/tsconfigparsing.go +++ b/internal/tsoptions/tsconfigparsing.go @@ -1358,7 +1358,7 @@ func parseJsonConfigFileContentWorker( continue } if ref.reference.Path == "" { - errors = append(errors, createDiagnosticAtProjectReferenceProperty(sourceFile, index, "path", diagnostics.Compiler_option_0_cannot_be_given_an_empty_string, "reference.path")) + errors = append(errors, createDiagnosticAtProjectReferenceProperty(sourceFile, index, "path", diagnostics.A_project_reference_path_cannot_be_an_empty_string_Did_you_mean)) continue } if ref.hasCircular && !ref.circularValid { diff --git a/internal/tsoptions/tsconfigparsing_test.go b/internal/tsoptions/tsconfigparsing_test.go index a53b3a66d27..86d71f5bc7c 100644 --- a/internal/tsoptions/tsconfigparsing_test.go +++ b/internal/tsoptions/tsconfigparsing_test.go @@ -302,6 +302,19 @@ var parseJsonConfigFileTests = []parseJsonConfigTestCase{ allFileList: map[string]string{"/apath/a.ts": ""}, }}, }, + { + title: "generates errors for empty reference path", + noSubmoduleBaseline: true, + input: []testConfig{{ + jsonText: `{ + "references": [{ "path": "" }], + "files": ["a.ts"] + }`, + configFileName: "/apath/tsconfig.json", + basePath: "/apath", + allFileList: map[string]string{"/apath/a.ts": ""}, + }}, + }, { title: "exclude outDir unless overridden", input: []testConfig{{ diff --git a/testdata/baselines/reference/config/tsconfigParsing/generates errors for empty reference path with json api.js b/testdata/baselines/reference/config/tsconfigParsing/generates errors for empty reference path with json api.js new file mode 100644 index 00000000000..85a74a4bd92 --- /dev/null +++ b/testdata/baselines/reference/config/tsconfigParsing/generates errors for empty reference path with json api.js @@ -0,0 +1,24 @@ +Fs:: +//// [/apath/a.ts] + + +//// [/apath/tsconfig.json] +{ + "references": [{ "path": "" }], + "files": ["a.ts"] + } + + +configFileName:: /apath/tsconfig.json +CompilerOptions:: +{ + "configFilePath": "/apath/tsconfig.json" +} + +TypeAcquisition:: +{} + +FileNames:: +/apath/a.ts +Errors:: +error TS18052: A project reference path cannot be an empty string. Did you mean '.'? diff --git a/testdata/baselines/reference/config/tsconfigParsing/generates errors for empty reference path with jsonSourceFile api.js b/testdata/baselines/reference/config/tsconfigParsing/generates errors for empty reference path with jsonSourceFile api.js new file mode 100644 index 00000000000..e147b73e1ce --- /dev/null +++ b/testdata/baselines/reference/config/tsconfigParsing/generates errors for empty reference path with jsonSourceFile api.js @@ -0,0 +1,28 @@ +Fs:: +//// [/apath/a.ts] + + +//// [/apath/tsconfig.json] +{ + "references": [{ "path": "" }], + "files": ["a.ts"] + } + + +configFileName:: /apath/tsconfig.json +CompilerOptions:: +{ + "configFilePath": "/apath/tsconfig.json" +} + +TypeAcquisition:: +{} + +FileNames:: +/apath/a.ts +Errors:: +tsconfig.json:2:42 - error TS18052: A project reference path cannot be an empty string. Did you mean '.'? + +2 "references": [{ "path": "" }], +   ~~ + diff --git a/testdata/baselines/reference/tsbuild/configFileErrors/reports-invalid-project-reference-fields.js b/testdata/baselines/reference/tsbuild/configFileErrors/reports-invalid-project-reference-fields.js index d3e97b877a8..a0ecb5a4022 100644 --- a/testdata/baselines/reference/tsbuild/configFileErrors/reports-invalid-project-reference-fields.js +++ b/testdata/baselines/reference/tsbuild/configFileErrors/reports-invalid-project-reference-fields.js @@ -60,7 +60,7 @@ Output:: 9 { "path": "./utils", "circular": "yes" },    ~~~~~ -tsconfig.json:10:19 - error TS18051: Compiler option 'reference.path' cannot be given an empty string. +tsconfig.json:10:19 - error TS18052: A project reference path cannot be an empty string. Did you mean '.'? 10 { "path": "" },    ~~