[ci] format

This commit is contained in:
matthewp 2022-08-08 19:38:05 +00:00 committed by fredkbot
parent 6bc2cbe5e9
commit f8c2d828bd
11 changed files with 41 additions and 48 deletions

View file

@ -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.

View file

@ -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<string | number, any>): 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(', ')}`
);
}

View file

@ -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';

View file

@ -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<any> {

View file

@ -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.`
);
}
}
}

View file

@ -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.

View file

@ -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<string | AsyncIterable<string | RenderInstruction>> {
Component = await Component;
switch(getComponentType(Component)) {
switch (getComponentType(Component)) {
case 'fragment': {
const children = await renderSlot(result, slots?.default);
if (children == null) {

View file

@ -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

View file

@ -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();

View file

@ -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';

View file

@ -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 =