validate_no_const_assignment() — svelte Function Reference
Architecture documentation for the validate_no_const_assignment() function in utils.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD 935c89a2_392f_449c_c3ba_d8e096769215["validate_no_const_assignment()"] 879a8cda_acdf_1869_e4c8_108f6fd29121["utils.js"] 935c89a2_392f_449c_c3ba_d8e096769215 -->|defined in| 879a8cda_acdf_1869_e4c8_108f6fd29121 84052d88_0ace_5ab4_e36c_eadcbaf66ef9["validate_assignment()"] 84052d88_0ace_5ab4_e36c_eadcbaf66ef9 -->|calls| 935c89a2_392f_449c_c3ba_d8e096769215 87886485_f7af_45a6_596d_7f22c5d05337["get()"] 935c89a2_392f_449c_c3ba_d8e096769215 -->|calls| 87886485_f7af_45a6_596d_7f22c5d05337 a641eb2a_af8d_03ca_fb25_c2842cc77388["constant_binding()"] 935c89a2_392f_449c_c3ba_d8e096769215 -->|calls| a641eb2a_af8d_03ca_fb25_c2842cc77388 e5b385f2_7c02_1ebf_b9ab_2efb1becda2e["constant_assignment()"] 935c89a2_392f_449c_c3ba_d8e096769215 -->|calls| e5b385f2_7c02_1ebf_b9ab_2efb1becda2e style 935c89a2_392f_449c_c3ba_d8e096769215 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/src/compiler/phases/2-analyze/visitors/shared/utils.js lines 84–123
export function validate_no_const_assignment(node, argument, scope, is_binding) {
if (argument.type === 'ArrayPattern') {
for (const element of argument.elements) {
if (element) {
validate_no_const_assignment(node, element, scope, is_binding);
}
}
} else if (argument.type === 'ObjectPattern') {
for (const element of argument.properties) {
if (element.type === 'Property') {
validate_no_const_assignment(node, element.value, scope, is_binding);
}
}
} else if (argument.type === 'Identifier') {
const binding = scope.get(argument.name);
if (
binding?.declaration_kind === 'import' ||
(binding?.declaration_kind === 'const' && binding.kind !== 'each')
) {
// e.invalid_const_assignment(
// node,
// is_binding,
// // This takes advantage of the fact that we don't assign initial for let directives and then/catch variables.
// // If we start doing that, we need another property on the binding to differentiate, or give up on the more precise error message.
// binding.kind !== 'state' &&
// binding.kind !== 'raw_state' &&
// (binding.kind !== 'normal' || !binding.initial)
// );
// TODO have a more specific error message for assignments to things like `{:then foo}`
const thing = binding.declaration_kind === 'import' ? 'import' : 'constant';
if (is_binding) {
e.constant_binding(node, thing);
} else {
e.constant_assignment(node, thing);
}
}
}
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does validate_no_const_assignment() do?
validate_no_const_assignment() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/2-analyze/visitors/shared/utils.js.
Where is validate_no_const_assignment() defined?
validate_no_const_assignment() is defined in packages/svelte/src/compiler/phases/2-analyze/visitors/shared/utils.js at line 84.
What does validate_no_const_assignment() call?
validate_no_const_assignment() calls 3 function(s): constant_assignment, constant_binding, get.
What calls validate_no_const_assignment()?
validate_no_const_assignment() is called by 1 function(s): validate_assignment.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free