Fix(51828): `extends` field in `tsconfig.json` does nothing with empty string (#51981)
This commit is contained in:
Родитель
9c9d4b029d
Коммит
f6fc444b33
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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",
|
||||
|
|
Загрузка…
Ссылка в новой задаче