pull/10906/head
Rich Harris 2 years ago
parent 7e5e462194
commit 15a60adf36

@ -0,0 +1,5 @@
---
'svelte': patch
---
feat: more efficient if block compiler output

@ -2573,15 +2573,20 @@ export const template_visitors = {
const args = [
context.state.node,
b.thunk(/** @type {import('estree').Expression} */ (context.visit(node.test))),
b.arrow([b.id('$$anchor')], consequent),
node.alternate
? b.arrow(
[b.id('$$anchor')],
/** @type {import('estree').BlockStatement} */ (context.visit(node.alternate))
)
: b.literal(null)
b.arrow([b.id('$$anchor')], consequent)
];
if (node.alternate || node.elseif) {
args.push(
node.alternate
? b.arrow(
[b.id('$$anchor')],
/** @type {import('estree').BlockStatement} */ (context.visit(node.alternate))
)
: b.literal(null)
);
}
if (node.elseif) {
// We treat this...
//

@ -12,11 +12,17 @@ import {
* @param {Comment} anchor
* @param {() => boolean} get_condition
* @param {(anchor: Node) => import('#client').Dom} consequent_fn
* @param {null | ((anchor: Node) => import('#client').Dom)} alternate_fn
* @param {null | ((anchor: Node) => import('#client').Dom)} [alternate_fn]
* @param {boolean} [elseif] True if this is an `{:else if ...}` block rather than an `{#if ...}`, as that affects which transitions are considered 'local'
* @returns {void}
*/
export function if_block(anchor, get_condition, consequent_fn, alternate_fn, elseif = false) {
export function if_block(
anchor,
get_condition,
consequent_fn,
alternate_fn = null,
elseif = false
) {
hydrate_block_anchor(anchor);
/** @type {import('#client').Effect | null} */

Loading…
Cancel
Save