UNPKG

svelte

Version:

Cybernetically enhanced web apps

67 lines (62 loc) 1.52 kB
/** @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('-') || node.attributes.some((attr) => attr.type === 'Attribute' && attr.name === 'is')) ); } /** * @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, metadata: { delegated: null, needs_clsx: false } }; } /** * @returns {ExpressionMetadata} */ export function create_expression_metadata() { return { dependencies: new Set(), has_state: false, has_call: false }; }