Skip to content

Commit aa5c442

Browse files
authored
fix: ensure nullish expressions render empty text (#12898)
1 parent 1f99935 commit aa5c442

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

.changeset/unlucky-points-clap.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: ensure nullish expressions render empty text

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ export function build_template_literal(values, visit, state) {
5959
id,
6060
create_derived(
6161
state,
62-
b.thunk(/** @type {Expression} */ (visit(node.expression, state)))
62+
b.thunk(
63+
b.logical(
64+
'??',
65+
/** @type {Expression} */ (visit(node.expression, state)),
66+
b.literal('')
67+
)
68+
)
6369
)
6470
)
6571
);
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: '<li></li>'
5+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<script>
2+
function fn() {}
3+
</script>
4+
<li>{fn()}{null && fn()}</li>

0 commit comments

Comments
 (0)