Skip to content

Commit 0e2720e

Browse files
committed
omit assignment when there is no text content
1 parent b3269f1 commit 0e2720e

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -368,15 +368,14 @@ export function RegularElement(node, context) {
368368
trimmed.some((node) => node.type === 'ExpressionTag');
369369

370370
if (use_text_content) {
371-
child_state.init.push(
372-
b.stmt(
373-
b.assignment(
374-
'=',
375-
b.member(context.state.node, 'textContent'),
376-
build_template_chunk(trimmed, context.visit, child_state).value
377-
)
378-
)
379-
);
371+
const { value } = build_template_chunk(trimmed, context.visit, child_state);
372+
const empty_string = value.type === 'Literal' && value.value === '';
373+
374+
if (!empty_string) {
375+
child_state.init.push(
376+
b.stmt(b.assignment('=', b.member(context.state.node, 'textContent'), value))
377+
);
378+
}
380379
} else {
381380
/** @type {Expression} */
382381
let arg = context.state.node;

0 commit comments

Comments
 (0)