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

100% Statements 30/30
95.45% Branches 21/22
100% Functions 1/1
100% Lines 29/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 263x 263x 263x 263x 263x 263x 263x 263x 263x 263x 263x 263x 16x 263x 263x 2x 2x 261x 261x 261x  
/** @import { ConstTag } from '#compiler' */
/** @import { Context } from '../types' */
import * as e from '../../../errors.js';
 
/**
 * @param {ConstTag} node
 * @param {Context} context
 */
export function ConstTag(node, context) {
	const parent = context.path.at(-1);
	const grand_parent = context.path.at(-2);
 
	if (
		parent?.type !== 'Fragment' ||
		(grand_parent?.type !== 'IfBlock' &&
			grand_parent?.type !== 'SvelteFragment' &&
			grand_parent?.type !== 'Component' &&
			grand_parent?.type !== 'SvelteComponent' &&
			grand_parent?.type !== 'EachBlock' &&
			grand_parent?.type !== 'AwaitBlock' &&
			grand_parent?.type !== 'SnippetBlock' &&
			((grand_parent?.type !== 'RegularElement' && grand_parent?.type !== 'SvelteElement') ||
				!grand_parent.attributes.some((a) => a.type === 'Attribute' && a.name === 'slot')))
	) {
		e.const_tag_invalid_placement(node);
	}
 
	context.next();
}