0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

[ci] format

This commit is contained in:
matthewp 2022-09-21 23:09:40 +00:00 committed by fredkbot
parent 73f215df76
commit 778dce8c05
10 changed files with 40 additions and 33 deletions

View file

@ -67,7 +67,12 @@ function * unescapeChunks(iterable: Iterable<any>): any {
} }
} }
export function unescapeHTML(str: any): BlessedType | Promise<BlessedType | AsyncGenerator<BlessedType, void, unknown>> | AsyncGenerator<BlessedType, void, unknown> { export function unescapeHTML(
str: any
):
| BlessedType
| Promise<BlessedType | AsyncGenerator<BlessedType, void, unknown>>
| AsyncGenerator<BlessedType, void, unknown> {
if (!!str && typeof str === 'object') { if (!!str && typeof str === 'object') {
if (str instanceof Uint8Array) { if (str instanceof Uint8Array) {
return markHTMLBytes(str); return markHTMLBytes(str);
@ -82,11 +87,9 @@ export function unescapeHTML(str: any): BlessedType | Promise<BlessedType | Asyn
return Promise.resolve(str).then((value) => { return Promise.resolve(str).then((value) => {
return unescapeHTML(value); return unescapeHTML(value);
}); });
} } else if (Symbol.iterator in str) {
else if(Symbol.iterator in str) {
return unescapeChunks(str); return unescapeChunks(str);
} } else if (Symbol.asyncIterator in str) {
else if(Symbol.asyncIterator in str) {
return unescapeChunksAsync(str); return unescapeChunksAsync(str);
} }
} }

View file

@ -1,6 +1,6 @@
export { createAstro } from './astro-global.js'; export { createAstro } from './astro-global.js';
export { renderEndpoint } from './endpoint.js'; export { renderEndpoint } from './endpoint.js';
export { escapeHTML, HTMLString, HTMLBytes, markHTMLString, unescapeHTML } from './escape.js'; export { escapeHTML, HTMLBytes, HTMLString, markHTMLString, unescapeHTML } from './escape.js';
export type { Metadata } from './metadata'; export type { Metadata } from './metadata';
export { createMetadata } from './metadata.js'; export { createMetadata } from './metadata.js';
export { export {

View file

@ -3,8 +3,8 @@ import { SSRResult } from '../../@types/astro.js';
import { AstroJSX, isVNode } from '../../jsx-runtime/index.js'; import { AstroJSX, isVNode } from '../../jsx-runtime/index.js';
import { import {
escapeHTML, escapeHTML,
HTMLString,
HTMLBytes, HTMLBytes,
HTMLString,
markHTMLString, markHTMLString,
renderComponent, renderComponent,
RenderInstruction, RenderInstruction,

View file

@ -29,7 +29,10 @@ export async function* renderChild(child: any): AsyncIterable<any> {
yield* renderAstroComponent(child); yield* renderAstroComponent(child);
} else if (ArrayBuffer.isView(child)) { } else if (ArrayBuffer.isView(child)) {
yield child; yield child;
} else if (typeof child === 'object' && (Symbol.asyncIterator in child || Symbol.iterator in child)) { } else if (
typeof child === 'object' &&
(Symbol.asyncIterator in child || Symbol.iterator in child)
) {
yield* child; yield* child;
} else { } else {
yield child; yield child;

View file

@ -2,7 +2,7 @@ import type { SSRResult } from '../../../@types/astro';
import type { AstroComponentFactory } from './index'; import type { AstroComponentFactory } from './index';
import type { RenderInstruction } from './types'; import type { RenderInstruction } from './types';
import { markHTMLString, HTMLBytes } from '../escape.js'; import { HTMLBytes, markHTMLString } from '../escape.js';
import { HydrationDirectiveProps } from '../hydration.js'; import { HydrationDirectiveProps } from '../hydration.js';
import { renderChild } from './any.js'; import { renderChild } from './any.js';
import { HTMLParts } from './common.js'; import { HTMLParts } from './common.js';

View file

@ -1,7 +1,7 @@
import type { SSRResult } from '../../../@types/astro'; import type { SSRResult } from '../../../@types/astro';
import type { RenderInstruction } from './types.js'; import type { RenderInstruction } from './types.js';
import { markHTMLString, HTMLBytes, isHTMLString } from '../escape.js'; import { HTMLBytes, markHTMLString } from '../escape.js';
import { import {
determineIfNeedsHydrationScript, determineIfNeedsHydrationScript,
determinesIfNeedsDirectiveScript, determinesIfNeedsDirectiveScript,
@ -77,7 +77,10 @@ export class HTMLParts {
} }
} }
export function chunkToByteArray(result: SSRResult, chunk: string | HTMLBytes | RenderInstruction): Uint8Array { export function chunkToByteArray(
result: SSRResult,
chunk: string | HTMLBytes | RenderInstruction
): Uint8Array {
if (chunk instanceof Uint8Array) { if (chunk instanceof Uint8Array) {
return chunk as Uint8Array; return chunk as Uint8Array;
} }
@ -86,10 +89,10 @@ export function chunkToByteArray(result: SSRResult, chunk: string | HTMLBytes |
export function concatUint8Arrays(arrays: Array<Uint8Array>) { export function concatUint8Arrays(arrays: Array<Uint8Array>) {
let len = 0; let len = 0;
arrays.forEach(arr => len += arr.length); arrays.forEach((arr) => (len += arr.length));
let merged = new Uint8Array(len); let merged = new Uint8Array(len);
let offset = 0; let offset = 0;
arrays.forEach(arr => { arrays.forEach((arr) => {
merged.set(arr, offset); merged.set(arr, offset);
offset += arr.length; offset += arr.length;
}); });

View file

@ -1,7 +1,7 @@
import type { AstroComponentMetadata, SSRLoadedRenderer, SSRResult } from '../../../@types/astro'; import type { AstroComponentMetadata, SSRLoadedRenderer, SSRResult } from '../../../@types/astro';
import type { RenderInstruction } from './types.js'; import type { RenderInstruction } from './types.js';
import { markHTMLString, HTMLBytes } from '../escape.js'; import { HTMLBytes, markHTMLString } from '../escape.js';
import { extractDirectives, generateHydrateScript } from '../hydration.js'; import { extractDirectives, generateHydrateScript } from '../hydration.js';
import { serializeProps } from '../serialize.js'; import { serializeProps } from '../serialize.js';
import { shorthash } from '../shorthash.js'; import { shorthash } from '../shorthash.js';

View file

@ -1,11 +1,11 @@
import type { SSRResult } from '../../../@types/astro'; import type { SSRResult } from '../../../@types/astro';
import type { AstroComponentFactory } from './index'; import type { AstroComponentFactory } from './index';
import { isHTMLString } from '../escape.js';
import { createResponse } from '../response.js'; import { createResponse } from '../response.js';
import { isAstroComponent, isAstroComponentFactory, renderAstroComponent } from './astro.js'; import { isAstroComponent, isAstroComponentFactory, renderAstroComponent } from './astro.js';
import { encoder, chunkToByteArray, HTMLParts } from './common.js'; import { chunkToByteArray, encoder, HTMLParts } from './common.js';
import { renderComponent } from './component.js'; import { renderComponent } from './component.js';
import { isHTMLString } from '../escape.js';
import { maybeRenderHead } from './head.js'; import { maybeRenderHead } from './head.js';
const needsHeadRenderingSymbol = Symbol.for('astro.needsHeadRendering'); const needsHeadRenderingSymbol = Symbol.for('astro.needsHeadRendering');

View file

@ -1,4 +1,3 @@
export function serializeListValue(value: any) { export function serializeListValue(value: any) {
const hash: Record<string, any> = {}; const hash: Record<string, any> = {};

View file

@ -2,7 +2,6 @@ import { expect } from 'chai';
import * as cheerio from 'cheerio'; import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js'; import { loadFixture } from './test-utils.js';
describe('set:html', () => { describe('set:html', () => {
/** @type {import('./test-utils').Fixture} */ /** @type {import('./test-utils').Fixture} */
let fixture; let fixture;