All files / src/compiler/phases/2-analyze/visitors SlotElement.js

95.65% Statements 44/46
92.3% Branches 12/13
100% Functions 1/1
95.23% Lines 40/42

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 432x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 500x 19x 19x 500x 500x 500x 500x 500x 500x 500x 358x 348x 172x 1x 1x 171x 171x 172x 1x 1x 172x 358x     358x 498x 498x 498x 498x 498x  
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import { is_text_attribute } from '../../../utils/ast.js';
import * as e from '../../../errors.js';
import * as w from '../../../warnings.js';
import { mark_subtree_dynamic } from './shared/fragment.js';
 
/**
 * @param {AST.SlotElement} node
 * @param {Context} context
 */
export function SlotElement(node, context) {
	if (context.state.analysis.runes && !context.state.analysis.custom_element) {
		w.slot_element_deprecated(node);
	}
 
	mark_subtree_dynamic(context.path);
 
	/** @type {string} */
	let name = 'default';
 
	for (const attribute of node.attributes) {
		if (attribute.type === 'Attribute') {
			if (attribute.name === 'name') {
				if (!is_text_attribute(attribute)) {
					e.slot_element_invalid_name(attribute);
				}
 
				name = attribute.value[0].data;
				if (name === 'default') {
					e.slot_element_invalid_name_default(attribute);
				}
			}
		} else if (attribute.type !== 'SpreadAttribute' && attribute.type !== 'LetDirective') {
			e.slot_element_invalid_attribute(attribute);
		}
	}
 
	context.state.analysis.slot_names.set(name, node);
 
	context.next();
}