Skip to content

Commit 0de2182

Browse files
committed
SelectorList, <svelte:whatever />
1 parent 0b9f560 commit 0de2182

File tree

1 file changed

+165
-1
lines changed
  • packages/svelte/src/compiler/print

1 file changed

+165
-1
lines changed

packages/svelte/src/compiler/print/index.js

Lines changed: 165 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ const visitors = {
261261

262262
ConstTag(node, context) {
263263
context.write('{@const ');
264-
context.visit(node.declaration); // TODO does this work?
264+
context.visit(node.declaration);
265265
context.write('}');
266266
},
267267

@@ -477,6 +477,18 @@ const visitors = {
477477
context.visit(node.block);
478478
},
479479

480+
SelectorList(node, context) {
481+
let started = false;
482+
for (const selector of node.children) {
483+
if (started) {
484+
context.write(', ');
485+
}
486+
487+
context.visit(selector);
488+
started = true;
489+
}
490+
},
491+
480492
SlotElement(node, context) {
481493
context.write('<slot');
482494

@@ -568,6 +580,158 @@ const visitors = {
568580
context.write('</style>');
569581
},
570582

583+
SvelteBoundary(node, context) {
584+
context.write('<svelte:boundary');
585+
586+
for (const attribute of node.attributes) {
587+
// TODO handle multiline
588+
context.write(' ');
589+
context.visit(attribute);
590+
}
591+
592+
if (node.fragment) {
593+
context.write('>');
594+
context.visit(node.fragment);
595+
context.write(`</svelte:boundary>`);
596+
} else {
597+
context.write('/>');
598+
}
599+
},
600+
601+
SvelteComponent(node, context) {
602+
context.write('<svelte:component');
603+
604+
context.write('this={');
605+
context.visit(node.expression);
606+
context.write('} ');
607+
608+
for (const attribute of node.attributes) {
609+
// TODO handle multiline
610+
context.write(' ');
611+
context.visit(attribute);
612+
}
613+
614+
if (node.fragment) {
615+
context.write('>');
616+
context.visit(node.fragment);
617+
context.write(`</svelte:component>`);
618+
} else {
619+
context.write('/>');
620+
}
621+
},
622+
623+
SvelteDocument(node, context) {
624+
context.write('<svelte:document');
625+
626+
for (const attribute of node.attributes) {
627+
// TODO handle multiline
628+
context.write(' ');
629+
context.visit(attribute);
630+
}
631+
632+
if (node.fragment) {
633+
context.write('>');
634+
context.visit(node.fragment);
635+
context.write(`</svelte:document>`);
636+
} else {
637+
context.write('/>');
638+
}
639+
},
640+
641+
SvelteElement(node, context) {
642+
context.write('<svelte:element');
643+
644+
context.write('this={');
645+
context.visit(node.expression);
646+
context.write('} ');
647+
648+
for (const attribute of node.attributes) {
649+
// TODO handle multiline
650+
context.write(' ');
651+
context.visit(attribute);
652+
}
653+
654+
if (node.fragment) {
655+
context.write('>');
656+
context.visit(node.fragment);
657+
context.write(`</svelte:element>`);
658+
} else {
659+
context.write('/>');
660+
}
661+
},
662+
663+
SvelteFragment(node, context) {
664+
context.write('<svelte:fragment');
665+
666+
for (const attribute of node.attributes) {
667+
// TODO handle multiline
668+
context.write(' ');
669+
context.visit(attribute);
670+
}
671+
672+
if (node.fragment) {
673+
context.write('>');
674+
context.visit(node.fragment);
675+
context.write(`</svelte:fragment>`);
676+
} else {
677+
context.write('/>');
678+
}
679+
},
680+
681+
SvelteHead(node, context) {
682+
context.write('<svelte:head');
683+
684+
for (const attribute of node.attributes) {
685+
// TODO handle multiline
686+
context.write(' ');
687+
context.visit(attribute);
688+
}
689+
690+
if (node.fragment) {
691+
context.write('>');
692+
context.visit(node.fragment);
693+
context.write(`</svelte:head>`);
694+
} else {
695+
context.write('/>');
696+
}
697+
},
698+
699+
SvelteSelf(node, context) {
700+
context.write('<svelte:self');
701+
702+
for (const attribute of node.attributes) {
703+
// TODO handle multiline
704+
context.write(' ');
705+
context.visit(attribute);
706+
}
707+
708+
if (node.fragment) {
709+
context.write('>');
710+
context.visit(node.fragment);
711+
context.write(`</svelte:self>`);
712+
} else {
713+
context.write('/>');
714+
}
715+
},
716+
717+
SvelteWindow(node, context) {
718+
context.write('<svelte:window');
719+
720+
for (const attribute of node.attributes) {
721+
// TODO handle multiline
722+
context.write(' ');
723+
context.visit(attribute);
724+
}
725+
726+
if (node.fragment) {
727+
context.write('>');
728+
context.visit(node.fragment);
729+
context.write(`</svelte:window>`);
730+
} else {
731+
context.write('/>');
732+
}
733+
},
734+
571735
Text(node, context) {
572736
context.write(node.data);
573737
},

0 commit comments

Comments
 (0)