Skip to content

Use the correct old file when re-using file resolutions #20403

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

Closed
wants to merge 1 commit into from

Conversation

RyanCavanaugh
Copy link
Member

Also optimizes re-use of ambient module non-resolution by not incorrectly treating a resolution to a global sourcefile (as sometimes happens when we resolve an @types/ reference) as it it were an external module. This saves us re-doing module resolution for those files during program recompute.

Fixes #14565

@RyanCavanaugh RyanCavanaugh requested review from billti, mhegazy and a user December 2, 2017 00:05
@@ -1945,7 +1945,7 @@ namespace ts {
if (file.imports.length || file.moduleAugmentations.length) {
// Because global augmentation doesn't have string literal name, we can check for global augmentation as such.
const moduleNames = getModuleNames(file);
const oldProgramState = { program: oldProgram, file, modifiedFilePaths };
const oldProgramState = { program: oldProgram, file: oldProgram ? oldProgram.getSourceFile(file.fileName) : undefined, modifiedFilePaths };
Copy link
Contributor

Choose a reason for hiding this comment

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

consider renaming file to oldSourceFile to avoid future confusion.

if (resolutionToFile) {
// module used to be resolved to file - ignore it
const resolvedFile = resolutionToFile && oldProgramState.program && oldProgramState.program.getSourceFile(resolutionToFile.resolvedFileName);
if (resolutionToFile && resolvedFile && !resolvedFile.externalModuleIndicator) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a unit test for this one.

@mhegazy
Copy link
Contributor

mhegazy commented Dec 4, 2017

do we need to port this to 2.6.3? or is just for 2.7?

// module used to be resolved to file - ignore it
const resolutionToFile = getResolvedModule(oldProgramState.oldSourceFile, moduleName);
const resolvedFile = resolutionToFile && oldProgramState.program && oldProgramState.program.getSourceFile(resolutionToFile.resolvedFileName);
if (resolutionToFile && resolvedFile && !resolvedFile.externalModuleIndicator) {
Copy link

Choose a reason for hiding this comment

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

Nit: No need to test resolutionToFile && since resolvedFile will only be defined if that is.

@@ -1945,7 +1945,7 @@ namespace ts {
if (file.imports.length || file.moduleAugmentations.length) {
// Because global augmentation doesn't have string literal name, we can check for global augmentation as such.
const moduleNames = getModuleNames(file);
const oldProgramState = { program: oldProgram, file, modifiedFilePaths };
const oldProgramState: OldProgramState = { program: oldProgram, oldSourceFile: oldProgram ? oldProgram.getSourceFile(file.fileName) : undefined, modifiedFilePaths };
Copy link

Choose a reason for hiding this comment

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

Nit: oldProgram && oldProgram.getSourceFile(file.fileName) is shorter

@@ -704,7 +704,7 @@ namespace ts {

interface OldProgramState {
program: Program | undefined;
file: SourceFile;
oldSourceFile: SourceFile;
Copy link

Choose a reason for hiding this comment

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

This should be SourceFile | undefined

@RyanCavanaugh
Copy link
Member Author

Picking up from the other PR

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
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.

Duplicate identifier error for d.ts files in Visual Studio 2017
2 participants