Home / File/ index.js — svelte Source File

index.js — svelte Source File

Architecture documentation for index.js, a javascript file in the svelte codebase. 3 imports, 2 dependents.

File javascript Compiler Parser 3 imports 2 dependents 2 functions

Entity Profile

Dependency Diagram

graph LR
  b14524b3_fb6c_95cc_463c_fff3e50c6bc6["index.js"]
  73865c3c_2786_c9ac_d34f_b51d28b3a29e["constants.js"]
  b14524b3_fb6c_95cc_463c_fff3e50c6bc6 --> 73865c3c_2786_c9ac_d34f_b51d28b3a29e
  62f818c8_e890_17ed_5ec1_92f953d4a7a6["state.js"]
  b14524b3_fb6c_95cc_463c_fff3e50c6bc6 --> 62f818c8_e890_17ed_5ec1_92f953d4a7a6
  18e3101f_3e97_34c3_7373_b587af4b78e1["builders.js"]
  b14524b3_fb6c_95cc_463c_fff3e50c6bc6 --> 18e3101f_3e97_34c3_7373_b587af4b78e1
  96f4a58f_3498_1ea2_7ff9_3d805414893b["Fragment.js"]
  96f4a58f_3498_1ea2_7ff9_3d805414893b --> b14524b3_fb6c_95cc_463c_fff3e50c6bc6
  4610488f_3cf2_5f73_043e_da0aa9d026fe["RegularElement.js"]
  4610488f_3cf2_5f73_043e_da0aa9d026fe --> b14524b3_fb6c_95cc_463c_fff3e50c6bc6
  style b14524b3_fb6c_95cc_463c_fff3e50c6bc6 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { Namespace } from '#compiler' */
/** @import { ComponentClientTransformState } from '../types.js' */
/** @import { Node } from './types.js' */
import { TEMPLATE_USE_MATHML, TEMPLATE_USE_SVG } from '../../../../../constants.js';
import { dev, locator } from '../../../../state.js';
import * as b from '../../../../utils/builders.js';

/**
 * @param {Node[]} nodes
 */
function build_locations(nodes) {
	const array = b.array([]);

	for (const node of nodes) {
		if (node.type !== 'element') continue;

		const { line, column } = locator(node.start);

		const expression = b.array([b.literal(line), b.literal(column)]);
		const children = build_locations(node.children);

		if (children.elements.length > 0) {
			expression.elements.push(children);
		}

		array.elements.push(expression);
	}

	return array;
}

/**
 * @param {ComponentClientTransformState} state
 * @param {Namespace} namespace
 * @param {number} [flags]
 */
export function transform_template(state, namespace, flags = 0) {
	const tree = state.options.fragments === 'tree';

	const expression = tree ? state.template.as_tree() : state.template.as_html();

	if (tree) {
		if (namespace === 'svg') flags |= TEMPLATE_USE_SVG;
		if (namespace === 'mathml') flags |= TEMPLATE_USE_MATHML;
	}

	let call = b.call(
		tree ? `$.from_tree` : `$.from_${namespace}`,
		expression,
		flags ? b.literal(flags) : undefined
	);

	if (state.template.contains_script_tag) {
		call = b.call(`$.with_script`, call);
	}

	if (dev) {
		call = b.call(
			'$.add_locations',
			call,
			b.member(b.id(state.analysis.name), '$.FILENAME', true),
			build_locations(state.template.nodes)
		);
	}

	return call;
}

Domain

Subdomains

Frequently Asked Questions

What does index.js do?
index.js is a source file in the svelte codebase, written in javascript. It belongs to the Compiler domain, Parser subdomain.
What functions are defined in index.js?
index.js defines 2 function(s): build_locations, transform_template.
What does index.js depend on?
index.js imports 3 module(s): builders.js, constants.js, state.js.
What files import index.js?
index.js is imported by 2 file(s): Fragment.js, RegularElement.js.
Where is index.js in the architecture?
index.js is located at packages/svelte/src/compiler/phases/3-transform/client/transform-template/index.js (domain: Compiler, subdomain: Parser, directory: packages/svelte/src/compiler/phases/3-transform/client/transform-template).

Analyze Your Own Codebase

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

Try Supermodel Free