refactor(parser): align jsx parsing to tsc#11314
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. |
CodSpeed Instrumentation Performance ReportMerging #11314 will degrade performances by 8.23%Comparing Summary
Benchmarks breakdown
|
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the JSX parser to mirror TypeScript’s approach by centralizing JSX element and fragment parsing and updating lookahead logic.
- Replaced manual lookahead branches in
parse_jsx_attribute_valuewith a unifiedparse_jsx_expressionmatch. - Enhanced
parse_literal_or_identifierlookahead to detect fragments viaKind::RAngle. - Removed outdated JSX comment and streamlined fragment detection.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/oxc_parser/src/jsx/mod.rs | Simplify attribute value parsing using parse_jsx_expression |
| crates/oxc_parser/src/js/expression.rs | Extend lookahead to recognize <> fragment start |
Comments suppressed due to low confidence (1)
crates/oxc_parser/src/js/expression.rs:1018
- The new lookahead condition for fragment detection (
p.at(Kind::RAngle)) isn't covered by existing tests. Add a parser test case for<> ... </>inside expressions to ensure this branch is exercised.
p.at(Kind::RAngle) || p.cur_kind().is_identifier_or_keyword()
Merge activity
|
My original plan was to rework the JSX parser from the entry point, as I had found in #11232. However, when I read through all the TSC JSX parser code, I found that what we are doing is not much different. --- As for perf perspective, the OXC currently requires rewind in 3 places for JSX: - 1: `parse_jsx_expression()` - `lookahead` - To determine if it is a `JSXElement`(`<C`) OR `JSXFragment`(`<>`) at the entry point - 2: `parse_jsx_child()` - `checkpoint+rewind` - The same above OR breaking list(`</`) - 3: `parse_jsx_child()` - `checkpoint+rewind` - To determine if it is `JSXChild::Spread`(`{...Expression}`) OR `JSXChild::ExpressionContainer`(`{JSXExpression}`) These don't exist in TSC, they just use union type or loose ASTs. But we have different and explicit ASTs in Rust, it seems they can't be easily eliminated. And unfortunately, I tried, but there was no remarkable improvement. - For 1, 3045952 => Minifier +3%, but no effect for parser - For 2, I wish we had `Kind::LessThanSlash`... - For 3, a12ff21 => No effect for parser As a result, I think it would be better to keep the current clean and explicit code.
My original plan was to rework the JSX parser from the entry point, as I had found in #11232.
However, when I read through all the TSC JSX parser code, I found that what we are doing is not much different.
As for perf perspective, the OXC currently requires rewind in 3 places for JSX:
parse_jsx_expression()-lookaheadJSXElement(<C) ORJSXFragment(<>) at the entry pointparse_jsx_child()-checkpoint+rewind</)parse_jsx_child()-checkpoint+rewindJSXChild::Spread({...Expression}) ORJSXChild::ExpressionContainer({JSXExpression})These don't exist in TSC, they just use union type or loose ASTs.
But we have different and explicit ASTs in Rust, it seems they can't be easily eliminated.
And unfortunately, I tried, but there was no remarkable improvement.
Kind::LessThanSlash...As a result, I think it would be better to keep the current clean and explicit code.