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

94.59% Statements 35/37
92.3% Branches 12/13
100% Functions 1/1
94.11% Lines 32/34

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 352x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 493x 17x 17x 493x 493x 353x 343x 168x 1x 1x 167x 167x 168x 1x 1x 168x 353x     353x 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);
	}
 
	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);
				}
 
				const slot_name = attribute.value[0].data;
				if (slot_name === 'default') {
					e.slot_element_invalid_name_default(attribute);
				}
			}
		} else if (attribute.type !== 'SpreadAttribute' && attribute.type !== 'LetDirective') {
			e.slot_element_invalid_attribute(attribute);
		}
	}
 
	context.next();
}