build_element_special_value_attribute() — svelte Function Reference
Architecture documentation for the build_element_special_value_attribute() function in RegularElement.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD e962c3e1_86a1_deae_f6f6_e1f565fa9687["build_element_special_value_attribute()"] 4610488f_3cf2_5f73_043e_da0aa9d026fe["RegularElement.js"] e962c3e1_86a1_deae_f6f6_e1f565fa9687 -->|defined in| 4610488f_3cf2_5f73_043e_da0aa9d026fe 1e3b81f2_cd53_e5a5_0140_a9af38facf99["RegularElement()"] 1e3b81f2_cd53_e5a5_0140_a9af38facf99 -->|calls| e962c3e1_86a1_deae_f6f6_e1f565fa9687 653284b2_68fd_eee3_0064_918a4c065d4a["is_text_attribute()"] e962c3e1_86a1_deae_f6f6_e1f565fa9687 -->|calls| 653284b2_68fd_eee3_0064_918a4c065d4a e31bc2c2_91c1_b9a9_f78a_2832bddce6c5["build_attribute_value()"] e962c3e1_86a1_deae_f6f6_e1f565fa9687 -->|calls| e31bc2c2_91c1_b9a9_f78a_2832bddce6c5 5ff7d39f_78e8_c057_8c8e_279f6e72149e["add()"] e962c3e1_86a1_deae_f6f6_e1f565fa9687 -->|calls| 5ff7d39f_78e8_c057_8c8e_279f6e72149e 804afe56_25d1_9f41_dafe_adc75e952134["object()"] e962c3e1_86a1_deae_f6f6_e1f565fa9687 -->|calls| 804afe56_25d1_9f41_dafe_adc75e952134 style e962c3e1_86a1_deae_f6f6_e1f565fa9687 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/src/compiler/phases/3-transform/client/visitors/RegularElement.js lines 730–788
function build_element_special_value_attribute(
element,
node_id,
attribute,
context,
synthetic = false
) {
const state = context.state;
const is_select_with_value =
// attribute.metadata.dynamic would give false negatives because even if the value does not change,
// the inner options could still change, so we need to always treat it as reactive
element === 'select' && attribute.value !== true && !is_text_attribute(attribute);
const { value, has_state } = build_attribute_value(attribute.value, context, (value, metadata) =>
state.memoizer.add(value, metadata)
);
const evaluated = context.state.scope.evaluate(value);
const assignment = b.assignment('=', b.member(node_id, '__value'), value);
const set_value_assignment = b.assignment(
'=',
b.member(node_id, 'value'),
evaluated.is_defined ? assignment : b.logical('??', assignment, b.literal(''))
);
const update = b.stmt(
is_select_with_value
? b.sequence([
set_value_assignment,
// This ensures a one-way street to the DOM in case it's <select {value}>
// and not <select bind:value>. We need it in addition to $.init_select
// because the select value is not reflected as an attribute, so the
// mutation observer wouldn't notice.
b.call('$.select_option', node_id, value)
])
: synthetic
? assignment
: set_value_assignment
);
if (has_state) {
const id = b.id(state.scope.generate(`${node_id.name}_value`));
// `<option>` is a special case: The value property reflects to the DOM. If the value is set to undefined,
// that means the value should be set to the empty string. To be able to do that when the value is
// initially undefined, we need to set a value that is guaranteed to be different.
const init = element === 'option' ? b.object([]) : undefined;
state.init.push(b.var(id, init));
state.update.push(b.if(b.binary('!==', id, b.assignment('=', id, value)), b.block([update])));
} else {
state.init.push(update);
}
if (is_select_with_value) {
state.init.push(b.stmt(b.call('$.init_select', node_id)));
}
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does build_element_special_value_attribute() do?
build_element_special_value_attribute() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/3-transform/client/visitors/RegularElement.js.
Where is build_element_special_value_attribute() defined?
build_element_special_value_attribute() is defined in packages/svelte/src/compiler/phases/3-transform/client/visitors/RegularElement.js at line 730.
What does build_element_special_value_attribute() call?
build_element_special_value_attribute() calls 4 function(s): add, build_attribute_value, is_text_attribute, object.
What calls build_element_special_value_attribute()?
build_element_special_value_attribute() is called by 1 function(s): RegularElement.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free