Home / File/ annotations.ts — astro Source File

annotations.ts — astro Source File

Architecture documentation for annotations.ts, a typescript file in the astro codebase.

Entity Profile

Relationship Graph

Source Code

export interface Annotation {
	file: string;
	location: string;
}
const ELEMENT_ANNOTATIONS = new WeakMap<Element, Annotation>();
export function getAnnotationsForElement(element: Element) {
	return ELEMENT_ANNOTATIONS.get(element);
}

const ANNOTATION_MAP: Record<string, keyof Annotation> = {
	'data-astro-source-file': 'file',
	'data-astro-source-loc': 'location',
};
function extractAnnotations(element: Element) {
	const annotations: Annotation = {} as any;
	for (const [attr, key] of Object.entries(ANNOTATION_MAP) as [string, keyof Annotation][]) {
		annotations[key] = element.getAttribute(attr)!;
	}
	for (const attr of Object.keys(ANNOTATION_MAP)) {
		element.removeAttribute(attr);
	}
	return annotations;
}

export function processAnnotations() {
	for (const element of document.querySelectorAll(`[data-astro-source-file]`)) {
		ELEMENT_ANNOTATIONS.set(element, extractAnnotations(element));
	}
}

Domain

Subdomains

Types

Frequently Asked Questions

What does annotations.ts do?
annotations.ts is a source file in the astro codebase, written in typescript. It belongs to the DevToolbar domain, ToolbarClient subdomain.
What functions are defined in annotations.ts?
annotations.ts defines 3 function(s): extractAnnotations, getAnnotationsForElement, processAnnotations.
Where is annotations.ts in the architecture?
annotations.ts is located at packages/astro/src/runtime/client/dev-toolbar/apps/audit/annotations.ts (domain: DevToolbar, subdomain: ToolbarClient, directory: packages/astro/src/runtime/client/dev-toolbar/apps/audit).

Analyze Your Own Codebase

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

Try Supermodel Free