Skip to content

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

Merged
4 commits merged into from
Oct 30, 2018
Merged

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
@@ -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 =>
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)

@@ -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 =>
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
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant