From 5fa7e354b3e66ea95b2c210f51cc2517897bf8f0 Mon Sep 17 00:00:00 2001 From: natemoo-re Date: Wed, 26 May 2021 18:31:27 +0000 Subject: [PATCH] [ci] yarn format --- .changeset/shaggy-countries-battle.md | 5 +- packages/astro-parser/src/parse/utils/html.ts | 33 +------- packages/astro/src/@types/astro.ts | 4 +- packages/astro/src/@types/hydrate.ts | 2 +- packages/astro/src/build/page.ts | 2 +- packages/astro/src/compiler/codegen/index.ts | 7 +- .../astro/src/compiler/transform/hydration.ts | 19 ++--- .../astro/src/frontend/__astro_component.ts | 82 +++++++++---------- packages/astro/src/frontend/renderer-astro.ts | 4 +- packages/astro/src/runtime.ts | 78 +++++++++--------- packages/renderers/preact/index.js | 2 +- packages/renderers/preact/server.js | 12 +-- packages/renderers/preact/static-html.js | 16 ++-- packages/renderers/react/client.js | 3 +- packages/renderers/react/index.js | 2 +- packages/renderers/react/server.js | 10 +-- packages/renderers/react/static-html.js | 16 ++-- packages/renderers/svelte/client.js | 6 +- packages/renderers/svelte/index.js | 2 +- packages/renderers/svelte/server.js | 6 +- packages/renderers/vue/client.js | 4 +- packages/renderers/vue/index.js | 2 +- packages/renderers/vue/server.js | 6 +- packages/renderers/vue/static-html.js | 22 ++--- .../plugins/typescript/DocumentSnapshot.ts | 2 +- .../typescript/LanguageServiceManager.ts | 4 +- 26 files changed, 159 insertions(+), 192 deletions(-) diff --git a/.changeset/shaggy-countries-battle.md b/.changeset/shaggy-countries-battle.md index 66bd7f7f4..7174a7643 100644 --- a/.changeset/shaggy-countries-battle.md +++ b/.changeset/shaggy-countries-battle.md @@ -9,10 +9,11 @@ Updated the rendering pipeline for `astro` to truly support any framework. For the vast majority of use cases, `astro` should _just work_ out of the box. Astro now depends on `@astro-renderer/preact`, `@astro-renderer/react`, `@astro-renderer/svelte`, and `@astro-renderer/vue`, rather than these being built into the core library. This opens the door for anyone to contribute additional renderers for Astro to support their favorite framework, as well as the ability for users to control which renderers should be used. **Features** + - Expose a pluggable interface for controlling server-side rendering and client-side hydration -- Allows components from different frameworks to be nested within each other. +- Allows components from different frameworks to be nested within each other. > Note: `svelte` currently does support non-destructive hydration, so components from other frameworks cannot currently be nested inside of a Svelte component. See https://github.com/sveltejs/svelte/issues/4308. **Breaking Changes** -- To improve compiler performance, improve framework support, and minimize JS payloads, any children passed to hydrated components are automatically wrapped with an `` element. +- To improve compiler performance, improve framework support, and minimize JS payloads, any children passed to hydrated components are automatically wrapped with an `` element. diff --git a/packages/astro-parser/src/parse/utils/html.ts b/packages/astro-parser/src/parse/utils/html.ts index 3b406c9cc..e4669a2db 100644 --- a/packages/astro-parser/src/parse/utils/html.ts +++ b/packages/astro-parser/src/parse/utils/html.ts @@ -3,38 +3,7 @@ import entities from './entities.js'; const windows_1252 = [ - 8364, - 129, - 8218, - 402, - 8222, - 8230, - 8224, - 8225, - 710, - 8240, - 352, - 8249, - 338, - 141, - 381, - 143, - 144, - 8216, - 8217, - 8220, - 8221, - 8226, - 8211, - 8212, - 732, - 8482, - 353, - 8250, - 339, - 157, - 382, - 376, + 8364, 129, 8218, 402, 8222, 8230, 8224, 8225, 710, 8240, 352, 8249, 338, 141, 381, 143, 144, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 732, 8482, 353, 8250, 339, 157, 382, 376, ]; const entity_pattern = new RegExp(`&(#?(?:x[\\w\\d]+|\\d+|${Object.keys(entities).join('|')}))(?:;|\\b)`, 'g'); diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index ddd08b726..5db544b2a 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -125,9 +125,7 @@ export interface CollectionRSS { /** Specify custom data in opening of file */ customData?: string; /** Return data about each item */ - item: ( - item: T - ) => { + item: (item: T) => { /** (required) Title of item */ title: string; /** (required) Link to item */ diff --git a/packages/astro/src/@types/hydrate.ts b/packages/astro/src/@types/hydrate.ts index 1f89b6464..ff1ab0781 100644 --- a/packages/astro/src/@types/hydrate.ts +++ b/packages/astro/src/@types/hydrate.ts @@ -1 +1 @@ -export type GetHydrateCallback = () => Promise<(element: Element, innerHTML: string|null) => void>; +export type GetHydrateCallback = () => Promise<(element: Element, innerHTML: string | null) => void>; diff --git a/packages/astro/src/build/page.ts b/packages/astro/src/build/page.ts index b53b5f5bc..ccc04fe2e 100644 --- a/packages/astro/src/build/page.ts +++ b/packages/astro/src/build/page.ts @@ -103,6 +103,6 @@ export async function buildStaticPage({ astroConfig, buildState, filepath, runti contentType: 'text/html', encoding: 'utf8', }; - }) + }), ]); } diff --git a/packages/astro/src/compiler/codegen/index.ts b/packages/astro/src/compiler/codegen/index.ts index 25243a79c..b6027b946 100644 --- a/packages/astro/src/compiler/codegen/index.ts +++ b/packages/astro/src/compiler/codegen/index.ts @@ -146,7 +146,8 @@ function getComponentWrapper(_name: string, { url, importSpecifier }: ComponentI }; const getComponentExport = () => { switch (importSpecifier.type) { - case 'ImportDefaultSpecifier': return { value: 'default' }; + case 'ImportDefaultSpecifier': + return { value: 'default' }; case 'ImportSpecifier': { if (importSpecifier.imported.type === 'Identifier') { return { value: importSpecifier.imported.name }; @@ -158,13 +159,13 @@ function getComponentWrapper(_name: string, { url, importSpecifier }: ComponentI return { value }; } } - } + }; const importInfo = kind ? { componentUrl: getComponentUrl(), componentExport: getComponentExport() } : {}; return { wrapper: `__astro_component(${name}, ${JSON.stringify({ hydrate: kind, displayName: name, ...importInfo })})`, wrapperImport: `import {__astro_component} from '${internalImport('__astro_component.js')}';`, - } + }; } /** Evaluate expression (safely) */ diff --git a/packages/astro/src/compiler/transform/hydration.ts b/packages/astro/src/compiler/transform/hydration.ts index 23b0fd4ba..8a6b2700a 100644 --- a/packages/astro/src/compiler/transform/hydration.ts +++ b/packages/astro/src/compiler/transform/hydration.ts @@ -16,7 +16,7 @@ export default function (): Transformer { if (kind && !hasComponents) { hasComponents = true; } - } + }, }, Element: { enter(node) { @@ -30,10 +30,11 @@ export default function (): Transformer { body = node; return; } - default: return; + default: + return; } - } - } + }, + }, }, }, async finalize() { @@ -42,9 +43,7 @@ export default function (): Transformer { const style: TemplateNode = { type: 'Element', name: 'style', - attributes: [ - { name: 'type', type: 'Attribute', value: [{ type: 'Text', raw: 'text/css', data: 'text/css' }] }, - ], + attributes: [{ name: 'type', type: 'Attribute', value: [{ type: 'Text', raw: 'text/css', data: 'text/css' }] }], start: 0, end: 0, children: [ @@ -53,9 +52,9 @@ export default function (): Transformer { end: 0, type: 'Text', data: 'astro-root, astro-fragment { display: contents; }', - raw: 'astro-root, astro-fragment { display: contents; }' - } - ] + raw: 'astro-root, astro-fragment { display: contents; }', + }, + ], }; head.children = [...(head.children ?? []), style]; }, diff --git a/packages/astro/src/frontend/__astro_component.ts b/packages/astro/src/frontend/__astro_component.ts index dca4e45f2..b6678c5e3 100644 --- a/packages/astro/src/frontend/__astro_component.ts +++ b/packages/astro/src/frontend/__astro_component.ts @@ -7,17 +7,17 @@ import * as astro from './renderer-astro'; // see https://github.com/remcohaszing/estree-util-value-to-estree#readme const serialize = (value: Value) => generate(valueToEstree(value)); -/** - * These values are dynamically injected by Snowpack. - * See comment in `snowpack-plugin.cjs`! - * - * In a world where Snowpack supports virtual files, this won't be necessary. - * It would ideally look something like: - * - * ```ts - * import { __rendererSources, __renderers } from "virtual:astro/runtime" - * ``` - */ +/** + * These values are dynamically injected by Snowpack. + * See comment in `snowpack-plugin.cjs`! + * + * In a world where Snowpack supports virtual files, this won't be necessary. + * It would ideally look something like: + * + * ```ts + * import { __rendererSources, __renderers } from "virtual:astro/runtime" + * ``` + */ declare let __rendererSources: string[]; declare let __renderers: any[]; @@ -33,7 +33,7 @@ function resolveRenderer(Component: any, props: any = {}) { } for (const __renderer of __renderers) { - const shouldUse = __renderer.check(Component, props) + const shouldUse = __renderer.check(Component, props); if (shouldUse) { rendererCache.set(Component, __renderer); return __renderer; @@ -43,15 +43,14 @@ function resolveRenderer(Component: any, props: any = {}) { interface AstroComponentProps { displayName: string; - hydrate?: 'load'|'idle'|'visible'; - componentUrl?: string; - componentExport?: { value: string, namespace?: boolean }; + hydrate?: 'load' | 'idle' | 'visible'; + componentUrl?: string; + componentExport?: { value: string; namespace?: boolean }; } - /** For hydrated components, generate a