-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Miscellaneous code cleanup relating to module resolution #28092
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
e0b782d
to
f432ce4
Compare
src/server/project.ts
Outdated
@@ -1194,6 +1151,27 @@ namespace ts.server { | |||
} | |||
} | |||
|
|||
function getUnresolvedImports(program: Program, cachedUnresolvedImportsPerFile: Map<ReadonlyArray<string>>): SortedReadonlyArray<string> { | |||
const ambientModules = program.getTypeChecker().getAmbientModules().map(mod => stripQuotes(mod.getName())); | |||
return toDeduplicatedSortedArray(flatMap(program.getSourceFiles(), sourceFile => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flatMap will never return undefined (since there will be source files) and thus we are allocating single length array in all these updates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As of #28205 it should return the constant emptyArray
instead of a new one.
src/server/project.ts
Outdated
let unresolvedImports: string[] | undefined; | ||
file.resolvedModules.forEach((resolvedModule, name) => { | ||
// pick unresolved non-relative names | ||
if ((!resolvedModule || !resolutionExtensionIsTSOrJson(resolvedModule.extension)) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not change this condition in this pR please. THis is unrelated to this change and should be done in the other PR.
Original condition is and should be retained:
f (!resolvedModule && !isExternalModuleNameRelative(name) && !isAmbientlyDeclaredModule(name)
src/server/project.ts
Outdated
@@ -1194,6 +1151,25 @@ namespace ts.server { | |||
} | |||
} | |||
|
|||
function getUnresolvedImports(program: Program, cachedUnresolvedImportsPerFile: Map<ReadonlyArray<string>>): SortedReadonlyArray<string> { | |||
const ambientModules = program.getTypeChecker().getAmbientModules().map(mod => stripQuotes(mod.getName())); | |||
return toDeduplicatedSortedArray(flatMapToMutable(program.getSourceFiles(), sourceFile => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reverts it back to allocating array?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
D'oh, #28214
Readonly
types more often.class Project
which is big enough already. Also simplified the logic usingparsePackageName
.