Skip to content

Conversation

@ghost
Copy link

@ghost ghost commented Oct 24, 2018

  • Use Readonly types more often.
  • Remove some unnecessary non-null assertions.
  • Extract a function for getting unresolved imports out of class Project which is big enough already. Also simplified the logic using parsePackageName.

@ghost ghost requested a review from sheetalkamat October 24, 2018 00:40
@ghost ghost force-pushed the importResolution branch from e0b782d to f432ce4 Compare October 24, 2018 22:36

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 =>
Copy link
Member

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.

Copy link
Author

@ghost ghost Oct 29, 2018

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.

@ghost ghost closed this in #28205 Oct 29, 2018
@ghost ghost reopened this Oct 29, 2018
let unresolvedImports: string[] | undefined;
file.resolvedModules.forEach((resolvedModule, name) => {
// pick unresolved non-relative names
if ((!resolvedModule || !resolutionExtensionIsTSOrJson(resolvedModule.extension)) &&
Copy link
Member

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)


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 =>
Copy link
Member

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

D'oh, #28214

@ghost ghost merged commit acc34bd into master Oct 30, 2018
@ghost ghost deleted the importResolution branch October 30, 2018 17:15
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant