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

Add support for using h, s as a JSX pragmas #15

Merged
merged 3 commits into from
Apr 26, 2021
Merged

Add support for using h, s as a JSX pragmas #15

merged 3 commits into from
Apr 26, 2021

Conversation

wooorm
Copy link
Member

@wooorm wooorm commented Nov 6, 2020

This change tests that hastscript can be used as the pragma for JSX with bublé
and babel.

Code-wise, this adds support for using h to generate root nodes.
This is done by omitting the tag name (like so: h(), h(null, 'child')).
Previously, omitting a name resulted in the default element to be created
(div for h, g for s).

This change thus is a breaking change.
The old behavior is still available when passing an empty string: h('').

Another aspect of supporting JSX is supporting fragments as children.
As fragments yield root nodes, we unravel them and use only their children.
While this could be seen a change, hast prohibits roots occurring in nodes,
so the unraveling instead fixes what would otherwise be a broken tree.

Related to: syntax-tree/xastscript#3.
Related to: syntax-tree/xastscript#4.

This change tests that `hastscript` can be used as the pragma for JSX with bublé
and babel.

Code-wise, this adds support for using `h` to generate root nodes.
This is done by omitting the tag name (like so: `h()`, `h(null, 'child')`).
Previously, omitting a `name` resulted in the default element to be created
(`div` for `h`, `g` for `s`).

This change thus is a breaking change.
The old behavior is still available when passing an empty string: `h('')`.

Another aspect of supporting JSX is supporting fragments as children.
As fragments yield root nodes, we unravel them and use only their children.
While this could be seen a change, hast prohibits roots occurring in nodes,
so the unraveling instead fixes what would otherwise be a broken tree.

Related to: syntax-tree/xastscript#3.
Related to: syntax-tree/xastscript#4.
@wooorm wooorm added 🦋 type/enhancement This is great to have 🧑 semver/major This is a change 🗄 area/interface This affects the public interface 🙆 yes/confirmed This is confirmed and ready to be worked on labels Nov 6, 2020
@ChristianMurphy
Copy link
Member

It looks like null can now be used as a element name, would the typings need to be updated to include null?

@wooorm
Copy link
Member Author

wooorm commented Nov 6, 2020

Correct!

@remcohaszing
Copy link
Member

It looks like the build was succesful, but Travis had some internal error. Can we rebase and release this? I don’t need this, but I do think it’s cool 😃

I think the JSX type definitions can be literally copy-pasted from xastscript.

@wooorm
Copy link
Member Author

wooorm commented Mar 2, 2021

I think it’s a major, so I was hoping to put that into the ESM rush™

@wooorm wooorm merged commit dd94377 into main Apr 26, 2021
@wooorm wooorm deleted the jsx branch April 26, 2021 18:42
@wooorm wooorm added 💪 phase/solved Post is done and removed 🙆 yes/confirmed This is confirmed and ready to be worked on labels Apr 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗄 area/interface This affects the public interface 💪 phase/solved Post is done 🧑 semver/major This is a change 🦋 type/enhancement This is great to have
Development

Successfully merging this pull request may close these issues.

3 participants