All files / src/compiler/phases/3-transform/server/visitors Fragment.js

100% Statements 49/49
100% Branches 4/4
100% Functions 1/1
100% Lines 46/46

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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 472x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 4141x 4141x 4141x 4141x 4141x 4141x 4141x 4141x 4141x 4141x 4141x 4141x 4141x 4141x 4141x 4141x 4141x 4141x 4141x 4141x 4141x 4141x 4141x 236x 236x 4141x 4141x 213x 213x 213x 4141x 4141x 4141x 4141x 4141x  
/** @import { Fragment } from '#compiler' */
/** @import { ComponentContext, ComponentServerTransformState } from '../types.js' */
import { clean_nodes, infer_namespace } from '../../utils.js';
import * as b from '../../../../utils/builders.js';
import { empty_comment, process_children, build_template } from './shared/utils.js';
 
/**
 * @param {Fragment} node
 * @param {ComponentContext} context
 */
export function Fragment(node, context) {
	const parent = context.path.at(-1) ?? node;
	const namespace = infer_namespace(context.state.namespace, parent, node.nodes);
 
	const { hoisted, trimmed, is_standalone, is_text_first } = clean_nodes(
		parent,
		node.nodes,
		context.path,
		namespace,
		context.state,
		context.state.preserve_whitespace,
		context.state.options.preserveComments
	);
 
	/** @type {ComponentServerTransformState} */
	const state = {
		...context.state,
		init: [],
		template: [],
		namespace,
		skip_hydration_boundaries: is_standalone
	};
 
	for (const node of hoisted) {
		context.visit(node, state);
	}
 
	if (is_text_first) {
		// insert `<!---->` to prevent this from being glued to the previous fragment
		state.template.push(empty_comment);
	}
 
	process_children(trimmed, { ...context, state });
 
	return b.block([...state.init, ...build_template(state.template)]);
}