[ci] format

This commit is contained in:
natemoo-re 2022-09-07 18:50:48 +00:00 committed by fredkbot
parent 999250d651
commit c01194b9d8
4 changed files with 25 additions and 12 deletions

View file

@ -302,7 +302,10 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr
// Include componentExport name, componentUrl, and props in hash to dedupe identical islands
const astroId = shorthash(
`<!--${metadata.componentExport!.value}:${metadata.componentUrl}-->\n${html}\n${serializeProps(props, metadata)}`
`<!--${metadata.componentExport!.value}:${metadata.componentUrl}-->\n${html}\n${serializeProps(
props,
metadata
)}`
);
const island = await generateHydrateScript(

View file

@ -1,6 +1,4 @@
import type {
AstroComponentMetadata,
} from '../../@types/astro';
import type { AstroComponentMetadata } from '../../@types/astro';
type ValueOf<T> = T[keyof T];
@ -19,11 +17,14 @@ function serializeArray(value: any[], metadata: AstroComponentMetadata): any[] {
return value.map((v) => convertToSerializedForm(v, metadata));
}
function serializeObject(value: Record<any, any>, metadata: AstroComponentMetadata): Record<any, any> {
function serializeObject(
value: Record<any, any>,
metadata: AstroComponentMetadata
): Record<any, any> {
if (cyclicRefs.has(value)) {
throw new Error(`Cyclic reference detected while serializing props for <${metadata.displayName} client:${metadata.hydrate}>!
Cyclic references cannot be safely serialized for client-side usage. Please remove the cyclic reference.`)
Cyclic references cannot be safely serialized for client-side usage. Please remove the cyclic reference.`);
}
cyclicRefs.add(value);
return Object.fromEntries(
@ -33,7 +34,10 @@ Cyclic references cannot be safely serialized for client-side usage. Please remo
);
}
function convertToSerializedForm(value: any, metadata: AstroComponentMetadata): [ValueOf<typeof PROP_TYPE>, any] {
function convertToSerializedForm(
value: any,
metadata: AstroComponentMetadata
): [ValueOf<typeof PROP_TYPE>, any] {
const tag = Object.prototype.toString.call(value);
switch (tag) {
case '[object Date]': {
@ -43,10 +47,16 @@ function convertToSerializedForm(value: any, metadata: AstroComponentMetadata):
return [PROP_TYPE.RegExp, (value as RegExp).source];
}
case '[object Map]': {
return [PROP_TYPE.Map, JSON.stringify(serializeArray(Array.from(value as Map<any, any>), metadata))];
return [
PROP_TYPE.Map,
JSON.stringify(serializeArray(Array.from(value as Map<any, any>), metadata)),
];
}
case '[object Set]': {
return [PROP_TYPE.Set, JSON.stringify(serializeArray(Array.from(value as Set<any>), metadata))];
return [
PROP_TYPE.Set,
JSON.stringify(serializeArray(Array.from(value as Set<any>), metadata)),
];
}
case '[object BigInt]': {
return [PROP_TYPE.BigInt, (value as bigint).toString()];

View file

@ -120,7 +120,7 @@ async function handle500Response(
) {
res.on('close', () => setTimeout(() => viteServer.ws.send(getViteErrorPayload(err)), 200));
if (res.headersSent) {
res.write(`<script type="module" src="/@vite/client"></script>`)
res.write(`<script type="module" src="/@vite/client"></script>`);
res.end();
} else {
writeHtmlResponse(

View file

@ -1,4 +1,4 @@
import "preact/debug"
import clientFn from "./client.js";
import 'preact/debug';
import clientFn from './client.js';
export default clientFn;