LetDirective.js — svelte Source File
Architecture documentation for LetDirective.js, a javascript file in the svelte codebase. 3 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 6db00b99_6c00_8c37_49e7_072e5c55ca92["LetDirective.js"] c518b20b_2355_7b11_4ac2_2d9bb5dcfb43["utils.js"] 6db00b99_6c00_8c37_49e7_072e5c55ca92 --> c518b20b_2355_7b11_4ac2_2d9bb5dcfb43 c6147fac_8ab6_4ed2_9c90_08e83553fb43["create_derived"] 6db00b99_6c00_8c37_49e7_072e5c55ca92 --> c6147fac_8ab6_4ed2_9c90_08e83553fb43 95c28355_f14c_c3cd_5a03_d5a53ca255bc["builders"] 6db00b99_6c00_8c37_49e7_072e5c55ca92 --> 95c28355_f14c_c3cd_5a03_d5a53ca255bc 7665e008_f37d_b860_a594_f2539a66af4e["transform-client.js"] 7665e008_f37d_b860_a594_f2539a66af4e --> 6db00b99_6c00_8c37_49e7_072e5c55ca92 style 6db00b99_6c00_8c37_49e7_072e5c55ca92 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/** @import { Expression } from 'estree' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import * as b from '#compiler/builders';
import { create_derived } from '../utils.js';
/**
* @param {AST.LetDirective} node
* @param {ComponentContext} context
*/
export function LetDirective(node, context) {
// let:x --> const x = $.derived(() => $$slotProps.x);
// let:x={{y, z}} --> const derived_x = $.derived(() => { const { y, z } = $$slotProps.x; return { y, z }));
if (node.expression && node.expression.type !== 'Identifier') {
const name = context.state.scope.generate(node.name);
const bindings = context.state.scope.get_bindings(node);
for (const binding of bindings) {
context.state.transform[binding.node.name] = {
read: (node) => b.member(b.call('$.get', b.id(name)), node)
};
}
context.state.let_directives.push(
b.const(
name,
b.call(
'$.derived',
b.thunk(
b.block([
b.let(
/** @type {Expression} */ (node.expression).type === 'ObjectExpression'
? // @ts-expect-error types don't match, but it can't contain spread elements and the structure is otherwise fine
b.object_pattern(node.expression.properties)
: // @ts-expect-error types don't match, but it can't contain spread elements and the structure is otherwise fine
b.array_pattern(node.expression.elements),
b.member(b.id('$$slotProps'), node.name)
),
b.return(b.object(bindings.map((binding) => b.init(binding.node.name, binding.node))))
])
)
)
)
);
} else {
const name = node.expression === null ? node.name : node.expression.name;
context.state.transform[name] = {
read: (node) => b.call('$.get', node)
};
context.state.let_directives.push(
b.const(name, create_derived(context.state, b.member(b.id('$$slotProps'), node.name)))
);
}
}
Domain
Subdomains
Functions
Dependencies
- builders
- create_derived
- utils.js
Source
Frequently Asked Questions
What does LetDirective.js do?
LetDirective.js is a source file in the svelte codebase, written in javascript. It belongs to the Compiler domain, Transformer subdomain.
What functions are defined in LetDirective.js?
LetDirective.js defines 1 function(s): LetDirective.
What does LetDirective.js depend on?
LetDirective.js imports 3 module(s): builders, create_derived, utils.js.
What files import LetDirective.js?
LetDirective.js is imported by 1 file(s): transform-client.js.
Where is LetDirective.js in the architecture?
LetDirective.js is located at packages/svelte/src/compiler/phases/3-transform/client/visitors/LetDirective.js (domain: Compiler, subdomain: Transformer, directory: packages/svelte/src/compiler/phases/3-transform/client/visitors).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free