mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
[ci] format
This commit is contained in:
parent
73f215df76
commit
778dce8c05
10 changed files with 40 additions and 33 deletions
|
@ -55,38 +55,41 @@ export function isHTMLBytes(value: any): value is HTMLBytes {
|
|||
return Object.prototype.toString.call(value) === '[object HTMLBytes]';
|
||||
}
|
||||
|
||||
async function * unescapeChunksAsync(iterable: AsyncIterable<Uint8Array>): any {
|
||||
async function* unescapeChunksAsync(iterable: AsyncIterable<Uint8Array>): any {
|
||||
for await (const chunk of iterable) {
|
||||
yield unescapeHTML(chunk as BlessedType);
|
||||
}
|
||||
}
|
||||
|
||||
function * unescapeChunks(iterable: Iterable<any>): any {
|
||||
for(const chunk of iterable) {
|
||||
function* unescapeChunks(iterable: Iterable<any>): any {
|
||||
for (const chunk of iterable) {
|
||||
yield unescapeHTML(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
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 instanceof Uint8Array) {
|
||||
if (str instanceof Uint8Array) {
|
||||
return markHTMLBytes(str);
|
||||
}
|
||||
// If a response, stream out the chunks
|
||||
else if(str instanceof Response && str.body) {
|
||||
else if (str instanceof Response && str.body) {
|
||||
const body = str.body as unknown as AsyncIterable<Uint8Array>;
|
||||
return unescapeChunksAsync(body);
|
||||
}
|
||||
// If a promise, await the result and mark that.
|
||||
else if(typeof str.then === 'function') {
|
||||
else if (typeof str.then === 'function') {
|
||||
return Promise.resolve(str).then((value) => {
|
||||
return unescapeHTML(value);
|
||||
});
|
||||
}
|
||||
else if(Symbol.iterator in str) {
|
||||
} else if (Symbol.iterator in str) {
|
||||
return unescapeChunks(str);
|
||||
}
|
||||
else if(Symbol.asyncIterator in str) {
|
||||
} else if (Symbol.asyncIterator in str) {
|
||||
return unescapeChunksAsync(str);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
export { createAstro } from './astro-global.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 { createMetadata } from './metadata.js';
|
||||
export {
|
||||
|
|
|
@ -3,8 +3,8 @@ import { SSRResult } from '../../@types/astro.js';
|
|||
import { AstroJSX, isVNode } from '../../jsx-runtime/index.js';
|
||||
import {
|
||||
escapeHTML,
|
||||
HTMLString,
|
||||
HTMLBytes,
|
||||
HTMLString,
|
||||
markHTMLString,
|
||||
renderComponent,
|
||||
RenderInstruction,
|
||||
|
|
|
@ -27,9 +27,12 @@ export async function* renderChild(child: any): AsyncIterable<any> {
|
|||
Object.prototype.toString.call(child) === '[object AstroComponent]'
|
||||
) {
|
||||
yield* renderAstroComponent(child);
|
||||
} else if(ArrayBuffer.isView(child)) {
|
||||
} else if (ArrayBuffer.isView(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;
|
||||
} else {
|
||||
yield child;
|
||||
|
|
|
@ -2,7 +2,7 @@ import type { SSRResult } from '../../../@types/astro';
|
|||
import type { AstroComponentFactory } from './index';
|
||||
import type { RenderInstruction } from './types';
|
||||
|
||||
import { markHTMLString, HTMLBytes } from '../escape.js';
|
||||
import { HTMLBytes, markHTMLString } from '../escape.js';
|
||||
import { HydrationDirectiveProps } from '../hydration.js';
|
||||
import { renderChild } from './any.js';
|
||||
import { HTMLParts } from './common.js';
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import type { SSRResult } from '../../../@types/astro';
|
||||
import type { RenderInstruction } from './types.js';
|
||||
|
||||
import { markHTMLString, HTMLBytes, isHTMLString } from '../escape.js';
|
||||
import { HTMLBytes, markHTMLString } from '../escape.js';
|
||||
import {
|
||||
determineIfNeedsHydrationScript,
|
||||
determinesIfNeedsDirectiveScript,
|
||||
|
@ -50,7 +50,7 @@ export class HTMLParts {
|
|||
this.parts = [];
|
||||
}
|
||||
append(part: string | HTMLBytes | RenderInstruction, result: SSRResult) {
|
||||
if(ArrayBuffer.isView(part)) {
|
||||
if (ArrayBuffer.isView(part)) {
|
||||
this.parts.push(part);
|
||||
} else {
|
||||
this.parts.push(stringifyChunk(result, part));
|
||||
|
@ -58,8 +58,8 @@ export class HTMLParts {
|
|||
}
|
||||
toString() {
|
||||
let html = '';
|
||||
for(const part of this.parts) {
|
||||
if(ArrayBuffer.isView(part)) {
|
||||
for (const part of this.parts) {
|
||||
if (ArrayBuffer.isView(part)) {
|
||||
html += decoder.decode(part);
|
||||
} else {
|
||||
html += part;
|
||||
|
@ -69,7 +69,7 @@ export class HTMLParts {
|
|||
}
|
||||
toArrayBuffer() {
|
||||
this.parts.forEach((part, i) => {
|
||||
if(typeof part === 'string') {
|
||||
if (typeof part === 'string') {
|
||||
this.parts[i] = encoder.encode(String(part));
|
||||
}
|
||||
});
|
||||
|
@ -77,8 +77,11 @@ export class HTMLParts {
|
|||
}
|
||||
}
|
||||
|
||||
export function chunkToByteArray(result: SSRResult, chunk: string | HTMLBytes | RenderInstruction): Uint8Array {
|
||||
if(chunk instanceof Uint8Array) {
|
||||
export function chunkToByteArray(
|
||||
result: SSRResult,
|
||||
chunk: string | HTMLBytes | RenderInstruction
|
||||
): Uint8Array {
|
||||
if (chunk instanceof Uint8Array) {
|
||||
return chunk as Uint8Array;
|
||||
}
|
||||
return encoder.encode(stringifyChunk(result, chunk));
|
||||
|
@ -86,10 +89,10 @@ export function chunkToByteArray(result: SSRResult, chunk: string | HTMLBytes |
|
|||
|
||||
export function concatUint8Arrays(arrays: Array<Uint8Array>) {
|
||||
let len = 0;
|
||||
arrays.forEach(arr => len += arr.length);
|
||||
arrays.forEach((arr) => (len += arr.length));
|
||||
let merged = new Uint8Array(len);
|
||||
let offset = 0;
|
||||
arrays.forEach(arr => {
|
||||
arrays.forEach((arr) => {
|
||||
merged.set(arr, offset);
|
||||
offset += arr.length;
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import type { AstroComponentMetadata, SSRLoadedRenderer, SSRResult } from '../../../@types/astro';
|
||||
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 { serializeProps } from '../serialize.js';
|
||||
import { shorthash } from '../shorthash.js';
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import type { SSRResult } from '../../../@types/astro';
|
||||
import type { AstroComponentFactory } from './index';
|
||||
|
||||
import { isHTMLString } from '../escape.js';
|
||||
import { createResponse } from '../response.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 { isHTMLString } from '../escape.js';
|
||||
import { maybeRenderHead } from './head.js';
|
||||
|
||||
const needsHeadRenderingSymbol = Symbol.for('astro.needsHeadRendering');
|
||||
|
@ -72,14 +72,14 @@ export async function renderPage(
|
|||
let i = 0;
|
||||
try {
|
||||
for await (const chunk of iterable) {
|
||||
if(isHTMLString(chunk)) {
|
||||
if (isHTMLString(chunk)) {
|
||||
if (i === 0) {
|
||||
if (!/<!doctype html/i.test(String(chunk))) {
|
||||
controller.enqueue(encoder.encode('<!DOCTYPE html>\n'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let bytes = chunkToByteArray(result, chunk);
|
||||
controller.enqueue(bytes);
|
||||
i++;
|
||||
|
@ -96,7 +96,7 @@ export async function renderPage(
|
|||
let parts = new HTMLParts();
|
||||
let i = 0;
|
||||
for await (const chunk of iterable) {
|
||||
if(isHTMLString(chunk)) {
|
||||
if (isHTMLString(chunk)) {
|
||||
if (i === 0) {
|
||||
if (!/<!doctype html/i.test(String(chunk))) {
|
||||
parts.append('<!DOCTYPE html>\n', result);
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
export function serializeListValue(value: any) {
|
||||
const hash: Record<string, any> = {};
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ import { expect } from 'chai';
|
|||
import * as cheerio from 'cheerio';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
|
||||
|
||||
describe('set:html', () => {
|
||||
/** @type {import('./test-utils').Fixture} */
|
||||
let fixture;
|
||||
|
|
Loading…
Reference in a new issue