fix: skip runtime IR emission for const enum declarations#89
Open
AugustHagedal wants to merge 1 commit intoSnapchat:mainfrom
Open
fix: skip runtime IR emission for const enum declarations#89AugustHagedal wants to merge 1 commit intoSnapchat:mainfrom
AugustHagedal wants to merge 1 commit intoSnapchat:mainfrom
Conversation
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>
There was a problem hiding this comment.
🎉 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!
ff03372 to
f4c3ba5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Found a bug in
processEnumDeclaration()— it was emitting a runtime object and property assignments forconst enumdeclarations, which it shouldn't. Const enums are compile-time only; TypeScript inlines their values at every usage site viaemitResolver.getConstantValue(), so there's nothing to emit at the declaration site.The fix is a small early return when the
Constmodifier is detected. The TODO comment that was sitting there is gone too.Type of Change
Testing
Testing Details
Added two tests to
NativeCompiler.spec.tsalongside the existing const enum test:Color.Greenbecomesstoreint 1with nonewobjectin the outputDirection.Upbecomesstorestring 'UP'with nonewobjectAll 118 tests pass.
Checklist