RegularElement() — svelte Function Reference
Architecture documentation for the RegularElement() function in RegularElement.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD 874d992f_5e60_ebce_f4ce_ea5fed014bc4["RegularElement()"] 60af7ccf_2ceb_e5af_2432_c5b753a12c2a["RegularElement.js"] 874d992f_5e60_ebce_f4ce_ea5fed014bc4 -->|defined in| 60af7ccf_2ceb_e5af_2432_c5b753a12c2a 8b731563_0657_df8d_6a4b_cd33990e2ed2["validate_element()"] 874d992f_5e60_ebce_f4ce_ea5fed014bc4 -->|calls| 8b731563_0657_df8d_6a4b_cd33990e2ed2 c342967b_b314_8027_476d_d085ed0e13f0["check_element()"] 874d992f_5e60_ebce_f4ce_ea5fed014bc4 -->|calls| c342967b_b314_8027_476d_d085ed0e13f0 574638db_a1c7_ebc4_cc07_35138e188e4b["textarea_invalid_content()"] 874d992f_5e60_ebce_f4ce_ea5fed014bc4 -->|calls| 574638db_a1c7_ebc4_cc07_35138e188e4b 53888034_73fb_39d8_be82_b1928817ff74["create_attribute()"] 874d992f_5e60_ebce_f4ce_ea5fed014bc4 -->|calls| 53888034_73fb_39d8_be82_b1928817ff74 02aa96ac_ad32_58cd_41f5_e0ee1020af5f["is_customizable_select_element()"] 874d992f_5e60_ebce_f4ce_ea5fed014bc4 -->|calls| 02aa96ac_ad32_58cd_41f5_e0ee1020af5f 313d2a82_30ea_3161_3aad_0cc2094979aa["mark_subtree_dynamic()"] 874d992f_5e60_ebce_f4ce_ea5fed014bc4 -->|calls| 313d2a82_30ea_3161_3aad_0cc2094979aa 6ba24563_c42d_46c3_1fd0_b2bfc03b5d98["component_name_lowercase()"] 874d992f_5e60_ebce_f4ce_ea5fed014bc4 -->|calls| 6ba24563_c42d_46c3_1fd0_b2bfc03b5d98 a7190cf9_11f3_7b29_6ed5_5ee01fc100af["is_svg()"] 874d992f_5e60_ebce_f4ce_ea5fed014bc4 -->|calls| a7190cf9_11f3_7b29_6ed5_5ee01fc100af ded343d4_9f64_40db_2c3d_049cfb2ee86e["is_mathml()"] 874d992f_5e60_ebce_f4ce_ea5fed014bc4 -->|calls| ded343d4_9f64_40db_2c3d_049cfb2ee86e 76437ce7_73fa_a7f2_397a_1ddd381e8282["is_custom_element_node()"] 874d992f_5e60_ebce_f4ce_ea5fed014bc4 -->|calls| 76437ce7_73fa_a7f2_397a_1ddd381e8282 b52e7925_73b5_1187_beab_fb7eb59cc45d["is_tag_valid_with_parent()"] 874d992f_5e60_ebce_f4ce_ea5fed014bc4 -->|calls| b52e7925_73b5_1187_beab_fb7eb59cc45d 26a7a8d0_0795_b4a2_1180_25080b73f735["node_invalid_placement_ssr()"] 874d992f_5e60_ebce_f4ce_ea5fed014bc4 -->|calls| 26a7a8d0_0795_b4a2_1180_25080b73f735 83398170_c952_50c5_93ea_2776bbf2a83b["node_invalid_placement()"] 874d992f_5e60_ebce_f4ce_ea5fed014bc4 -->|calls| 83398170_c952_50c5_93ea_2776bbf2a83b style 874d992f_5e60_ebce_f4ce_ea5fed014bc4 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/src/compiler/phases/2-analyze/visitors/RegularElement.js lines 24–210
export function RegularElement(node, context) {
validate_element(node, context);
check_element(node, context);
node.metadata.path = [...context.path];
context.state.analysis.elements.push(node);
// Special case: Move the children of <textarea> into a value attribute if they are dynamic
if (node.name === 'textarea' && node.fragment.nodes.length > 0) {
for (const attribute of node.attributes) {
if (attribute.type === 'Attribute' && attribute.name === 'value') {
e.textarea_invalid_content(node);
}
}
if (node.fragment.nodes.length > 1 || node.fragment.nodes[0].type !== 'Text') {
const first = node.fragment.nodes[0];
if (first.type === 'Text') {
// The leading newline character needs to be stripped because of a qirk:
// It is ignored by browsers if the tag and its contents are set through
// innerHTML, but we're now setting it through the value property at which
// point it is _not_ ignored, so we need to strip it ourselves.
// see https://html.spec.whatwg.org/multipage/syntax.html#element-restrictions
// see https://html.spec.whatwg.org/multipage/grouping-content.html#the-pre-element
first.data = first.data.replace(regex_starts_with_newline, '');
first.raw = first.raw.replace(regex_starts_with_newline, '');
}
node.attributes.push(
create_attribute(
'value',
null,
-1,
-1,
// @ts-ignore
node.fragment.nodes
)
);
node.fragment.nodes = [];
}
}
// Special case: single expression tag child of option element -> add "fake" attribute
// to ensure that value types are the same (else for example numbers would be strings)
if (
node.name === 'option' &&
node.fragment.nodes?.length === 1 &&
node.fragment.nodes[0].type === 'ExpressionTag' &&
!node.attributes.some(
(attribute) => attribute.type === 'Attribute' && attribute.name === 'value'
)
) {
const child = node.fragment.nodes[0];
node.metadata.synthetic_value_node = child;
}
// Special case: <select>, <option> or <optgroup> with rich content needs special hydration handling
// We mark the subtree as dynamic so parent elements properly include the child init code
if (is_customizable_select_element(node) || node.name === 'selectedcontent') {
// Mark the element's own fragment as dynamic so it's not treated as static
node.fragment.metadata.dynamic = true;
// Also mark ancestor fragments so parents properly include the child init code
mark_subtree_dynamic(context.path);
}
const binding = context.state.scope.get(node.name);
if (
binding !== null &&
binding.declaration_kind === 'import' &&
binding.references.length === 0
) {
w.component_name_lowercase(node, node.name);
}
node.metadata.has_spread = node.attributes.some(
(attribute) => attribute.type === 'SpreadAttribute'
);
const is_svg_element = () => {
if (is_svg(node.name)) {
Domain
Subdomains
Calls
- check_element()
- component_name_lowercase()
- create_attribute()
- element_invalid_self_closing_tag()
- is_custom_element_node()
- is_customizable_select_element()
- is_mathml()
- is_svg()
- is_tag_valid_with_ancestor()
- is_tag_valid_with_parent()
- is_void()
- mark_subtree_dynamic()
- node_invalid_placement()
- node_invalid_placement_ssr()
- textarea_invalid_content()
- validate_element()
Source
Frequently Asked Questions
What does RegularElement() do?
RegularElement() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/2-analyze/visitors/RegularElement.js.
Where is RegularElement() defined?
RegularElement() is defined in packages/svelte/src/compiler/phases/2-analyze/visitors/RegularElement.js at line 24.
What does RegularElement() call?
RegularElement() calls 16 function(s): check_element, component_name_lowercase, create_attribute, element_invalid_self_closing_tag, is_custom_element_node, is_customizable_select_element, is_mathml, is_svg, and 8 more.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free