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 dotted component name support for babel-plugin-transform-jsx-to-htm #98

Merged
merged 4 commits into from
Jul 4, 2019
Merged

Add dotted component name support for babel-plugin-transform-jsx-to-htm #98

merged 4 commits into from
Jul 4, 2019

Conversation

jviide
Copy link
Collaborator

@jviide jviide commented Jul 3, 2019

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 as a.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).

@jviide jviide requested a review from developit July 3, 2019 18:17
@dy
Copy link

dy commented Jul 3, 2019

@jviide isn't that a potential blocker for snabbdom hyperscript use-cases?
Eg. that supports extended hyperscript notation as:

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)

@jviide
Copy link
Collaborator Author

jviide commented Jul 3, 2019

html`<div#container.two.classes></>` is supported by HTM. This pull request is about the babel-plugin-transform-jsx-to-htm plugin, and doesn't modify HTM's behavior. babel-plugin-transform-jsx-to-htm is a Babel-plugin that transforms JSX to HTM, and <div#container.two.classes /> doesn't seem to be valid JSX as seen here.

@jviide jviide changed the title Add dotted component name support for babel-transform-jsx Add dotted component name support for babel-plugin-transform-jsx-to-htm Jul 3, 2019
@jviide
Copy link
Collaborator Author

jviide commented Jul 3, 2019

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.

@jviide
Copy link
Collaborator Author

jviide commented Jul 3, 2019

@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: [] }

@dy
Copy link

dy commented Jul 3, 2019

@jviide (FYI) I've researched some of useful edge-cases, which would be nice to keep covered by htm:

// passing non-stringy tags
html`<${document.body}>
  <div>Our app code to render into body</div>
<//>`

// react fragments
html`<></>`

// second slash for closing tag is optional
html`<a></>`

// "fragment" tag with properties
html`<mount=${target}></mount>`
html`< mount=${target}></mount>`

// html "spread" (useful for reducers)
html`<...>`

// direct selectors
html`<#reference-id></>`

The only feature remains uncovered by htm is anonymous props as <a ${disabled}></>, had some thoughts on how that could be implemented, but seems that doesn't make a big use-case.

@jviide
Copy link
Collaborator Author

jviide commented Jul 3, 2019

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 html`<a /><b /><c />` .

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 :)

@jviide jviide merged commit 8c3b084 into developit:master Jul 4, 2019
@jviide jviide deleted the dotted-components branch July 4, 2019 09:04
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.

3 participants