visit_assignment_expression() — svelte Function Reference
Architecture documentation for the visit_assignment_expression() function in assignments.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD 3f298b15_f3b3_11d6_21ea_d35e2d476f80["visit_assignment_expression()"] 47b19192_eefb_9217_3996_3a0f4e07c6ed["assignments.js"] 3f298b15_f3b3_11d6_21ea_d35e2d476f80 -->|defined in| 47b19192_eefb_9217_3996_3a0f4e07c6ed 1f789731_ba68_8335_c783_30bddb35964b["AssignmentExpression()"] 1f789731_ba68_8335_c783_30bddb35964b -->|calls| 3f298b15_f3b3_11d6_21ea_d35e2d476f80 9efa5288_dec8_6b06_a88a_18ddc2785900["AssignmentExpression()"] 9efa5288_dec8_6b06_a88a_18ddc2785900 -->|calls| 3f298b15_f3b3_11d6_21ea_d35e2d476f80 c254e734_2224_c309_f1f8_bb064e80b1af["extract_paths()"] 3f298b15_f3b3_11d6_21ea_d35e2d476f80 -->|calls| c254e734_2224_c309_f1f8_bb064e80b1af bdb5b0f7_5673_570b_155a_0bd0f9f8169a["is_expression_async()"] 3f298b15_f3b3_11d6_21ea_d35e2d476f80 -->|calls| bdb5b0f7_5673_570b_155a_0bd0f9f8169a style 3f298b15_f3b3_11d6_21ea_d35e2d476f80 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/src/compiler/phases/3-transform/shared/assignments.js lines 15–93
export function visit_assignment_expression(node, context, build_assignment) {
if (
node.left.type === 'ArrayPattern' ||
node.left.type === 'ObjectPattern' ||
node.left.type === 'RestElement'
) {
const value = /** @type {Expression} */ (context.visit(node.right));
const should_cache = value.type !== 'Identifier';
const rhs = should_cache ? b.id('$$value') : value;
let changed = false;
const { inserts, paths } = extract_paths(node.left, rhs);
for (const { id } of inserts) {
id.name = context.state.scope.generate('$$array');
}
const assignments = paths.map((path) => {
const value = path.expression;
let assignment = build_assignment('=', path.node, value, context);
if (assignment !== null) changed = true;
return (
assignment ??
b.assignment(
'=',
/** @type {Pattern} */ (context.visit(path.node)),
/** @type {Expression} */ (context.visit(value))
)
);
});
if (!changed) {
// No change to output -> nothing to transform -> we can keep the original assignment
return null;
}
const is_standalone = /** @type {Node} */ (context.path.at(-1)).type.endsWith('Statement');
if (inserts.length > 0 || should_cache) {
/** @type {Statement[]} */
const statements = [
...inserts.map(({ id, value }) => b.var(id, value)),
...assignments.map(b.stmt)
];
if (!is_standalone) {
// this is part of an expression, we need the sequence to end with the value
statements.push(b.return(rhs));
}
const async =
is_expression_async(value) ||
assignments.some((assignment) => is_expression_async(assignment));
const iife = b.arrow([rhs], b.block(statements), async);
const call = b.call(iife, value);
return async ? b.await(call) : call;
}
const sequence = b.sequence(assignments);
if (!is_standalone) {
// this is part of an expression, we need the sequence to end with the value
sequence.expressions.push(rhs);
}
return sequence;
}
if (node.left.type !== 'Identifier' && node.left.type !== 'MemberExpression') {
throw new Error(`Unexpected assignment type ${node.left.type}`);
}
return build_assignment(node.operator, node.left, node.right, context);
}
Domain
Subdomains
Source
Frequently Asked Questions
What does visit_assignment_expression() do?
visit_assignment_expression() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/3-transform/shared/assignments.js.
Where is visit_assignment_expression() defined?
visit_assignment_expression() is defined in packages/svelte/src/compiler/phases/3-transform/shared/assignments.js at line 15.
What does visit_assignment_expression() call?
visit_assignment_expression() calls 2 function(s): extract_paths, is_expression_async.
What calls visit_assignment_expression()?
visit_assignment_expression() is called by 2 function(s): AssignmentExpression, AssignmentExpression.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free