From f8c2d828bd6fd15fabac334a489d1c3ab7e2d209 Mon Sep 17 00:00:00 2001 From: matthewp Date: Mon, 8 Aug 2022 19:38:05 +0000 Subject: [PATCH] [ci] format --- packages/astro/src/runtime/server/endpoint.ts | 7 +----- .../astro/src/runtime/server/hydration.ts | 6 +++-- packages/astro/src/runtime/server/index.ts | 23 +++++++++---------- .../astro/src/runtime/server/render/any.ts | 2 +- .../astro/src/runtime/server/render/astro.ts | 16 +++++++------ .../astro/src/runtime/server/render/common.ts | 3 +-- .../src/runtime/server/render/component.ts | 18 ++++++--------- .../astro/src/runtime/server/render/index.ts | 8 +++---- .../astro/src/runtime/server/render/page.ts | 2 +- .../astro/src/runtime/server/render/types.ts | 2 +- .../astro/src/runtime/server/render/util.ts | 2 +- 11 files changed, 41 insertions(+), 48 deletions(-) diff --git a/packages/astro/src/runtime/server/endpoint.ts b/packages/astro/src/runtime/server/endpoint.ts index 95bea8b64..a5ecc29e0 100644 --- a/packages/astro/src/runtime/server/endpoint.ts +++ b/packages/astro/src/runtime/server/endpoint.ts @@ -1,9 +1,4 @@ - -import type { - APIContext, - EndpointHandler, - Params -} from '../../@types/astro'; +import type { APIContext, EndpointHandler, Params } from '../../@types/astro'; function getHandlerFromModule(mod: EndpointHandler, method: string) { // If there was an exact match on `method`, return that function. diff --git a/packages/astro/src/runtime/server/hydration.ts b/packages/astro/src/runtime/server/hydration.ts index c4cfc6ec6..0a4341ab0 100644 --- a/packages/astro/src/runtime/server/hydration.ts +++ b/packages/astro/src/runtime/server/hydration.ts @@ -10,7 +10,7 @@ import { serializeListValue } from './util.js'; const HydrationDirectivesRaw = ['load', 'idle', 'media', 'visible', 'only']; const HydrationDirectives = new Set(HydrationDirectivesRaw); -export const HydrationDirectiveProps = new Set(HydrationDirectivesRaw.map(n => `client:${n}`)); +export const HydrationDirectiveProps = new Set(HydrationDirectivesRaw.map((n) => `client:${n}`)); export interface HydrationMetadata { directive: string; @@ -72,7 +72,9 @@ export function extractDirectives(inputProps: Record): Ext // throw an error if an invalid hydration directive was provided if (!HydrationDirectives.has(extracted.hydration.directive)) { throw new Error( - `Error: invalid hydration directive "${key}". Supported hydration methods: ${Array.from(HydrationDirectiveProps).join(', ')}` + `Error: invalid hydration directive "${key}". Supported hydration methods: ${Array.from( + HydrationDirectiveProps + ).join(', ')}` ); } diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts index c60aaf59b..9604d0b17 100644 --- a/packages/astro/src/runtime/server/index.ts +++ b/packages/astro/src/runtime/server/index.ts @@ -1,3 +1,5 @@ +export { createAstro } from './astro-global.js'; +export { renderEndpoint } from './endpoint.js'; export { escapeHTML, HTMLString, @@ -6,32 +8,29 @@ export { } from './escape.js'; export type { Metadata } from './metadata'; export { createMetadata } from './metadata.js'; -export type { AstroComponentFactory, RenderInstruction } from './render/index.js'; -import type { AstroComponentFactory } from './render/index.js'; - -import { Renderer } from './render/index.js'; -import { markHTMLString } from './escape.js'; - -export { createAstro } from './astro-global.js'; export { addAttribute, - voidElementNames, defineScriptVars, + Fragment, maybeRenderHead, renderAstroComponent, renderComponent, + Renderer as Renderer, renderHead, renderHTMLElement, renderPage, renderSlot, - renderTemplate, renderTemplate as render, + renderTemplate, renderToString, stringifyChunk, - Fragment, - Renderer as Renderer + voidElementNames, } from './render/index.js'; -export { renderEndpoint } from './endpoint.js'; +export type { AstroComponentFactory, RenderInstruction } from './render/index.js'; +import type { AstroComponentFactory } from './render/index.js'; + +import { markHTMLString } from './escape.js'; +import { Renderer } from './render/index.js'; import { addAttribute } from './render/index.js'; diff --git a/packages/astro/src/runtime/server/render/any.ts b/packages/astro/src/runtime/server/render/any.ts index 2f4987708..9c6e199c2 100644 --- a/packages/astro/src/runtime/server/render/any.ts +++ b/packages/astro/src/runtime/server/render/any.ts @@ -1,5 +1,5 @@ +import { escapeHTML, HTMLString, markHTMLString } from '../escape.js'; import { AstroComponent, renderAstroComponent } from './astro.js'; -import { markHTMLString, HTMLString, escapeHTML } from '../escape.js'; import { stringifyChunk } from './common.js'; export async function* renderChild(child: any): AsyncIterable { diff --git a/packages/astro/src/runtime/server/render/astro.ts b/packages/astro/src/runtime/server/render/astro.ts index c9e9ac91f..b7e47a68c 100644 --- a/packages/astro/src/runtime/server/render/astro.ts +++ b/packages/astro/src/runtime/server/render/astro.ts @@ -1,19 +1,21 @@ import type { SSRResult } from '../../../@types/astro'; -import type { RenderInstruction } from './types'; import type { AstroComponentFactory } from './index'; +import type { RenderInstruction } from './types'; -import { HydrationDirectiveProps } from '../hydration.js'; -import { stringifyChunk } from './common.js'; import { markHTMLString } from '../escape.js'; +import { HydrationDirectiveProps } from '../hydration.js'; import { renderChild } from './any.js'; +import { stringifyChunk } from './common.js'; // In dev mode, check props and make sure they are valid for an Astro component function validateComponentProps(props: any, displayName: string) { - if(import.meta.env?.DEV && props != null) { - for(const prop of Object.keys(props)) { - if(HydrationDirectiveProps.has(prop)) { + if (import.meta.env?.DEV && props != null) { + for (const prop of Object.keys(props)) { + if (HydrationDirectiveProps.has(prop)) { // eslint-disable-next-line - console.warn(`You are attempting to render <${displayName} ${prop} />, but ${displayName} is an Astro component. Astro components do not render in the client and should not have a hydration directive. Please use a framework component for client rendering.`); + console.warn( + `You are attempting to render <${displayName} ${prop} />, but ${displayName} is an Astro component. Astro components do not render in the client and should not have a hydration directive. Please use a framework component for client rendering.` + ); } } } diff --git a/packages/astro/src/runtime/server/render/common.ts b/packages/astro/src/runtime/server/render/common.ts index cebbf5966..27b012aa4 100644 --- a/packages/astro/src/runtime/server/render/common.ts +++ b/packages/astro/src/runtime/server/render/common.ts @@ -6,13 +6,12 @@ import { determineIfNeedsHydrationScript, determinesIfNeedsDirectiveScript, getPrescripts, -PrescriptType, + PrescriptType, } from '../scripts.js'; export const Fragment = Symbol.for('astro:fragment'); export const Renderer = Symbol.for('astro:renderer'); - // Rendering produces either marked strings of HTML or instructions for hydration. // These directive instructions bubble all the way up to renderPage so that we // can ensure they are added only once, and as soon as possible. diff --git a/packages/astro/src/runtime/server/render/component.ts b/packages/astro/src/runtime/server/render/component.ts index 38e6add65..200b8dccd 100644 --- a/packages/astro/src/runtime/server/render/component.ts +++ b/packages/astro/src/runtime/server/render/component.ts @@ -1,17 +1,13 @@ -import type { - AstroComponentMetadata, - SSRLoadedRenderer, - SSRResult, -} from '../../../@types/astro'; +import type { AstroComponentMetadata, SSRLoadedRenderer, SSRResult } from '../../../@types/astro'; import type { RenderInstruction } from './types.js'; +import { markHTMLString } from '../escape.js'; import { extractDirectives, generateHydrateScript } from '../hydration.js'; import { serializeProps } from '../serialize.js'; import { shorthash } from '../shorthash.js'; -import { Fragment, Renderer } from './common.js'; -import { markHTMLString } from '../escape.js'; import { renderSlot } from './any.js'; -import { renderToIterable, renderAstroComponent, renderTemplate } from './astro.js'; +import { renderAstroComponent, renderTemplate, renderToIterable } from './astro.js'; +import { Fragment, Renderer } from './common.js'; import { componentIsHTMLElement, renderHTMLElement } from './dom.js'; import { formatList, internalSpreadAttributes, renderElement, voidElementNames } from './util.js'; @@ -38,10 +34,10 @@ function getComponentType(Component: unknown): ComponentType { if (Component === Fragment) { return 'fragment'; } - if(Component && typeof Component === 'object' && (Component as any)['astro:html']) { + if (Component && typeof Component === 'object' && (Component as any)['astro:html']) { return 'html'; } - if(Component && (Component as any).isAstroComponentFactory) { + if (Component && (Component as any).isAstroComponentFactory) { return 'astro-factory'; } return 'unknown'; @@ -56,7 +52,7 @@ export async function renderComponent( ): Promise> { Component = await Component; - switch(getComponentType(Component)) { + switch (getComponentType(Component)) { case 'fragment': { const children = await renderSlot(result, slots?.default); if (children == null) { diff --git a/packages/astro/src/runtime/server/render/index.ts b/packages/astro/src/runtime/server/render/index.ts index e74c3ffb6..a7de515e2 100644 --- a/packages/astro/src/runtime/server/render/index.ts +++ b/packages/astro/src/runtime/server/render/index.ts @@ -1,13 +1,13 @@ import { renderTemplate } from './astro.js'; -export type { RenderInstruction } from './types'; export { renderSlot } from './any.js'; -export { renderTemplate, renderAstroComponent, renderToString } from './astro.js'; -export { stringifyChunk, Fragment, Renderer } from './common.js'; +export { renderAstroComponent, renderTemplate, renderToString } from './astro.js'; +export { Fragment, Renderer, stringifyChunk } from './common.js'; export { renderComponent } from './component.js'; export { renderHTMLElement } from './dom.js'; -export { renderHead, maybeRenderHead } from './head.js'; +export { maybeRenderHead, renderHead } from './head.js'; export { renderPage } from './page.js'; +export type { RenderInstruction } from './types'; export { addAttribute, defineScriptVars, voidElementNames } from './util.js'; // The callback passed to to $$createComponent diff --git a/packages/astro/src/runtime/server/render/page.ts b/packages/astro/src/runtime/server/render/page.ts index 99c047e57..9e2c0fd2b 100644 --- a/packages/astro/src/runtime/server/render/page.ts +++ b/packages/astro/src/runtime/server/render/page.ts @@ -1,11 +1,11 @@ import type { SSRResult } from '../../../@types/astro'; import type { AstroComponentFactory } from './index'; +import { createResponse } from '../response.js'; import { isAstroComponent, renderAstroComponent } from './astro.js'; import { stringifyChunk } from './common.js'; import { renderComponent } from './component.js'; import { maybeRenderHead } from './head.js'; -import { createResponse } from '../response.js'; const encoder = new TextEncoder(); diff --git a/packages/astro/src/runtime/server/render/types.ts b/packages/astro/src/runtime/server/render/types.ts index 3cc534ac6..a9e1afe65 100644 --- a/packages/astro/src/runtime/server/render/types.ts +++ b/packages/astro/src/runtime/server/render/types.ts @@ -1,5 +1,5 @@ import type { SSRResult } from '../../../@types/astro'; -import type { HydrationMetadata } from '../hydration.js'; +import type { HydrationMetadata } from '../hydration.js'; export interface RenderInstruction { type: 'directive'; diff --git a/packages/astro/src/runtime/server/render/util.ts b/packages/astro/src/runtime/server/render/util.ts index d3585fb81..afccf9df9 100644 --- a/packages/astro/src/runtime/server/render/util.ts +++ b/packages/astro/src/runtime/server/render/util.ts @@ -1,6 +1,6 @@ import type { SSRElement } from '../../../@types/astro'; -import { markHTMLString, HTMLString } from '../escape.js'; +import { HTMLString, markHTMLString } from '../escape.js'; import { serializeListValue } from '../util.js'; export const voidElementNames =