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 8989x 8989x 2x 2x 2x 2x 2x 2x 12996x 12996x 2x 2x 2x 2x 2x 2x 2x 2x 2x 6672x 6672x 6672x 6672x 6672x 6672x 6672x 6672x 6672x 6672x 6672x 6672x 6672x 2x 2x 2x 2x 2x 20727x 20727x 20727x 20727x 20727x 20727x  
/** @import { Ast, ExpressionMetadata } 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 {Ast.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
	};
}