Skip to content

Commit 7223945

Browse files
author
Andy
authored
Use array helper in computeCommonSourceDirectory and remove two unnecessary tests (#26416)
1 parent a2e4a28 commit 7223945

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

src/compiler/program.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,27 +2319,20 @@ namespace ts {
23192319
}
23202320

23212321
function computeCommonSourceDirectory(sourceFiles: SourceFile[]): string {
2322-
const fileNames: string[] = [];
2323-
for (const file of sourceFiles) {
2324-
if (!file.isDeclarationFile) {
2325-
fileNames.push(file.fileName);
2326-
}
2327-
}
2322+
const fileNames = mapDefined(sourceFiles, file => file.isDeclarationFile ? undefined : file.fileName);
23282323
return computeCommonSourceDirectoryOfFilenames(fileNames, currentDirectory, getCanonicalFileName);
23292324
}
23302325

2331-
function checkSourceFilesBelongToPath(sourceFiles: SourceFile[], rootDirectory: string): boolean {
2326+
function checkSourceFilesBelongToPath(sourceFiles: ReadonlyArray<SourceFile>, rootDirectory: string): boolean {
23322327
let allFilesBelongToPath = true;
2333-
if (sourceFiles) {
2334-
const absoluteRootDirectoryPath = host.getCanonicalFileName(getNormalizedAbsolutePath(rootDirectory, currentDirectory));
2335-
2336-
for (const sourceFile of sourceFiles) {
2337-
if (!sourceFile.isDeclarationFile) {
2338-
const absoluteSourceFilePath = host.getCanonicalFileName(getNormalizedAbsolutePath(sourceFile.fileName, currentDirectory));
2339-
if (absoluteSourceFilePath.indexOf(absoluteRootDirectoryPath) !== 0) {
2340-
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, sourceFile.fileName, rootDirectory));
2341-
allFilesBelongToPath = false;
2342-
}
2328+
const absoluteRootDirectoryPath = host.getCanonicalFileName(getNormalizedAbsolutePath(rootDirectory, currentDirectory));
2329+
2330+
for (const sourceFile of sourceFiles) {
2331+
if (!sourceFile.isDeclarationFile) {
2332+
const absoluteSourceFilePath = host.getCanonicalFileName(getNormalizedAbsolutePath(sourceFile.fileName, currentDirectory));
2333+
if (absoluteSourceFilePath.indexOf(absoluteRootDirectoryPath) !== 0) {
2334+
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, sourceFile.fileName, rootDirectory));
2335+
allFilesBelongToPath = false;
23432336
}
23442337
}
23452338
}

src/compiler/utilities.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7302,8 +7302,6 @@ namespace ts {
73027302
if (pathComponents.length === 0) return "";
73037303

73047304
const root = pathComponents[0] && ensureTrailingDirectorySeparator(pathComponents[0]);
7305-
if (pathComponents.length === 1) return root;
7306-
73077305
return root + pathComponents.slice(1).join(directorySeparator);
73087306
}
73097307

0 commit comments

Comments
 (0)