validate_element() — svelte Function Reference
Architecture documentation for the validate_element() function in element.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD 8b731563_0657_df8d_6a4b_cd33990e2ed2["validate_element()"] bab84a6b_4a21_0643_e6ee_13798dfa8b84["element.js"] 8b731563_0657_df8d_6a4b_cd33990e2ed2 -->|defined in| bab84a6b_4a21_0643_e6ee_13798dfa8b84 874d992f_5e60_ebce_f4ce_ea5fed014bc4["RegularElement()"] 874d992f_5e60_ebce_f4ce_ea5fed014bc4 -->|calls| 8b731563_0657_df8d_6a4b_cd33990e2ed2 33910f4c_6ec4_15d9_8342_5265e706975f["SvelteElement()"] 33910f4c_6ec4_15d9_8342_5265e706975f -->|calls| 8b731563_0657_df8d_6a4b_cd33990e2ed2 e4437bdc_6df3_4ac6_3252_12819762cc5e["is_expression_attribute()"] 8b731563_0657_df8d_6a4b_cd33990e2ed2 -->|calls| e4437bdc_6df3_4ac6_3252_12819762cc5e c3dd29c6_654d_d119_4318_e8151ff6da98["validate_attribute()"] 8b731563_0657_df8d_6a4b_cd33990e2ed2 -->|calls| c3dd29c6_654d_d119_4318_e8151ff6da98 a997caf9_1d66_f005_5b11_675724bd0ed8["get_attribute_expression()"] 8b731563_0657_df8d_6a4b_cd33990e2ed2 -->|calls| a997caf9_1d66_f005_5b11_675724bd0ed8 fbc806ef_711d_452a_360d_cef95188c05b["attribute_invalid_sequence_expression()"] 8b731563_0657_df8d_6a4b_cd33990e2ed2 -->|calls| fbc806ef_711d_452a_360d_cef95188c05b e73283ea_05bb_92fa_9364_565b479dd199["attribute_invalid_name()"] 8b731563_0657_df8d_6a4b_cd33990e2ed2 -->|calls| e73283ea_05bb_92fa_9364_565b479dd199 dcc6b182_fc15_94d7_602f_2bac23cdc0a1["attribute_invalid_event_handler()"] 8b731563_0657_df8d_6a4b_cd33990e2ed2 -->|calls| dcc6b182_fc15_94d7_602f_2bac23cdc0a1 20822aeb_87b0_f003_dec6_dfdb38cb5617["attribute_global_event_reference()"] 8b731563_0657_df8d_6a4b_cd33990e2ed2 -->|calls| 20822aeb_87b0_f003_dec6_dfdb38cb5617 c3969ef3_0f9b_1699_e3b6_75b4a9916c7d["validate_slot_attribute()"] 8b731563_0657_df8d_6a4b_cd33990e2ed2 -->|calls| c3969ef3_0f9b_1699_e3b6_75b4a9916c7d a9def843_85d9_35c4_1934_af79aeed77d6["attribute_avoid_is()"] 8b731563_0657_df8d_6a4b_cd33990e2ed2 -->|calls| a9def843_85d9_35c4_1934_af79aeed77d6 cca6176b_18a6_2bfa_62c4_cdf0a8244d73["attribute_invalid_property_name()"] 8b731563_0657_df8d_6a4b_cd33990e2ed2 -->|calls| cca6176b_18a6_2bfa_62c4_cdf0a8244d73 cea20d98_b8d1_aa5c_5f46_4ac417b7053c["validate_attribute_name()"] 8b731563_0657_df8d_6a4b_cd33990e2ed2 -->|calls| cea20d98_b8d1_aa5c_5f46_4ac417b7053c style 8b731563_0657_df8d_6a4b_cd33990e2ed2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/src/compiler/phases/2-analyze/visitors/shared/element.js lines 29–155
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);
}
if (attribute.name.startsWith('on') && attribute.name.length > 2) {
if (!is_expression) {
e.attribute_invalid_event_handler(attribute);
}
const value = get_attribute_expression(attribute);
if (
value.type === 'Identifier' &&
value.name === attribute.name &&
!context.state.scope.get(value.name)
) {
w.attribute_global_event_reference(attribute, attribute.name);
}
}
if (attribute.name === 'slot') {
/** @type {AST.RegularElement | AST.SvelteElement | AST.Component | AST.SvelteComponent | AST.SvelteSelf | undefined} */
validate_slot_attribute(context, attribute);
}
if (attribute.name === 'is') {
w.attribute_avoid_is(attribute);
}
const correct_name = react_attributes.get(attribute.name);
if (correct_name) {
w.attribute_invalid_property_name(attribute, attribute.name, correct_name);
}
validate_attribute_name(attribute);
} else if (attribute.type === 'AnimateDirective') {
const parent = context.path.at(-2);
if (parent?.type !== 'EachBlock') {
e.animation_invalid_placement(attribute);
} else if (!parent.key) {
e.animation_missing_key(attribute);
} else if (
parent.body.nodes.filter(
(n) =>
n.type !== 'Comment' &&
n.type !== 'ConstTag' &&
(n.type !== 'Text' || n.data.trim() !== '')
).length > 1
) {
e.animation_invalid_placement(attribute);
}
if (has_animate_directive) {
Domain
Subdomains
Calls
- animation_duplicate()
- animation_invalid_placement()
- animation_missing_key()
- attribute_avoid_is()
- attribute_global_event_reference()
- attribute_invalid_event_handler()
- attribute_invalid_name()
- attribute_invalid_property_name()
- attribute_invalid_sequence_expression()
- event_handler_invalid_modifier()
- event_handler_invalid_modifier_combination()
- get_attribute_expression()
- is_expression_attribute()
- transition_conflict()
- transition_duplicate()
- validate_attribute()
- validate_attribute_name()
- validate_slot_attribute()
Called By
Source
Frequently Asked Questions
What does validate_element() do?
validate_element() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/2-analyze/visitors/shared/element.js.
Where is validate_element() defined?
validate_element() is defined in packages/svelte/src/compiler/phases/2-analyze/visitors/shared/element.js at line 29.
What does validate_element() call?
validate_element() calls 18 function(s): animation_duplicate, animation_invalid_placement, animation_missing_key, attribute_avoid_is, attribute_global_event_reference, attribute_invalid_event_handler, attribute_invalid_name, attribute_invalid_property_name, and 10 more.
What calls validate_element()?
validate_element() is called by 2 function(s): RegularElement, SvelteElement.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free