Skip to content

fix(transformer): ignore @jsxImportSource inside inline code spans in comments#20674

Merged
graphite-app[bot] merged 1 commit intomainfrom
fix/jsx-pragma-backtick
Mar 24, 2026
Merged

fix(transformer): ignore @jsxImportSource inside inline code spans in comments#20674
graphite-app[bot] merged 1 commit intomainfrom
fix/jsx-pragma-backtick

Conversation

@Dunqing
Copy link
Copy Markdown
Member

@Dunqing Dunqing commented Mar 24, 2026

Summary

  • Fix JSX pragma scanner incorrectly matching @jsxImportSource inside backtick code spans (e.g. `@jsxImportSource custom/source`) in doc comments
  • Add validation that @ must be preceded by whitespace, *, or be at the start of the comment

Problem

The memchr-based @ search found pragma directives anywhere in a comment, including inside inline code spans. This caused:

  1. A @jsxImportSource inside a doc comment overriding the actual file-level pragma
  2. The trailing backtick being included in the import specifier (custom/source`)

This broke Vite 8 dev server when .tsx files had JSDoc comments mentioning @jsxImportSource.

Design

Tool @ position check
esbuild None — matches @jsx anywhere in comment
Babel Full start-of-line regex (^\s*(?:\*\s*)?@jsx)
Oxc (this PR) Preceding byte must be whitespace, *, or start of comment

We intentionally sit between esbuild and Babel — checking only the immediately preceding byte is sufficient for the backtick case without being as strict as Babel's full start-of-line regex.

Fixes #20669

Test plan

  • Unit tests added for backtick-wrapped pragmas
  • Conformance test fixture added (issue-20669)
  • All existing transformer tests pass
  • Clippy clean

🤖 Generated with Claude Code

@github-actions github-actions bot added the A-transformer Area - Transformer / Transpiler label Mar 24, 2026
Copy link
Copy Markdown
Member Author

Dunqing commented Mar 24, 2026


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 changes, fast-track this PR to the front of 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.

@github-actions github-actions bot added the C-bug Category - Bug label Mar 24, 2026
@Dunqing Dunqing force-pushed the fix/jsx-pragma-backtick branch 2 times, most recently from af50cc8 to da1550c Compare March 24, 2026 02:38
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 24, 2026

Merging this PR will improve performance by 3.2%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 48 untouched benchmarks
⏩ 7 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation mangler[RadixUIAdoptionSection.jsx_keep_names] 20.1 µs 19.5 µs +3.2%

Comparing fix/jsx-pragma-backtick (9439b5d) with main (2917bb2)2

Open in CodSpeed

Footnotes

  1. 7 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.

  2. No successful run was found on main (6b5cd8c) during the generation of this report, so 2917bb2 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@Dunqing Dunqing force-pushed the fix/jsx-pragma-backtick branch from da1550c to 9439b5d Compare March 24, 2026 03:25
@Dunqing Dunqing marked this pull request as ready for review March 24, 2026 03:25
@Dunqing Dunqing requested a review from overlookmotel as a code owner March 24, 2026 03:25
@Dunqing Dunqing requested a review from sapphi-red March 24, 2026 03:26
Copy link
Copy Markdown
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

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

It seems TypeScript has the same behavior with us (and esbuild).
TS playground

That said, I think it is safe to diverge for this bit.

@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Mar 24, 2026
@graphite-app
Copy link
Copy Markdown
Contributor

graphite-app bot commented Mar 24, 2026

Merge activity

…in comments (#20674)

## Summary

- Fix JSX pragma scanner incorrectly matching `@jsxImportSource` inside backtick code spans (e.g. `` `@jsxImportSource custom/source` ``) in doc comments
- Add validation that `@` must be preceded by whitespace, `*`, or be at the start of the comment

## Problem

The `memchr`-based `@` search found pragma directives anywhere in a comment, including inside inline code spans. This caused:
1. A `@jsxImportSource` inside a doc comment overriding the actual file-level pragma
2. The trailing backtick being included in the import specifier (`` custom/source` ``)

This broke Vite 8 dev server when `.tsx` files had JSDoc comments mentioning `@jsxImportSource`.

## Design

| Tool | `@` position check |
|------|-------------------|
| esbuild | None — matches `@jsx` anywhere in comment |
| Babel | Full start-of-line regex (`^\s*(?:\*\s*)?@jsx`) |
| **Oxc (this PR)** | Preceding byte must be whitespace, `*`, or start of comment |

We intentionally sit between esbuild and Babel — checking only the immediately preceding byte is sufficient for the backtick case without being as strict as Babel's full start-of-line regex.

Fixes #20669

## Test plan

- [x] Unit tests added for backtick-wrapped pragmas
- [x] Conformance test fixture added (`issue-20669`)
- [x] All existing transformer tests pass
- [x] Clippy clean

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@graphite-app graphite-app bot force-pushed the fix/jsx-pragma-backtick branch from 9439b5d to 3931b98 Compare March 24, 2026 09:22
@graphite-app graphite-app bot merged commit 3931b98 into main Mar 24, 2026
26 checks passed
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Mar 24, 2026
@graphite-app graphite-app bot deleted the fix/jsx-pragma-backtick branch March 24, 2026 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-transformer Area - Transformer / Transpiler C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@jsxImportSource in non-leading JSDoc comment overrides file pragma

2 participants