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 9099x 9099x 2x 2x 2x 2x 2x 2x 13161x 13161x 2x 2x 2x 2x 2x 2x 2x 2x 2x 6777x 6777x 6777x 6777x 6777x 6777x 6777x 6777x 6777x 6777x 6777x 6777x 6777x 2x 2x 2x 2x 2x 20972x 20972x 20972x 20972x 20972x 20972x  
/** @import { AST, ExpressionMetadata, SvelteNode } 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 {SvelteNode} node
 * @returns {node is AST.Component | AST.RegularElement | AST.SlotElement | AST.SvelteComponent | AST.SvelteElement | AST.SvelteFragment | AST.SvelteSelf}
 */
export function is_element_node(node) {
	return element_nodes.includes(node.type);
}
 
/**
 * @param {AST.RegularElement | AST.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 {AST.Attribute['value']} value
 * @returns {AST.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 {ExpressionMetadata}
 */
export function create_expression_metadata() {
	return {
		dependencies: new Set(),
		has_state: false,
		has_call: false
	};
}