Home / File/ element.js — svelte Source File

element.js — svelte Source File

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

File javascript Compiler Transformer 12 imports 2 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  bab84a6b_4a21_0643_e6ee_13798dfa8b84["element.js"]
  0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c["ast.js"]
  bab84a6b_4a21_0643_e6ee_13798dfa8b84 --> 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c
  a997caf9_1d66_f005_5b11_675724bd0ed8["get_attribute_expression"]
  bab84a6b_4a21_0643_e6ee_13798dfa8b84 --> a997caf9_1d66_f005_5b11_675724bd0ed8
  e4437bdc_6df3_4ac6_3252_12819762cc5e["is_expression_attribute"]
  bab84a6b_4a21_0643_e6ee_13798dfa8b84 --> e4437bdc_6df3_4ac6_3252_12819762cc5e
  ce051dbd_4cf1_f117_d66e_12cfa122de37["patterns.js"]
  bab84a6b_4a21_0643_e6ee_13798dfa8b84 --> ce051dbd_4cf1_f117_d66e_12cfa122de37
  495501a4_a342_6a4d_ac11_e3e2fee8b218["errors.js"]
  bab84a6b_4a21_0643_e6ee_13798dfa8b84 --> 495501a4_a342_6a4d_ac11_e3e2fee8b218
  a146f6ac_0088_8736_b6ce_318f9f115170["e"]
  bab84a6b_4a21_0643_e6ee_13798dfa8b84 --> a146f6ac_0088_8736_b6ce_318f9f115170
  56a689f9_11c0_cc76_bd60_41bb6dc96475["warnings.js"]
  bab84a6b_4a21_0643_e6ee_13798dfa8b84 --> 56a689f9_11c0_cc76_bd60_41bb6dc96475
  3246e0bc_b9fc_f638_5e35_41e8c39a2408["w"]
  bab84a6b_4a21_0643_e6ee_13798dfa8b84 --> 3246e0bc_b9fc_f638_5e35_41e8c39a2408
  32df1fa2_adf7_5122_0b02_c399ea508ae0["attribute.js"]
  bab84a6b_4a21_0643_e6ee_13798dfa8b84 --> 32df1fa2_adf7_5122_0b02_c399ea508ae0
  c3dd29c6_654d_d119_4318_e8151ff6da98["validate_attribute"]
  bab84a6b_4a21_0643_e6ee_13798dfa8b84 --> c3dd29c6_654d_d119_4318_e8151ff6da98
  cea20d98_b8d1_aa5c_5f46_4ac417b7053c["validate_attribute_name"]
  bab84a6b_4a21_0643_e6ee_13798dfa8b84 --> cea20d98_b8d1_aa5c_5f46_4ac417b7053c
  c3969ef3_0f9b_1699_e3b6_75b4a9916c7d["validate_slot_attribute"]
  bab84a6b_4a21_0643_e6ee_13798dfa8b84 --> c3969ef3_0f9b_1699_e3b6_75b4a9916c7d
  60af7ccf_2ceb_e5af_2432_c5b753a12c2a["RegularElement.js"]
  60af7ccf_2ceb_e5af_2432_c5b753a12c2a --> bab84a6b_4a21_0643_e6ee_13798dfa8b84
  f7b5a3fc_d53e_8647_11c4_d826334aec0c["SvelteElement.js"]
  f7b5a3fc_d53e_8647_11c4_d826334aec0c --> bab84a6b_4a21_0643_e6ee_13798dfa8b84
  style bab84a6b_4a21_0643_e6ee_13798dfa8b84 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { AST } from '#compiler' */
/** @import { Context } from '../../types' */
import { get_attribute_expression, is_expression_attribute } from '../../../../utils/ast.js';
import { regex_illegal_attribute_character } from '../../../patterns.js';
import * as e from '../../../../errors.js';
import * as w from '../../../../warnings.js';
import {
	validate_attribute,
	validate_attribute_name,
	validate_slot_attribute
} from './attribute.js';

const EVENT_MODIFIERS = [
	'preventDefault',
	'stopPropagation',
	'stopImmediatePropagation',
	'capture',
	'once',
	'passive',
	'nonpassive',
	'self',
	'trusted'
];

/**
 * @param {AST.RegularElement | AST.SvelteElement} node
 * @param {Context} context
 */
export function validate_element(node, context) {
	let has_animate_directive = false;

	/** @type {AST.TransitionDirective | null} */
	let in_transition = null;

	/** @type {AST.TransitionDirective | null} */
	let out_transition = null;

	for (const attribute of node.attributes) {
		if (attribute.type === 'Attribute') {
			const is_expression = is_expression_attribute(attribute);

			if (context.state.analysis.runes) {
				validate_attribute(attribute, node);

				if (is_expression) {
					const expression = get_attribute_expression(attribute);
					if (expression.type === 'SequenceExpression') {
						let i = /** @type {number} */ (expression.start);
						while (--i > 0) {
							const char = context.state.analysis.source[i];
							if (char === '(') break; // parenthesized sequence expressions are ok
							if (char === '{') e.attribute_invalid_sequence_expression(expression);
						}
					}
				}
			}

			if (regex_illegal_attribute_character.test(attribute.name)) {
				e.attribute_invalid_name(attribute, attribute.name);
			}
// ... (101 more lines)

Domain

Subdomains

Functions

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 1 function(s): validate_element.
What does element.js depend on?
element.js imports 12 module(s): ast.js, attribute.js, e, errors.js, get_attribute_expression, is_expression_attribute, patterns.js, validate_attribute, and 4 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/2-analyze/visitors/shared/element.js (domain: Compiler, subdomain: Transformer, directory: packages/svelte/src/compiler/phases/2-analyze/visitors/shared).

Analyze Your Own Codebase

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

Try Supermodel Free