Home / File/ slot.ts — astro Source File

slot.ts — astro Source File

Architecture documentation for slot.ts, a typescript file in the astro codebase. 6 imports, 0 dependents.

File typescript FrameworkCore IntegrationHooks 6 imports 7 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  4c7f81d8_9b7a_7a7d_7b5a_7d0076667ccb["slot.ts"]
  a6eda4f2_aa96_f87e_73dc_4dc9d6f1ea5c["../types/public/internal.js"]
  4c7f81d8_9b7a_7a7d_7b5a_7d0076667ccb --> a6eda4f2_aa96_f87e_73dc_4dc9d6f1ea5c
  8c75d3f7_dd37_1bc5_408b_28166187c7f6["./escape.js"]
  4c7f81d8_9b7a_7a7d_7b5a_7d0076667ccb --> 8c75d3f7_dd37_1bc5_408b_28166187c7f6
  2707e8aa_6e61_49e0_8599_541e05c8df81["./any.js"]
  4c7f81d8_9b7a_7a7d_7b5a_7d0076667ccb --> 2707e8aa_6e61_49e0_8599_541e05c8df81
  a647ce9f_b0b0_e404_5fed_b199624f45ea["./astro/render-template.js"]
  4c7f81d8_9b7a_7a7d_7b5a_7d0076667ccb --> a647ce9f_b0b0_e404_5fed_b199624f45ea
  245a4587_cc91_a187_0aed_84b85546c358["./common.js"]
  4c7f81d8_9b7a_7a7d_7b5a_7d0076667ccb --> 245a4587_cc91_a187_0aed_84b85546c358
  7d7cc5bb_2b88_85f2_401f_e284d9f3f394["./instruction.js"]
  4c7f81d8_9b7a_7a7d_7b5a_7d0076667ccb --> 7d7cc5bb_2b88_85f2_401f_e284d9f3f394
  style 4c7f81d8_9b7a_7a7d_7b5a_7d0076667ccb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { SSRResult } from '../../../types/public/internal.js';
import { HTMLString, markHTMLString, unescapeHTML } from '../escape.js';
import { renderChild } from './any.js';
import { renderTemplate } from './astro/render-template.js';
import { chunkToString, type RenderDestination, type RenderInstance } from './common.js';
import type { RenderInstruction } from './instruction.js';

type RenderTemplateResult = ReturnType<typeof renderTemplate>;
export type ComponentSlots = Record<string, ComponentSlotValue>;
export type ComponentSlotValue = (
	result: SSRResult,
) => RenderTemplateResult | Promise<RenderTemplateResult>;

const slotString = Symbol.for('astro:slot-string');

export class SlotString extends HTMLString {
	public instructions: null | RenderInstruction[];
	public [slotString]: boolean;
	constructor(content: string, instructions: null | RenderInstruction[]) {
		super(content);
		this.instructions = instructions;
		this[slotString] = true;
	}
}

export function isSlotString(str: string): str is any {
	return !!(str as any)[slotString];
}

/**
 * Collects instructions from a SlotString into the target array.
 * Returns the (possibly newly created) instructions array.
 */
export function mergeSlotInstructions(
	target: RenderInstruction[] | null,
	source: SlotString,
): RenderInstruction[] | null {
	if (source.instructions?.length) {
		target ??= [];
		target.push(...source.instructions);
	}
	return target;
}

export function renderSlot(
	result: SSRResult,
	slotted: ComponentSlotValue | RenderTemplateResult,
	fallback?: ComponentSlotValue | RenderTemplateResult,
): RenderInstance {
	if (!slotted && fallback) {
		return renderSlot(result, fallback);
	}
	return {
		async render(destination) {
			await renderChild(destination, typeof slotted === 'function' ? slotted(result) : slotted);
		},
	};
}

export async function renderSlotToString(
// ... (63 more lines)

Domain

Subdomains

Classes

Dependencies

  • ../types/public/internal.js
  • ./any.js
  • ./astro/render-template.js
  • ./common.js
  • ./escape.js
  • ./instruction.js

Frequently Asked Questions

What does slot.ts do?
slot.ts is a source file in the astro codebase, written in typescript. It belongs to the FrameworkCore domain, IntegrationHooks subdomain.
What functions are defined in slot.ts?
slot.ts defines 7 function(s): createSlotValueFromString, isSlotString, mergeSlotInstructions, renderSlot, renderSlotToString, renderSlots, result.
What does slot.ts depend on?
slot.ts imports 6 module(s): ../types/public/internal.js, ./any.js, ./astro/render-template.js, ./common.js, ./escape.js, ./instruction.js.
Where is slot.ts in the architecture?
slot.ts is located at packages/astro/src/runtime/server/render/slot.ts (domain: FrameworkCore, subdomain: IntegrationHooks, directory: packages/astro/src/runtime/server/render).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free