Attribute() — svelte Function Reference
Architecture documentation for the Attribute() function in Attribute.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD 3267915a_919c_3f5d_3f91_77e46597d1e0["Attribute()"] 28ec60f4_a82f_1f06_ded7_1786b05aa1c0["Attribute.js"] 3267915a_919c_3f5d_3f91_77e46597d1e0 -->|defined in| 28ec60f4_a82f_1f06_ded7_1786b05aa1c0 313d2a82_30ea_3161_3aad_0cc2094979aa["mark_subtree_dynamic()"] 3267915a_919c_3f5d_3f91_77e46597d1e0 -->|calls| 313d2a82_30ea_3161_3aad_0cc2094979aa e9a2c29e_d0ca_ab9f_b86f_f22ff802db91["is_event_attribute()"] 3267915a_919c_3f5d_3f91_77e46597d1e0 -->|calls| e9a2c29e_d0ca_ab9f_b86f_f22ff802db91 236530b5_f75d_4a7b_e916_b2d6a6d54dfb["cannot_be_set_statically()"] 3267915a_919c_3f5d_3f91_77e46597d1e0 -->|calls| 236530b5_f75d_4a7b_e916_b2d6a6d54dfb f6625393_617b_8f3b_aaa5_b87527fde52f["get_attribute_chunks()"] 3267915a_919c_3f5d_3f91_77e46597d1e0 -->|calls| f6625393_617b_8f3b_aaa5_b87527fde52f 5605d535_663e_c67f_f365_389c8234aff5["can_delegate_event()"] 3267915a_919c_3f5d_3f91_77e46597d1e0 -->|calls| 5605d535_663e_c67f_f365_389c8234aff5 style 3267915a_919c_3f5d_3f91_77e46597d1e0 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/src/compiler/phases/2-analyze/visitors/Attribute.js lines 11–66
export function Attribute(node, context) {
context.next();
const parent = /** @type {AST.SvelteNode} */ (context.path.at(-1));
if (parent.type === 'RegularElement') {
// special case <option value="" />
if (node.name === 'value' && parent.name === 'option') {
mark_subtree_dynamic(context.path);
}
}
if (is_event_attribute(node)) {
mark_subtree_dynamic(context.path);
}
if (cannot_be_set_statically(node.name)) {
mark_subtree_dynamic(context.path);
}
// class={[...]} or class={{...}} or `class={x}` need clsx to resolve the classes
if (
node.name === 'class' &&
!Array.isArray(node.value) &&
node.value !== true &&
node.value.expression.type !== 'Literal' &&
node.value.expression.type !== 'TemplateLiteral' &&
node.value.expression.type !== 'BinaryExpression'
) {
mark_subtree_dynamic(context.path);
node.metadata.needs_clsx = true;
}
if (node.value !== true) {
for (const chunk of get_attribute_chunks(node.value)) {
if (chunk.type !== 'ExpressionTag') continue;
if (
chunk.expression.type === 'FunctionExpression' ||
chunk.expression.type === 'ArrowFunctionExpression'
) {
continue;
}
}
if (is_event_attribute(node)) {
const parent = context.path.at(-1);
if (parent?.type === 'RegularElement' || parent?.type === 'SvelteElement') {
context.state.analysis.uses_event_attributes = true;
}
node.metadata.delegated =
parent?.type === 'RegularElement' && can_delegate_event(node.name.slice(2));
}
}
}
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does Attribute() do?
Attribute() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/2-analyze/visitors/Attribute.js.
Where is Attribute() defined?
Attribute() is defined in packages/svelte/src/compiler/phases/2-analyze/visitors/Attribute.js at line 11.
What does Attribute() call?
Attribute() calls 5 function(s): can_delegate_event, cannot_be_set_statically, get_attribute_chunks, is_event_attribute, mark_subtree_dynamic.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free