Skip to content

Commit 73ede59

Browse files
Don't recurse when the answer doesn't change to 'true', just continue.
1 parent e9f82e4 commit 73ede59

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/server/editorServices.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3775,24 +3775,28 @@ namespace ts.server {
37753775
getPackageJsonsVisibleToFile(fileName: string, rootDir?: string): readonly PackageJsonInfo[] {
37763776
const packageJsonCache = this.packageJsonCache;
37773777
const watchPackageJsonFile = this.watchPackageJsonFile.bind(this);
3778-
const toPath = this.toPath.bind(this);
3779-
const rootPath = rootDir && toPath(rootDir);
3780-
const filePath = toPath(fileName);
3778+
const rootPath = rootDir && this.toPath(rootDir);
3779+
const filePath = this.toPath(fileName);
37813780
const result: PackageJsonInfo[] = [];
3782-
forEachAncestorDirectory(getDirectoryPath(filePath), function processDirectory(directory): boolean | undefined {
3781+
forEachAncestorDirectory(getDirectoryPath(filePath), directory => {
37833782
switch (packageJsonCache.directoryHasPackageJson(directory)) {
37843783
// Sync and check same directory again
37853784
case Ternary.Maybe:
37863785
packageJsonCache.searchDirectoryAndAncestors(directory);
3787-
return processDirectory(directory);
3788-
// Check package.json
3786+
const newResult = packageJsonCache.directoryHasPackageJson(directory);
3787+
if (newResult !== Ternary.True) {
3788+
Debug.assertEqual(newResult, Ternary.False);
3789+
break;
3790+
}
3791+
// fall through
3792+
// Check the package.json
37893793
case Ternary.True:
37903794
const packageJsonFileName = combinePaths(directory, "package.json");
37913795
watchPackageJsonFile(packageJsonFileName);
37923796
const info = packageJsonCache.getInDirectory(directory);
37933797
if (info) result.push(info);
37943798
}
3795-
if (rootPath && rootPath === toPath(directory)) {
3799+
if (rootPath && rootPath === this.toPath(directory)) {
37963800
return true;
37973801
}
37983802
});

0 commit comments

Comments
 (0)