feat(semantic): ScopeFlags::With#16291
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via 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. |
There was a problem hiding this comment.
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::Withflag definition with documentation - Added
is_with()helper method for checking the flag - Applied the flag when entering
withstatement 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.
CodSpeed Performance ReportMerging #16291 will not alter performanceComparing Summary
Footnotes
|
lilnasy
left a comment
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
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 Currently, I am applying this optimisation based on the Scoping information mainly, hence my interest in the flag :) |
…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.
|
Didn't find any problems from PR review, merge so we can get a release out next week. |
Simple addition but unfortunately untested: I locally fail tsgo related tests, probably for reasons related to not having tsgo installed?