Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

a-tarasyuk
Copy link
Contributor

Fixes #61258

Comment on lines 10 to 14
module foo {
>foo : typeof foo
> : ^^^^^^^^^^

const enum E { X }
Copy link
Member

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?

Copy link
Contributor Author

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 :)

export function getMeaningFromDeclaration(node: Node): SemanticMeaning {

This helper is used by findAll to obtain semantic meaning for the search

const searchMeaning = node ? getIntersectingMeaningFromDeclarations(node, symbol) : SemanticMeaning.All;

const declarationMeaning = getMeaningFromDeclaration(declaration);

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

if (!hasMatchingMeaning(referenceLocation, state)) return;

Copy link
Member

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?

Copy link
Contributor Author

@a-tarasyuk a-tarasyuk Mar 1, 2025

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);
}

Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Not started
Development

Successfully merging this pull request may close these issues.

Renaming namespace with const enum doesn't update enum references
2 participants