Skip to content

feat(semantic): ScopeFlags::With#16291

Merged
Boshen merged 4 commits intooxc-project:mainfrom
aapoalas:feat/semantic-scope-flags-with-statement
Dec 12, 2025
Merged

feat(semantic): ScopeFlags::With#16291
Boshen merged 4 commits intooxc-project:mainfrom
aapoalas:feat/semantic-scope-flags-with-statement

Conversation

@aapoalas
Copy link
Copy Markdown
Contributor

Simple addition but unfortunately untested: I locally fail tsgo related tests, probably for reasons related to not having tsgo installed?

Copilot AI review requested due to automatic review settings November 30, 2025 11:34
@aapoalas aapoalas requested a review from Dunqing as a code owner November 30, 2025 11:34
@graphite-app
Copy link
Copy Markdown
Contributor

graphite-app bot commented Nov 30, 2025

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 hot fixes, skip the queue and merge this PR next

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.

@github-actions github-actions bot added A-semantic Area - Semantic C-enhancement Category - New feature or request labels Nov 30, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for the ScopeFlags::With flag to mark scopes created by JavaScript with statements. The implementation adds the flag definition, a helper method to check for it, and applies it when entering with statement scopes during semantic analysis.

  • Added ScopeFlags::With flag definition with documentation
  • Added is_with() helper method for checking the flag
  • Applied the flag when entering with statement scopes

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
crates/oxc_syntax/src/scope.rs Defines the new With scope flag and adds the is_with() helper method; also adds #[inline] to is_ts_conditional()
crates/oxc_semantic/src/builder.rs Updates the semantic builder to use ScopeFlags::With instead of ScopeFlags::empty() when entering with statement scopes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions github-actions bot added the A-ast Area - AST label Nov 30, 2025
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Nov 30, 2025

CodSpeed Performance Report

Merging #16291 will not alter performance

Comparing aapoalas:feat/semantic-scope-flags-with-statement (7653a33) with main (1da3dc1)1

Summary

✅ 42 untouched
⏩ 3 skipped2

Footnotes

  1. No successful run was found on main (250feb3) during the generation of this report, so 1da3dc1 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 3 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.

Copy link
Copy Markdown
Contributor

@lilnasy lilnasy left a comment

Choose a reason for hiding this comment

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

Looks good to me! I need to review oxc_semantic for an upcoming feature, and I figured this would be a good opportunity. I am not too familiar with it yet so take my comments with a grain of salt.

graphite-app bot pushed a commit that referenced this pull request Nov 30, 2025
…ditional` (#16309)

Add `#[inline]` attr to this method, for consistency with all the rest.

This omission was spotted by @aapoalas in #16291.
Copy link
Copy Markdown
Member

@overlookmotel overlookmotel left a comment

Choose a reason for hiding this comment

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

with complicates symbol resolution a lot. Is there anything else we need to do to make Semantic make sense of it?

For example, I guess minifier should not mangle var names where they're accessed "through" a with, in the same way that it I think takes account of whether a var can be "seen" by an eval().

e.g. let foo = 1; with ({foo: 2}) foo = 3; would change behavior if foo var is renamed. Though maybe that's such an edge case, we shouldn't worry about it.

Out of interest, what's your use case for this in Nova? My sincere condolences if you actually need to make with behave correctly. Nightmare!

@aapoalas
Copy link
Copy Markdown
Contributor Author

aapoalas commented Dec 1, 2025

with complicates symbol resolution a lot. Is there anything else we need to do to make Semantic make sense of it?

For example, I guess minifier should not mangle var names where they're accessed "through" a with, in the same way that it I think takes account of whether a var can be "seen" by an eval().

e.g. let foo = 1; with ({foo: 2}) foo = 3; would change behavior if foo var is renamed. Though maybe that's such an edge case, we shouldn't worry about it.

Out of interest, what's your use case for this in Nova? My sincere condolences if you actually need to make with behave correctly. Nightmare!

with is actually really simple! That is, from an engine point of view if the engine is not interested in doing any optimisations. I have like 90% of with done and am only missing the bytecode instruction for it because I'm lazy and don't like it as a feature :D

The use-case I have is actually the same that you describe, basically: I am currently writing a sorts of "runtime minification" (or just an optimisation) probably better known as register allocation, wherein I'd like to rewrite eg. the foo variable in your example into a stack slot if the transformation is sound. In a with scope, such a transformation is not sound as your example illustrates, so if I had proper with support then I'd need to be able to detect them for this optimisation to be soundly applied.

Currently, I am applying this optimisation based on the Scoping information mainly, hence my interest in the flag :)

taearls pushed a commit to taearls/oxc that referenced this pull request Dec 11, 2025
…ditional` (oxc-project#16309)

Add `#[inline]` attr to this method, for consistency with all the rest.

This omission was spotted by @aapoalas in oxc-project#16291.
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Dec 12, 2025
@graphite-app
Copy link
Copy Markdown
Contributor

graphite-app bot commented Dec 12, 2025

Merge activity

  • Dec 12, 6:28 AM UTC: @aapoalas we removed the merge queue label because we could not find a Graphite account associated with your GitHub profile.

You must have a Graphite account in order to use the merge queue. Create an account and try again using this link

@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Dec 12, 2025
@Boshen
Copy link
Copy Markdown
Member

Boshen commented Dec 12, 2025

Didn't find any problems from PR review, merge so we can get a release out next week.

@Boshen Boshen merged commit d221921 into oxc-project:main Dec 12, 2025
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast Area - AST A-semantic Area - Semantic C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants