-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
fix(61258): Renaming namespace with const enum doesn't update enum references #61263
base: main
Are you sure you want to change the base?
Conversation
module foo { | ||
>foo : typeof foo | ||
> : ^^^^^^^^^^ | ||
|
||
const enum E { X } |
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 am suspicious of this; this implies that we are giving foo
a type when it doesn't actually exist, no?
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’m surprised that a helper from services changes types :)
TypeScript/src/services/utilities.ts
Line 411 in 7507b05
export function getMeaningFromDeclaration(node: Node): SemanticMeaning { |
This helper is used by findAll
to obtain semantic meaning for the search
TypeScript/src/services/findAllReferences.ts
Line 1305 in 7507b05
const searchMeaning = node ? getIntersectingMeaningFromDeclarations(node, symbol) : SemanticMeaning.All; |
TypeScript/src/services/findAllReferences.ts
Line 2741 in 7507b05
const declarationMeaning = getMeaningFromDeclaration(declaration); |
TypeScript/src/services/utilities.ts
Lines 452 to 454 in 7507b05
else if (getModuleInstanceState(node as ModuleDeclaration) === ModuleInstanceState.Instantiated) { | |
return SemanticMeaning.Namespace | SemanticMeaning.Value; | |
} |
Since the module instance state for constant enums uses the separate value ConstEnumOnly
instead of Instantiated
, the Value
meaning is not allowed in the search, and findAll
skips it
TypeScript/src/services/findAllReferences.ts
Line 1928 in 7507b05
if (!hasMatchingMeaning(referenceLocation, state)) return; |
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.
Yeah, getMeaningFromDeclaration
is just itself used in the type baselines to skip things that are already types.
const enums are a little funky, though, since they do exist at runtime depending on the flags, so I'm not too concerned about the change here.
This acutally makes me wonder if #61011 should have used !== ModuleInstanceState.NonInstantiated
(or similar). But I don't remember if there are any other ways to have this sitaution that aren't const enums?
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 acutally makes me wonder if #61011 should have used !== ModuleInstanceState.NonInstantiated
Do you mean explicitly using == ModuleInstanceState.Instantiated
or == ModuleInstanceState.ConstEnum
?
In the checker
, there is a helper that considers a module with ConstEnums
instantiated only if preserveConstEnums
is present. Should services follow the same logic?
export function isInstantiatedModule(node: ModuleDeclaration, preserveConstEnums: boolean): boolean {
const moduleState = getModuleInstanceState(node);
return moduleState === ModuleInstanceState.Instantiated ||
(preserveConstEnums && moduleState === ModuleInstanceState.ConstEnumOnly);
}
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.
No, we shouldn't, actually; I think you've done the right thing and so did Ryan's PR. The problem is that we need renaming to work regardless of whether or not preserveConstEnums
has been set.
Now, maybe this means the test harness should skip via isInstantiatedModule
for its own walk, but I don't know how annoying that'd be to do.
Fixes #61258