All files / src/compiler/phases nodes.js

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

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 522x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 4087x 4087x 2x 2x 2x 2x 2x 2x 3767x 3767x 2x 2x 2x 2x 2x 2x 2x 2x 2x 6256x 6256x 6256x 6256x 6256x 6256x 6256x 6256x 6256x 6256x 6256x 6256x 6256x  
/**
 * 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 {import('#compiler').SvelteNode} node
 * @returns {node is import('#compiler').Component | import('#compiler').RegularElement | import('#compiler').SlotElement | import('#compiler').SvelteComponent | import('#compiler').SvelteElement | import('#compiler').SvelteFragment | import('#compiler').SvelteSelf}
 */
export function is_element_node(node) {
	return element_nodes.includes(node.type);
}
 
/**
 * @param {import('#compiler').RegularElement | import('#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<import('#compiler').Text | import('#compiler').ExpressionTag>} value
 * @returns {import('#compiler').Attribute}
 */
export function create_attribute(name, start, end, value) {
	return {
		type: 'Attribute',
		start,
		end,
		name,
		value,
		parent: null,
		metadata: {
			dynamic: false,
			delegated: null
		}
	};
}