-
Notifications
You must be signed in to change notification settings - Fork 171
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
Concatenate mixed static + dynamic attribute values #93
Conversation
Marked this PR as draft, because it doesn't yet implement the string concatenation for the Babel plugins. |
Now babel-plugin-htm also supports concatenating mixed static + dynamic attribute values. Some refactoring was necessary. The The logic tries to keep the resulting code at least somewhat compact. For example |
Pushed a commit that fixed a performance regression in the non-mini version. Now the master and this PR get the same results when running As a nice bonus the build size shrunk by 3 bytes, so the in total this branch adds +23 bytes to the non-mini build. |
packages/babel-plugin-htm/index.mjs
Outdated
@@ -1,4 +1,4 @@ | |||
import htm from 'htm'; | |||
import { build, treeify } from '../../src/build.mjs'; |
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.
Does this get bundled? If not the path will fail when published.
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.
Yes, build
and treeify
get bundled to dist/babel-plugin-htm.js
(and the corresponding .mjs
file).
(Fixed the weird tab between { build,
and treeify }
though 🙂)
This pull request implements string concatenation for mixed static + dynamic attributes and adds related tests. As long as there's more than one dynamic and/or static value they get interpreted as strings and concatenated. In practice this means that
<div a="${1}2" />
,<div a="1${2}" />
,<div a="${1}${2}" />
,<div a=${1}${2} />
and so on are effectively parsed as<div a=${"1" + "2"} />
.As a side effect HTM now allows empty attribute names like
<div =1 />
or<div ""=1 />
.The
htm.mjs.br
size changes by +26 bytes (540 B -> 566 B) for the default build and +18 bytes (376 B -> 394 B) for the mini build.Closes #58.