1
1
import type { AST as SV } from "svelte/compiler" ;
2
2
3
- import type { printAttributeLike , printFragment } from "../../template/mod.js" ;
3
+ import { printAttributeLike } from "../../attribute.ts" ;
4
+ import { printFragment } from "../../fragment.ts" ;
4
5
import * as char from "../char.js" ;
5
6
import { HTMLClosingTag , HTMLOpeningTag , HTMLSelfClosingTag } from "../html.js" ;
6
7
import type { PrintOptions } from "../option.js" ;
@@ -91,10 +92,8 @@ function is_el_self_closing(n: SV.ElementLike): boolean {
91
92
export function print_maybe_self_closing_el < N extends SV . ElementLike > ( params : {
92
93
n : N ;
93
94
opts : Partial < PrintOptions > ;
94
- attr_printer : typeof printAttributeLike ;
95
- frag_printer : typeof printFragment ;
96
95
} ) : Result < N > {
97
- const { n, opts, attr_printer , frag_printer } = params ;
96
+ const { n, opts } = params ;
98
97
const st = State . get ( n , opts ) ;
99
98
const self_closing = is_el_self_closing ( n ) ;
100
99
if ( self_closing ) {
@@ -104,22 +103,22 @@ export function print_maybe_self_closing_el<N extends SV.ElementLike>(params: {
104
103
n . name ,
105
104
) ;
106
105
if ( n . attributes . length > 0 ) {
107
- for ( const a of n . attributes ) tag . insert ( char . SPACE , attr_printer ( a ) ) ;
106
+ for ( const a of n . attributes ) tag . insert ( char . SPACE , printAttributeLike ( a ) ) ;
108
107
}
109
108
tag . insert ( char . SPACE ) ;
110
109
st . add ( tag ) ;
111
110
return st . result ;
112
111
}
113
112
const opening = new HTMLOpeningTag ( "inline" , n . name ) ;
114
113
if ( n . attributes . length > 0 ) {
115
- for ( const a of n . attributes ) opening . insert ( char . SPACE , attr_printer ( a ) ) ;
114
+ for ( const a of n . attributes ) opening . insert ( char . SPACE , printAttributeLike ( a ) ) ;
116
115
}
117
116
st . add ( opening ) ;
118
117
const should_break =
119
118
// @ts -expect-error `Set.prototype.has()` doesn't accept loose string
120
119
! NATIVE_INLINE_ELS . has ( n . name ) && ! has_frag_text_or_exp_tag_only ( n . fragment . nodes ) ;
121
120
if ( should_break ) st . break ( + 1 ) ;
122
- if ( n . fragment ) st . add ( frag_printer ( n . fragment , opts ) ) ;
121
+ if ( n . fragment ) st . add ( printFragment ( n . fragment , opts ) ) ;
123
122
if ( should_break ) st . break ( - 1 ) ;
124
123
st . add ( new HTMLClosingTag ( "inline" , n . name ) ) ;
125
124
return st . result ;
@@ -132,13 +131,12 @@ export function print_maybe_self_closing_el<N extends SV.ElementLike>(params: {
132
131
export function print_self_closing_el < N extends SV . ElementLike > ( params : {
133
132
n : N ;
134
133
opts : Partial < PrintOptions > ;
135
- attr_printer : typeof printAttributeLike ;
136
134
} ) : Result < N > {
137
- const { n, opts, attr_printer } = params ;
135
+ const { n, opts } = params ;
138
136
const st = State . get ( params . n , opts ) ;
139
137
const tag = new HTMLSelfClosingTag ( "inline" , n . name ) ;
140
138
if ( n . attributes . length > 0 ) {
141
- for ( const a of n . attributes ) tag . insert ( char . SPACE , attr_printer ( a , opts ) ) ;
139
+ for ( const a of n . attributes ) tag . insert ( char . SPACE , printAttributeLike ( a , opts ) ) ;
142
140
}
143
141
tag . insert ( char . SPACE ) ;
144
142
st . add ( tag ) ;
@@ -152,21 +150,19 @@ export function print_self_closing_el<N extends SV.ElementLike>(params: {
152
150
export function print_non_self_closing_el < N extends SV . ElementLike > ( params : {
153
151
n : N ;
154
152
opts : Partial < PrintOptions > ;
155
- attr_printer : typeof printAttributeLike ;
156
- frag_printer : typeof printFragment ;
157
153
} ) : Result < N > {
158
- const { n, opts, attr_printer , frag_printer } = params ;
154
+ const { n, opts } = params ;
159
155
const st = State . get ( n , opts ) ;
160
156
const opening = new HTMLOpeningTag ( "inline" , n . name ) ;
161
157
if ( n . attributes . length > 0 ) {
162
- for ( const a of n . attributes ) opening . insert ( char . SPACE , attr_printer ( a ) ) ;
158
+ for ( const a of n . attributes ) opening . insert ( char . SPACE , printAttributeLike ( a ) ) ;
163
159
}
164
160
st . add ( opening ) ;
165
161
const should_break =
166
162
// @ts -expect-error `Set.prototype.has()` doesn't accept loose string
167
163
! NATIVE_INLINE_ELS . has ( n . name ) && ! has_frag_text_or_exp_tag_only ( n . fragment . nodes ) ;
168
164
if ( should_break ) st . break ( + 1 ) ;
169
- st . add ( frag_printer ( n . fragment , opts ) ) ;
165
+ st . add ( printFragment ( n . fragment , opts ) ) ;
170
166
if ( should_break ) st . break ( - 1 ) ;
171
167
st . add ( new HTMLClosingTag ( "inline" , n . name ) ) ;
172
168
return st . result ;
0 commit comments