Home / File/ slots.ts — astro Source File

slots.ts — astro Source File

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

File typescript CoreAstro RenderingEngine 5 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  b284acc9_ccb3_1b9d_31cb_02b2e7dedc9d["slots.ts"]
  a23a07d0_d3e7_8ff8_5fc3_de6da7bcaed7["./utils.js"]
  b284acc9_ccb3_1b9d_31cb_02b2e7dedc9d --> a23a07d0_d3e7_8ff8_5fc3_de6da7bcaed7
  f76e2597_e3e8_c502_d293_a666b44d49ce["hast"]
  b284acc9_ccb3_1b9d_31cb_02b2e7dedc9d --> f76e2597_e3e8_c502_d293_a666b44d49ce
  57045b72_8cbd_6e93_7687_5176cbcd502d["magic-string"]
  b284acc9_ccb3_1b9d_31cb_02b2e7dedc9d --> 57045b72_8cbd_6e93_7687_5176cbcd502d
  54ce55cc_9dc1_4ebd_28dd_358c1e22d4e7["unified"]
  b284acc9_ccb3_1b9d_31cb_02b2e7dedc9d --> 54ce55cc_9dc1_4ebd_28dd_358c1e22d4e7
  d7b51bf7_4a46_1479_0cea_09e174fc7c48["unist-util-visit"]
  b284acc9_ccb3_1b9d_31cb_02b2e7dedc9d --> d7b51bf7_4a46_1479_0cea_09e174fc7c48
  style b284acc9_ccb3_1b9d_31cb_02b2e7dedc9d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { Root, RootContent } from 'hast';
import type MagicString from 'magic-string';
import type { Plugin } from 'unified';
import { visit } from 'unist-util-visit';
import { escapeTemplateLiteralCharacters } from './utils.js';

const rehypeSlots: Plugin<[{ s: MagicString }], Root> = ({ s }) => {
	return (tree, file) => {
		visit(tree, (node: Root | RootContent) => {
			if (node.type === 'element' && node.tagName === 'slot') {
				if (typeof node.properties?.['is:inline'] !== 'undefined') return;
				const name = node.properties?.['name'] ?? 'default';
				const start = node.position?.start.offset ?? 0;
				const end = node.position?.end.offset ?? 0;
				const first = node.children.at(0) ?? node;
				const last = node.children.at(-1) ?? node;
				const text = file.value
					.slice(first.position?.start.offset ?? 0, last.position?.end.offset ?? 0)
					.toString();
				s.overwrite(
					start,
					end,
					`\${${SLOT_PREFIX}["${name}"] ?? \`${escapeTemplateLiteralCharacters(text).trim()}\`}`,
				);
			}
		});
	};
};

export default rehypeSlots;

export const SLOT_PREFIX = `___SLOTS___`;

Domain

Subdomains

Functions

Dependencies

  • ./utils.js
  • hast
  • magic-string
  • unified
  • unist-util-visit

Frequently Asked Questions

What does slots.ts do?
slots.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What functions are defined in slots.ts?
slots.ts defines 1 function(s): rehypeSlots.
What does slots.ts depend on?
slots.ts imports 5 module(s): ./utils.js, hast, magic-string, unified, unist-util-visit.
Where is slots.ts in the architecture?
slots.ts is located at packages/astro/src/vite-plugin-html/transform/slots.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/vite-plugin-html/transform).

Analyze Your Own Codebase

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

Try Supermodel Free