All files / src/compiler/phases/3-transform/client/visitors Component.js

100% Statements 34/34
100% Branches 3/3
100% Functions 1/1
100% Lines 32/32

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 332x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 614x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 610x 610x 610x 610x  
/** @import { Expression } from 'estree' */
/** @import { Component } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import * as b from '../../../../utils/builders.js';
import { build_component } from './shared/component.js';
 
/**
 * @param {Component} node
 * @param {ComponentContext} context
 */
export function Component(node, context) {
	if (node.metadata.dynamic) {
		// Handle dynamic references to what seems like static inline components
		const component = build_component(node, '$$component', context, b.id('$$anchor'));
		context.state.init.push(
			b.stmt(
				b.call(
					'$.component',
					context.state.node,
					// TODO use untrack here to not update when binding changes?
					// Would align with Svelte 4 behavior, but it's arguably nicer/expected to update this
					b.thunk(/** @type {Expression} */ (context.visit(b.member_id(node.name)))),
					b.arrow([b.id('$$anchor'), b.id('$$component')], b.block([component]))
				)
			)
		);
		return;
	}
 
	const component = build_component(node, node.name, context);
	context.state.init.push(component);
}