Repository: sveltejs/svelte
File: packages/svelte/src/compiler/phases/3-transform/utils.js (JavaScript)

Code before:
				}
				if (next?.type !== 'ExpressionTag') {
					node.data = node.data.replace(regex_ends_with_whitespaces, ' ');
					node.raw = node.raw.replace(regex_ends_with_whitespaces, ' ');
				}
				if (node.data && (node.data !== ' ' || !can_remove_entirely)) {
					trimmed.push(node);
				}
			} else {
				trimmed.push(node);
			}
		}
	}

	var first = trimmed[0];

	/**
	 * In a case like `{#if x}<Foo />{/if}`, we don't need to wrap the child in
	 * comments — we can just use the parent block's anchor for the component.
	 * TODO extend this optimisation to other cases
	 */
	const is_standalone =
		trimmed.length === 1 &&
		((first.type === 'RenderTag' && !first.metadata.dynamic) ||
			(first.type === 'Component' &&
				!first.attributes.some(
					(attribute) => attribute.type === 'Attribute' && attribute.name.startsWith('--')
				)));

	return { hoisted, trimmed, is_standalone };
}

/**
 * Infers the namespace for the children of a node that should be used when creating the `$.template(...)`.
 * @param {Compiler.Namespace} namespace
 * @param {Compiler.SvelteNode} parent
 * @param {Compiler.SvelteNode[]} nodes
 */
export function infer_namespace(namespace, parent, nodes) {
	if (namespace !== 'foreign') {
		if (parent.type === 'RegularElement' && parent.name === 'foreignObject') {
			return 'html';
		}

		if (parent.type === 'RegularElement' || parent.type === 'SvelteElement') {
			if (parent.metadata.svg) {
				return 'svg';
			}
			return parent.metadata.mathml ? 'mathml' : 'html';
		}


Review comment (suggestion):
My proposal for a comment:
```suggestion
				// HMR components can be destroyed/recreated independently. In that sense they're a bit
				// like a dynamic Svelte component and therefore the anchor is necessary.
				!state.options.hmr &&
```

Code after:
				}
				if (next?.type !== 'ExpressionTag') {
					node.data = node.data.replace(regex_ends_with_whitespaces, ' ');
					node.raw = node.raw.replace(regex_ends_with_whitespaces, ' ');
				}
				if (node.data && (node.data !== ' ' || !can_remove_entirely)) {
					trimmed.push(node);
				}
			} else {
				trimmed.push(node);
			}
		}
	}

	var first = trimmed[0];

	/**
	 * In a case like `{#if x}<Foo />{/if}`, we don't need to wrap the child in
	 * comments — we can just use the parent block's anchor for the component.
	 * TODO extend this optimisation to other cases
	 */
	const is_standalone =
		trimmed.length === 1 &&
		((first.type === 'RenderTag' && !first.metadata.dynamic) ||
			(first.type === 'Component' &&
				!state.options.hmr &&
				!first.attributes.some(
					(attribute) => attribute.type === 'Attribute' && attribute.name.startsWith('--')
				)));

	return { hoisted, trimmed, is_standalone };
}

/**
 * Infers the namespace for the children of a node that should be used when creating the `$.template(...)`.
 * @param {Compiler.Namespace} namespace
 * @param {Compiler.SvelteNode} parent
 * @param {Compiler.SvelteNode[]} nodes
 */
export function infer_namespace(namespace, parent, nodes) {
	if (namespace !== 'foreign') {
		if (parent.type === 'RegularElement' && parent.name === 'foreignObject') {
			return 'html';
		}

		if (parent.type === 'RegularElement' || parent.type === 'SvelteElement') {
			if (parent.metadata.svg) {
				return 'svg';
			}
			return parent.metadata.mathml ? 'mathml' : 'html';
		}