All files / src/compiler/phases nodes.js

100% Statements 52/52
100% Branches 4/4
100% Functions 3/3
100% Lines 52/52

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 40 41 42 43 44 45 46 47 48 49 50 51 52 532x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 4178x 4178x 2x 2x 2x 2x 2x 2x 3907x 3907x 2x 2x 2x 2x 2x 2x 2x 2x 2x 6474x 6474x 6474x 6474x 6474x 6474x 6474x 6474x 6474x 6474x 6474x 6474x 6474x  
/** @import * as Compiler from '#compiler' */
/**
 * All nodes that can appear elsewhere than the top level, have attributes and can contain children
 */
const element_nodes = [
	'SvelteElement',
	'RegularElement',
	'SvelteFragment',
	'Component',
	'SvelteComponent',
	'SvelteSelf',
	'SlotElement'
];
 
/**
 * Returns true for all nodes that can appear elsewhere than the top level, have attributes and can contain children
 * @param {Compiler.SvelteNode} node
 * @returns {node is Compiler.Component | Compiler.RegularElement | Compiler.SlotElement | Compiler.SvelteComponent | Compiler.SvelteElement | Compiler.SvelteFragment | Compiler.SvelteSelf}
 */
export function is_element_node(node) {
	return element_nodes.includes(node.type);
}
 
/**
 * @param {Compiler.RegularElement | Compiler.SvelteElement} node
 * @returns {boolean}
 */
export function is_custom_element_node(node) {
	return node.type === 'RegularElement' && node.name.includes('-');
}
 
/**
 * @param {string} name
 * @param {number} start
 * @param {number} end
 * @param {true | Array<Compiler.Text | Compiler.ExpressionTag>} value
 * @returns {Compiler.Attribute}
 */
export function create_attribute(name, start, end, value) {
	return {
		type: 'Attribute',
		start,
		end,
		name,
		value,
		parent: null,
		metadata: {
			dynamic: false,
			delegated: null
		}
	};
}