Home / File/ RegularElement.js — svelte Source File

RegularElement.js — svelte Source File

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

File javascript Compiler Transformer 16 imports 1 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  4022e2d8_1e79_6b7b_f1e7_0e8528bc6d82["RegularElement.js"]
  2aa63f4e_82c9_33e3_ac6c_5f3d46250522["utils.js"]
  4022e2d8_1e79_6b7b_f1e7_0e8528bc6d82 --> 2aa63f4e_82c9_33e3_ac6c_5f3d46250522
  02a8b5a2_13c5_e5b3_1ed2_617763d0904d["is_void"]
  4022e2d8_1e79_6b7b_f1e7_0e8528bc6d82 --> 02a8b5a2_13c5_e5b3_1ed2_617763d0904d
  62f818c8_e890_17ed_5ec1_92f953d4a7a6["state.js"]
  4022e2d8_1e79_6b7b_f1e7_0e8528bc6d82 --> 62f818c8_e890_17ed_5ec1_92f953d4a7a6
  f3fad5a9_6b91_ed4f_9331_7f9fc18491c3["utils.js"]
  4022e2d8_1e79_6b7b_f1e7_0e8528bc6d82 --> f3fad5a9_6b91_ed4f_9331_7f9fc18491c3
  48b02cf8_c90b_7278_8655_c24e3431a4b3["clean_nodes"]
  4022e2d8_1e79_6b7b_f1e7_0e8528bc6d82 --> 48b02cf8_c90b_7278_8655_c24e3431a4b3
  a475d4d0_a1fa_71f2_13d3_ba42155a8763["determine_namespace_for_children"]
  4022e2d8_1e79_6b7b_f1e7_0e8528bc6d82 --> a475d4d0_a1fa_71f2_13d3_ba42155a8763
  b25fbb61_695c_e699_cbac_73059624d603["element.js"]
  4022e2d8_1e79_6b7b_f1e7_0e8528bc6d82 --> b25fbb61_695c_e699_cbac_73059624d603
  17370b4c_df64_f183_35da_1de383ea4963["build_element_attributes"]
  4022e2d8_1e79_6b7b_f1e7_0e8528bc6d82 --> 17370b4c_df64_f183_35da_1de383ea4963
  6bb21aff_7c01_9593_26a7_a77307bf55bb["prepare_element_spread_object"]
  4022e2d8_1e79_6b7b_f1e7_0e8528bc6d82 --> 6bb21aff_7c01_9593_26a7_a77307bf55bb
  74eddc85_a390_2aab_af5a_ef32b77d5430["utils.js"]
  4022e2d8_1e79_6b7b_f1e7_0e8528bc6d82 --> 74eddc85_a390_2aab_af5a_ef32b77d5430
  4ec029f0_bbf8_66de_0dbf_d15eef3e10a0["process_children"]
  4022e2d8_1e79_6b7b_f1e7_0e8528bc6d82 --> 4ec029f0_bbf8_66de_0dbf_d15eef3e10a0
  49bc6956_1326_e1db_837c_bb4db2493060["build_template"]
  4022e2d8_1e79_6b7b_f1e7_0e8528bc6d82 --> 49bc6956_1326_e1db_837c_bb4db2493060
  89f84d70_5c6c_1980_33f9_650ce42a04ab["PromiseOptimiser"]
  4022e2d8_1e79_6b7b_f1e7_0e8528bc6d82 --> 89f84d70_5c6c_1980_33f9_650ce42a04ab
  bbca3d2a_42c8_b215_d3b5_5077ccaf0797["nodes.js"]
  4022e2d8_1e79_6b7b_f1e7_0e8528bc6d82 --> bbca3d2a_42c8_b215_d3b5_5077ccaf0797
  style 4022e2d8_1e79_6b7b_f1e7_0e8528bc6d82 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { Expression } from 'estree' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext, ComponentServerTransformState } from '../types.js' */
/** @import { Scope } from '../../../scope.js' */
import { is_void } from '../../../../../utils.js';
import { dev, locator } from '../../../../state.js';
import * as b from '#compiler/builders';
import { clean_nodes, determine_namespace_for_children } from '../../utils.js';
import { build_element_attributes, prepare_element_spread_object } from './shared/element.js';
import { process_children, build_template, PromiseOptimiser } from './shared/utils.js';
import { is_customizable_select_element } from '../../../nodes.js';

/**
 * @param {AST.RegularElement} node
 * @param {ComponentContext} context
 */
export function RegularElement(node, context) {
	const namespace = determine_namespace_for_children(node, context.state.namespace);

	/** @type {ComponentServerTransformState} */
	const state = {
		...context.state,
		namespace,
		preserve_whitespace:
			context.state.preserve_whitespace || node.name === 'pre' || node.name === 'textarea',
		init: [],
		template: []
	};

	const node_is_void = is_void(node.name);

	const optimiser = new PromiseOptimiser();

	// If this element needs special handling (like <select value> / <option>),
	// avoid calling build_element_attributes here to prevent evaluating/awaiting
	// attribute expressions twice. We'll handle attributes in the special branch.
	const is_select_special =
		node.name === 'select' &&
		node.attributes.some(
			(attribute) =>
				((attribute.type === 'Attribute' || attribute.type === 'BindDirective') &&
					attribute.name === 'value') ||
				attribute.type === 'SpreadAttribute'
		);
	const is_option_special = node.name === 'option';
	const is_special = is_select_special || is_option_special;

	let body = /** @type {Expression | null} */ (null);
	if (!is_special) {
		// only open the tag in the non-special path
		state.template.push(b.literal(`<${node.name}`));
		body = build_element_attributes(node, { ...context, state }, optimiser.transform);
		state.template.push(b.literal(node_is_void ? '/>' : '>')); // add `/>` for XHTML compliance
	}

	if ((node.name === 'script' || node.name === 'style') && node.fragment.nodes.length === 1) {
		state.template.push(
			b.literal(/** @type {AST.Text} */ (node.fragment.nodes[0]).data),
			b.literal(`</${node.name}>`)
		);
// ... (159 more lines)

Domain

Subdomains

Functions

Frequently Asked Questions

What does RegularElement.js do?
RegularElement.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 RegularElement.js?
RegularElement.js defines 1 function(s): RegularElement.
What does RegularElement.js depend on?
RegularElement.js imports 16 module(s): PromiseOptimiser, build_element_attributes, build_template, builders, clean_nodes, determine_namespace_for_children, element.js, is_customizable_select_element, and 8 more.
What files import RegularElement.js?
RegularElement.js is imported by 1 file(s): transform-server.js.
Where is RegularElement.js in the architecture?
RegularElement.js is located at packages/svelte/src/compiler/phases/3-transform/server/visitors/RegularElement.js (domain: Compiler, subdomain: Transformer, directory: packages/svelte/src/compiler/phases/3-transform/server/visitors).

Analyze Your Own Codebase

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

Try Supermodel Free