BindDirective() — svelte Function Reference
Architecture documentation for the BindDirective() function in BindDirective.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD 4931635c_2415_3c69_a7a7_e98ad2cfd475["BindDirective()"] 6b8c189e_23e1_77d3_9ee3_3eec5012a9b2["BindDirective.js"] 4931635c_2415_3c69_a7a7_e98ad2cfd475 -->|defined in| 6b8c189e_23e1_77d3_9ee3_3eec5012a9b2 fb1e56a4_ffa9_d40d_f0ee_79fcaa5ba0b4["bind_invalid_target()"] 4931635c_2415_3c69_a7a7_e98ad2cfd475 -->|calls| fb1e56a4_ffa9_d40d_f0ee_79fcaa5ba0b4 f0a7ea80_5f7f_2d26_5521_d7d215a0669b["bind_invalid_name()"] 4931635c_2415_3c69_a7a7_e98ad2cfd475 -->|calls| f0a7ea80_5f7f_2d26_5521_d7d215a0669b 653284b2_68fd_eee3_0064_918a4c065d4a["is_text_attribute()"] 4931635c_2415_3c69_a7a7_e98ad2cfd475 -->|calls| 653284b2_68fd_eee3_0064_918a4c065d4a ed48fcc1_8cdb_cd71_179f_225cc93495f1["attribute_invalid_type()"] 4931635c_2415_3c69_a7a7_e98ad2cfd475 -->|calls| ed48fcc1_8cdb_cd71_179f_225cc93495f1 3b65e6f2_178e_7611_c23c_d64fc2929e00["attribute_invalid_multiple()"] 4931635c_2415_3c69_a7a7_e98ad2cfd475 -->|calls| 3b65e6f2_178e_7611_c23c_d64fc2929e00 a7190cf9_11f3_7b29_6ed5_5ee01fc100af["is_svg()"] 4931635c_2415_3c69_a7a7_e98ad2cfd475 -->|calls| a7190cf9_11f3_7b29_6ed5_5ee01fc100af d74f6e21_de3c_dbc0_f6e6_a119f708c4c8["is_content_editable_binding()"] 4931635c_2415_3c69_a7a7_e98ad2cfd475 -->|calls| d74f6e21_de3c_dbc0_f6e6_a119f708c4c8 26fd9f57_8bec_82c5_ce02_8ba55773ba52["attribute_contenteditable_missing()"] 4931635c_2415_3c69_a7a7_e98ad2cfd475 -->|calls| 26fd9f57_8bec_82c5_ce02_8ba55773ba52 16ed74ea_3224_fd5b_4e83_f84743e02fcf["attribute_contenteditable_dynamic()"] 4931635c_2415_3c69_a7a7_e98ad2cfd475 -->|calls| 16ed74ea_3224_fd5b_4e83_f84743e02fcf 0913e53f_3cfc_070a_7b42_568cf6860af3["fuzzymatch()"] 4931635c_2415_3c69_a7a7_e98ad2cfd475 -->|calls| 0913e53f_3cfc_070a_7b42_568cf6860af3 a01c3244_fda5_b63a_e031_199eb01fb5d4["bind_group_invalid_expression()"] 4931635c_2415_3c69_a7a7_e98ad2cfd475 -->|calls| a01c3244_fda5_b63a_e031_199eb01fb5d4 397323eb_2007_3cb5_4abf_7b960e87d9f9["bind_invalid_parens()"] 4931635c_2415_3c69_a7a7_e98ad2cfd475 -->|calls| 397323eb_2007_3cb5_4abf_7b960e87d9f9 4e62d15e_0f42_4e8b_b39f_3ac51eb77332["bind_invalid_expression()"] 4931635c_2415_3c69_a7a7_e98ad2cfd475 -->|calls| 4e62d15e_0f42_4e8b_b39f_3ac51eb77332 style 4931635c_2415_3c69_a7a7_e98ad2cfd475 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/src/compiler/phases/2-analyze/visitors/BindDirective.js lines 20–280
export function BindDirective(node, context) {
const parent = context.path.at(-1);
if (
parent?.type === 'RegularElement' ||
parent?.type === 'SvelteElement' ||
parent?.type === 'SvelteWindow' ||
parent?.type === 'SvelteDocument' ||
parent?.type === 'SvelteBody'
) {
if (node.name in binding_properties) {
const property = binding_properties[node.name];
if (property.valid_elements && !property.valid_elements.includes(parent.name)) {
e.bind_invalid_target(
node,
node.name,
property.valid_elements.map((valid_element) => `\`<${valid_element}>\``).join(', ')
);
}
if (property.invalid_elements && property.invalid_elements.includes(parent.name)) {
const valid_bindings = Object.entries(binding_properties)
.filter(([_, binding_property]) => {
return (
binding_property.valid_elements?.includes(parent.name) ||
(!binding_property.valid_elements &&
!binding_property.invalid_elements?.includes(parent.name))
);
})
.map(([property_name]) => property_name)
.sort();
e.bind_invalid_name(
node,
node.name,
`Possible bindings for <${parent.name}> are ${valid_bindings.join(', ')}`
);
}
if (parent.name === 'input' && node.name !== 'this') {
const type = /** @type {AST.Attribute | undefined} */ (
parent.attributes.find((a) => a.type === 'Attribute' && a.name === 'type')
);
if (type && !is_text_attribute(type)) {
if (node.name !== 'value' || type.value === true) {
e.attribute_invalid_type(type);
}
} else {
if (node.name === 'checked' && type?.value[0].data !== 'checkbox') {
e.bind_invalid_target(
node,
node.name,
`\`<input type="checkbox">\`${type?.value[0].data === 'radio' ? ` — for \`<input type="radio">\`, use \`bind:group\`` : ''}`
);
}
if (node.name === 'files' && type?.value[0].data !== 'file') {
e.bind_invalid_target(node, node.name, '`<input type="file">`');
}
}
}
if (parent.name === 'select' && node.name !== 'this') {
const multiple = parent.attributes.find(
(a) =>
a.type === 'Attribute' &&
a.name === 'multiple' &&
!is_text_attribute(a) &&
a.value !== true
);
if (multiple) {
e.attribute_invalid_multiple(multiple);
}
}
if (node.name === 'offsetWidth' && is_svg(parent.name)) {
e.bind_invalid_target(
node,
node.name,
Domain
Subdomains
Calls
- attribute_contenteditable_dynamic()
- attribute_contenteditable_missing()
- attribute_invalid_multiple()
- attribute_invalid_type()
- bind_group_invalid_expression()
- bind_group_invalid_snippet_parameter()
- bind_invalid_each_rest()
- bind_invalid_expression()
- bind_invalid_name()
- bind_invalid_parens()
- bind_invalid_target()
- bind_invalid_value()
- extract_all_identifiers_from_expression()
- fuzzymatch()
- get()
- illegal_await_expression()
- is_content_editable_binding()
- is_svg()
- is_text_attribute()
- mark_subtree_dynamic()
- object()
- validate_assignment()
Source
Frequently Asked Questions
What does BindDirective() do?
BindDirective() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/2-analyze/visitors/BindDirective.js.
Where is BindDirective() defined?
BindDirective() is defined in packages/svelte/src/compiler/phases/2-analyze/visitors/BindDirective.js at line 20.
What does BindDirective() call?
BindDirective() calls 22 function(s): attribute_contenteditable_dynamic, attribute_contenteditable_missing, attribute_invalid_multiple, attribute_invalid_type, bind_group_invalid_expression, bind_group_invalid_snippet_parameter, bind_invalid_each_rest, bind_invalid_expression, and 14 more.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free