Skip to content

fix: skip runtime IR emission for const enum declarations#89

Open
AugustHagedal wants to merge 1 commit intoSnapchat:mainfrom
AugustHagedal:fix/const-enum-declaration
Open

fix: skip runtime IR emission for const enum declarations#89
AugustHagedal wants to merge 1 commit intoSnapchat:mainfrom
AugustHagedal:fix/const-enum-declaration

Conversation

@AugustHagedal
Copy link

Description

Found a bug in processEnumDeclaration() — it was emitting a runtime object and property assignments for const enum declarations, which it shouldn't. Const enums are compile-time only; TypeScript inlines their values at every usage site via emitResolver.getConstantValue(), so there's nothing to emit at the declaration site.

The fix is a small early return when the Const modifier is detected. The TODO comment that was sitting there is gone too.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • Test improvement

Testing

  • Tests pass locally
  • Added/updated tests for changes (if applicable)

Testing Details

Added two tests to NativeCompiler.spec.ts alongside the existing const enum test:

  • Inline integer const enum: checks Color.Green becomes storeint 1 with no newobject in the output
  • Inline string const enum: checks Direction.Up becomes storestring 'UP' with no newobject

All 118 tests pass.

Checklist

  • Code follows project style guidelines
  • No breaking changes
  • Commit messages follow conventional format
  • No secrets, API keys, or internal URLs included

Const enums are purely compile-time constructs — TypeScript inlines their
values at every usage site via emitResolver.getConstantValue(). The
processEnumDeclaration() method was emitting a runtime object and property
assignments for all enums, including const enums, which is incorrect.

Adds an early return when the enum has the Const modifier flag, and two new
test cases covering inline integer and string const enums.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

🎉 Thanks for your first contribution to Valdi!

A maintainer will review your PR soon. Here are a few things to check while you wait:

  • ✅ All tests pass (bazel test //...)
  • ✅ Your changes follow our coding standards
  • ✅ You've added tests for your changes (if applicable)
  • ✅ You've updated documentation (if needed)

Join our Discord community if you have questions!

@AugustHagedal AugustHagedal force-pushed the fix/const-enum-declaration branch from ff03372 to f4c3ba5 Compare February 21, 2026 23: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