Make our h handle void tags properly
This commit is contained in:
parent
c14af18bef
commit
aff6390cc7
1 changed files with 8 additions and 0 deletions
|
@ -3,6 +3,9 @@ export type HChild = string | undefined | (() => string);
|
||||||
export type HMXComponent = (props: HProps, ...children: Array<HChild>) => string;
|
export type HMXComponent = (props: HProps, ...children: Array<HChild>) => string;
|
||||||
export type HTag = string | HMXComponent;
|
export type HTag = string | HMXComponent;
|
||||||
|
|
||||||
|
const voidTags = new Set(['area', 'base', 'br', 'col', 'command', 'embed', 'hr',
|
||||||
|
'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr']);
|
||||||
|
|
||||||
function* _h(tag: string, attrs: HProps, children: Array<HChild>) {
|
function* _h(tag: string, attrs: HProps, children: Array<HChild>) {
|
||||||
yield `<${tag}`;
|
yield `<${tag}`;
|
||||||
if (attrs) {
|
if (attrs) {
|
||||||
|
@ -13,6 +16,11 @@ function* _h(tag: string, attrs: HProps, children: Array<HChild>) {
|
||||||
}
|
}
|
||||||
yield '>';
|
yield '>';
|
||||||
|
|
||||||
|
// Void tags have no children.
|
||||||
|
if(voidTags.has(tag)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (let child of children) {
|
for (let child of children) {
|
||||||
// Special: If a child is a function, call it automatically.
|
// Special: If a child is a function, call it automatically.
|
||||||
// This lets you do {() => ...} without the extra boilerplate
|
// This lets you do {() => ...} without the extra boilerplate
|
||||||
|
|
Loading…
Reference in a new issue