summaryrefslogtreecommitdiff
path: root/src/frontend/h.ts
diff options
context:
space:
mode:
authorGravatar Drew Powers <1369770+drwpow@users.noreply.github.com> 2021-04-01 10:25:28 -0600
committerGravatar GitHub <noreply@github.com> 2021-04-01 10:25:28 -0600
commitc26c244ca2634d462616d6cf71072fbe26becba2 (patch)
tree1bd5e83eff9ca88200aacb272c84439f192015ec /src/frontend/h.ts
parentf6a7ac67befff863e34133673efb78ea7ac0fe48 (diff)
downloadastro-c26c244ca2634d462616d6cf71072fbe26becba2.tar.gz
astro-c26c244ca2634d462616d6cf71072fbe26becba2.tar.zst
astro-c26c244ca2634d462616d6cf71072fbe26becba2.zip
Annoying Lint PR #2 (#47)
Diffstat (limited to 'src/frontend/h.ts')
-rw-r--r--src/frontend/h.ts3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/frontend/h.ts b/src/frontend/h.ts
index 7d26d21d2..c1e21dc95 100644
--- a/src/frontend/h.ts
+++ b/src/frontend/h.ts
@@ -5,6 +5,7 @@ export type HTag = string | AstroComponent;
const voidTags = new Set(['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr']);
+/** Generator for primary h() function */
function* _h(tag: string, attrs: HProps, children: Array<HChild>) {
if (tag === '!doctype') {
yield '<!doctype ';
@@ -47,6 +48,7 @@ function* _h(tag: string, attrs: HProps, children: Array<HChild>) {
yield `</${tag}>`;
}
+/** Astro‘s primary h() function. Allows it to use JSX-like syntax. */
export async function h(tag: HTag, attrs: HProps, ...pChildren: Array<Promise<HChild>>) {
const children = await Promise.all(pChildren.flat(Infinity));
if (typeof tag === 'function') {
@@ -57,6 +59,7 @@ export async function h(tag: HTag, attrs: HProps, ...pChildren: Array<Promise<HC
return Array.from(_h(tag, attrs, children)).join('');
}
+/** Fragment helper, similar to React.Fragment */
export function Fragment(_: HProps, ...children: Array<string>) {
return children.join('');
}