-
Notifications
You must be signed in to change notification settings - Fork 170
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 dotted component name support for babel-plugin-transform-jsx-to-htm #98
Conversation
@jviide isn't that a potential blocker for snabbdom hyperscript use-cases? h('div#container.two.classes', ...) which is with htm would be html`<div#container.two.classes></>` - can be quite handy, although not fully valid html. (although that seems to be not relevant concern here) |
|
Eh, sorry, I meant babel-plugin-transform-jsx-to-htm, not babel-transform-jsx. Sorry for the confusion! Updated my previous comments to reflect this. |
@dy The snabbdom use-case you gave is very interesting though, so I double checked just to be sure. HTM does indeed support this :) > const htm = require("./dist/htm");
> const html = htm.bind((type, props, ...children) => ({ type, props, children }));
> html`<div#container.two.classes></>`
{ type: 'div#container.two.classes', props: null, children: [] } |
@jviide (FYI) I've researched some of useful edge-cases, which would be nice to keep covered by htm:
The only feature remains uncovered by |
Thanks. Of the cases you mentioned, non-stringy tags are an integral part of HTM. HTM also supports fragments (or "multiple root elements") natively, for example try out Supporting the other cases "officially" is probably best discussed in its own issue (or issues), as they seem to be a bit outside of the scope of this specific pull request :) |
This pull request is an offshoot of #85 (by @blikblum), and modifies babel-plugin-transform-jsx-to-htm to support dotted component names like
<a.b.c />
.The new logic considers all element names that either start with a capital letter,
$
or_
or are not valid identifiers as component references. It should be noted that dotted names (member expressions) such asa.b.c
are not valid identifiers, and are therefore considered to be component references.This PR also adds tests for dotted components. There are also new tests for special-cased component names such as
$foo
and_foo
(introduced in #92).