build_element_attributes() — svelte Function Reference
Architecture documentation for the build_element_attributes() function in element.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD 17370b4c_df64_f183_35da_1de383ea4963["build_element_attributes()"] b25fbb61_695c_e699_cbac_73059624d603["element.js"] 17370b4c_df64_f183_35da_1de383ea4963 -->|defined in| b25fbb61_695c_e699_cbac_73059624d603 602abe50_d235_587e_7077_a4250fe9dc79["RegularElement()"] 602abe50_d235_587e_7077_a4250fe9dc79 -->|calls| 17370b4c_df64_f183_35da_1de383ea4963 c4f05925_802b_7561_caa7_d44e5e7a50fd["SvelteElement()"] c4f05925_802b_7561_caa7_d44e5e7a50fd -->|calls| 17370b4c_df64_f183_35da_1de383ea4963 784480d0_767d_ac40_b03e_ae8ddcc82684["Set()"] 17370b4c_df64_f183_35da_1de383ea4963 -->|calls| 784480d0_767d_ac40_b03e_ae8ddcc82684 9f24c33c_da34_a132_f273_3ffd2f6e5cf8["build_attribute_value()"] 17370b4c_df64_f183_35da_1de383ea4963 -->|calls| 9f24c33c_da34_a132_f273_3ffd2f6e5cf8 e9a2c29e_d0ca_ab9f_b86f_f22ff802db91["is_event_attribute()"] 17370b4c_df64_f183_35da_1de383ea4963 -->|calls| e9a2c29e_d0ca_ab9f_b86f_f22ff802db91 92af2a3e_97f5_d3f7_30f9_40cc10f923d0["is_load_error_element()"] 17370b4c_df64_f183_35da_1de383ea4963 -->|calls| 92af2a3e_97f5_d3f7_30f9_40cc10f923d0 653284b2_68fd_eee3_0064_918a4c065d4a["is_text_attribute()"] 17370b4c_df64_f183_35da_1de383ea4963 -->|calls| 653284b2_68fd_eee3_0064_918a4c065d4a d74f6e21_de3c_dbc0_f6e6_a119f708c4c8["is_content_editable_binding()"] 17370b4c_df64_f183_35da_1de383ea4963 -->|calls| d74f6e21_de3c_dbc0_f6e6_a119f708c4c8 53888034_73fb_39d8_be82_b1928817ff74["create_attribute()"] 17370b4c_df64_f183_35da_1de383ea4963 -->|calls| 53888034_73fb_39d8_be82_b1928817ff74 55eb3f8e_68bc_d21e_cf79_8580012854f2["build_element_spread_attributes()"] 17370b4c_df64_f183_35da_1de383ea4963 -->|calls| 55eb3f8e_68bc_d21e_cf79_8580012854f2 6f6a3489_4061_e976_4be8_4905a2ae23cc["get_attribute_name()"] 17370b4c_df64_f183_35da_1de383ea4963 -->|calls| 6f6a3489_4061_e976_4be8_4905a2ae23cc d6dfd043_7103_f2c7_aab3_9660fb0a5f75["escape_html()"] 17370b4c_df64_f183_35da_1de383ea4963 -->|calls| d6dfd043_7103_f2c7_aab3_9660fb0a5f75 2efbc29a_f2d9_3c09_add9_6804350010a0["build_attr_class()"] 17370b4c_df64_f183_35da_1de383ea4963 -->|calls| 2efbc29a_f2d9_3c09_add9_6804350010a0 style 17370b4c_df64_f183_35da_1de383ea4963 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/element.js lines 31–279
export function build_element_attributes(node, context, transform) {
/** @type {Array<AST.Attribute | AST.SpreadAttribute>} */
const attributes = [];
/** @type {AST.ClassDirective[]} */
const class_directives = [];
/** @type {AST.StyleDirective[]} */
const style_directives = [];
/** @type {Expression | null} */
let content = null;
let has_spread = false;
let events_to_capture = new Set();
for (const attribute of node.attributes) {
if (attribute.type === 'Attribute') {
if (attribute.name === 'value') {
if (node.name === 'textarea') {
if (
attribute.value !== true &&
Array.isArray(attribute.value) &&
attribute.value[0].type === 'Text' &&
regex_starts_with_newline.test(attribute.value[0].data)
) {
// Two or more leading newlines are required to restore the leading newline immediately after `<textarea>`.
// see https://html.spec.whatwg.org/multipage/syntax.html#element-restrictions
// also see related code in analysis phase
attribute.value[0].data = '\n' + attribute.value[0].data;
}
content = b.call('$.escape', build_attribute_value(attribute.value, context, transform));
} else if (node.name !== 'select') {
// omit value attribute for select elements, it's irrelevant for the initially selected value and has no
// effect on the selected value after the user interacts with the select element (the value _property_ does, but not the attribute)
attributes.push(attribute);
}
// omit event handlers except for special cases
} else if (is_event_attribute(attribute)) {
if (
(attribute.name === 'onload' || attribute.name === 'onerror') &&
is_load_error_element(node.name)
) {
events_to_capture.add(attribute.name);
}
// the defaultValue/defaultChecked properties don't exist as attributes
} else if (attribute.name !== 'defaultValue' && attribute.name !== 'defaultChecked') {
if (attribute.name === 'class') {
if (attribute.metadata.needs_clsx) {
attributes.push({
...attribute,
value: {
.../** @type {AST.ExpressionTag} */ (attribute.value),
expression: b.call(
'$.clsx',
/** @type {AST.ExpressionTag} */ (attribute.value).expression
)
}
});
} else {
attributes.push(attribute);
}
} else {
attributes.push(attribute);
}
}
} else if (attribute.type === 'BindDirective') {
if (attribute.name === 'value' && node.name === 'select') continue;
if (
attribute.name === 'value' &&
attributes.some(
(attr) =>
attr.type === 'Attribute' &&
attr.name === 'type' &&
is_text_attribute(attr) &&
attr.value[0].data === 'file'
)
) {
continue;
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does build_element_attributes() do?
build_element_attributes() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/element.js.
Where is build_element_attributes() defined?
build_element_attributes() is defined in packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/element.js at line 31.
What does build_element_attributes() call?
build_element_attributes() calls 13 function(s): Set, build_attr_class, build_attr_style, build_attribute_value, build_element_spread_attributes, create_attribute, escape_html, get_attribute_name, and 5 more.
What calls build_element_attributes()?
build_element_attributes() 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