Skip to content

Commit 5db4ea8

Browse files
committed
fix
1 parent 0a61c80 commit 5db4ea8

File tree

1 file changed

+23
-19
lines changed
  • packages/svelte/tests/parser-modern

1 file changed

+23
-19
lines changed

packages/svelte/tests/parser-modern/test.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { parse, print } from 'svelte/compiler';
44
import { try_load_json } from '../helpers.js';
55
import { suite, type BaseTest } from '../suite.js';
66
import { walk } from 'zimmerframe';
7+
import type { AST } from 'svelte/compiler';
78

89
interface ParserTest extends BaseTest {}
910

@@ -55,7 +56,7 @@ const { test, run } = suite<ParserTest>(async (config, cwd) => {
5556
}
5657
});
5758

58-
function clean(ast: import('svelte/compiler').AST.SvelteNode) {
59+
function clean(ast: AST.SvelteNode) {
5960
return walk(ast, null, {
6061
_(node, context) {
6162
// @ts-ignore
@@ -72,24 +73,27 @@ function clean(ast: import('svelte/compiler').AST.SvelteNode) {
7273
context.next();
7374
},
7475
Fragment(node, context) {
75-
return {
76-
...node,
77-
nodes: node.nodes
78-
.map((child, i) => {
79-
if (child.type === 'Text') {
80-
if (i === 0) {
81-
child = { ...child, data: child.data.trimStart() };
82-
}
83-
84-
if (i === node.nodes.length - 1) {
85-
child = { ...child, data: child.data.trimEnd() };
86-
}
87-
88-
if (!child.data) return null;
89-
}
90-
})
91-
.filter(Boolean)
92-
};
76+
const nodes: AST.SvelteNode[] = [];
77+
78+
for (let i = 0; i < node.nodes.length; i += 1) {
79+
let child = node.nodes[i];
80+
81+
if (child.type === 'Text') {
82+
if (i === 0) {
83+
child = { ...child, data: child.data.trimStart() };
84+
}
85+
86+
if (i === node.nodes.length - 1) {
87+
child = { ...child, data: child.data.trimEnd() };
88+
}
89+
90+
if (!child.data) continue;
91+
}
92+
93+
nodes.push(context.visit(child));
94+
}
95+
96+
return { ...node, nodes } as AST.Fragment;
9397
}
9498
});
9599
}

0 commit comments

Comments
 (0)