All files / src/compiler/phases nodes.js

100% Statements 63/63
100% Branches 5/5
100% Functions 4/4
100% Lines 63/63

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 53 54 55 56 57 58 59 60 61 62 63 642x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 8964x 8964x 2x 2x 2x 2x 2x 2x 3998x 3998x 2x 2x 2x 2x 2x 2x 2x 2x 2x 6644x 6644x 6644x 6644x 6644x 6644x 6644x 6644x 6644x 6644x 6644x 6644x 6644x 2x 2x 2x 2x 2x 19687x 19687x 19687x 19687x 19687x 19687x  
/** @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 {Compiler.Attribute['value']} value
 * @returns {Compiler.Attribute}
 */
export function create_attribute(name, start, end, value) {
	return {
		type: 'Attribute',
		start,
		end,
		name,
		value,
		parent: null,
		metadata: {
			expression: create_expression_metadata(),
			delegated: null
		}
	};
}
 
/**
 * @returns {Compiler.ExpressionMetadata}
 */
export function create_expression_metadata() {
	return {
		dependencies: new Set(),
		has_state: false,
		has_call: false
	};
}