Skip to content

Commit 15a60ad

Browse files
committed
changeset
1 parent 7e5e462 commit 15a60ad

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

.changeset/many-rockets-give.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+
feat: more efficient if block compiler output

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2573,15 +2573,20 @@ export const template_visitors = {
25732573
const args = [
25742574
context.state.node,
25752575
b.thunk(/** @type {import('estree').Expression} */ (context.visit(node.test))),
2576-
b.arrow([b.id('$$anchor')], consequent),
2577-
node.alternate
2578-
? b.arrow(
2579-
[b.id('$$anchor')],
2580-
/** @type {import('estree').BlockStatement} */ (context.visit(node.alternate))
2581-
)
2582-
: b.literal(null)
2576+
b.arrow([b.id('$$anchor')], consequent)
25832577
];
25842578

2579+
if (node.alternate || node.elseif) {
2580+
args.push(
2581+
node.alternate
2582+
? b.arrow(
2583+
[b.id('$$anchor')],
2584+
/** @type {import('estree').BlockStatement} */ (context.visit(node.alternate))
2585+
)
2586+
: b.literal(null)
2587+
);
2588+
}
2589+
25852590
if (node.elseif) {
25862591
// We treat this...
25872592
//

packages/svelte/src/internal/client/dom/blocks/if.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@ import {
1212
* @param {Comment} anchor
1313
* @param {() => boolean} get_condition
1414
* @param {(anchor: Node) => import('#client').Dom} consequent_fn
15-
* @param {null | ((anchor: Node) => import('#client').Dom)} alternate_fn
15+
* @param {null | ((anchor: Node) => import('#client').Dom)} [alternate_fn]
1616
* @param {boolean} [elseif] True if this is an `{:else if ...}` block rather than an `{#if ...}`, as that affects which transitions are considered 'local'
1717
* @returns {void}
1818
*/
19-
export function if_block(anchor, get_condition, consequent_fn, alternate_fn, elseif = false) {
19+
export function if_block(
20+
anchor,
21+
get_condition,
22+
consequent_fn,
23+
alternate_fn = null,
24+
elseif = false
25+
) {
2026
hydrate_block_anchor(anchor);
2127

2228
/** @type {import('#client').Effect | null} */

0 commit comments

Comments
 (0)