-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Stop reassigning .valueDeclaration to avoid replacing earlier declarations with late ones
#60857
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
Stop reassigning .valueDeclaration to avoid replacing earlier declarations with late ones
#60857
Conversation
.valueDeclaration to avoid replacing earlier declarations with late ones
| symbol.declarations.push(member); | ||
| } | ||
| if (symbolFlags & SymbolFlags.Value) { | ||
| if (!symbol.valueDeclaration || symbol.valueDeclaration.kind !== member.kind) { |
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.
Was the original logic trying to preserve the somewhat-sketchy logic in the binder around which type of declaration "wins" out?
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 sure looks like it, but there's a separate utility function for that now: setValueDeclaration, which is more complicated*. Specifically, the kind check is only for namespaces there, which wouldn't apply to this property assignments.
I think the better fix to try is
if (symbolFlags & SymbolFlags.Value) {
setValueDeclaration(symbol, member)
}In other words, what the binder does in addDeclarationToSymbol.
*It also has a 3rd case for function property assignments in .d.ts files.
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 pushed out this change. Could you take another look?
| symbol.declarations.push(member); | ||
| } | ||
| if (symbolFlags & SymbolFlags.Value) { | ||
| if (!symbol.valueDeclaration || symbol.valueDeclaration.kind !== member.kind) { |
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 sure looks like it, but there's a separate utility function for that now: setValueDeclaration, which is more complicated*. Specifically, the kind check is only for namespaces there, which wouldn't apply to this property assignments.
I think the better fix to try is
if (symbolFlags & SymbolFlags.Value) {
setValueDeclaration(symbol, member)
}In other words, what the binder does in addDeclarationToSymbol.
*It also has a 3rd case for function property assignments in .d.ts files.
sandersn
left a comment
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 noticed this after ignoring it for far too long. Would you mind merging from main before this goes in?
|
@sandersn done |
DingJun1028
left a comment
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.
.
cc @sandersn
fixes #60590