Skip to content

Commit f6fc444

Browse files
authored
Fix(51828): extends field in tsconfig.json does nothing with empty string (#51981)
1 parent 9c9d4b0 commit f6fc444

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

src/compiler/commandLineParser.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3279,7 +3279,7 @@ function parseOwnConfigOfJson(
32793279
json.compileOnSave = convertCompileOnSaveOptionFromJson(json, basePath, errors);
32803280
let extendedConfigPath: string | string[] | undefined;
32813281

3282-
if (json.extends) {
3282+
if (json.extends || json.extends === "") {
32833283
if (!isCompilerOptionsValue(extendsOptionDeclaration, json.extends)) {
32843284
errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "extends", getCompilerOptionValueTypeString(extendsOptionDeclaration)));
32853285
}
@@ -3293,7 +3293,7 @@ function parseOwnConfigOfJson(
32933293
for (const fileName of json.extends as unknown[]) {
32943294
if (isString(fileName)) {
32953295
extendedConfigPath = append(extendedConfigPath, getExtendsConfigPath(fileName, host, newBase, errors, createCompilerDiagnostic));
3296-
}
3296+
}
32973297
else {
32983298
errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "extends", getCompilerOptionValueTypeString(extendsOptionDeclaration.element)));
32993299
}
@@ -3428,7 +3428,12 @@ function getExtendsConfigPath(
34283428
if (resolved.resolvedModule) {
34293429
return resolved.resolvedModule.resolvedFileName;
34303430
}
3431-
errors.push(createDiagnostic(Diagnostics.File_0_not_found, extendedConfig));
3431+
if (extendedConfig === "") {
3432+
errors.push(createDiagnostic(Diagnostics.Compiler_option_0_cannot_be_given_an_empty_string, "extends"));
3433+
}
3434+
else {
3435+
errors.push(createDiagnostic(Diagnostics.File_0_not_found, extendedConfig));
3436+
}
34323437
return undefined;
34333438
}
34343439

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7636,5 +7636,9 @@
76367636
"The value '{0}' cannot be used here.": {
76377637
"category": "Error",
76387638
"code": 18050
7639+
},
7640+
"Compiler option '{0}' cannot be given an empty string.": {
7641+
"category": "Error",
7642+
"code": 18051
76397643
}
76407644
}

src/testRunner/unittests/config/configurationExtension.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ function createFileSystem(ignoreCase: boolean, cwd: string, root: string) {
199199
}),
200200
"dev/extends.json": JSON.stringify({ extends: 42 }),
201201
"dev/extends2.json": JSON.stringify({ extends: "configs/base" }),
202+
"dev/extends3.json": JSON.stringify({ extends: "" }),
203+
"dev/extends4.json": JSON.stringify({ extends: [""] }),
202204
"dev/main.ts": "",
203205
"dev/supplemental.ts": "",
204206
"dev/tests/unit/spec.ts": "",
@@ -358,6 +360,16 @@ describe("unittests:: config:: configurationExtension", () => {
358360
messageText: `Compiler option 'extends' requires a value of type string or Array.`
359361
}]);
360362

363+
testFailure("can error when 'extends' is given an empty string", "extends3.json", [{
364+
code: 18051,
365+
messageText: `Compiler option 'extends' cannot be given an empty string.`
366+
}]);
367+
368+
testFailure("can error when 'extends' is given an empty string in an array", "extends4.json", [{
369+
code: 18051,
370+
messageText: `Compiler option 'extends' cannot be given an empty string.`
371+
}]);
372+
361373
testSuccess("can overwrite compiler options using extended 'null'", "configs/third.json", {
362374
allowJs: true,
363375
noImplicitAny: true,

tests/baselines/reference/tsserver/plugins/getSupportedCodeFixes-can-be-proxied.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,6 +1470,7 @@ Info 32 [00:01:13.000] response:
14701470
"18048",
14711471
"18049",
14721472
"18050",
1473+
"18051",
14731474
"80005",
14741475
"80003",
14751476
"80008",
@@ -2804,6 +2805,7 @@ Info 38 [00:01:19.000] response:
28042805
"18048",
28052806
"18049",
28062807
"18050",
2808+
"18051",
28072809
"80005",
28082810
"80003",
28092811
"80008",
@@ -4050,6 +4052,7 @@ Info 40 [00:01:21.000] response:
40504052
"18048",
40514053
"18049",
40524054
"18050",
4055+
"18051",
40534056
"80005",
40544057
"80003",
40554058
"80008",

0 commit comments

Comments
 (0)