Home / File/ Text.js — svelte Source File

Text.js — svelte Source File

Architecture documentation for Text.js, a javascript file in the svelte codebase. 9 imports, 1 dependents.

File javascript Compiler Transformer 9 imports 1 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  f8debeb0_6284_1c94_22a8_0f28192b28a5["Text.js"]
  302f84f3_ec7c_fd57_5b8e_e2f3ec2953b7["html-tree-validation.js"]
  f8debeb0_6284_1c94_22a8_0f28192b28a5 --> 302f84f3_ec7c_fd57_5b8e_e2f3ec2953b7
  b52e7925_73b5_1187_beab_fb7eb59cc45d["is_tag_valid_with_parent"]
  f8debeb0_6284_1c94_22a8_0f28192b28a5 --> b52e7925_73b5_1187_beab_fb7eb59cc45d
  ce051dbd_4cf1_f117_d66e_12cfa122de37["patterns.js"]
  f8debeb0_6284_1c94_22a8_0f28192b28a5 --> ce051dbd_4cf1_f117_d66e_12cfa122de37
  495501a4_a342_6a4d_ac11_e3e2fee8b218["errors.js"]
  f8debeb0_6284_1c94_22a8_0f28192b28a5 --> 495501a4_a342_6a4d_ac11_e3e2fee8b218
  a146f6ac_0088_8736_b6ce_318f9f115170["e"]
  f8debeb0_6284_1c94_22a8_0f28192b28a5 --> a146f6ac_0088_8736_b6ce_318f9f115170
  56a689f9_11c0_cc76_bd60_41bb6dc96475["warnings.js"]
  f8debeb0_6284_1c94_22a8_0f28192b28a5 --> 56a689f9_11c0_cc76_bd60_41bb6dc96475
  3246e0bc_b9fc_f638_5e35_41e8c39a2408["w"]
  f8debeb0_6284_1c94_22a8_0f28192b28a5 --> 3246e0bc_b9fc_f638_5e35_41e8c39a2408
  d1869e84_a713_3c60_3aae_40e1a6b78424["extract_svelte_ignore.js"]
  f8debeb0_6284_1c94_22a8_0f28192b28a5 --> d1869e84_a713_3c60_3aae_40e1a6b78424
  4422a3ac_4abf_f704_22f3_7d5d175ce307["extract_svelte_ignore"]
  f8debeb0_6284_1c94_22a8_0f28192b28a5 --> 4422a3ac_4abf_f704_22f3_7d5d175ce307
  4aa8a188_84d4_0274_ed83_cac0ab1d3572["index.js"]
  4aa8a188_84d4_0274_ed83_cac0ab1d3572 --> f8debeb0_6284_1c94_22a8_0f28192b28a5
  style f8debeb0_6284_1c94_22a8_0f28192b28a5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import { is_tag_valid_with_parent } from '../../../../html-tree-validation.js';
import { regex_bidirectional_control_characters, regex_not_whitespace } from '../../patterns.js';
import * as e from '../../../errors.js';
import * as w from '../../../warnings.js';
import { extract_svelte_ignore } from '../../../utils/extract_svelte_ignore.js';

/**
 * @param {AST.Text} node
 * @param {Context} context
 */
export function Text(node, context) {
	const parent = /** @type {AST.SvelteNode} */ (context.path.at(-1));

	if (
		parent.type === 'Fragment' &&
		context.state.parent_element &&
		regex_not_whitespace.test(node.data)
	) {
		const message = is_tag_valid_with_parent('#text', context.state.parent_element);
		if (message) {
			e.node_invalid_placement(node, message);
		}
	}

	regex_bidirectional_control_characters.lastIndex = 0;
	for (const match of node.data.matchAll(regex_bidirectional_control_characters)) {
		let is_ignored = false;

		// if we have a svelte-ignore comment earlier in the text, bail
		// (otherwise we can only use svelte-ignore on parent elements/blocks)
		if (parent.type === 'Fragment') {
			for (const child of parent.nodes) {
				if (child === node) break;

				if (child.type === 'Comment') {
					is_ignored ||= extract_svelte_ignore(
						child.start + 4,
						child.data,
						context.state.analysis.runes
					).includes('bidirectional_control_characters');
				}
			}
		}

		if (!is_ignored) {
			let start = match.index + node.start;
			w.bidirectional_control_characters({ start, end: start + match[0].length });
		}
	}
}

Domain

Subdomains

Functions

Frequently Asked Questions

What does Text.js do?
Text.js is a source file in the svelte codebase, written in javascript. It belongs to the Compiler domain, Transformer subdomain.
What functions are defined in Text.js?
Text.js defines 1 function(s): Text.
What does Text.js depend on?
Text.js imports 9 module(s): e, errors.js, extract_svelte_ignore, extract_svelte_ignore.js, html-tree-validation.js, is_tag_valid_with_parent, patterns.js, w, and 1 more.
What files import Text.js?
Text.js is imported by 1 file(s): index.js.
Where is Text.js in the architecture?
Text.js is located at packages/svelte/src/compiler/phases/2-analyze/visitors/Text.js (domain: Compiler, subdomain: Transformer, directory: packages/svelte/src/compiler/phases/2-analyze/visitors).

Analyze Your Own Codebase

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

Try Supermodel Free