pull/10912/head
Rich Harris 1 year ago committed by GitHub
parent 302b0ec973
commit f1d9afe32f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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

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

@ -12,11 +12,17 @@ import {
* @param {Comment} anchor * @param {Comment} anchor
* @param {() => boolean} get_condition * @param {() => boolean} get_condition
* @param {(anchor: Node) => import('#client').Dom} consequent_fn * @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' * @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} * @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); hydrate_block_anchor(anchor);
/** @type {import('#client').Effect | null} */ /** @type {import('#client').Effect | null} */

Loading…
Cancel
Save