summaryrefslogtreecommitdiff
path: root/src/frontend/render
diff options
context:
space:
mode:
authorGravatar natemoo-re <natemoo-re@users.noreply.github.com> 2021-04-15 15:56:27 +0000
committerGravatar GitHub Actions <actions@github.com> 2021-04-15 15:56:27 +0000
commit2a7aa765b47c2d3acd038224ea167c54de910f29 (patch)
tree9cefbfbd60e966b71e5cb1ef6e030c8a047321e9 /src/frontend/render
parent22ca9e0aacf26bf82aa5d0ddd6d1e1d495a1a945 (diff)
downloadastro-2a7aa765b47c2d3acd038224ea167c54de910f29.tar.gz
astro-2a7aa765b47c2d3acd038224ea167c54de910f29.tar.zst
astro-2a7aa765b47c2d3acd038224ea167c54de910f29.zip
[ci] npm run format
Diffstat (limited to 'src/frontend/render')
-rw-r--r--src/frontend/render/preact.ts2
-rw-r--r--src/frontend/render/react.ts2
-rw-r--r--src/frontend/render/renderer.ts2
-rw-r--r--src/frontend/render/svelte.ts2
-rw-r--r--src/frontend/render/utils.ts48
-rw-r--r--src/frontend/render/vue.ts8
6 files changed, 32 insertions, 32 deletions
diff --git a/src/frontend/render/preact.ts b/src/frontend/render/preact.ts
index df7c903b0..5c50b6fe3 100644
--- a/src/frontend/render/preact.ts
+++ b/src/frontend/render/preact.ts
@@ -13,7 +13,7 @@ const Preact: ComponentRenderer<ComponentType> = {
renderStatic(Component) {
return async (props, ...children) => {
return renderToString(h(Component, props, childrenToVnodes(h, children)));
- }
+ };
},
imports: {
preact: ['render', 'Fragment', 'h'],
diff --git a/src/frontend/render/react.ts b/src/frontend/render/react.ts
index ac812e9c1..51c0c9729 100644
--- a/src/frontend/render/react.ts
+++ b/src/frontend/render/react.ts
@@ -10,7 +10,7 @@ const ReactRenderer: ComponentRenderer<ComponentType> = {
renderStatic(Component) {
return async (props, ...children) => {
return ReactDOMServer.renderToString(React.createElement(Component, props, childrenToVnodes(React.createElement, children)));
- }
+ };
},
imports: {
react: ['default: React'],
diff --git a/src/frontend/render/renderer.ts b/src/frontend/render/renderer.ts
index 25aec3653..00b4f5622 100644
--- a/src/frontend/render/renderer.ts
+++ b/src/frontend/render/renderer.ts
@@ -40,7 +40,7 @@ export function createRenderer(renderer: SupportedComponentRenderer) {
...innerContext,
props: serializeProps(props),
children: `[${childrenToH(renderer, children) ?? ''}]`,
- childrenAsString: `\`${children}\``
+ childrenAsString: `\`${children}\``,
})}
${typeof wrapperEnd === 'function' ? wrapperEnd(innerContext) : wrapperEnd}
`;
diff --git a/src/frontend/render/svelte.ts b/src/frontend/render/svelte.ts
index 7d657c3f7..f78591071 100644
--- a/src/frontend/render/svelte.ts
+++ b/src/frontend/render/svelte.ts
@@ -11,7 +11,7 @@ const SvelteRenderer: ComponentRenderer<SvelteComponent> = {
};
},
imports: {
- 'astro/frontend/runtime/svelte': ['default: render']
+ 'astro/frontend/runtime/svelte': ['default: render'],
},
render({ Component, root, props, childrenAsString }) {
return `render(${root}, ${Component}, ${props}, ${childrenAsString});`;
diff --git a/src/frontend/render/utils.ts b/src/frontend/render/utils.ts
index 7001a7f95..2a1cc9ecf 100644
--- a/src/frontend/render/utils.ts
+++ b/src/frontend/render/utils.ts
@@ -6,7 +6,7 @@ import moize from 'moize';
/** @internal */
function childrenToTree(children: string[]) {
- return children.map(child => (unified().use(parse, { fragment: true }).parse(child) as any).children.pop());
+ return children.map((child) => (unified().use(parse, { fragment: true }).parse(child) as any).children.pop());
}
/**
@@ -15,10 +15,10 @@ function childrenToTree(children: string[]) {
* @param children the HTML string children
*/
export const childrenToVnodes = moize.deep(function childrenToVnodes(h: any, children: string[]) {
- const tree = childrenToTree(children);
- const vnodes = tree.map(subtree => toH(h, subtree));
- return vnodes;
-})
+ const tree = childrenToTree(children);
+ const vnodes = tree.map((subtree) => toH(h, subtree));
+ return vnodes;
+});
/**
* Converts an HTML fragment string into h function calls as a string
@@ -26,22 +26,22 @@ export const childrenToVnodes = moize.deep(function childrenToVnodes(h: any, chi
* @param children the HTML string children
*/
export const childrenToH = moize.deep(function childrenToH(renderer: ComponentRenderer<any>, children: string[]): any {
- if (!renderer.jsxPragma) return;
- const tree = childrenToTree(children);
- const innerH = (name: any, attrs: Record<string, any>|null = null, _children: string[]|null = null) => {
- const vnode = renderer.jsxPragma?.(name, attrs, _children);
- const childStr = _children ? `, [${_children.map(child => serializeChild(child)).join(',')}]` : '';
- /* fix(react): avoid hard-coding keys into the serialized tree */
- if (attrs && attrs.key) attrs.key = undefined;
- const __SERIALIZED = `${renderer.jsxPragmaName}("${name}", ${attrs ? JSON.stringify(attrs) : 'null'}${childStr})` as string;
- return { ...vnode, __SERIALIZED }
- }
- const serializeChild = (child: unknown) => {
- if (typeof child === 'string') return `\`${child}\``;
- if (typeof child === 'number' || typeof child === 'boolean') return `${child}`;
- if (child === null) return `null`;
- if ((child as any).__SERIALIZED) return (child as any).__SERIALIZED;
- return innerH(child).__SERIALIZED;
- }
- return tree.map(subtree => toH(innerH, subtree).__SERIALIZED);
-})
+ if (!renderer.jsxPragma) return;
+ const tree = childrenToTree(children);
+ const innerH = (name: any, attrs: Record<string, any> | null = null, _children: string[] | null = null) => {
+ const vnode = renderer.jsxPragma?.(name, attrs, _children);
+ const childStr = _children ? `, [${_children.map((child) => serializeChild(child)).join(',')}]` : '';
+ /* fix(react): avoid hard-coding keys into the serialized tree */
+ if (attrs && attrs.key) attrs.key = undefined;
+ const __SERIALIZED = `${renderer.jsxPragmaName}("${name}", ${attrs ? JSON.stringify(attrs) : 'null'}${childStr})` as string;
+ return { ...vnode, __SERIALIZED };
+ };
+ const serializeChild = (child: unknown) => {
+ if (typeof child === 'string') return `\`${child}\``;
+ if (typeof child === 'number' || typeof child === 'boolean') return `${child}`;
+ if (child === null) return `null`;
+ if ((child as any).__SERIALIZED) return (child as any).__SERIALIZED;
+ return innerH(child).__SERIALIZED;
+ };
+ return tree.map((subtree) => toH(innerH, subtree).__SERIALIZED);
+});
diff --git a/src/frontend/render/vue.ts b/src/frontend/render/vue.ts
index cf2c203be..dce13556a 100644
--- a/src/frontend/render/vue.ts
+++ b/src/frontend/render/vue.ts
@@ -4,7 +4,7 @@ import { renderToString } from '@vue/server-renderer';
import { defineComponent, createSSRApp, h as createElement } from 'vue';
import { createRenderer } from './renderer';
-/**
+/**
* Users might attempt to use :vueAttribute syntax to pass primitive values.
* If so, try to JSON.parse them to get the primitives
*/
@@ -31,12 +31,12 @@ const Vue: ComponentRenderer<VueComponent> = {
return async (props, ...children) => {
const App = defineComponent({
components: {
- Component
+ Component,
},
data() {
- return { props }
+ return { props };
},
- template: `<Component v-bind="props">${children.join('\n')}</Component>`
+ template: `<Component v-bind="props">${children.join('\n')}</Component>`,
});
const app = createSSRApp(App);