- Notifications
You must be signed in to change notification settings - Fork 13.1k
Pick correct compilerOptions when checking if we can share emitSignatures #50910
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
The fix works on my project (ported manually in JS code). |
oldState?.emitSignatures && | ||
!outFilePath && | ||
!compilerOptionsAffectDeclarationPath(compilerOptions, oldCompilerOptions!); | ||
!compilerOptionsAffectDeclarationPath(compilerOptions, oldState.compilerOptions); |
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.
I think a comment would help to explain why this one spot doesn't use oldCompilerOptions
. (To be honest, I couldn't figure it out from your PR description.) It's especially disconcerting that we might be dotting into oldState
when useOldState
is false, so please consider explaining that as well.
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.
Please check if its more clear now.
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.
It sounds like maybe useOldState
should be renamed? Maybe something like useOldStateFor...
?
I'll attempt to paraphrase - please check my understanding:
We can only reuse emit signatures (i.e. .d.ts signatures) if the .d.ts file is unchanged, which will only be the case if the declarationDir
and outDir
options are unchanged.
We need to look in oldState.compilerOptions
, rather than oldCompilerOptions
(i.e. we need to disregard useOldState
) because oldCompilerOptions
will be undefined if the file references map indicates that the files to be emitted have changed, which isn't relevant for checking signature reuses.
Was I close?
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.
We need to look in oldState.compilerOptions, rather than oldCompilerOptions (i.e. we need to disregard useOldState)
Since useOldState is determined by whether we create reference map to check for files to emit or not. So if say module option changes from Module.None
to some other Module
kind then oldCompilerOptions
will be undefined
but that shouldn't be taken into account when considering whether to reuse d.ts emit signature
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.
Maybe something like useOldStateFor...?
not ideal since useOldStateFor
since its everything - like semantic diagnostics, files to emit, changed files and so on except d.ts emit signature
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.
That's much clearer - thanks! For my own edification: every use case other than signature emit should still use oldCompilerOptions
, correct?
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.
Yes
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.
Thanks for the explanation!
Can/should this fix be cherrypicked to the 4.8 branch? |
@DanielRosenwasser and @RyanCavanaugh who can decide if it would be fit for 4.8 patch |
OldCompilerOptions is set only if referencemaps are created vs not created.
Module.None
does not create reference map but other values do create it. Which is what determines if we can say copy semantic diagnostics etc..But emit signatures are purely based on declaration path and their contents so they should only use the compilerOptions directly from old state.
Fixes #50902