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

95.23% Statements 40/42
92.3% Branches 12/13
100% Functions 1/1
94.87% Lines 37/39

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 402x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 493x 17x 17x 493x 493x 493x 493x 493x 353x 343x 168x 1x 1x 167x 167x 168x 1x 1x 168x 353x     353x 491x 491x 491x 491x 491x  
/** @import { SlotElement } 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';
 
/**
 * @param {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);
	}
 
	/** @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();
}