Home / File/ element.js — svelte Source File

element.js — svelte Source File

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

File javascript Compiler Transformer 19 imports 2 dependents 8 functions

Entity Profile

Dependency Diagram

graph LR
  b25fbb61_695c_e699_cbac_73059624d603["element.js"]
  0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c["ast.js"]
  b25fbb61_695c_e699_cbac_73059624d603 --> 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c
  e9a2c29e_d0ca_ab9f_b86f_f22ff802db91["is_event_attribute"]
  b25fbb61_695c_e699_cbac_73059624d603 --> e9a2c29e_d0ca_ab9f_b86f_f22ff802db91
  653284b2_68fd_eee3_0064_918a4c065d4a["is_text_attribute"]
  b25fbb61_695c_e699_cbac_73059624d603 --> 653284b2_68fd_eee3_0064_918a4c065d4a
  70f59999_db72_c4f6_2b0c_4234646f3763["bindings.js"]
  b25fbb61_695c_e699_cbac_73059624d603 --> 70f59999_db72_c4f6_2b0c_4234646f3763
  bbca3d2a_42c8_b215_d3b5_5077ccaf0797["nodes.js"]
  b25fbb61_695c_e699_cbac_73059624d603 --> bbca3d2a_42c8_b215_d3b5_5077ccaf0797
  53888034_73fb_39d8_be82_b1928817ff74["create_attribute"]
  b25fbb61_695c_e699_cbac_73059624d603 --> 53888034_73fb_39d8_be82_b1928817ff74
  6e00a8f3_2371_ecf1_5a93_296f787aca83["ExpressionMetadata"]
  b25fbb61_695c_e699_cbac_73059624d603 --> 6e00a8f3_2371_ecf1_5a93_296f787aca83
  76437ce7_73fa_a7f2_397a_1ddd381e8282["is_custom_element_node"]
  b25fbb61_695c_e699_cbac_73059624d603 --> 76437ce7_73fa_a7f2_397a_1ddd381e8282
  ce051dbd_4cf1_f117_d66e_12cfa122de37["patterns.js"]
  b25fbb61_695c_e699_cbac_73059624d603 --> ce051dbd_4cf1_f117_d66e_12cfa122de37
  73865c3c_2786_c9ac_d34f_b51d28b3a29e["constants.js"]
  b25fbb61_695c_e699_cbac_73059624d603 --> 73865c3c_2786_c9ac_d34f_b51d28b3a29e
  74eddc85_a390_2aab_af5a_ef32b77d5430["utils.js"]
  b25fbb61_695c_e699_cbac_73059624d603 --> 74eddc85_a390_2aab_af5a_ef32b77d5430
  9f24c33c_da34_a132_f273_3ffd2f6e5cf8["build_attribute_value"]
  b25fbb61_695c_e699_cbac_73059624d603 --> 9f24c33c_da34_a132_f273_3ffd2f6e5cf8
  2aa63f4e_82c9_33e3_ac6c_5f3d46250522["utils.js"]
  b25fbb61_695c_e699_cbac_73059624d603 --> 2aa63f4e_82c9_33e3_ac6c_5f3d46250522
  db3fdf7c_1bf2_5a09_e360_135ad90dbca3["is_boolean_attribute"]
  b25fbb61_695c_e699_cbac_73059624d603 --> db3fdf7c_1bf2_5a09_e360_135ad90dbca3
  style b25fbb61_695c_e699_cbac_73059624d603 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { ArrayExpression, Expression, Literal, ObjectExpression } from 'estree' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext, ComponentServerTransformState } from '../../types.js' */
import { is_event_attribute, is_text_attribute } from '../../../../../utils/ast.js';
import { binding_properties } from '../../../../bindings.js';
import { create_attribute, ExpressionMetadata, is_custom_element_node } from '../../../../nodes.js';
import { regex_starts_with_newline } from '../../../../patterns.js';
import * as b from '#compiler/builders';
import {
	ELEMENT_IS_INPUT,
	ELEMENT_IS_NAMESPACED,
	ELEMENT_PRESERVE_ATTRIBUTE_CASE
} from '../../../../../../constants.js';
import { build_attribute_value } from './utils.js';
import {
	is_boolean_attribute,
	is_content_editable_binding,
	is_load_error_element
} from '../../../../../../utils.js';
import { escape_html } from '../../../../../../escaping.js';

const WHITESPACE_INSENSITIVE_ATTRIBUTES = ['class', 'style'];

/**
 * Writes the output to the template output. Some elements may have attributes on them that require the
 * their output to be the child content instead. In this case, an object is returned.
 * @param {AST.RegularElement | AST.SvelteElement} node
 * @param {import('zimmerframe').Context<AST.SvelteNode, ComponentServerTransformState>} context
 * @param {(expression: Expression, metadata: ExpressionMetadata) => Expression} transform
 */
export function build_element_attributes(node, context, transform) {
	/** @type {Array<AST.Attribute | AST.SpreadAttribute>} */
	const attributes = [];

	/** @type {AST.ClassDirective[]} */
	const class_directives = [];

	/** @type {AST.StyleDirective[]} */
	const style_directives = [];

	/** @type {Expression | null} */
	let content = null;

	let has_spread = false;
	let events_to_capture = new Set();

	for (const attribute of node.attributes) {
		if (attribute.type === 'Attribute') {
			if (attribute.name === 'value') {
				if (node.name === 'textarea') {
					if (
						attribute.value !== true &&
						Array.isArray(attribute.value) &&
						attribute.value[0].type === 'Text' &&
						regex_starts_with_newline.test(attribute.value[0].data)
					) {
						// Two or more leading newlines are required to restore the leading newline immediately after `<textarea>`.
						// see https://html.spec.whatwg.org/multipage/syntax.html#element-restrictions
						// also see related code in analysis phase
						attribute.value[0].data = '\n' + attribute.value[0].data;
// ... (498 more lines)

Domain

Subdomains

Frequently Asked Questions

What does element.js do?
element.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 element.js?
element.js defines 8 function(s): build_attr_class, build_attr_style, build_element_attributes, build_element_spread_attributes, build_spread_object, get_attribute_name, prepare_element_spread, prepare_element_spread_object.
What does element.js depend on?
element.js imports 19 module(s): ExpressionMetadata, ast.js, bindings.js, build_attribute_value, builders, constants.js, create_attribute, escape_html, and 11 more.
What files import element.js?
element.js is imported by 2 file(s): RegularElement.js, SvelteElement.js.
Where is element.js in the architecture?
element.js is located at packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/element.js (domain: Compiler, subdomain: Transformer, directory: packages/svelte/src/compiler/phases/3-transform/server/visitors/shared).

Analyze Your Own Codebase

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

Try Supermodel Free