fix(transformer/jsx): fix parsing JSX pragma comments#10983
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 Instrumentation Performance ReportMerging #10983 will degrade performances by 3.51%Comparing Summary
Benchmarks breakdown
|
I'll try to address this perf regression in a follow-up. |
Weird, shouldn't have any performance impact in this benchmark, as it applies when the source type is JSX. Could you investigate why this is happening? oxc/crates/oxc_transformer/src/lib.rs Lines 123 to 130 in 287b3c3 |
Merge activity
|
Fixes #10955. Allow multiple JSX pragmas in a single comment, or even in the same line. e.g. ```js /* @jsx h @jsxRuntime classic */ // @jsx h @jsxRuntime classic /** * @jsx h * @jsxRuntime classic */ ``` Also, allow pragmas to be anywhere in the comment, including surrounded by unrelated text. ```js // Unrelated text @jsx h Unrelated text @jsxRuntime classic /** * Unrelated text. * @jsx h * Unrelated text. * @jsxRuntime classic */ ``` This is more liberal than Babel, which [has a test](https://github.com/babel/babel/blob/226318d54eaff275500b2723c46ee608c0632df0/packages/babel-plugin-transform-react-jsx/test/fixtures/react/should-not-allow-jsx-pragma-to-be-anywhere-in-comment/input.js) specifically to outlaw placing pragmas amongst other text in a comment - this test is disabled in this PR. Instead, we're aligning with ESBuild ([ESBuild playground](https://esbuild.github.io/try/#dAAwLjI1LjQALS1sb2FkZXI9anN4IC0tanN4PWF1dG9tYXRpYwAvLyBAanN4IFNvbWV0aGluZyBibGFoIGJsYWggQGpzeFJ1bnRpbWUgY2xhc3NpYwo8YmxhaC8+Cg)) which seems to allow a `@jsx` pragma anywhere in the text of the comment.
0990df0 to
27a21a7
Compare
|
…11001) Use `memchr` for finding `@` when parsing JSX pragmas from comments. This wins back most (but not all) of the perf loss of #10983 on `antd.js` benchmark, and preserves the perf gain of #10983 on `cal.com.tsx` benchmark. Interestingly, using `memchr` to search just for `@` and then checking next 3 bytes are `jsx` separately is measurably faster than using `memchr::memmem::Finder` to search for `@jsx`.

Fixes #10955.
Allow multiple JSX pragmas in a single comment, or even in the same line. e.g.
Also, allow pragmas to be anywhere in the comment, including surrounded by unrelated text.
This is more liberal than Babel, which has a test specifically to outlaw placing pragmas amongst other text in a comment - this test is disabled in this PR.
Instead, we're aligning with ESBuild (ESBuild playground) which seems to allow a
@jsxpragma anywhere in the text of the comment.