mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
[ci] npm run format
This commit is contained in:
parent
22ca9e0aac
commit
2a7aa765b4
10 changed files with 171 additions and 173 deletions
|
@ -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) <Component {...props}>
|
||||
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) <Component {...props}>",
|
||||
ctx
|
||||
});
|
||||
dispatch_dev('SvelteRegisterBlock', {
|
||||
block,
|
||||
id: create_default_slot.name,
|
||||
type: 'slot',
|
||||
source: '(5:0) <Component {...props}>',
|
||||
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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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'],
|
||||
|
|
|
@ -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'],
|
||||
|
|
|
@ -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}
|
||||
`;
|
||||
|
|
|
@ -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});`;
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
};
|
||||
|
|
|
@ -261,7 +261,7 @@ async function createSnowpack(astroConfig: AstroConfig, env: Record<string, any>
|
|||
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: {
|
||||
|
|
Loading…
Reference in a new issue