Skip to content

Commit 577ee49

Browse files
Merge pull request #27139 from ajafff/config-extends
fix getExtendedConfig in commandLineParser
2 parents ba76a84 + f71030f commit 577ee49

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/compiler/commandLineParser.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,7 +2030,7 @@ namespace ts {
20302030
if (ownConfig.extendedConfigPath) {
20312031
// copy the resolution stack so it is never reused between branches in potential diamond-problem scenarios.
20322032
resolutionStack = resolutionStack.concat([resolvedPath]);
2033-
const extendedConfig = getExtendedConfig(sourceFile!, ownConfig.extendedConfigPath, host, basePath, resolutionStack, errors);
2033+
const extendedConfig = getExtendedConfig(sourceFile, ownConfig.extendedConfigPath, host, basePath, resolutionStack, errors);
20342034
if (extendedConfig && isSuccessfulParsedTsconfig(extendedConfig)) {
20352035
const baseRaw = extendedConfig.raw;
20362036
const raw = ownConfig.raw;
@@ -2171,7 +2171,7 @@ namespace ts {
21712171
}
21722172

21732173
function getExtendedConfig(
2174-
sourceFile: TsConfigSourceFile,
2174+
sourceFile: TsConfigSourceFile | undefined,
21752175
extendedConfigPath: string,
21762176
host: ParseConfigHost,
21772177
basePath: string,
@@ -2180,7 +2180,7 @@ namespace ts {
21802180
): ParsedTsconfig | undefined {
21812181
const extendedResult = readJsonConfigFile(extendedConfigPath, path => host.readFile(path));
21822182
if (sourceFile) {
2183-
(sourceFile.extendedSourceFiles || (sourceFile.extendedSourceFiles = [])).push(extendedResult.fileName);
2183+
sourceFile.extendedSourceFiles = [extendedResult.fileName];
21842184
}
21852185
if (extendedResult.parseDiagnostics.length) {
21862186
errors.push(...extendedResult.parseDiagnostics);
@@ -2190,8 +2190,8 @@ namespace ts {
21902190
const extendedDirname = getDirectoryPath(extendedConfigPath);
21912191
const extendedConfig = parseConfig(/*json*/ undefined, extendedResult, host, extendedDirname,
21922192
getBaseFileName(extendedConfigPath), resolutionStack, errors);
2193-
if (sourceFile) {
2194-
sourceFile.extendedSourceFiles!.push(...extendedResult.extendedSourceFiles!);
2193+
if (sourceFile && extendedResult.extendedSourceFiles) {
2194+
sourceFile.extendedSourceFiles!.push(...extendedResult.extendedSourceFiles);
21952195
}
21962196

21972197
if (isSuccessfulParsedTsconfig(extendedConfig)) {

src/testRunner/unittests/configurationExtension.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,20 @@ namespace ts {
244244
}, [
245245
combinePaths(basePath, "main.ts")
246246
]);
247+
248+
it("adds extendedSourceFiles only once", () => {
249+
const sourceFile = readJsonConfigFile("configs/fourth.json", (path) => host.readFile(path));
250+
const dir = combinePaths(basePath, "configs");
251+
const expected = [
252+
combinePaths(dir, "third.json"),
253+
combinePaths(dir, "second.json"),
254+
combinePaths(dir, "base.json"),
255+
];
256+
parseJsonSourceFileConfigFileContent(sourceFile, host, dir, {}, "fourth.json");
257+
assert.deepEqual(sourceFile.extendedSourceFiles, expected);
258+
parseJsonSourceFileConfigFileContent(sourceFile, host, dir, {}, "fourth.json");
259+
assert.deepEqual(sourceFile.extendedSourceFiles, expected);
260+
});
247261
});
248262
});
249263
});

0 commit comments

Comments
 (0)