From 5db4ea878afb7a71e543e7bc32c20eec411e31b2 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 23 Jun 2025 06:52:56 -0400 Subject: [PATCH] fix --- packages/svelte/tests/parser-modern/test.ts | 42 +++++++++++---------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/packages/svelte/tests/parser-modern/test.ts b/packages/svelte/tests/parser-modern/test.ts index 74fabda633..152f8332a6 100644 --- a/packages/svelte/tests/parser-modern/test.ts +++ b/packages/svelte/tests/parser-modern/test.ts @@ -4,6 +4,7 @@ import { parse, print } from 'svelte/compiler'; import { try_load_json } from '../helpers.js'; import { suite, type BaseTest } from '../suite.js'; import { walk } from 'zimmerframe'; +import type { AST } from 'svelte/compiler'; interface ParserTest extends BaseTest {} @@ -55,7 +56,7 @@ const { test, run } = suite(async (config, cwd) => { } }); -function clean(ast: import('svelte/compiler').AST.SvelteNode) { +function clean(ast: AST.SvelteNode) { return walk(ast, null, { _(node, context) { // @ts-ignore @@ -72,24 +73,27 @@ function clean(ast: import('svelte/compiler').AST.SvelteNode) { context.next(); }, Fragment(node, context) { - return { - ...node, - nodes: node.nodes - .map((child, i) => { - if (child.type === 'Text') { - if (i === 0) { - child = { ...child, data: child.data.trimStart() }; - } - - if (i === node.nodes.length - 1) { - child = { ...child, data: child.data.trimEnd() }; - } - - if (!child.data) return null; - } - }) - .filter(Boolean) - }; + const nodes: AST.SvelteNode[] = []; + + for (let i = 0; i < node.nodes.length; i += 1) { + let child = node.nodes[i]; + + if (child.type === 'Text') { + if (i === 0) { + child = { ...child, data: child.data.trimStart() }; + } + + if (i === node.nodes.length - 1) { + child = { ...child, data: child.data.trimEnd() }; + } + + if (!child.data) continue; + } + + nodes.push(context.visit(child)); + } + + return { ...node, nodes } as AST.Fragment; } }); }