Proposal for Improving JSX Transform #10557
magic-akari
started this conversation in
Ideas
Replies: 2 comments 17 replies
-
Can we support JSX pragma from the |
Beta Was this translation helpful? Give feedback.
16 replies
-
I've noticed that the react-refresh module executes before the JSX transform step. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Related Issues:
Observed Behavior in Ecosystem
Current JSX transform implementations (Babel, esbuild, TypeScript) exhibit distinct behaviors regarding scoped
@jsx
pragma resolution that SWC does not fully replicate. This proposal addresses inconsistencies in local JSX pragma handling.Pragma resolution adheres to lexical scoping
The
jsxPragma
always references the nearest available declaration within scope. Example:This behavior is consistent across Babel, esbuild, and TypeScript.
Nested pragma comments are permitted
/* @jsx */
directives function in non-top-level scopes:Post-JSX pragmas in the same scope are honored (Babel/esbuild only):
TypeScript limitation: Only processes top-level pragmas
Current SWC Behavior
SWC's JSX transform consistently resolves
jsxPragma
to top-level declarations, disregarding scoping rules. Example:Transforms to:
Proposed Enhancement
Classic JSX transform (non-Automatic) should operate context-independently via
jsxPragma
directives. Implementation strategies:Option 1: Early JSX Transformation
Tradeoffs:
Constitutes a breaking change: plugins receive transformed JSX AST, eliminating custom JSX handling. Mitigation approaches:
preserveJsx
option for plugin-managed JSXOption 2: Implement Hygiene + Dual Resolve Passes
Tradeoff:
Performance impact from dual resolution passes.
Note
Applies exclusively to Classic JSX (
jsxPragma
-based). Automatic JSX (usingjsx/jsxs
runtime) does not respect/* @jsx */
pragma comments and always utilizes injected runtime pragmas.Beta Was this translation helpful? Give feedback.
All reactions