Home / File/ element.js — svelte Source File

element.js — svelte Source File

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

File javascript Compiler Transformer 18 imports 5 dependents 5 functions

Entity Profile

Dependency Diagram

graph LR
  7880f852_1b7b_9ea3_4e22_732f4a684bbe["element.js"]
  cb064307_faf7_de99_b8a6_9523086a7c01["escaping.js"]
  7880f852_1b7b_9ea3_4e22_732f4a684bbe --> cb064307_faf7_de99_b8a6_9523086a7c01
  d6dfd043_7103_f2c7_aab3_9660fb0a5f75["escape_html"]
  7880f852_1b7b_9ea3_4e22_732f4a684bbe --> d6dfd043_7103_f2c7_aab3_9660fb0a5f75
  2aa63f4e_82c9_33e3_ac6c_5f3d46250522["utils.js"]
  7880f852_1b7b_9ea3_4e22_732f4a684bbe --> 2aa63f4e_82c9_33e3_ac6c_5f3d46250522
  24db9b65_9e63_0d64_2b00_0225bd02845d["normalize_attribute"]
  7880f852_1b7b_9ea3_4e22_732f4a684bbe --> 24db9b65_9e63_0d64_2b00_0225bd02845d
  62f818c8_e890_17ed_5ec1_92f953d4a7a6["state.js"]
  7880f852_1b7b_9ea3_4e22_732f4a684bbe --> 62f818c8_e890_17ed_5ec1_92f953d4a7a6
  7a7783f8_ffa6_0cc3_61b0_031882649535["is_ignored"]
  7880f852_1b7b_9ea3_4e22_732f4a684bbe --> 7a7783f8_ffa6_0cc3_61b0_031882649535
  0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c["ast.js"]
  7880f852_1b7b_9ea3_4e22_732f4a684bbe --> 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c
  e9a2c29e_d0ca_ab9f_b86f_f22ff802db91["is_event_attribute"]
  7880f852_1b7b_9ea3_4e22_732f4a684bbe --> e9a2c29e_d0ca_ab9f_b86f_f22ff802db91
  4610488f_3cf2_5f73_043e_da0aa9d026fe["RegularElement.js"]
  7880f852_1b7b_9ea3_4e22_732f4a684bbe --> 4610488f_3cf2_5f73_043e_da0aa9d026fe
  524a9152_ab34_9e69_70d1_b4f6c414a673["build_class_directives_object"]
  7880f852_1b7b_9ea3_4e22_732f4a684bbe --> 524a9152_ab34_9e69_70d1_b4f6c414a673
  4fce48f1_e9d7_958a_ce38_30799ece4fc7["build_style_directives_object"]
  7880f852_1b7b_9ea3_4e22_732f4a684bbe --> 4fce48f1_e9d7_958a_ce38_30799ece4fc7
  d04d7971_88df_542d_dd4f_26170ce6f581["utils.js"]
  7880f852_1b7b_9ea3_4e22_732f4a684bbe --> d04d7971_88df_542d_dd4f_26170ce6f581
  66243dec_e2be_a66d_3992_3ea42cf964b5["build_expression"]
  7880f852_1b7b_9ea3_4e22_732f4a684bbe --> 66243dec_e2be_a66d_3992_3ea42cf964b5
  f3280f06_553d_66c3_8ca2_c3c36dcdda64["build_template_chunk"]
  7880f852_1b7b_9ea3_4e22_732f4a684bbe --> f3280f06_553d_66c3_8ca2_c3c36dcdda64
  style 7880f852_1b7b_9ea3_4e22_732f4a684bbe fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { Expression, Identifier, ObjectExpression } from 'estree' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../../types' */
import { escape_html } from '../../../../../../escaping.js';
import { normalize_attribute } from '../../../../../../utils.js';
import { is_ignored } from '../../../../../state.js';
import { is_event_attribute } from '../../../../../utils/ast.js';
import * as b from '#compiler/builders';
import { build_class_directives_object, build_style_directives_object } from '../RegularElement.js';
import { build_expression, build_template_chunk, Memoizer } from './utils.js';
import { ExpressionMetadata } from '../../../../nodes.js';

/**
 * @param {Array<AST.Attribute | AST.SpreadAttribute>} attributes
 * @param {AST.ClassDirective[]} class_directives
 * @param {AST.StyleDirective[]} style_directives
 * @param {ComponentContext} context
 * @param {AST.RegularElement | AST.SvelteElement} element
 * @param {Identifier} element_id
 * @param {boolean} [should_remove_defaults]
 */
export function build_attribute_effect(
	attributes,
	class_directives,
	style_directives,
	context,
	element,
	element_id,
	should_remove_defaults = false
) {
	/** @type {ObjectExpression['properties']} */
	const values = [];

	const memoizer = new Memoizer();

	for (const attribute of attributes) {
		if (attribute.type === 'Attribute') {
			const { value } = build_attribute_value(attribute.value, context, (value, metadata) =>
				memoizer.add(value, metadata)
			);

			if (
				is_event_attribute(attribute) &&
				(value.type === 'ArrowFunctionExpression' || value.type === 'FunctionExpression')
			) {
				// Give the event handler a stable ID so it isn't removed and readded on every update
				const id = context.state.scope.generate('event_handler');
				context.state.init.push(b.var(id, value));
				values.push(b.init(attribute.name, b.id(id)));
			} else {
				values.push(b.init(attribute.name, value));
			}
		} else {
			let value = /** @type {Expression} */ (context.visit(attribute));

			value = memoizer.add(value, attribute.metadata.expression);

			values.push(b.spread(value));
		}
	}
// ... (204 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 5 function(s): build_attribute_effect, build_attribute_value, build_set_class, build_set_style, get_attribute_name.
What does element.js depend on?
element.js imports 18 module(s): ExpressionMetadata, Memoizer, RegularElement.js, ast.js, build_class_directives_object, build_expression, build_style_directives_object, build_template_chunk, and 10 more.
What files import element.js?
element.js is imported by 5 file(s): BindDirective.js, RegularElement.js, SlotElement.js, SvelteElement.js, component.js.
Where is element.js in the architecture?
element.js is located at packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/element.js (domain: Compiler, subdomain: Transformer, directory: packages/svelte/src/compiler/phases/3-transform/client/visitors/shared).

Analyze Your Own Codebase

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

Try Supermodel Free