Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support JSX annotation #138

Closed
sarsamurmu opened this issue May 24, 2020 · 6 comments
Closed

Support JSX annotation #138

sarsamurmu opened this issue May 24, 2020 · 6 comments

Comments

@sarsamurmu
Copy link

Can we support JSX annotations?

Input

// @jsx h
<div />

Output

h('div') // Expected
React.createElement('div') // Actual

I am using esbuild in a build tool, that's why I need it.

@evanw
Copy link
Owner

evanw commented May 25, 2020

The way to do this is to pass the --jsx-factory=h flag to esbuild or, if you're using the API, enable the jsxFactory: 'h' option. See also the Using with React section in the readme.

@evanw evanw closed this as completed in 5c6b3ab Jul 12, 2020
@evanw
Copy link
Owner

evanw commented Jul 16, 2020

This is now supported as of version 0.6.3.

@sarsamurmu
Copy link
Author

That's great, Thanks

@bluepnume
Copy link

Is there a plan to also support @jsxFragment pragma? e.g. @jsxFragment MyCustomJSXFragment

@evanw
Copy link
Owner

evanw commented May 8, 2024

Is there a plan to also support @jsxFragment pragma? e.g. @jsxFragment MyCustomJSXFragment

Here are the release notes for version 0.6.3 (from the commit that closed this issue, linked above):

  • Add support for @jsx and @jsxFrag comments (#138)

    You can now override the JSX factory and fragment values on a per-file basis using comments:

    // @jsx h
    // @jsxFrag Fragment
    import {h, Fragment} from 'preact'
    console.log(<><a/></>)

    This now generates the following code:

    import {h, Fragment} from "preact";
    console.log(h(Fragment, null, h("a", null)));

As you can see, esbuild uses @jsxFrag instead of @jsxFragment. I did that because that's what https://babeljs.io/docs/babel-plugin-transform-react-jsx does, so AFAIK that's what the community is used to. I have no plans to also support @jsxFragment in addition to @jsxFrag.

@bluepnume
Copy link

That's perfect, sorry, should have read the commit! Thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants