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

feat: support jsx #200

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Conversation

yuusheng
Copy link

@yuusheng yuusheng commented Jan 5, 2024

πŸ”— Linked issue

#138

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Currently jiti has no jsx support. This PR aims to support jsx with some simple configurations.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@yuusheng yuusheng marked this pull request as ready for review January 5, 2024 19:14
src/options.ts Show resolved Hide resolved
@pi0 pi0 changed the title feat(jsx): add basic jsx support for jiti feat: support jsx Jan 10, 2024
src/babel.ts Outdated
}

_opts.presets.push([
require("@babel/preset-react"),
Copy link
Member

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

Copy link
Author

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.

Copy link
Author

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.

Copy link
Member

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)

Copy link
Author

@yuusheng yuusheng Jan 11, 2024

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.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@yuusheng
Copy link
Author

Should this PR merge into the main branch? Maybe merge into the v1 branch?

@pi0
Copy link
Member

pi0 commented Jan 10, 2024

main should we fine we shall announce it for v2 πŸ‘πŸΌ

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

Successfully merging this pull request may close these issues.

None yet

2 participants