Skip to content

Commit d1cf0a8

Browse files
committed
fix: treat nullish expression as empty string
1 parent df03af2 commit d1cf0a8

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

.changeset/blue-badgers-play.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: treat nullish expression as empty string

packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export function build_template_chunk(
7777
// If we have a single expression, then pass that in directly to possibly avoid doing
7878
// extra work in the template_effect (instead we do the work in set_text).
7979
if (evaluated.is_known) {
80-
value = b.literal(evaluated.value);
80+
value = b.literal((evaluated.value ?? '') + '');
8181
}
8282

8383
return { value, has_state };
@@ -96,7 +96,7 @@ export function build_template_chunk(
9696
}
9797

9898
if (evaluated.is_known) {
99-
quasi.value.cooked += evaluated.value + '';
99+
quasi.value.cooked += (evaluated.value ?? '') + '';
100100
} else {
101101
if (!evaluated.is_defined) {
102102
// add `?? ''` where necessary
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
html: '[]'
5+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{undefined ?? null}]

0 commit comments

Comments
 (0)