Skip to content

Commit ebebac9

Browse files
author
Andy Hanson
committed
Add helper function
1 parent 03ce7b0 commit ebebac9

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

src/harness/harness.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,21 +1037,7 @@ namespace Harness {
10371037
if (path[path.length - 1] === "/") {
10381038
path = <ts.Path>path.substr(0, path.length - 1);
10391039
}
1040-
1041-
let exists = false;
1042-
fileMap.forEachValue(fileName => {
1043-
if (!exists && pathStartsWithDirectory(fileName, path)) {
1044-
exists = true;
1045-
}
1046-
});
1047-
if (!exists && realPathMap) {
1048-
realPathMap.forEachValue(fileName => {
1049-
if (!exists && pathStartsWithDirectory(fileName, path)) {
1050-
exists = true;
1051-
}
1052-
});
1053-
}
1054-
return exists;
1040+
return mapHasFileInDirectory(path, fileMap) || mapHasFileInDirectory(path, realPathMap);
10551041
},
10561042
getDirectories: d => {
10571043
const path = ts.toPath(d, currentDirectory, getCanonicalFileName);
@@ -1072,8 +1058,17 @@ namespace Harness {
10721058
};
10731059
}
10741060

1075-
function pathStartsWithDirectory(fileName: string, directory: string) {
1076-
return ts.startsWith(fileName, directory) && fileName[directory.length] === "/";
1061+
function mapHasFileInDirectory(directoryPath: ts.Path, map: ts.FileMap<any>): boolean {
1062+
if (!map) {
1063+
return false;
1064+
}
1065+
let exists = false;
1066+
map.forEachValue(fileName => {
1067+
if (!exists && ts.startsWith(fileName, directoryPath) && fileName[directoryPath.length] === "/") {
1068+
exists = true;
1069+
}
1070+
});
1071+
return exists;
10771072
}
10781073

10791074
interface HarnessOptions {

0 commit comments

Comments
 (0)