summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@skypack.dev> 2021-03-15 15:41:15 -0400
committerGravatar Matthew Phillips <matthew@skypack.dev> 2021-03-15 15:41:15 -0400
commitaff6390cc79a09d2e413917912ff598e7f3d3c32 (patch)
treed0b08f18632a5cefdcd1ebc5c63dc6195c8fccd4
parentc14af18bef1ba450870c299e8cbc663f5537089a (diff)
downloadastro-aff6390cc79a09d2e413917912ff598e7f3d3c32.tar.gz
astro-aff6390cc79a09d2e413917912ff598e7f3d3c32.tar.zst
astro-aff6390cc79a09d2e413917912ff598e7f3d3c32.zip
Make our h handle void tags properly
-rw-r--r--src/frontend/h.ts8
1 files changed, 8 insertions, 0 deletions
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<HChild>) => 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<HChild>) {
yield `<${tag}`;
if (attrs) {
@@ -13,6 +16,11 @@ function* _h(tag: string, attrs: HProps, children: Array<HChild>) {
}
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