build_set_class() — svelte Function Reference
Architecture documentation for the build_set_class() function in element.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD 987af9d2_1405_9935_a024_303199b22e0f["build_set_class()"] c8762c21_89f7_0b18_bda8_c3d75b58469c["element.js"] 987af9d2_1405_9935_a024_303199b22e0f -->|defined in| c8762c21_89f7_0b18_bda8_c3d75b58469c 81f87edd_21fb_a028_9969_dcf665f1732e["RegularElement()"] 81f87edd_21fb_a028_9969_dcf665f1732e -->|calls| 987af9d2_1405_9935_a024_303199b22e0f 6fbf0dfd_f1db_6f12_abb5_8f39441b1d1a["SvelteElement()"] 6fbf0dfd_f1db_6f12_abb5_8f39441b1d1a -->|calls| 987af9d2_1405_9935_a024_303199b22e0f 3bb0c49e_3431_adbe_8613_4e604cdaf605["build_attribute_value()"] 987af9d2_1405_9935_a024_303199b22e0f -->|calls| 3bb0c49e_3431_adbe_8613_4e604cdaf605 c4bb0705_b721_4ee2_2762_07ce6998b36d["add()"] 987af9d2_1405_9935_a024_303199b22e0f -->|calls| c4bb0705_b721_4ee2_2762_07ce6998b36d 6e980be5_a805_893d_4816_e9c5d20aaa71["build_class_directives_object()"] 987af9d2_1405_9935_a024_303199b22e0f -->|calls| 6e980be5_a805_893d_4816_e9c5d20aaa71 955a22d9_0b20_9a9e_7fa9_725097f479a4["is_async()"] 987af9d2_1405_9935_a024_303199b22e0f -->|calls| 955a22d9_0b20_9a9e_7fa9_725097f479a4 494ad35f_066a_eaba_ab89_2ae759e5e121["object()"] 987af9d2_1405_9935_a024_303199b22e0f -->|calls| 494ad35f_066a_eaba_ab89_2ae759e5e121 7b2393c6_d157_8940_d23b_cd1502b0417d["escape_html()"] 987af9d2_1405_9935_a024_303199b22e0f -->|calls| 7b2393c6_d157_8940_d23b_cd1502b0417d style 987af9d2_1405_9935_a024_303199b22e0f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/element.js lines 152–218
export function build_set_class(element, node_id, attribute, class_directives, context, is_html) {
let { value, has_state } = build_attribute_value(attribute.value, context, (value, metadata) => {
if (attribute.metadata.needs_clsx) {
value = b.call('$.clsx', value);
}
return context.state.memoizer.add(value, metadata);
});
/** @type {Identifier | undefined} */
let previous_id;
/** @type {ObjectExpression | Identifier | undefined} */
let prev;
/** @type {Expression | undefined} */
let next;
if (class_directives.length) {
next = build_class_directives_object(class_directives, context);
has_state ||= class_directives.some(
(d) => d.metadata.expression.has_state || d.metadata.expression.is_async()
);
if (has_state) {
previous_id = b.id(context.state.scope.generate('classes'));
context.state.init.push(b.declaration('let', [b.declarator(previous_id)]));
prev = previous_id;
} else {
prev = b.object([]);
}
}
/** @type {Expression | undefined} */
let css_hash;
if (element.metadata.scoped && context.state.analysis.css.hash) {
if (value.type === 'Literal' && (value.value === '' || value.value === null)) {
value = b.literal(context.state.analysis.css.hash);
} else if (value.type === 'Literal' && typeof value.value === 'string') {
value = b.literal(escape_html(value.value, true) + ' ' + context.state.analysis.css.hash);
} else {
css_hash = b.literal(context.state.analysis.css.hash);
}
}
if (!css_hash && next) {
css_hash = b.null;
}
/** @type {Expression} */
let set_class = b.call(
'$.set_class',
node_id,
is_html ? b.literal(1) : b.literal(0),
value,
css_hash,
prev,
next
);
if (previous_id) {
set_class = b.assignment('=', previous_id, set_class);
}
(has_state ? context.state.update : context.state.init).push(b.stmt(set_class));
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does build_set_class() do?
build_set_class() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/element.js.
Where is build_set_class() defined?
build_set_class() is defined in packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/element.js at line 152.
What does build_set_class() call?
build_set_class() calls 6 function(s): add, build_attribute_value, build_class_directives_object, escape_html, is_async, object.
What calls build_set_class()?
build_set_class() 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