@@ -4,6 +4,7 @@ import { parse, print } from 'svelte/compiler';
4
4
import { try_load_json } from '../helpers.js' ;
5
5
import { suite , type BaseTest } from '../suite.js' ;
6
6
import { walk } from 'zimmerframe' ;
7
+ import type { AST } from 'svelte/compiler' ;
7
8
8
9
interface ParserTest extends BaseTest { }
9
10
@@ -55,7 +56,7 @@ const { test, run } = suite<ParserTest>(async (config, cwd) => {
55
56
}
56
57
} ) ;
57
58
58
- function clean ( ast : import ( 'svelte/compiler' ) . AST . SvelteNode ) {
59
+ function clean ( ast : AST . SvelteNode ) {
59
60
return walk ( ast , null , {
60
61
_ ( node , context ) {
61
62
// @ts -ignore
@@ -72,24 +73,27 @@ function clean(ast: import('svelte/compiler').AST.SvelteNode) {
72
73
context . next ( ) ;
73
74
} ,
74
75
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 ;
93
97
}
94
98
} ) ;
95
99
}
0 commit comments