fix: treat nullish expression as empty string (#15901)

* fix: treat nullish expression as empty string

* fix
pull/15902/head
Rich Harris 4 months ago committed by GitHub
parent 8a351944a3
commit 895337cf47
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: treat nullish expression as empty string

@ -77,7 +77,7 @@ export function build_template_chunk(
// If we have a single expression, then pass that in directly to possibly avoid doing
// extra work in the template_effect (instead we do the work in set_text).
if (evaluated.is_known) {
value = b.literal(evaluated.value);
value = b.literal((evaluated.value ?? '') + '');
}
return { value, has_state };
@ -96,7 +96,7 @@ export function build_template_chunk(
}
if (evaluated.is_known) {
quasi.value.cooked += evaluated.value + '';
quasi.value.cooked += (evaluated.value ?? '') + '';
} else {
if (!evaluated.is_defined) {
// add `?? ''` where necessary

@ -0,0 +1,5 @@
import { test } from '../../test';
export default test({
html: '[]'
});

@ -8,7 +8,7 @@ export default function Purity($$anchor) {
var fragment = root();
var p = $.first_child(fragment);
p.textContent = 0;
p.textContent = '0';
var p_1 = $.sibling(p, 2);

Loading…
Cancel
Save