From f6fc444b33f86ed7e70bd0536380fdcf3c88e92c Mon Sep 17 00:00:00 2001 From: navya9singh <108360753+navya9singh@users.noreply.github.com> Date: Tue, 17 Jan 2023 12:31:23 -0800 Subject: [PATCH] Fix(51828): `extends` field in `tsconfig.json` does nothing with empty string (#51981) --- src/compiler/commandLineParser.ts | 11 ++++++++--- src/compiler/diagnosticMessages.json | 4 ++++ .../unittests/config/configurationExtension.ts | 12 ++++++++++++ .../plugins/getSupportedCodeFixes-can-be-proxied.js | 3 +++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index f4a00631c0b..a0b9471128c 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -3279,7 +3279,7 @@ function parseOwnConfigOfJson( json.compileOnSave = convertCompileOnSaveOptionFromJson(json, basePath, errors); let extendedConfigPath: string | string[] | undefined; - if (json.extends) { + if (json.extends || json.extends === "") { if (!isCompilerOptionsValue(extendsOptionDeclaration, json.extends)) { errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "extends", getCompilerOptionValueTypeString(extendsOptionDeclaration))); } @@ -3293,7 +3293,7 @@ function parseOwnConfigOfJson( for (const fileName of json.extends as unknown[]) { if (isString(fileName)) { extendedConfigPath = append(extendedConfigPath, getExtendsConfigPath(fileName, host, newBase, errors, createCompilerDiagnostic)); - } + } else { errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "extends", getCompilerOptionValueTypeString(extendsOptionDeclaration.element))); } @@ -3428,7 +3428,12 @@ function getExtendsConfigPath( if (resolved.resolvedModule) { return resolved.resolvedModule.resolvedFileName; } - errors.push(createDiagnostic(Diagnostics.File_0_not_found, extendedConfig)); + if (extendedConfig === "") { + errors.push(createDiagnostic(Diagnostics.Compiler_option_0_cannot_be_given_an_empty_string, "extends")); + } + else { + errors.push(createDiagnostic(Diagnostics.File_0_not_found, extendedConfig)); + } return undefined; } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 377bc39a74d..16102a7a392 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -7636,5 +7636,9 @@ "The value '{0}' cannot be used here.": { "category": "Error", "code": 18050 + }, + "Compiler option '{0}' cannot be given an empty string.": { + "category": "Error", + "code": 18051 } } diff --git a/src/testRunner/unittests/config/configurationExtension.ts b/src/testRunner/unittests/config/configurationExtension.ts index e4b3e598da7..db1b6dd9f7d 100644 --- a/src/testRunner/unittests/config/configurationExtension.ts +++ b/src/testRunner/unittests/config/configurationExtension.ts @@ -199,6 +199,8 @@ function createFileSystem(ignoreCase: boolean, cwd: string, root: string) { }), "dev/extends.json": JSON.stringify({ extends: 42 }), "dev/extends2.json": JSON.stringify({ extends: "configs/base" }), + "dev/extends3.json": JSON.stringify({ extends: "" }), + "dev/extends4.json": JSON.stringify({ extends: [""] }), "dev/main.ts": "", "dev/supplemental.ts": "", "dev/tests/unit/spec.ts": "", @@ -358,6 +360,16 @@ describe("unittests:: config:: configurationExtension", () => { messageText: `Compiler option 'extends' requires a value of type string or Array.` }]); + testFailure("can error when 'extends' is given an empty string", "extends3.json", [{ + code: 18051, + messageText: `Compiler option 'extends' cannot be given an empty string.` + }]); + + testFailure("can error when 'extends' is given an empty string in an array", "extends4.json", [{ + code: 18051, + messageText: `Compiler option 'extends' cannot be given an empty string.` + }]); + testSuccess("can overwrite compiler options using extended 'null'", "configs/third.json", { allowJs: true, noImplicitAny: true, diff --git a/tests/baselines/reference/tsserver/plugins/getSupportedCodeFixes-can-be-proxied.js b/tests/baselines/reference/tsserver/plugins/getSupportedCodeFixes-can-be-proxied.js index eaf791e9d05..855976efc5b 100644 --- a/tests/baselines/reference/tsserver/plugins/getSupportedCodeFixes-can-be-proxied.js +++ b/tests/baselines/reference/tsserver/plugins/getSupportedCodeFixes-can-be-proxied.js @@ -1470,6 +1470,7 @@ Info 32 [00:01:13.000] response: "18048", "18049", "18050", + "18051", "80005", "80003", "80008", @@ -2804,6 +2805,7 @@ Info 38 [00:01:19.000] response: "18048", "18049", "18050", + "18051", "80005", "80003", "80008", @@ -4050,6 +4052,7 @@ Info 40 [00:01:21.000] response: "18048", "18049", "18050", + "18051", "80005", "80003", "80008",