Repository navigation
Conversation
When a const enum member expression referenced a `const` variable with a constant initializer (e.g. `const x = 5`), the value was not being folded because the enum preprocessing pass runs before const variable declarations are visited. This pre-populates const_values for simple const declarations before enum preprocessing, and also checks should_fold_typescript_constant_expressions in handleIdentifier so const_values are used during enum folding even without the global inlining feature flag. Closes #19581 Co-Authored-By: Claude <noreply@anthropic.com>
Collaborator
Author
|
Updated 9:54 AM PT - Feb 19th, 2026
❌ Your commit
🧪 To try this PR locally: bunx bun-pr 27167That installs a local version of the PR into your bun-27167 --bun |
Contributor
|
✅ 2d295 — Looks good! Reviewed 4 files across |
Jarred-Sumner
requested changes
Feb 19, 2026
Jarred-Sumner
left a comment
Collaborator
There was a problem hiding this comment.
Do not add an extra loop over all the statements. Read over esbuild's implementation and understand what they do.
Contributor
|
Closing this PR because it has been inactive for more than 90 days. |
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.
Summary
const enummembers not being constant-folded when they referenceconstvariables with constant initializers (e.g.,const x = 5)const_valuesfor simple const declarations before the enum preprocessing pass runs, in both the tree-shaking and non-tree-shaking code pathsshould_fold_typescript_constant_expressionsinhandleIdentifierso thatconst_valuesare used during enum folding even without the globalinliningfeature flagBefore:
const multiplier = 5; const enum E { A = 1 * multiplier }→ keptmultiplieras a runtime referenceAfter: correctly folds to
const enum E { A = 5 }, matching TypeScript behaviorCloses #19581
Test plan
test/regression/issue/19581.test.tsthat verify:--no-bundlemode--minify(e.g.,console.log(25))USE_SYSTEM_BUN=1(confirming the bug)bun bd testtest/bundler/esbuild/ts.test.tstests pass (57/57)test/bundler/esbuild/default.test.tstests pass (150/150)🤖 Generated with Claude Code