diff options
author | 2021-04-30 16:33:35 -0500 | |
---|---|---|
committer | 2021-04-30 16:33:35 -0500 | |
commit | 4df1347156cf2632ea2f3475d3a5f8f08d197cc3 (patch) | |
tree | 9d50de89dfe62827c32a8a4046120af4ab61dc0c /src/frontend/h.ts | |
parent | 1d498facc8f78a3ffbfecd05cc6ecd45e8a4a1ae (diff) | |
download | astro-4df1347156cf2632ea2f3475d3a5f8f08d197cc3.tar.gz astro-4df1347156cf2632ea2f3475d3a5f8f08d197cc3.tar.zst astro-4df1347156cf2632ea2f3475d3a5f8f08d197cc3.zip |
Migrate to `yarn` monorepo (#157)
* chore: use monorepo
* chore: scaffold astro-scripts
* chore: move tests inside packages/astro
* chore: refactor tests, add scripts
* chore: move parser to own module
* chore: move runtime to packages/astro
* fix: move parser to own package
* test: fix prettier-plugin-astro tests
* fix: tests
* chore: update package-lock
* chore: add changesets
* fix: cleanup examples
* fix: starter example
* chore: update changeset config
* chore: update changeset config
* chore: setup changeset release workflow
* chore: bump lockfiles
* chore: prism => astro-prism
* fix: tsc --emitDeclarationOnly
* chore: final cleanup, switch to yarn
* chore: add lerna
* chore: update workflows to yarn
* chore: update workflows
* chore: remove lint workflow
* chore: add astro-dev script
* chore: add symlinked README
Diffstat (limited to 'src/frontend/h.ts')
-rw-r--r-- | src/frontend/h.ts | 65 |
1 files changed, 0 insertions, 65 deletions
diff --git a/src/frontend/h.ts b/src/frontend/h.ts deleted file mode 100644 index c1e21dc95..000000000 --- a/src/frontend/h.ts +++ /dev/null @@ -1,65 +0,0 @@ -export type HProps = Record<string, string> | null | undefined; -export type HChild = string | undefined | (() => string); -export type AstroComponent = (props: HProps, ...children: Array<HChild>) => string; -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 '; - if (attrs) { - yield Object.keys(attrs).join(' '); - } - yield '>'; - return; - } - - yield `<${tag}`; - if (attrs) { - yield ' '; - for (let [key, value] of Object.entries(attrs)) { - yield `${key}="${value}"`; - } - } - 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 - // of wrapping it in a function and calling it. - if (typeof child === 'function') { - yield child(); - } else if (typeof child === 'string') { - yield child; - } else if (!child) { - // do nothing, safe to ignore falsey values. - } else { - yield child; - } - } - - 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') { - // We assume it's an astro component - return tag(attrs, ...children); - } - - return Array.from(_h(tag, attrs, children)).join(''); -} - -/** Fragment helper, similar to React.Fragment */ -export function Fragment(_: HProps, ...children: Array<string>) { - return children.join(''); -} |