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 | 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 13x 13x 13x 13x 8x 8x 8x 8x 8x 8x 8x 8x 8x 11x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 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) {
// TODO throw validation error when attributes present / when children something else than text/expression tags
// TODO only create update when expression is dynamic
if (node.fragment.nodes.length === 1 && node.fragment.nodes[0].type === 'Text') {
context.state.init.push(
b.stmt(
b.assignment(
'=',
b.member(b.id('$.document'), b.id('title')),
b.literal(/** @type {Text} */ (node.fragment.nodes[0]).data)
)
)
);
} else {
context.state.update.push(
b.stmt(
b.assignment(
'=',
b.member(b.id('$.document'), b.id('title')),
build_template_literal(
/** @type {any} */ (node.fragment.nodes),
context.visit,
context.state
)[1]
)
)
);
}
}
|