Skip to content

fix(transformer): correct symbol flags for lowered enums#24226

Closed
camc314 wants to merge 1 commit into
c/fix-lowered-ns-scoping-flagsfrom
c/enum-symbl-flags-fix
Closed

fix(transformer): correct symbol flags for lowered enums#24226
camc314 wants to merge 1 commit into
c/fix-lowered-ns-scoping-flagsfrom
c/enum-symbl-flags-fix

Conversation

@camc314

@camc314 camc314 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Synchronize semantic symbol flags with the JavaScript emitted when lowering TypeScript enums.

  • Mark top-level lowered enums as function-scoped variables.
  • Mark exported and nested lowered enums as block-scoped variables.
  • Remove enum flags when lowering a merged enum to an assignment, while preserving flags from the existing runtime declaration.
  • Defer updates until program exit so enum inlining and removal can still identify enums during traversal.

This removes over 1,000 stale symbol-flag mismatches from semantic and transform-conformance snapshots.

Why Pending?

We delay it because SymbolFlags::RegularEnum/ConstEnum is still analysis input for the rest of traversal.

For example:

enum E {
  A = 1,
  B = foo(),
}
const x = E.A;

E is lowered when enter_statement visits the enum. Later, enter_expression visits E.A and checks the symbol flags to recognize and inline the enum member.

If lowering immediately changed E to FunctionScopedVariable, E.A would no longer be recognized as an enum, so the optimization would be skipped.

Thus the flags temporarily serve two roles:

  1. During traversal: describe the original TypeScript enum for analysis and inlining.
  2. After transformation: describe the emitted JavaScript binding (var, let, or a merged declaration).

Applying pending flags in exit_program updates them only after all enum-aware analysis is finished. It does not strictly need to be “at the end” if we introduced separate original/final flag storage, but with one shared SymbolFlags value, deferral is the simplest correct approach.

@github-actions github-actions Bot added the A-transformer Area - Transformer / Transpiler label Jul 6, 2026
@camc314
camc314 force-pushed the c/fix-lowered-ns-scoping-flags branch from bb60d68 to 3c4319a Compare July 6, 2026 13:06
@camc314
camc314 force-pushed the c/enum-symbl-flags-fix branch from fb50394 to 5bd386f Compare July 6, 2026 13:08
@codspeed-hq

codspeed-hq Bot commented Jul 6, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 52 untouched benchmarks
⏩ 19 skipped benchmarks1


Comparing c/enum-symbl-flags-fix (26882e6) with c/fix-lowered-ns-scoping-flags (9ae1a3c)2

Open in CodSpeed

Footnotes

  1. 19 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on c/fix-lowered-ns-scoping-flags (7f5ea01) during the generation of this report, so 34cf9bd was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

camc314 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent changes, fast-track this PR to the front of the merge queue

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Synchronizes semantic SymbolFlags with the JavaScript output produced when lowering TypeScript enums in oxc_transformer, reducing semantic/transform conformance noise from stale enum flags.

Changes:

  • Defers enum symbol-flag updates until exit_program, so enum inlining/removal can still detect enums during traversal.
  • Updates lowered enum symbols to FunctionScopedVariable (top-level) or BlockScopedVariable (exported/nested), and strips enum flags when a merged enum lowers to an assignment while preserving any existing runtime-declaration flags.
  • Refreshes transformer/semantic snapshots and allocation tracking to reflect the corrected scoping metadata.

Reviewed changes

Copilot reviewed 5 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tasks/transform_conformance/snapshots/oxc.snap.md Snapshot updates removing many enum-related symbol-flag mismatches.
tasks/transform_conformance/snapshots/babel.snap.md Snapshot updates removing enum-related symbol-flag mismatches in Babel suite.
tasks/track_memory_allocations/allocs_transformer.snap Allocation snapshot updated (small deltas) due to transformer changes.
tasks/coverage/snapshots/semantic_typescript.snap Semantic snapshot updates removing enum-related symbol-flag mismatches.
tasks/coverage/snapshots/semantic_misc.snap Semantic snapshot updates removing enum-related symbol-flag mismatches in misc suite.
tasks/coverage/snapshots/semantic_babel.snap Semantic snapshot updates removing enum-related symbol-flag mismatches in Babel semantic suite.
crates/oxc_transformer/src/typescript/mod.rs Applies deferred enum symbol-flag changes at program exit.
crates/oxc_transformer/src/typescript/enum.rs Collects and applies pending enum symbol-flag updates consistent with emitted JS.

@camc314
camc314 changed the base branch from c/fix-lowered-ns-scoping-flags to graphite-base/20476 July 6, 2026 13:17
@camc314
camc314 requested a review from Sysix as a code owner July 6, 2026 13:17
@camc314
camc314 changed the base branch from graphite-base/20476 to c/fix-lowered-ns-scoping-flags July 6, 2026 13:18
@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label Jul 6, 2026 — with Graphite App
@camc314
camc314 marked this pull request as draft July 6, 2026 13:25
@camc314 camc314 removed the 0-merge Merge with Graphite Merge Queue label Jul 6, 2026
@camc314
camc314 marked this pull request as ready for review July 6, 2026 18:34
@camc314
camc314 force-pushed the c/fix-lowered-ns-scoping-flags branch from 3c4319a to 8144154 Compare July 7, 2026 06:34
@camc314
camc314 force-pushed the c/enum-symbl-flags-fix branch from 3e0e6ad to d6c8134 Compare July 7, 2026 06:34
@camc314
camc314 force-pushed the c/fix-lowered-ns-scoping-flags branch from 8144154 to 9ae1a3c Compare July 7, 2026 06:37
@camc314
camc314 force-pushed the c/enum-symbl-flags-fix branch from d6c8134 to 296e712 Compare July 7, 2026 06:37
@graphite-app
graphite-app Bot force-pushed the c/fix-lowered-ns-scoping-flags branch from 9ae1a3c to 4f4364b Compare July 7, 2026 06:58
@graphite-app
graphite-app Bot force-pushed the c/fix-lowered-ns-scoping-flags branch from 4f4364b to 7f5ea01 Compare July 7, 2026 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-transformer Area - Transformer / Transpiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants