Skip to content

Conversation

@a-tarasyuk
Copy link
Contributor

Fixes #2212

Comment on lines +7 to +8
- E[E["A"] = 0] = "A";
+ E[E["A"] = void 0] = "A";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, weird, what's going on here?

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 think this is because this case uses the default reference resolver

importElisionEnabled := !options.VerbatimModuleSyntax.IsTrue() && !ast.IsInJSFile(sourceFile.AsNode())
var emitResolver printer.EmitResolver
var referenceResolver binder.ReferenceResolver
if importElisionEnabled || options.GetJSXTransformEnabled() || !options.GetIsolatedModules() { // full emit resolver is needed for import ellision and const enum inlining
emitResolver = host.GetEmitResolver()
emitResolver.MarkLinkedReferencesRecursively(sourceFile)
referenceResolver = emitResolver
} else {
referenceResolver = binder.NewReferenceResolver(options, binder.ReferenceResolverHooks{})
}

@jakebailey
Copy link
Member

Ah, I had forgotten about the runtime changes we made to make it easier to emit these without using the checker.

How much of that actually has to go to fix the linked issue? Or is it just impossible to resolve?

@a-tarasyuk
Copy link
Contributor Author

a-tarasyuk commented Dec 8, 2025

I think replicating the following from the checker (evaluateEntity) should resolve the issue. This fix may not cover 100% of the previous behavior, however it should address this particular case without needing the entire GetEnumMemberValue dependency

func (tx *RuntimeSyntaxTransformer) evaluateEntity(node *ast.Node, location *ast.Node) evaluator.Result {
var result evaluator.Result
if ast.IsEnumDeclaration(location) {
memberCache := tx.enumMemberCache[location]
if memberCache != nil {
switch {
case ast.IsIdentifier(node):
result = memberCache[node.Text()]
case ast.IsPropertyAccessExpression(node):
access := node.AsPropertyAccessExpression()
expression := access.Expression
if ast.IsIdentifier(expression) && tx.isReferenceToEnum(expression, location) {
result = memberCache[access.Name().Text()]
}
case ast.IsElementAccessExpression(node):
access := node.AsElementAccessExpression()
expression := access.Expression
if ast.IsIdentifier(expression) && tx.isReferenceToEnum(expression, location) && ast.IsStringLiteralLike(access.ArgumentExpression) {
result = memberCache[access.ArgumentExpression.Text()]
}
}
}
}
return result
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect import elision when enum value references another enum from a different module

2 participants