-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Conversation
src/compiler/program.ts
Outdated
@@ -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 }; |
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.
consider renaming file
to oldSourceFile
to avoid future confusion.
src/compiler/program.ts
Outdated
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) { |
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.
can you add a unit test for this one.
do we need to port this to 2.6.3? or is just for 2.7? |
src/compiler/program.ts
Outdated
// 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) { |
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.
Nit: No need to test resolutionToFile &&
since resolvedFile
will only be defined if that is.
src/compiler/program.ts
Outdated
@@ -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 }; |
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.
Nit: oldProgram && oldProgram.getSourceFile(file.fileName)
is shorter
src/compiler/program.ts
Outdated
@@ -704,7 +704,7 @@ namespace ts { | |||
|
|||
interface OldProgramState { | |||
program: Program | undefined; | |||
file: SourceFile; | |||
oldSourceFile: 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 should be SourceFile | undefined
8b6072e
to
f952953
Compare
f952953
to
df34540
Compare
Picking up from the other PR |
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