Attribute.js — svelte Source File
Architecture documentation for Attribute.js, a javascript file in the svelte codebase. 8 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 28ec60f4_a82f_1f06_ded7_1786b05aa1c0["Attribute.js"] 2aa63f4e_82c9_33e3_ac6c_5f3d46250522["utils.js"] 28ec60f4_a82f_1f06_ded7_1786b05aa1c0 --> 2aa63f4e_82c9_33e3_ac6c_5f3d46250522 236530b5_f75d_4a7b_e916_b2d6a6d54dfb["cannot_be_set_statically"] 28ec60f4_a82f_1f06_ded7_1786b05aa1c0 --> 236530b5_f75d_4a7b_e916_b2d6a6d54dfb 5605d535_663e_c67f_f365_389c8234aff5["can_delegate_event"] 28ec60f4_a82f_1f06_ded7_1786b05aa1c0 --> 5605d535_663e_c67f_f365_389c8234aff5 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c["ast.js"] 28ec60f4_a82f_1f06_ded7_1786b05aa1c0 --> 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c f6625393_617b_8f3b_aaa5_b87527fde52f["get_attribute_chunks"] 28ec60f4_a82f_1f06_ded7_1786b05aa1c0 --> f6625393_617b_8f3b_aaa5_b87527fde52f e9a2c29e_d0ca_ab9f_b86f_f22ff802db91["is_event_attribute"] 28ec60f4_a82f_1f06_ded7_1786b05aa1c0 --> e9a2c29e_d0ca_ab9f_b86f_f22ff802db91 c4b4ac8d_9914_5ede_1aea_723bf80d2e9b["fragment.js"] 28ec60f4_a82f_1f06_ded7_1786b05aa1c0 --> c4b4ac8d_9914_5ede_1aea_723bf80d2e9b 313d2a82_30ea_3161_3aad_0cc2094979aa["mark_subtree_dynamic"] 28ec60f4_a82f_1f06_ded7_1786b05aa1c0 --> 313d2a82_30ea_3161_3aad_0cc2094979aa 4aa8a188_84d4_0274_ed83_cac0ab1d3572["index.js"] 4aa8a188_84d4_0274_ed83_cac0ab1d3572 --> 28ec60f4_a82f_1f06_ded7_1786b05aa1c0 style 28ec60f4_a82f_1f06_ded7_1786b05aa1c0 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import { cannot_be_set_statically, can_delegate_event } from '../../../../utils.js';
import { get_attribute_chunks, is_event_attribute } from '../../../utils/ast.js';
import { mark_subtree_dynamic } from './shared/fragment.js';
/**
* @param {AST.Attribute} node
* @param {Context} context
*/
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
Functions
Dependencies
Source
Frequently Asked Questions
What does Attribute.js do?
Attribute.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 Attribute.js?
Attribute.js defines 1 function(s): Attribute.
What does Attribute.js depend on?
Attribute.js imports 8 module(s): ast.js, can_delegate_event, cannot_be_set_statically, fragment.js, get_attribute_chunks, is_event_attribute, mark_subtree_dynamic, utils.js.
What files import Attribute.js?
Attribute.js is imported by 1 file(s): index.js.
Where is Attribute.js in the architecture?
Attribute.js is located at packages/svelte/src/compiler/phases/2-analyze/visitors/Attribute.js (domain: Compiler, subdomain: Transformer, directory: packages/svelte/src/compiler/phases/2-analyze/visitors).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free