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

100% Statements 40/40
80% Branches 8/10
100% Functions 1/1
100% Lines 36/36

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 372x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 36x 36x 79x 79x 79x 44x 36x 36x 36x 1x 1x 35x 35x 2x 2x 2x 2x 2x 2x 2x 2x 35x 35x 35x  
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import { visit_component } from './shared/component.js';
import * as e from '../../../errors.js';
import * as w from '../../../warnings.js';
import { filename } from '../../../state.js';
 
/**
 * @param {AST.SvelteSelf} node
 * @param {Context} context
 */
export function SvelteSelf(node, context) {
	const valid = context.path.some(
		(node) =>
			node.type === 'IfBlock' ||
			node.type === 'EachBlock' ||
			node.type === 'Component' ||
			node.type === 'SnippetBlock'
	);
 
	if (!valid) {
		e.svelte_self_invalid_placement(node);
	}
 
	if (context.state.analysis.runes) {
		const name = filename === '(unknown)' ? 'Self' : context.state.analysis.name;
		const basename =
			filename === '(unknown)'
				? 'Self.svelte'
				: /** @type {string} */ (filename.split(/[/\\]/).pop());
 
		w.svelte_self_deprecated(node, name, basename);
	}
 
	visit_component(node, context);
}