Skip to content

fix: handle complex enum initializer expressions + cross-file references#120

Open
jpdutoit wants to merge 1 commit intounplugin:mainfrom
jpdutoit:fix/enum-expression-resolution
Open

fix: handle complex enum initializer expressions + cross-file references#120
jpdutoit wants to merge 1 commit intounplugin:mainfrom
jpdutoit:fix/enum-expression-resolution

Conversation

@jpdutoit
Copy link
Copy Markdown

@jpdutoit jpdutoit commented Apr 5, 2026

Adds support for complex enum initializer expressions, and resolves cross-file enum dependencies via lazy evaluation. Also deduplicates reverse mappings for enums with shared numeric values.

Description

Expression handling

Fixes enum scanning for several initializer expression types that previously caused build failures with unhandled BinaryExpression operand type or unhandled initializer type errors.

  • Support nested BinaryExpression (e.g. Value = A | B | C)
  • Support MemberExpression initializers (e.g. Value = OtherEnum.Value)
  • Support bare Identifier referencing sibling members (e.g. Last = Previous)
  • Support UnaryExpression on complex operands (e.g. ~Flags.ABCD)

Reverse mapping deduplication

When multiple enum members share the same numeric value, only the last declared member gets a reverse mapping entry. This avoids duplicate keys in the generated object literal, matching TypeScript's runtime behavior.

Resolve cross-file references

Cross-file references fail when file A references an enum from file B, but B is scanned after A. Enum values are now stored as lazy resolvers. All resolvers are called once at the end when constructing enumData, at which point every enum has been scanned.

Tests

Added test enums covering nested binary expressions, self-referencing compound members, bare identifier references, unary on member expressions, duplicate numeric values, and cross-file enum references.

Linked Issues

None

@bolt-new-by-stackblitz
Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

- Support nested BinaryExpression (e.g. A | B | C)
- Support MemberExpression initializers (e.g. Value = OtherEnum.Value)
- Support bare Identifier referencing sibling members (e.g. Last = Third)
- Support UnaryExpression on complex operands (e.g. ~Flags.ABCD)
- Resolve cross-file enum references via lazy evaluation
- Deduplicate reverse mappings for duplicate numeric values (last wins)
@jpdutoit jpdutoit force-pushed the fix/enum-expression-resolution branch from 812acdd to 4a6f52e Compare April 5, 2026 20:21
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.

1 participant