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

100% Statements 26/26
100% Branches 4/4
100% Functions 1/1
100% Lines 24/24

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 252x 2x 2x 2x 2x 2x 2x 2x 2x 2x 13x 13x 13x 13x 13x 13x 13x 13x 13x 4x 11x 9x 9x 13x  
/** @import { TitleElement, Text } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import * as b from '../../../../utils/builders.js';
import { build_template_literal } from './shared/utils.js';
 
/**
 * @param {TitleElement} node
 * @param {ComponentContext} context
 */
export function TitleElement(node, context) {
	const { has_state, value } = build_template_literal(
		/** @type {any} */ (node.fragment.nodes),
		context.visit,
		context.state
	);
 
	const statement = b.stmt(b.assignment('=', b.member(b.id('$.document'), b.id('title')), value));
 
	if (has_state) {
		context.state.update.push(statement);
	} else {
		context.state.init.push(statement);
	}
}