-
Notifications
You must be signed in to change notification settings - Fork 47
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
feat: support jsx #200
base: main
Are you sure you want to change the base?
feat: support jsx #200
Conversation
src/babel.ts
Outdated
} | ||
|
||
_opts.presets.push([ | ||
require("@babel/preset-react"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should base on synctax-jsx
directly for basic/universal support https://babeljs.io/docs/babel-plugin-syntax-jsx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use @babel/preset-react
because @babel/plugin-syntax-jsx
can only support babel to parse this syntax, but cannot transform to code to h
function or React.createElement
. Or we can use both @babel/preset-react
and @babel/plugin-transform-react-jsx
to parse it and transform to h
function (or React.createElement
). @babel/preset-react
just do it inside.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use plugins to replace presets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for change. I will try to locally test but as explained in #138, my main idea to have minimal syntax changes and instead inject the react (or any other JSX renderer) render function in instead of tightly coupling with react (although rest of the ecosystem for many of historical reasons are currently are)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if I understand correctly. It seems that we didn't tightly couple with react. Installing react
as devDependencies is to solve the test error when running jsx files. And @babel/plugin-transform-react-jsx
can transform code from <div>foo</div>
to React.createElement('div', null, 'foo')
(or h('div', null, 'foo')
depends on configuration). That's all we do. The react (or other JSX renderer) renderer is injected by the users.
Should this PR merge into the |
|
π Linked issue
#138
β Type of change
π Description
Currently
jiti
has no jsx support. This PR aims to support jsx with some simple configurations.π Checklist