* @param {AST.BaseElement} node * @param {Context} context * @param {AST.JSComment[]} comments
(node, context, comments)
| 136 | * @param {AST.JSComment[]} comments |
| 137 | */ |
| 138 | function base_element(node, context, comments) { |
| 139 | const child_context = context.new(); |
| 140 | |
| 141 | child_context.write('<' + node.name); |
| 142 | |
| 143 | // Handle special Svelte components/elements that need 'this' attribute |
| 144 | if (node.type === 'SvelteComponent') { |
| 145 | child_context.write(' this={'); |
| 146 | child_context.visit(/** @type {AST.SvelteComponent} */ (node).expression); |
| 147 | child_context.write('}'); |
| 148 | } else if (node.type === 'SvelteElement') { |
| 149 | child_context.write(' this={'); |
| 150 | child_context.visit(/** @type {AST.SvelteElement} */ (node).tag); |
| 151 | child_context.write('}'); |
| 152 | } |
| 153 | |
| 154 | const multiline_attributes = attributes(node, node.attributes, child_context, comments); |
| 155 | const is_doctype_node = node.name.toLowerCase() === '!doctype'; |
| 156 | const is_self_closing = |
| 157 | is_void(node.name) || (node.type === 'Component' && node.fragment.nodes.length === 0); |
| 158 | |
| 159 | if (is_doctype_node) child_context.write(`>`); |
| 160 | else if (is_self_closing) { |
| 161 | child_context.write(`${multiline_attributes ? '' : ' '}/>`); |
| 162 | } else { |
| 163 | child_context.write('>'); |
| 164 | block(child_context, node.fragment, true); |
| 165 | child_context.write(`</${node.name}>`); |
| 166 | } |
| 167 | |
| 168 | context.append(child_context); |
| 169 | } |
| 170 | |
| 171 | /** @type {Visitors<AST.SvelteNode>} */ |
| 172 | const css_visitors = { |
no test coverage detected