Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored and astrobot-houston committed Aug 8, 2022
1 parent 6bc2cbe commit f8c2d82
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 48 deletions.
7 changes: 1 addition & 6 deletions packages/astro/src/runtime/server/endpoint.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
6 changes: 4 additions & 2 deletions packages/astro/src/runtime/server/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(', ')}`
);
}

Expand Down
23 changes: 11 additions & 12 deletions packages/astro/src/runtime/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export { createAstro } from './astro-global.js';
export { renderEndpoint } from './endpoint.js';
export {
escapeHTML,
HTMLString,
Expand All @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/runtime/server/render/any.ts
Original file line number Diff line number Diff line change
@@ -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> {
Expand Down
16 changes: 9 additions & 7 deletions packages/astro/src/runtime/server/render/astro.ts
Original file line number Diff line number Diff line change
@@ -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.`
);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions packages/astro/src/runtime/server/render/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 7 additions & 11 deletions packages/astro/src/runtime/server/render/component.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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';
Expand All @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions packages/astro/src/runtime/server/render/index.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/runtime/server/render/page.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/runtime/server/render/types.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/runtime/server/render/util.ts
Original file line number Diff line number Diff line change
@@ -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 =
Expand Down

0 comments on commit f8c2d82

Please sign in to comment.