fix(parser): preserve @__NO_SIDE_EFFECTS__ annotation with parenthesized expressions#17711
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. This stack of pull requests is managed by Graphite. Learn more about stacking. |
CodSpeed Performance ReportMerging #17711 will not alter performanceComparing Summary
Footnotes
|
|
cc @sapphi-red you may want to take a look at this |
3ba549a to
3478800
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where @__NO_SIDE_EFFECTS__ annotations were being lost when applied to parenthesized function expressions. The issue occurred in Vue's source code where functions were annotated and wrapped in parentheses like /* @__NO_SIDE_EFFECTS__ */ ((x) => x).
The fix addresses two root causes:
- Lexer checkpoints now preserve trivia flags (
has_pure_commentandhas_no_side_effects_comment) across lookahead operations parse_parenthesized_expressionnow captures the annotation flag before bumping the opening(token and propagates it to nested arrow/function expressions
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/oxc_parser/src/lexer/mod.rs | Added has_pure_comment and has_no_side_effects_comment fields to LexerCheckpoint struct and updated checkpoint save/restore logic to preserve trivia annotation flags across lexer rewind operations |
| crates/oxc_parser/src/js/expression.rs | Modified parse_parenthesized_expression to capture @__NO_SIDE_EFFECTS__ annotation before consuming the opening parenthesis and set the pure flag on nested arrow/function expressions |
| crates/oxc_codegen/tests/integration/snapshots/pure_comments.snap | Added snapshot expectations for 4 test cases covering parenthesized arrow and function expressions with @__NO_SIDE_EFFECTS__ annotation |
| crates/oxc_codegen/tests/integration/comments.rs | Added 4 test cases for @__NO_SIDE_EFFECTS__ annotation preservation with parenthesized expressions: multi-param arrow function, single-param arrow function, anonymous function expression, and named function expression |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merge activity
|
…sized expressions (#17711) Fixes #17670 Two issues caused the annotation to be lost: 1. LexerCheckpoint did not save/restore trivia flags, so lookahead operations would reset them 2. parse_parenthesized_expression did not capture the annotation before bumping `(` monitor oxc https://github.com/oxc-project/monitor-oxc/actions/runs/20745400998/job/59561563786 CI is not yet green, but the codegen diff looks a lot better
3478800 to
ef7e014
Compare
### 🚀 Features - 10426af codegen: Print soft space between inline block comments on the same line (#17799) (camc314) - 2261e6e semantic: Improve error message to add `#` for private identifiers (#17779) (Dunqing) ### 🐛 Bug Fixes - 7422b7e parser/trivia: Correctly mark whether a block comment is on a newline (#17754) (camc314) - c32e8d5 codegen: Wrap `TSAsExpression` in parens when used with in/instanceof operators (#17752) (camc314) - 5755b2d semantic: Report duplicate private identifier for static and instance elements (#17591) (camc314) - 0600df3 isolated_declarations: Only print jsdoc comments (#17748) (camc314) - ef7e014 parser: Preserve `@__NO_SIDE_EFFECTS__` annotation with parenthesized expressions (#17711) (camc314) - 59a6228 parser: Detect TS1363 error for type-only imports with mixed default and named/namespace bindings (#17712) (Copilot) ### ⚡ Performance - 864f1fa semantic: Mark duplicate class element error reporting as cold (#17746) (camc314) - 3a452b8 semantic: Use smallvec for storing reference IDs (#17731) (camchenry) - d5979dc minifier: Do not allocate when checking to convert `const` to `let` (#17730) (camchenry) - 3f4429c parser: Do not re-allocate TS interface heritage (#17692) (camchenry) ### 📚 Documentation - 120a27c minifier: Add prettier-ignore for js-in-md part (#17687) (leaysgur) Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>

Fixes #17670
Two issues caused the annotation to be lost:
(monitor oxc https://github.com/oxc-project/monitor-oxc/actions/runs/20745400998/job/59561563786
CI is not yet green, but the codegen diff looks a lot better