Skip to content

fix(transformer): correct symbol flags for lowered namespaces#24224

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

fix(transformer): correct symbol flags for lowered namespaces#24224
camc314 wants to merge 1 commit into
mainfrom
c/fix-lowered-ns-scoping-flags

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 namespaces.

  • Mark generated namespace let bindings as block-scoped variables.
  • Remove namespace module flags when a namespace merges with another runtime declaration.
  • Defer flag updates until all namespace declarations are classified, avoiding order-dependent behavior for merged namespaces.
  • Update semantic and transformer conformance snapshots.

Copilot AI review requested due to automatic review settings July 6, 2026 12:48
@camc314
camc314 requested a review from Dunqing as a code owner July 6, 2026 12:48
@camc314
camc314 force-pushed the c/fix-lowered-ns-scoping-flags branch from 9f52cc0 to da679cb Compare July 6, 2026 12:51
@github-actions github-actions Bot added the A-transformer Area - Transformer / Transpiler label Jul 6, 2026
@camc314
camc314 force-pushed the codex/preserve-transformed-binding-spans branch from 0f0ea8d to b59430b Compare July 6, 2026 12:52

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9f52cc0bb0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/oxc_transformer/src/typescript/namespace.rs

camc314 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

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.

@camc314
camc314 force-pushed the c/fix-lowered-ns-scoping-flags branch from 2126502 to 13cc094 Compare July 6, 2026 12:54

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

Adjusts the TypeScript namespace lowering transform so semantic SymbolFlags for namespace identifiers are corrected after the transform, reducing semantic “after transform vs rebuilt” mismatches in transformer/semantic conformance snapshots.

Changes:

  • Track namespace-related SymbolFlags updates during lowering and apply them after rewriting the program body.
  • Update namespace lowering to clear ValueModule/NamespaceModule flags when a namespace is treated as a redeclaration, and to force BlockScopedVariable for the emitted binding when it is not.
  • Refresh transformer/semantic conformance snapshots reflecting improved pass counts and updated mismatch output.

Reviewed changes

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

Show a summary per file
File Description
crates/oxc_transformer/src/typescript/namespace.rs Defers and applies namespace symbol-flag adjustments after lowering, updating how redeclarations and emitted bindings are flagged.
tasks/transform_conformance/snapshots/oxc.snap.md Updates transform conformance snapshot output after the namespace flag change.
tasks/transform_conformance/snapshots/babel.snap.md Updates Babel fixture transform conformance snapshot counts/output.
tasks/coverage/snapshots/semantic_typescript.snap Updates TypeScript semantic coverage snapshot counts/output.
tasks/coverage/snapshots/semantic_babel.snap Updates Babel semantic coverage snapshot counts/output.

@camc314
camc314 force-pushed the c/fix-lowered-ns-scoping-flags branch from 13cc094 to bb60d68 Compare July 6, 2026 12:56
@camc314
camc314 requested a review from overlookmotel as a code owner July 6, 2026 12:56
@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/fix-lowered-ns-scoping-flags (7f5ea01) with main (c3057da)

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bb60d68fcf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tasks/transform_conformance/snapshots/oxc.snap.md Outdated
@camc314
camc314 force-pushed the c/fix-lowered-ns-scoping-flags branch from bb60d68 to 3c4319a Compare July 6, 2026 13:06

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3c4319af35

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +309 to +310
*self.pending_symbol_flags_mut(binding.symbol_id, SymbolFlags::BlockScopedVariable) =
SymbolFlags::BlockScopedVariable;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve RegularEnum before enum optimization

When a namespace comes before an enum it merges with (namespace Foo { ... } enum Foo { A = 1 }) and optimizeEnums is enabled, this branch records Foo as only BlockScopedVariable. apply_pending_symbol_flags runs in enter_program before the traversal reaches TypeScriptEnum::enter_expression, and that inliner gates on flags.contains(SymbolFlags::RegularEnum), so later Foo.A references stop being inlined even though they were before this change and the option asks for regular enum inlining. Delay dropping RegularEnum until after enum inlining or keep enough enum state for that pass.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This finding is real, it seems break following code

namespace Foo {
  export const x = 1;
}
enum Foo {
  A = 1,
}
Foo.A; // before is `1`, now is `Foo.A`

@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
@graphite-app
graphite-app Bot changed the base branch from codex/preserve-transformed-binding-spans to graphite-base/24224 July 6, 2026 13:25

camc314 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Merge activity

  • Jul 6, 1:25 PM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.

@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

@Dunqing Dunqing left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@camc314
camc314 force-pushed the c/fix-lowered-ns-scoping-flags branch from 3c4319a to 8144154 Compare July 7, 2026 06:34
@camc314
camc314 requested a review from leaysgur as a code owner July 7, 2026 06:34
@camc314 camc314 changed the title fix(transformer): correct scope flags for lowered namespaces fix(transformer): correct symbol flags for lowered namespaces Jul 7, 2026
@camc314
camc314 changed the base branch from graphite-base/24224 to codex/preserve-transformed-binding-spans July 7, 2026 06:34
@camc314
camc314 force-pushed the codex/preserve-transformed-binding-spans branch from 9378b8f to 5553efa Compare July 7, 2026 06:37
@camc314
camc314 force-pushed the c/fix-lowered-ns-scoping-flags branch from 8144154 to 9ae1a3c Compare July 7, 2026 06:37
@graphite-app
graphite-app Bot changed the base branch from codex/preserve-transformed-binding-spans to graphite-base/24224 July 7, 2026 06:53
@graphite-app
graphite-app Bot force-pushed the graphite-base/24224 branch from 5553efa to c3057da Compare July 7, 2026 06:58
@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 changed the base branch from graphite-base/24224 to main July 7, 2026 06:59
@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
@Dunqing

Dunqing commented Jul 7, 2026

Copy link
Copy Markdown
Member

@codex review again

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7f5ea018c8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +309 to +310
*self.pending_symbol_flags_mut(binding.symbol_id, SymbolFlags::BlockScopedVariable) =
SymbolFlags::BlockScopedVariable;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve enum flags until enum optimization runs

When a value namespace is the first declaration in a merge and an enum/const enum with the same name appears later, this overwrites the merged symbol flags with only BlockScopedVariable during TypeScriptNamespace::enter_program, before TypeScriptEnum traverses the program. With optimizeEnums or optimizeConstEnums enabled, TypeScriptEnum::resolve_enum_member checks symbol_flags for RegularEnum/ConstEnum, so cases like namespace E { export const x = 1 } enum E { A = 1 } console.log(E.A) stop inlining E.A even though the enum data is still available. Please keep the enum flags available until the enum pass has run, or avoid clobbering non-namespace flags here.

Useful? React with 👍 / 👎.

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