svelte 5.56.7 → 5.56.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiler/index.js +1 -1
- package/package.json +1 -1
- package/src/compiler/index.js +2 -1
- package/src/compiler/phases/1-parse/index.js +4 -0
- package/src/compiler/phases/1-parse/read/style.js +59 -23
- package/src/compiler/phases/2-analyze/css/css-analyze.js +3 -0
- package/src/compiler/phases/2-analyze/css/css-warn.js +3 -0
- package/src/compiler/phases/3-transform/css/index.js +3 -0
- package/src/compiler/print/index.js +305 -176
- package/src/internal/client/dom/blocks/boundary.js +55 -34
- package/src/internal/client/dom/blocks/each.js +6 -2
- package/src/internal/client/dom/elements/bindings/select.js +4 -2
- package/src/version.js +1 -1
- package/types/index.d.ts +10 -0
- package/types/index.d.ts.map +1 -1
|
@@ -19,6 +19,10 @@ const LINE_BREAK_THRESHOLD = 50;
|
|
|
19
19
|
*/
|
|
20
20
|
export function print(ast, options = undefined) {
|
|
21
21
|
const comments = (ast.type === 'Root' && ast.comments) || [];
|
|
22
|
+
const state = { preserve_whitespace: 0 };
|
|
23
|
+
const css_comments =
|
|
24
|
+
(ast.type === 'Root' ? ast.css?.comments : ast.type === 'StyleSheet' ? ast.comments : null) ||
|
|
25
|
+
[];
|
|
22
26
|
|
|
23
27
|
return esrap.print(
|
|
24
28
|
ast,
|
|
@@ -28,8 +32,8 @@ export function print(ast, options = undefined) {
|
|
|
28
32
|
getLeadingComments: options?.getLeadingComments,
|
|
29
33
|
getTrailingComments: options?.getTrailingComments
|
|
30
34
|
}),
|
|
31
|
-
...svelte_visitors(comments),
|
|
32
|
-
...css_visitors
|
|
35
|
+
...svelte_visitors(comments, state),
|
|
36
|
+
...css_visitors(css_comments, comments)
|
|
33
37
|
}),
|
|
34
38
|
{
|
|
35
39
|
indent: options?.indent
|
|
@@ -40,9 +44,15 @@ export function print(ast, options = undefined) {
|
|
|
40
44
|
/**
|
|
41
45
|
* @param {Context} context
|
|
42
46
|
* @param {AST.SvelteNode} node
|
|
47
|
+
* @param {boolean} preserve_whitespace
|
|
43
48
|
* @param {boolean} allow_inline
|
|
44
49
|
*/
|
|
45
|
-
function block(context, node, allow_inline = false) {
|
|
50
|
+
function block(context, node, preserve_whitespace = false, allow_inline = false) {
|
|
51
|
+
if (preserve_whitespace) {
|
|
52
|
+
context.visit(node);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
46
56
|
const child_context = context.new();
|
|
47
57
|
child_context.visit(node);
|
|
48
58
|
|
|
@@ -82,6 +92,7 @@ function attributes(node, attributes, context, comments) {
|
|
|
82
92
|
}
|
|
83
93
|
|
|
84
94
|
const separator = context.new();
|
|
95
|
+
let previous_attribute_end = node.start;
|
|
85
96
|
|
|
86
97
|
const children = attributes.map((attribute) => {
|
|
87
98
|
const child_context = context.new();
|
|
@@ -90,12 +101,16 @@ function attributes(node, attributes, context, comments) {
|
|
|
90
101
|
const comment = comments[comment_index];
|
|
91
102
|
|
|
92
103
|
if (comment.start < attribute.start) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
104
|
+
// Inside a previous attribute's value can be comments which don't
|
|
105
|
+
// advance comment_index, therefore this additional check
|
|
106
|
+
if (comment.start >= previous_attribute_end) {
|
|
107
|
+
if (comment.type === 'Line') {
|
|
108
|
+
child_context.write('//' + comment.value);
|
|
109
|
+
child_context.newline();
|
|
110
|
+
} else {
|
|
111
|
+
child_context.write('/*' + comment.value + '*/'); // TODO match indentation?
|
|
112
|
+
child_context.append(separator);
|
|
113
|
+
}
|
|
99
114
|
}
|
|
100
115
|
|
|
101
116
|
comment_index += 1;
|
|
@@ -105,6 +120,7 @@ function attributes(node, attributes, context, comments) {
|
|
|
105
120
|
}
|
|
106
121
|
|
|
107
122
|
child_context.visit(attribute);
|
|
123
|
+
previous_attribute_end = attribute.end;
|
|
108
124
|
|
|
109
125
|
length += child_context.measure() + 1;
|
|
110
126
|
|
|
@@ -137,8 +153,9 @@ function attributes(node, attributes, context, comments) {
|
|
|
137
153
|
* @param {AST.BaseElement} node
|
|
138
154
|
* @param {Context} context
|
|
139
155
|
* @param {AST.JSComment[]} comments
|
|
156
|
+
* @param {{ preserve_whitespace: number }} state
|
|
140
157
|
*/
|
|
141
|
-
function base_element(node, context, comments) {
|
|
158
|
+
function base_element(node, context, comments, state) {
|
|
142
159
|
const child_context = context.new();
|
|
143
160
|
|
|
144
161
|
child_context.write('<' + node.name);
|
|
@@ -164,174 +181,294 @@ function base_element(node, context, comments) {
|
|
|
164
181
|
child_context.write(`${multiline_attributes ? '' : ' '}/>`);
|
|
165
182
|
} else {
|
|
166
183
|
child_context.write('>');
|
|
167
|
-
block(child_context, node.fragment, true);
|
|
184
|
+
block(child_context, node.fragment, state.preserve_whitespace > 0, true);
|
|
168
185
|
child_context.write(`</${node.name}>`);
|
|
169
186
|
}
|
|
170
187
|
|
|
171
188
|
context.append(child_context);
|
|
172
189
|
}
|
|
173
190
|
|
|
174
|
-
/**
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
191
|
+
/**
|
|
192
|
+
* @param {AST.BaseElement} node
|
|
193
|
+
* @param {Context} context
|
|
194
|
+
* @param {AST.JSComment[]} comments
|
|
195
|
+
* @param {{ preserve_whitespace: number }} state
|
|
196
|
+
*/
|
|
197
|
+
function print_element(node, context, comments, state) {
|
|
198
|
+
const name = node.name.toLowerCase();
|
|
199
|
+
const preserve =
|
|
200
|
+
(node.type === 'RegularElement' || node.type === 'TitleElement') &&
|
|
201
|
+
(name === 'pre' || name === 'textarea' || name === 'title');
|
|
202
|
+
|
|
203
|
+
if (preserve) state.preserve_whitespace += 1;
|
|
204
|
+
base_element(node, context, comments, state);
|
|
205
|
+
if (preserve) state.preserve_whitespace -= 1;
|
|
206
|
+
}
|
|
179
207
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
208
|
+
/**
|
|
209
|
+
* @param {AST.CSS.CSSComment[]} comments
|
|
210
|
+
* @param {AST.JSComment[]} js_comments
|
|
211
|
+
* @returns {Visitors<AST.SvelteNode>}
|
|
212
|
+
*/
|
|
213
|
+
function css_visitors(comments, js_comments) {
|
|
214
|
+
let comment_index = 0;
|
|
215
|
+
|
|
216
|
+
/** @param {number} end */
|
|
217
|
+
const has_comment_before = (end) => comments[comment_index]?.start < end;
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* @param {Context} context
|
|
221
|
+
* @param {AST.CSS.CSSComment} comment
|
|
222
|
+
*/
|
|
223
|
+
function write_comment(context, comment) {
|
|
224
|
+
context.write(`/*${comment.value}*/`);
|
|
225
|
+
}
|
|
187
226
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
227
|
+
/**
|
|
228
|
+
* @param {Context} context
|
|
229
|
+
* @param {number} end
|
|
230
|
+
*/
|
|
231
|
+
function write_inline_comments(context, end) {
|
|
232
|
+
let written = false;
|
|
233
|
+
|
|
234
|
+
while (has_comment_before(end)) {
|
|
235
|
+
if (written) context.write(' ');
|
|
236
|
+
write_comment(context, comments[comment_index++]);
|
|
237
|
+
written = true;
|
|
196
238
|
}
|
|
197
|
-
context.write(']');
|
|
198
|
-
},
|
|
199
239
|
|
|
200
|
-
|
|
201
|
-
|
|
240
|
+
return written;
|
|
241
|
+
}
|
|
202
242
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
243
|
+
/**
|
|
244
|
+
* @param {Context} context
|
|
245
|
+
* @param {string} value
|
|
246
|
+
* @param {number} end
|
|
247
|
+
*/
|
|
248
|
+
function write_value(context, value, end) {
|
|
249
|
+
let offset = 0;
|
|
250
|
+
|
|
251
|
+
while (has_comment_before(end)) {
|
|
252
|
+
const comment = comments[comment_index++];
|
|
253
|
+
const position = Math.max(offset, Math.min(comment.position ?? 0, value.length));
|
|
254
|
+
context.write(value.slice(offset, position));
|
|
255
|
+
write_comment(context, comment);
|
|
256
|
+
offset = position;
|
|
257
|
+
}
|
|
206
258
|
|
|
207
|
-
|
|
259
|
+
context.write(value.slice(offset));
|
|
260
|
+
}
|
|
208
261
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
262
|
+
/**
|
|
263
|
+
* @param {Context} context
|
|
264
|
+
* @param {Array<AST.CSS.Rule | AST.CSS.Atrule | AST.CSS.Declaration>} children
|
|
265
|
+
* @param {number} end
|
|
266
|
+
* @param {boolean} margins
|
|
267
|
+
*/
|
|
268
|
+
function print_children(context, children, end, margins) {
|
|
269
|
+
let started = false;
|
|
213
270
|
|
|
214
|
-
|
|
271
|
+
const separate = () => {
|
|
272
|
+
if (!started) return;
|
|
273
|
+
if (margins) context.margin();
|
|
274
|
+
context.newline();
|
|
275
|
+
};
|
|
215
276
|
|
|
277
|
+
for (const child of children) {
|
|
278
|
+
while (has_comment_before(child.start)) {
|
|
279
|
+
separate();
|
|
280
|
+
write_comment(context, comments[comment_index++]);
|
|
216
281
|
started = true;
|
|
217
282
|
}
|
|
218
283
|
|
|
219
|
-
|
|
220
|
-
context.
|
|
284
|
+
separate();
|
|
285
|
+
context.visit(child);
|
|
286
|
+
started = true;
|
|
221
287
|
}
|
|
222
288
|
|
|
223
|
-
|
|
224
|
-
|
|
289
|
+
while (has_comment_before(end)) {
|
|
290
|
+
separate();
|
|
291
|
+
write_comment(context, comments[comment_index++]);
|
|
292
|
+
started = true;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
225
295
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
296
|
+
/**
|
|
297
|
+
* @param {AST.CSS.SelectorList} node
|
|
298
|
+
* @param {Context} context
|
|
299
|
+
* @param {boolean} multiline
|
|
300
|
+
*/
|
|
301
|
+
function print_selector_list(node, context, multiline) {
|
|
302
|
+
let needs_separator = false;
|
|
303
|
+
let remaining_selectors = node.children.length;
|
|
229
304
|
|
|
230
|
-
ComplexSelector(node, context) {
|
|
231
305
|
for (const selector of node.children) {
|
|
306
|
+
while (has_comment_before(selector.start)) {
|
|
307
|
+
if (needs_separator) context.write(' ');
|
|
308
|
+
write_comment(context, comments[comment_index++]);
|
|
309
|
+
needs_separator = true;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (needs_separator) {
|
|
313
|
+
if (multiline) context.newline();
|
|
314
|
+
else context.write(' ');
|
|
315
|
+
}
|
|
316
|
+
|
|
232
317
|
context.visit(selector);
|
|
318
|
+
needs_separator = true;
|
|
319
|
+
remaining_selectors -= 1;
|
|
320
|
+
|
|
321
|
+
if (remaining_selectors > 0) context.write(',');
|
|
233
322
|
}
|
|
234
|
-
}
|
|
323
|
+
}
|
|
235
324
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
325
|
+
return {
|
|
326
|
+
Atrule(node, context) {
|
|
327
|
+
context.write(`@${node.name}`);
|
|
239
328
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
329
|
+
const prelude_end = node.block?.start ?? node.end;
|
|
330
|
+
if (node.prelude || has_comment_before(prelude_end)) {
|
|
331
|
+
context.write(' ');
|
|
332
|
+
write_value(context, node.prelude, prelude_end);
|
|
333
|
+
}
|
|
243
334
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
335
|
+
if (node.block) {
|
|
336
|
+
context.write(' ');
|
|
337
|
+
context.visit(node.block);
|
|
338
|
+
} else {
|
|
339
|
+
context.write(';');
|
|
340
|
+
}
|
|
341
|
+
},
|
|
342
|
+
|
|
343
|
+
AttributeSelector(node, context) {
|
|
344
|
+
context.write(`[${node.name}`);
|
|
345
|
+
if (node.matcher) {
|
|
346
|
+
context.write(node.matcher);
|
|
347
|
+
context.write(`"${node.value}"`);
|
|
348
|
+
if (node.flags) context.write(` ${node.flags}`);
|
|
349
|
+
}
|
|
350
|
+
context.write(']');
|
|
351
|
+
},
|
|
247
352
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
},
|
|
353
|
+
Block(node, context) {
|
|
354
|
+
context.write('{');
|
|
251
355
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
356
|
+
if (node.children.length > 0 || has_comment_before(node.end)) {
|
|
357
|
+
context.indent();
|
|
358
|
+
context.newline();
|
|
359
|
+
print_children(context, node.children, node.end, false);
|
|
360
|
+
context.dedent();
|
|
361
|
+
context.newline();
|
|
362
|
+
}
|
|
255
363
|
|
|
256
|
-
|
|
257
|
-
|
|
364
|
+
context.write('}');
|
|
365
|
+
},
|
|
258
366
|
|
|
259
|
-
|
|
260
|
-
context.write(
|
|
367
|
+
ClassSelector(node, context) {
|
|
368
|
+
context.write(`.${node.name}`);
|
|
369
|
+
},
|
|
261
370
|
|
|
262
|
-
|
|
371
|
+
ComplexSelector(node, context) {
|
|
372
|
+
for (const selector of node.children) context.visit(selector);
|
|
373
|
+
},
|
|
263
374
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
375
|
+
Declaration(node, context) {
|
|
376
|
+
context.write(`${node.property}: `);
|
|
377
|
+
write_value(context, node.value, node.end);
|
|
378
|
+
context.write(';');
|
|
379
|
+
},
|
|
268
380
|
|
|
269
|
-
|
|
381
|
+
IdSelector(node, context) {
|
|
382
|
+
context.write(`#${node.name}`);
|
|
383
|
+
},
|
|
270
384
|
|
|
271
|
-
|
|
272
|
-
|
|
385
|
+
NestingSelector(node, context) {
|
|
386
|
+
context.write('&');
|
|
387
|
+
},
|
|
273
388
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
389
|
+
Nth(node, context) {
|
|
390
|
+
context.write(node.value);
|
|
391
|
+
},
|
|
277
392
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
393
|
+
Percentage(node, context) {
|
|
394
|
+
context.write(node.value);
|
|
395
|
+
},
|
|
281
396
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
context.
|
|
397
|
+
PseudoClassSelector(node, context) {
|
|
398
|
+
context.write(`:${node.name}`);
|
|
399
|
+
|
|
400
|
+
if (node.args) {
|
|
401
|
+
context.write('(');
|
|
402
|
+
context.visit(node.args);
|
|
403
|
+
if (has_comment_before(node.end)) {
|
|
404
|
+
context.write(' ');
|
|
405
|
+
write_inline_comments(context, node.end);
|
|
406
|
+
}
|
|
407
|
+
context.write(')');
|
|
288
408
|
}
|
|
289
|
-
}
|
|
409
|
+
},
|
|
410
|
+
|
|
411
|
+
PseudoElementSelector(node, context) {
|
|
412
|
+
context.write(`::${node.name}`);
|
|
413
|
+
if (node.args) {
|
|
414
|
+
context.write('(');
|
|
415
|
+
context.visit(node.args);
|
|
416
|
+
if (has_comment_before(node.end)) {
|
|
417
|
+
context.write(' ');
|
|
418
|
+
write_inline_comments(context, node.end);
|
|
419
|
+
}
|
|
420
|
+
context.write(')');
|
|
421
|
+
}
|
|
422
|
+
},
|
|
290
423
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
424
|
+
RelativeSelector(node, context) {
|
|
425
|
+
if (node.combinator) {
|
|
426
|
+
if (node.combinator.name === ' ') context.write(' ');
|
|
427
|
+
else context.write(` ${node.combinator.name} `);
|
|
428
|
+
}
|
|
295
429
|
|
|
296
|
-
|
|
297
|
-
|
|
430
|
+
for (const selector of node.selectors) context.visit(selector);
|
|
431
|
+
},
|
|
298
432
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
433
|
+
Rule(node, context) {
|
|
434
|
+
print_selector_list(node.prelude, context, true);
|
|
435
|
+
context.write(' ');
|
|
436
|
+
if (write_inline_comments(context, node.block.start)) context.write(' ');
|
|
437
|
+
context.visit(node.block);
|
|
438
|
+
},
|
|
304
439
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
}
|
|
440
|
+
SelectorList(node, context) {
|
|
441
|
+
print_selector_list(node, context, false);
|
|
442
|
+
},
|
|
308
443
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
444
|
+
StyleSheet(node, context) {
|
|
445
|
+
context.write('<style');
|
|
446
|
+
attributes(node, node.attributes, context, js_comments);
|
|
447
|
+
context.write('>');
|
|
312
448
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
context.
|
|
449
|
+
if (node.children.length > 0 || node.comments.length > 0) {
|
|
450
|
+
context.indent();
|
|
451
|
+
context.newline();
|
|
452
|
+
print_children(context, node.children, node.content.end, true);
|
|
453
|
+
context.dedent();
|
|
454
|
+
context.newline();
|
|
318
455
|
}
|
|
319
456
|
|
|
320
|
-
context.
|
|
321
|
-
|
|
322
|
-
}
|
|
323
|
-
},
|
|
457
|
+
context.write('</style>');
|
|
458
|
+
},
|
|
324
459
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
};
|
|
460
|
+
TypeSelector(node, context) {
|
|
461
|
+
context.write(node.name);
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
}
|
|
329
465
|
|
|
330
466
|
/**
|
|
331
467
|
* @param {AST.JSComment[]} comments
|
|
468
|
+
* @param {{ preserve_whitespace: number }} state
|
|
332
469
|
* @returns {Visitors<AST.SvelteNode>}
|
|
333
470
|
*/
|
|
334
|
-
const svelte_visitors = (comments) => ({
|
|
471
|
+
const svelte_visitors = (comments, state) => ({
|
|
335
472
|
Root(node, context) {
|
|
336
473
|
if (node.options) {
|
|
337
474
|
context.write('<svelte:options');
|
|
@@ -363,11 +500,27 @@ const svelte_visitors = (comments) => ({
|
|
|
363
500
|
context.write('<script');
|
|
364
501
|
attributes(node, node.attributes, context, comments);
|
|
365
502
|
context.write('>');
|
|
366
|
-
block(context, node.content);
|
|
503
|
+
block(context, node.content, state.preserve_whitespace > 0);
|
|
367
504
|
context.write('</script>');
|
|
368
505
|
},
|
|
369
506
|
|
|
370
507
|
Fragment(node, context) {
|
|
508
|
+
if (state.preserve_whitespace > 0) {
|
|
509
|
+
for (const child of node.nodes) {
|
|
510
|
+
context.visit(child);
|
|
511
|
+
context.multiline ||= child.type === 'Text' && /[\r\n]/.test(child.data);
|
|
512
|
+
}
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
const first = node.nodes[0];
|
|
517
|
+
const last = node.nodes.at(-1);
|
|
518
|
+
const has_surrounding_whitespace =
|
|
519
|
+
first?.type === 'Text' &&
|
|
520
|
+
/^\s/.test(first.data) &&
|
|
521
|
+
last?.type === 'Text' &&
|
|
522
|
+
/\s$/.test(last.data);
|
|
523
|
+
|
|
371
524
|
/** @type {AST.SvelteNode[][]} */
|
|
372
525
|
const items = [];
|
|
373
526
|
|
|
@@ -459,6 +612,10 @@ const svelte_visitors = (comments) => ({
|
|
|
459
612
|
});
|
|
460
613
|
|
|
461
614
|
multiline ||= width > LINE_BREAK_THRESHOLD;
|
|
615
|
+
// Normally context.newline() also makes context.multiline true, but the below loop only
|
|
616
|
+
// does that if we have more than one child context. If there's one long text block inside
|
|
617
|
+
// with whitespace at the edges we wanna split that up, too.
|
|
618
|
+
context.multiline ||= has_surrounding_whitespace && width > LINE_BREAK_THRESHOLD * 2;
|
|
462
619
|
|
|
463
620
|
for (let i = 0; i < child_contexts.length; i += 1) {
|
|
464
621
|
const prev = child_contexts[i];
|
|
@@ -525,7 +682,7 @@ const svelte_visitors = (comments) => ({
|
|
|
525
682
|
|
|
526
683
|
if (node.pending) {
|
|
527
684
|
context.write('}');
|
|
528
|
-
block(context, node.pending);
|
|
685
|
+
block(context, node.pending, state.preserve_whitespace > 0);
|
|
529
686
|
context.write('{:');
|
|
530
687
|
} else {
|
|
531
688
|
context.write(' ');
|
|
@@ -536,7 +693,7 @@ const svelte_visitors = (comments) => ({
|
|
|
536
693
|
if (node.value) context.visit(node.value);
|
|
537
694
|
context.write('}');
|
|
538
695
|
|
|
539
|
-
block(context, node.then);
|
|
696
|
+
block(context, node.then, state.preserve_whitespace > 0);
|
|
540
697
|
|
|
541
698
|
if (node.catch) {
|
|
542
699
|
context.write('{:');
|
|
@@ -548,7 +705,7 @@ const svelte_visitors = (comments) => ({
|
|
|
548
705
|
if (node.error) context.visit(node.error);
|
|
549
706
|
context.write('}');
|
|
550
707
|
|
|
551
|
-
block(context, node.catch);
|
|
708
|
+
block(context, node.catch, state.preserve_whitespace > 0);
|
|
552
709
|
}
|
|
553
710
|
|
|
554
711
|
context.write('{/await}');
|
|
@@ -592,7 +749,7 @@ const svelte_visitors = (comments) => ({
|
|
|
592
749
|
},
|
|
593
750
|
|
|
594
751
|
Component(node, context) {
|
|
595
|
-
|
|
752
|
+
print_element(node, context, comments, state);
|
|
596
753
|
},
|
|
597
754
|
|
|
598
755
|
ConstTag(node, context) {
|
|
@@ -682,11 +839,11 @@ const svelte_visitors = (comments) => ({
|
|
|
682
839
|
|
|
683
840
|
context.write('}');
|
|
684
841
|
|
|
685
|
-
block(context, node.body);
|
|
842
|
+
block(context, node.body, state.preserve_whitespace > 0);
|
|
686
843
|
|
|
687
844
|
if (node.fallback) {
|
|
688
845
|
context.write('{:else}');
|
|
689
|
-
block(context, node.fallback);
|
|
846
|
+
block(context, node.fallback, state.preserve_whitespace > 0);
|
|
690
847
|
}
|
|
691
848
|
|
|
692
849
|
context.write('{/each}');
|
|
@@ -710,13 +867,13 @@ const svelte_visitors = (comments) => ({
|
|
|
710
867
|
context.visit(node.test);
|
|
711
868
|
context.write('}');
|
|
712
869
|
|
|
713
|
-
block(context, node.consequent);
|
|
870
|
+
block(context, node.consequent, state.preserve_whitespace > 0);
|
|
714
871
|
} else {
|
|
715
872
|
context.write('{#if ');
|
|
716
873
|
context.visit(node.test);
|
|
717
874
|
context.write('}');
|
|
718
875
|
|
|
719
|
-
block(context, node.consequent);
|
|
876
|
+
block(context, node.consequent, state.preserve_whitespace > 0);
|
|
720
877
|
}
|
|
721
878
|
|
|
722
879
|
if (node.alternate !== null) {
|
|
@@ -728,7 +885,7 @@ const svelte_visitors = (comments) => ({
|
|
|
728
885
|
)
|
|
729
886
|
) {
|
|
730
887
|
context.write('{:else}');
|
|
731
|
-
block(context, node.alternate);
|
|
888
|
+
block(context, node.alternate, state.preserve_whitespace > 0);
|
|
732
889
|
} else {
|
|
733
890
|
context.visit(node.alternate);
|
|
734
891
|
}
|
|
@@ -743,7 +900,7 @@ const svelte_visitors = (comments) => ({
|
|
|
743
900
|
context.write('{#key ');
|
|
744
901
|
context.visit(node.expression);
|
|
745
902
|
context.write('}');
|
|
746
|
-
block(context, node.fragment);
|
|
903
|
+
block(context, node.fragment, state.preserve_whitespace > 0);
|
|
747
904
|
context.write('{/key}');
|
|
748
905
|
},
|
|
749
906
|
|
|
@@ -775,7 +932,7 @@ const svelte_visitors = (comments) => ({
|
|
|
775
932
|
},
|
|
776
933
|
|
|
777
934
|
RegularElement(node, context) {
|
|
778
|
-
|
|
935
|
+
print_element(node, context, comments, state);
|
|
779
936
|
},
|
|
780
937
|
|
|
781
938
|
RenderTag(node, context) {
|
|
@@ -785,7 +942,7 @@ const svelte_visitors = (comments) => ({
|
|
|
785
942
|
},
|
|
786
943
|
|
|
787
944
|
SlotElement(node, context) {
|
|
788
|
-
|
|
945
|
+
print_element(node, context, comments, state);
|
|
789
946
|
},
|
|
790
947
|
|
|
791
948
|
SnippetBlock(node, context) {
|
|
@@ -804,7 +961,7 @@ const svelte_visitors = (comments) => ({
|
|
|
804
961
|
}
|
|
805
962
|
|
|
806
963
|
context.write(')}');
|
|
807
|
-
block(context, node.body);
|
|
964
|
+
block(context, node.body, state.preserve_whitespace > 0);
|
|
808
965
|
context.write('{/snippet}');
|
|
809
966
|
},
|
|
810
967
|
|
|
@@ -839,40 +996,12 @@ const svelte_visitors = (comments) => ({
|
|
|
839
996
|
}
|
|
840
997
|
},
|
|
841
998
|
|
|
842
|
-
StyleSheet(node, context) {
|
|
843
|
-
context.write('<style');
|
|
844
|
-
attributes(node, node.attributes, context, comments);
|
|
845
|
-
context.write('>');
|
|
846
|
-
|
|
847
|
-
if (node.children.length > 0) {
|
|
848
|
-
context.indent();
|
|
849
|
-
context.newline();
|
|
850
|
-
|
|
851
|
-
let started = false;
|
|
852
|
-
|
|
853
|
-
for (const child of node.children) {
|
|
854
|
-
if (started) {
|
|
855
|
-
context.margin();
|
|
856
|
-
context.newline();
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
context.visit(child);
|
|
860
|
-
started = true;
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
context.dedent();
|
|
864
|
-
context.newline();
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
context.write('</style>');
|
|
868
|
-
},
|
|
869
|
-
|
|
870
999
|
SvelteBody(node, context) {
|
|
871
|
-
|
|
1000
|
+
print_element(node, context, comments, state);
|
|
872
1001
|
},
|
|
873
1002
|
|
|
874
1003
|
SvelteBoundary(node, context) {
|
|
875
|
-
|
|
1004
|
+
print_element(node, context, comments, state);
|
|
876
1005
|
},
|
|
877
1006
|
|
|
878
1007
|
SvelteComponent(node, context) {
|
|
@@ -884,7 +1013,7 @@ const svelte_visitors = (comments) => ({
|
|
|
884
1013
|
attributes(node, node.attributes, context, comments);
|
|
885
1014
|
if (node.fragment && node.fragment.nodes.length > 0) {
|
|
886
1015
|
context.write('>');
|
|
887
|
-
block(context, node.fragment, true);
|
|
1016
|
+
block(context, node.fragment, state.preserve_whitespace > 0, true);
|
|
888
1017
|
context.write(`</svelte:component>`);
|
|
889
1018
|
} else {
|
|
890
1019
|
context.write(' />');
|
|
@@ -892,7 +1021,7 @@ const svelte_visitors = (comments) => ({
|
|
|
892
1021
|
},
|
|
893
1022
|
|
|
894
1023
|
SvelteDocument(node, context) {
|
|
895
|
-
|
|
1024
|
+
print_element(node, context, comments, state);
|
|
896
1025
|
},
|
|
897
1026
|
|
|
898
1027
|
SvelteElement(node, context) {
|
|
@@ -905,7 +1034,7 @@ const svelte_visitors = (comments) => ({
|
|
|
905
1034
|
|
|
906
1035
|
if (node.fragment && node.fragment.nodes.length > 0) {
|
|
907
1036
|
context.write('>');
|
|
908
|
-
block(context, node.fragment);
|
|
1037
|
+
block(context, node.fragment, state.preserve_whitespace > 0);
|
|
909
1038
|
context.write(`</svelte:element>`);
|
|
910
1039
|
} else {
|
|
911
1040
|
context.write(' />');
|
|
@@ -913,19 +1042,19 @@ const svelte_visitors = (comments) => ({
|
|
|
913
1042
|
},
|
|
914
1043
|
|
|
915
1044
|
SvelteFragment(node, context) {
|
|
916
|
-
|
|
1045
|
+
print_element(node, context, comments, state);
|
|
917
1046
|
},
|
|
918
1047
|
|
|
919
1048
|
SvelteHead(node, context) {
|
|
920
|
-
|
|
1049
|
+
print_element(node, context, comments, state);
|
|
921
1050
|
},
|
|
922
1051
|
|
|
923
1052
|
SvelteSelf(node, context) {
|
|
924
|
-
|
|
1053
|
+
print_element(node, context, comments, state);
|
|
925
1054
|
},
|
|
926
1055
|
|
|
927
1056
|
SvelteWindow(node, context) {
|
|
928
|
-
|
|
1057
|
+
print_element(node, context, comments, state);
|
|
929
1058
|
},
|
|
930
1059
|
|
|
931
1060
|
Text(node, context) {
|
|
@@ -933,7 +1062,7 @@ const svelte_visitors = (comments) => ({
|
|
|
933
1062
|
},
|
|
934
1063
|
|
|
935
1064
|
TitleElement(node, context) {
|
|
936
|
-
|
|
1065
|
+
print_element(node, context, comments, state);
|
|
937
1066
|
},
|
|
938
1067
|
|
|
939
1068
|
TransitionDirective(node, context) {
|