From 2a7aa765b47c2d3acd038224ea167c54de910f29 Mon Sep 17 00:00:00 2001 From: natemoo-re Date: Thu, 15 Apr 2021 15:56:27 +0000 Subject: [PATCH] [ci] npm run format --- src/frontend/SvelteWrapper.svelte.client.ts | 260 ++++++++++---------- src/frontend/SvelteWrapper.svelte.server.ts | 6 +- src/frontend/render/preact.ts | 2 +- src/frontend/render/react.ts | 2 +- src/frontend/render/renderer.ts | 2 +- src/frontend/render/svelte.ts | 2 +- src/frontend/render/utils.ts | 48 ++-- src/frontend/render/vue.ts | 8 +- src/frontend/runtime/svelte.ts | 12 +- src/runtime.ts | 2 +- 10 files changed, 171 insertions(+), 173 deletions(-) diff --git a/src/frontend/SvelteWrapper.svelte.client.ts b/src/frontend/SvelteWrapper.svelte.client.ts index 9ef0edd923..9df168895e 100644 --- a/src/frontend/SvelteWrapper.svelte.client.ts +++ b/src/frontend/SvelteWrapper.svelte.client.ts @@ -2,167 +2,165 @@ // @ts-nocheck // TODO: don't precompile this, but it works for now import { - HtmlTag, - SvelteComponentDev, - assign, - claim_component, - create_component, - destroy_component, - detach_dev, - dispatch_dev, - empty, - exclude_internal_props, - get_spread_object, - get_spread_update, - init, - insert_dev, - mount_component, - noop, - not_equal, - transition_in, - transition_out, - validate_slots -} from "svelte/internal"; + HtmlTag, + SvelteComponentDev, + assign, + claim_component, + create_component, + destroy_component, + detach_dev, + dispatch_dev, + empty, + exclude_internal_props, + get_spread_object, + get_spread_update, + init, + insert_dev, + mount_component, + noop, + not_equal, + transition_in, + transition_out, + validate_slots, +} from 'svelte/internal'; -const file = "App.svelte"; +const file = 'App.svelte'; // (5:0) function create_default_slot(ctx) { - let html_tag; - let html_anchor; + let html_tag; + let html_anchor; - const block = { - c: function create() { - html_anchor = empty(); - this.h(); - }, - l: function claim(nodes) { - html_anchor = empty(); - this.h(); - }, - h: function hydrate() { - html_tag = new HtmlTag(html_anchor); - }, - m: function mount(target, anchor) { - html_tag.m(/*__astro_children*/ ctx[1], target, anchor); - insert_dev(target, html_anchor, anchor); - }, - p: noop, - d: function destroy(detaching) { - if (detaching) detach_dev(html_anchor); - if (detaching) html_tag.d(); - } - }; + const block = { + c: function create() { + html_anchor = empty(); + this.h(); + }, + l: function claim(nodes) { + html_anchor = empty(); + this.h(); + }, + h: function hydrate() { + html_tag = new HtmlTag(html_anchor); + }, + m: function mount(target, anchor) { + html_tag.m(/*__astro_children*/ ctx[1], target, anchor); + insert_dev(target, html_anchor, anchor); + }, + p: noop, + d: function destroy(detaching) { + if (detaching) detach_dev(html_anchor); + if (detaching) html_tag.d(); + }, + }; - dispatch_dev("SvelteRegisterBlock", { - block, - id: create_default_slot.name, - type: "slot", - source: "(5:0) ", - ctx - }); + dispatch_dev('SvelteRegisterBlock', { + block, + id: create_default_slot.name, + type: 'slot', + source: '(5:0) ', + ctx, + }); - return block; + return block; } function create_fragment(ctx) { - let component; - let current; - const component_spread_levels = [/*props*/ ctx[2]]; + let component; + let current; + const component_spread_levels = [/*props*/ ctx[2]]; - let component_props = { - $$slots: { default: [create_default_slot] }, - $$scope: { ctx } - }; + let component_props = { + $$slots: { default: [create_default_slot] }, + $$scope: { ctx }, + }; - for (let i = 0; i < component_spread_levels.length; i += 1) { - component_props = assign(component_props, component_spread_levels[i]); - } + for (let i = 0; i < component_spread_levels.length; i += 1) { + component_props = assign(component_props, component_spread_levels[i]); + } - component = new /*Component*/ ctx[0]({ props: component_props, $$inline: true }); + component = new /*Component*/ ctx[0]({ props: component_props, $$inline: true }); - const block = { - c: function create() { - create_component(component.$$.fragment); - }, - l: function claim(nodes) { - claim_component(component.$$.fragment, nodes); - }, - m: function mount(target, anchor) { - mount_component(component, target, anchor); - current = true; - }, - p: function update(ctx, [dirty]) { - const component_changes = (dirty & /*props*/ 4) - ? get_spread_update(component_spread_levels, [get_spread_object(/*props*/ ctx[2])]) - : {}; + const block = { + c: function create() { + create_component(component.$$.fragment); + }, + l: function claim(nodes) { + claim_component(component.$$.fragment, nodes); + }, + m: function mount(target, anchor) { + mount_component(component, target, anchor); + current = true; + }, + p: function update(ctx, [dirty]) { + const component_changes = dirty & /*props*/ 4 ? get_spread_update(component_spread_levels, [get_spread_object(/*props*/ ctx[2])]) : {}; - if (dirty & /*$$scope*/ 16) { - component_changes.$$scope = { dirty, ctx }; - } + if (dirty & /*$$scope*/ 16) { + component_changes.$$scope = { dirty, ctx }; + } - component.$set(component_changes); - }, - i: function intro(local) { - if (current) return; - transition_in(component.$$.fragment, local); - current = true; - }, - o: function outro(local) { - transition_out(component.$$.fragment, local); - current = false; - }, - d: function destroy(detaching) { - destroy_component(component, detaching); - } - }; + component.$set(component_changes); + }, + i: function intro(local) { + if (current) return; + transition_in(component.$$.fragment, local); + current = true; + }, + o: function outro(local) { + transition_out(component.$$.fragment, local); + current = false; + }, + d: function destroy(detaching) { + destroy_component(component, detaching); + }, + }; - dispatch_dev("SvelteRegisterBlock", { - block, - id: create_fragment.name, - type: "component", - source: "", - ctx - }); + dispatch_dev('SvelteRegisterBlock', { + block, + id: create_fragment.name, + type: 'component', + source: '', + ctx, + }); - return block; + return block; } function instance($$self, $$props, $$invalidate) { - let { $$slots: slots = {}, $$scope } = $$props; - validate_slots("App", slots, []); - const { __astro_component: Component, __astro_children, ...props } = $$props; + let { $$slots: slots = {}, $$scope } = $$props; + validate_slots('App', slots, []); + const { __astro_component: Component, __astro_children, ...props } = $$props; - $$self.$$set = $$new_props => { - $$invalidate(3, $$props = assign(assign({}, $$props), exclude_internal_props($$new_props))); - }; + $$self.$$set = ($$new_props) => { + $$invalidate(3, ($$props = assign(assign({}, $$props), exclude_internal_props($$new_props)))); + }; - $$self.$capture_state = () => ({ Component, __astro_children, props }); + $$self.$capture_state = () => ({ Component, __astro_children, props }); - $$self.$inject_state = $$new_props => { - $$invalidate(3, $$props = assign(assign({}, $$props), $$new_props)); - }; + $$self.$inject_state = ($$new_props) => { + $$invalidate(3, ($$props = assign(assign({}, $$props), $$new_props))); + }; - if ($$props && "$$inject" in $$props) { - $$self.$inject_state($$props.$$inject); - } + if ($$props && '$$inject' in $$props) { + $$self.$inject_state($$props.$$inject); + } - $$props = exclude_internal_props($$props); - return [Component, __astro_children, props]; + $$props = exclude_internal_props($$props); + return [Component, __astro_children, props]; } class App extends SvelteComponentDev { - constructor(options) { - super(options); - init(this, options, instance, create_fragment, not_equal, {}); + constructor(options) { + super(options); + init(this, options, instance, create_fragment, not_equal, {}); - dispatch_dev("SvelteRegisterComponent", { - component: this, - tagName: "App", - options, - id: create_fragment.name - }); - } + dispatch_dev('SvelteRegisterComponent', { + component: this, + tagName: 'App', + options, + id: create_fragment.name, + }); + } } export default App; diff --git a/src/frontend/SvelteWrapper.svelte.server.ts b/src/frontend/SvelteWrapper.svelte.server.ts index d0e3679f1b..c5a25ff03b 100644 --- a/src/frontend/SvelteWrapper.svelte.server.ts +++ b/src/frontend/SvelteWrapper.svelte.server.ts @@ -2,11 +2,11 @@ // @ts-nocheck // TODO: don't precompile this, but it works for now /* App.svelte generated by Svelte v3.37.0 */ -import { create_ssr_component, validate_component } from "svelte/internal"; +import { create_ssr_component, validate_component } from 'svelte/internal'; const App = create_ssr_component(($$result, $$props, $$bindings, slots) => { - const { __astro_component: Component, __astro_children, ...props } = $$props; - return `${validate_component(Component, "Component").$$render($$result, Object.assign(props), {}, { default: () => `${__astro_children}` })}`; + const { __astro_component: Component, __astro_children, ...props } = $$props; + return `${validate_component(Component, 'Component').$$render($$result, Object.assign(props), {}, { default: () => `${__astro_children}` })}`; }); export default App; diff --git a/src/frontend/render/preact.ts b/src/frontend/render/preact.ts index df7c903b07..5c50b6fe33 100644 --- a/src/frontend/render/preact.ts +++ b/src/frontend/render/preact.ts @@ -13,7 +13,7 @@ const Preact: ComponentRenderer = { 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 ac812e9c16..51c0c9729c 100644 --- a/src/frontend/render/react.ts +++ b/src/frontend/render/react.ts @@ -10,7 +10,7 @@ const ReactRenderer: ComponentRenderer = { 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 25aec36536..00b4f56227 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 7d657c3f7c..f785910711 100644 --- a/src/frontend/render/svelte.ts +++ b/src/frontend/render/svelte.ts @@ -11,7 +11,7 @@ const SvelteRenderer: ComponentRenderer = { }; }, 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 7001a7f95e..2a1cc9ecf6 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, children: string[]): any { - if (!renderer.jsxPragma) return; - const tree = childrenToTree(children); - const innerH = (name: any, attrs: Record|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 | 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 cf2c203bee..dce13556ad 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 = { return async (props, ...children) => { const App = defineComponent({ components: { - Component + Component, }, data() { - return { props } + return { props }; }, - template: `${children.join('\n')}` + template: `${children.join('\n')}`, }); const app = createSSRApp(App); diff --git a/src/frontend/runtime/svelte.ts b/src/frontend/runtime/svelte.ts index 8d7f28b76e..78b6af6b67 100644 --- a/src/frontend/runtime/svelte.ts +++ b/src/frontend/runtime/svelte.ts @@ -2,9 +2,9 @@ import SvelteWrapper from '../SvelteWrapper.svelte.client'; import type { SvelteComponent } from 'svelte'; export default (target: Element, component: SvelteComponent, props: any, children: string) => { - new SvelteWrapper({ - target, - props: { __astro_component: component, __astro_children: children, ...props }, - hydrate: true - }) -} + new SvelteWrapper({ + target, + props: { __astro_component: component, __astro_children: children, ...props }, + hydrate: true, + }); +}; diff --git a/src/runtime.ts b/src/runtime.ts index fd203d2bdf..b21d790ec1 100644 --- a/src/runtime.ts +++ b/src/runtime.ts @@ -261,7 +261,7 @@ async function createSnowpack(astroConfig: AstroConfig, env: Record plugins: [ [fileURLToPath(new URL('../snowpack-plugin.cjs', import.meta.url)), astroPlugOptions], require.resolve('@snowpack/plugin-sass'), - [require.resolve('@snowpack/plugin-svelte'), { compilerOptions: { hydratable: true }}], + [require.resolve('@snowpack/plugin-svelte'), { compilerOptions: { hydratable: true } }], require.resolve('@snowpack/plugin-vue'), ], devOptions: {