Skip to content

perf(transformer): only scan comments before first statement for JSX pragmas#20675

Merged
graphite-app[bot] merged 1 commit intomainfrom
refactor/jsx-pragma-leading-comments-only
Mar 24, 2026
Merged

perf(transformer): only scan comments before first statement for JSX pragmas#20675
graphite-app[bot] merged 1 commit intomainfrom
refactor/jsx-pragma-leading-comments-only

Conversation

@Dunqing
Copy link
Copy Markdown
Member

@Dunqing Dunqing commented Mar 24, 2026

Summary

  • Restrict JSX pragma scanning to only comments appearing before the first statement, since pragmas are file-level directives
  • Pass first_statement_start position to update_options_with_comments and skip comments at or after that position

Motivation

Previously all comments in a file were scanned for JSX pragmas, which meant pragmas in doc comments on functions could override file-level pragmas. This aligns Oxc with TypeScript and SWC, which both restrict pragma scanning to leading comments.

Tool Pragma scan scope
TypeScript Leading comments before first token
SWC Leading block comments, stops at first pragma-bearing statement
Babel All comments (last wins)
esbuild All comments (last wins)
Oxc (after) Comments before first statement

Test plan

  • All transformer tests pass
  • Conformance tests pass (including issue-20669 fixture from parent PR)
  • Clippy clean

🤖 Generated with Claude Code

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 A-transformer Area - Transformer / Transpiler C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels Mar 24, 2026
@Dunqing Dunqing changed the title refactor(transformer): only scan comments before first statement for JSX pragmas perf(transformer): only scan comments before first statement for JSX pragmas Mar 24, 2026
@github-actions github-actions bot added the C-performance Category - Solution not expected to change functional behavior, only performance label Mar 24, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 24, 2026

Merging this PR will not alter performance

✅ 49 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing refactor/jsx-pragma-leading-comments-only (cd25e3f) with fix/jsx-pragma-backtick (da1550c)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 fix/jsx-pragma-backtick (9439b5d) during the generation of this report, so e8697ce 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 refactor/jsx-pragma-leading-comments-only branch 2 times, most recently from a740466 to 225ded7 Compare March 24, 2026 02:20
@Dunqing Dunqing force-pushed the fix/jsx-pragma-backtick branch from 9ce3b27 to af50cc8 Compare March 24, 2026 02:36
@Dunqing Dunqing force-pushed the refactor/jsx-pragma-leading-comments-only branch 2 times, most recently from df98a5e to fa8b679 Compare March 24, 2026 02:38
@Dunqing Dunqing force-pushed the fix/jsx-pragma-backtick branch 2 times, most recently from da1550c to 9439b5d Compare March 24, 2026 03:25
@Dunqing Dunqing force-pushed the refactor/jsx-pragma-leading-comments-only branch from fa8b679 to cd25e3f Compare March 24, 2026 03:25
@Dunqing Dunqing marked this pull request as ready for review March 24, 2026 03:26
@Dunqing Dunqing requested a review from overlookmotel as a code owner March 24, 2026 03:26
@Dunqing Dunqing requested a review from sapphi-red March 24, 2026 03:26
@Dunqing
Copy link
Copy Markdown
Member Author

Dunqing commented Mar 24, 2026

@sapphi-red I'd like to hear your thoughts on this, as this would diverge from esbuild and babel but align with typescript and swc. I think it is fine. What do you think?

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.

I think this behavior makes sense and I wouldn't expect any code to break by this change.

Maybe we should clarify the behavior in https://oxc.rs/docs/guide/usage/transformer/jsx.html, adding a section about how pragma comments are parsed

@Dunqing
Copy link
Copy Markdown
Member Author

Dunqing commented Mar 24, 2026

Maybe we should clarify the behavior in https://oxc.rs/docs/guide/usage/transformer/jsx.html, adding a section about how pragma comments are parsed

Thank you for reminding me. I will send a PR to follow it later

@Dunqing Dunqing added the 0-merge Merge with Graphite Merge Queue label Mar 24, 2026
Copy link
Copy Markdown
Member Author

Dunqing commented Mar 24, 2026

Merge activity

…pragmas (#20675)

## Summary

- Restrict JSX pragma scanning to only comments appearing before the first statement, since pragmas are file-level directives
- Pass `first_statement_start` position to `update_options_with_comments` and skip comments at or after that position

## Motivation

Previously all comments in a file were scanned for JSX pragmas, which meant pragmas in doc comments on functions could override file-level pragmas. This aligns Oxc with TypeScript and SWC, which both restrict pragma scanning to leading comments.

| Tool | Pragma scan scope |
|------|-------------------|
| TypeScript | Leading comments before first token |
| SWC | Leading block comments, stops at first pragma-bearing statement |
| Babel | All comments (last wins) |
| esbuild | All comments (last wins) |
| **Oxc (after)** | Comments before first statement |

## Test plan

- [x] All transformer tests pass
- [x] Conformance tests pass (including `issue-20669` fixture from parent PR)
- [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 force-pushed the refactor/jsx-pragma-leading-comments-only branch from cd25e3f to bd10021 Compare March 24, 2026 09:23
Base automatically changed from fix/jsx-pragma-backtick to main March 24, 2026 09:26
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Mar 24, 2026
@graphite-app graphite-app bot merged commit bd10021 into main Mar 24, 2026
27 checks passed
@graphite-app graphite-app bot deleted the refactor/jsx-pragma-leading-comments-only branch March 24, 2026 09:27
Dunqing added a commit to oxc-project/website that referenced this pull request Mar 25, 2026
Clarify that Oxc only scans comments before the first statement for
JSX pragmas, aligning with TypeScript and SWC behavior. This was
requested in oxc-project/oxc#20675 review feedback.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Dunqing added a commit to oxc-project/website that referenced this pull request Mar 25, 2026
Clarify that Oxc only scans comments before the first statement for
JSX pragmas, aligning with TypeScript and SWC behavior. This was
requested in oxc-project/oxc#20675 review feedback.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
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-cleanup Category - technical debt or refactoring. Solution not expected to change behavior C-performance Category - Solution not expected to change functional behavior, only performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants