Skip to content

Commit 4a87f5a

Browse files
committed
fix self closing tag problems
1 parent 90ea50b commit 4a87f5a

File tree

6 files changed

+23
-27
lines changed

6 files changed

+23
-27
lines changed

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

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -714,35 +714,34 @@ const svelte_visitors = {
714714
context.visit(attribute);
715715
}
716716

717-
if (node.fragment) {
717+
if (node.fragment && node.fragment.nodes.length > 0) {
718718
context.write('>');
719719
block(context, node.fragment, true);
720720
context.write(`</svelte:boundary>`);
721721
} else {
722-
context.write('/>');
722+
context.write(' />');
723723
}
724724
},
725725

726726
SvelteComponent(node, context) {
727727
context.write('<svelte:component');
728728

729-
context.write('this={');
729+
context.write(' this={');
730730
context.visit(node.expression);
731-
context.write('} ');
731+
context.write('}');
732732

733733
for (const attribute of node.attributes) {
734734
// TODO handle multiline
735735
context.write(' ');
736736
context.visit(attribute);
737737
}
738738

739-
// TODO handling of self-closing does not seem to work
740-
if (node.fragment) {
739+
if (node.fragment && node.fragment.nodes.length > 0) {
741740
context.write('>');
742741
block(context, node.fragment, true);
743742
context.write(`</svelte:component>`);
744743
} else {
745-
context.write('/>');
744+
context.write(' />');
746745
}
747746
},
748747

@@ -755,13 +754,12 @@ const svelte_visitors = {
755754
context.visit(attribute);
756755
}
757756

758-
// TODO handling of self-closing does not seem to work
759-
if (node.fragment) {
757+
if (node.fragment && node.fragment.nodes.length > 0) {
760758
context.write('>');
761759
block(context, node.fragment, true);
762760
context.write(`</svelte:document>`);
763761
} else {
764-
context.write('/>');
762+
context.write(' />');
765763
}
766764
},
767765

@@ -779,12 +777,12 @@ const svelte_visitors = {
779777
}
780778

781779
// TODO new line handling not working?
782-
if (node.fragment) {
780+
if (node.fragment && node.fragment.nodes.length > 0) {
783781
context.write('>');
784782
block(context, node.fragment, true);
785783
context.write(`</svelte:element>`);
786784
} else {
787-
context.write('/>');
785+
context.write(' />');
788786
}
789787
},
790788

@@ -797,12 +795,12 @@ const svelte_visitors = {
797795
context.visit(attribute);
798796
}
799797

800-
if (node.fragment) {
798+
if (node.fragment && node.fragment.nodes.length > 0) {
801799
context.write('>');
802800
block(context, node.fragment, true);
803801
context.write(`</svelte:fragment>`);
804802
} else {
805-
context.write('/>');
803+
context.write(' />');
806804
}
807805
},
808806

@@ -815,12 +813,12 @@ const svelte_visitors = {
815813
context.visit(attribute);
816814
}
817815

818-
if (node.fragment) {
816+
if (node.fragment && node.fragment.nodes.length > 0) {
819817
context.write('>');
820818
block(context, node.fragment, true);
821819
context.write(`</svelte:head>`);
822820
} else {
823-
context.write('/>');
821+
context.write(' />');
824822
}
825823
},
826824

@@ -833,13 +831,12 @@ const svelte_visitors = {
833831
context.visit(attribute);
834832
}
835833

836-
// TODO handling of self-closing does not seem to work
837-
if (node.fragment) {
834+
if (node.fragment && node.fragment.nodes.length > 0) {
838835
context.write('>');
839836
block(context, node.fragment, true);
840837
context.write(`</svelte:self>`);
841838
} else {
842-
context.write('/>');
839+
context.write(' />');
843840
}
844841
},
845842

@@ -852,13 +849,12 @@ const svelte_visitors = {
852849
context.visit(attribute);
853850
}
854851

855-
// TODO handling of self-closing does not seem to work
856-
if (node.fragment) {
852+
if (node.fragment && node.fragment.nodes.length > 0) {
857853
context.write('>');
858854
block(context, node.fragment, true);
859855
context.write(`</svelte:window>`);
860856
} else {
861-
context.write('/>');
857+
context.write(' />');
862858
}
863859
},
864860

packages/svelte/tests/print/samples/if-block/output.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{#if porridge.temperature > 100}
2-
<p>too hot1!</p>
2+
<p>too hot!</p>
33
{:else if 80 > porridge.temperature}
44
<p>too cold!</p>
55
{:else}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<svelte:componentthis={MyComponent} ></svelte:component>
1+
<svelte:component this={MyComponent} />
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<svelte:document onvisibilitychange={handleVisibilityChange} use:someAction></svelte:document>
1+
<svelte:document onvisibilitychange={handleVisibilityChange} use:someAction />

packages/svelte/tests/print/samples/svelte-self/output.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
{#if count > 0}
66
<p>counting down... {count}</p>
7-
<svelte:self count={count - 1}></svelte:self>
7+
<svelte:self count={count - 1} />
88
{:else}
99
<p>lift-off!</p>
1010
{/if}

packages/svelte/tests/print/samples/svelte-window/output.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
}
55
</script>
66

7-
<svelte:window onkeydown={handleKeydown}></svelte:window>
7+
<svelte:window onkeydown={handleKeydown} />

0 commit comments

Comments
 (0)