diff --git a/packages/svelte/src/compiler/phases/3-transform/utils.js b/packages/svelte/src/compiler/phases/3-transform/utils.js index e60c81451b..e70e862caa 100644 --- a/packages/svelte/src/compiler/phases/3-transform/utils.js +++ b/packages/svelte/src/compiler/phases/3-transform/utils.js @@ -230,12 +230,6 @@ export function infer_namespace(namespace, parent, nodes, path) { return namespace; } -/** - * @param {import('#compiler').SvelteNode} node} - * @param {{next: () => void}} context - */ -const SvelteBlock = (node, { next }) => next(); - /** * Heuristic: Keep current namespace, unless we find a regular element, * in which case we always want html, or we only find svg nodes, @@ -244,11 +238,17 @@ const SvelteBlock = (node, { next }) => next(); * @param {import('#compiler').Namespace | 'keep' | 'maybe_html'} namespace */ function check_nodes_for_namespace(nodes, namespace) { + /** + * @param {import('#compiler').SvelteNode} node} + * @param {{next: () => void}} context + */ + const SvelteBlock = (node, { next }) => next(); + /** * @param {import('#compiler').SvelteElement | import('#compiler').RegularElement} node} * @param {{stop: () => void}} context */ - const SvelteElement = (node, { stop }) => { + const RegularElement = (node, { stop }) => { if (!node.metadata.svg) { namespace = 'html'; stop(); @@ -262,22 +262,24 @@ function check_nodes_for_namespace(nodes, namespace) { node, {}, { - RegularElement: SvelteElement, - SvelteElement: SvelteElement, + EachBlock: SvelteBlock, + IfBlock: SvelteBlock, + AwaitBlock: SvelteBlock, + KeyBlock: SvelteBlock, + SvelteElement: RegularElement, + RegularElement, Text(node) { - if (node.data.trim() !== '') namespace = 'maybe_html'; + if (node.data.trim() !== '') { + namespace = 'maybe_html'; + } }, HtmlTag() { namespace = 'maybe_html'; - }, - EachBlock: SvelteBlock, - IfBlock: SvelteBlock, - AwaitBlock: SvelteBlock, - KeyBlock: SvelteBlock + } } ); - if (namespace === 'html') break; + if (namespace === 'html') return namespace; } return namespace;