diff --git a/src/frontend/h.ts b/src/frontend/h.ts index 3d9e62f43..3ba0541e8 100644 --- a/src/frontend/h.ts +++ b/src/frontend/h.ts @@ -3,6 +3,9 @@ export type HChild = string | undefined | (() => string); export type HMXComponent = (props: HProps, ...children: Array) => string; 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) { yield `<${tag}`; if (attrs) { @@ -13,6 +16,11 @@ function* _h(tag: string, attrs: HProps, children: Array) { } yield '>'; + // Void tags have no children. + if(voidTags.has(tag)) { + return; + } + for (let child of children) { // Special: If a child is a function, call it automatically. // This lets you do {() => ...} without the extra boilerplate