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

93.54% Statements 29/31
90.9% Branches 10/11
100% Functions 1/1
93.1% Lines 27/29

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 302x 2x 2x 2x 2x 2x 2x 2x 2x 2x 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';
 
/**
 * @param {SlotElement} node
 * @param {Context} context
 */
export function SlotElement(node, context) {
	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();
}