Comparing version 5.6.1 to 5.6.2
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "5.6.1", | ||
"version": "5.6.2", | ||
"type": "module", | ||
@@ -8,0 +8,0 @@ "types": "./types/index.d.ts", |
@@ -12,19 +12,40 @@ /** @import { BlockStatement, Expression } from 'estree' */ | ||
context.state.template.push('<!>'); | ||
const statements = []; | ||
const consequent = /** @type {BlockStatement} */ (context.visit(node.consequent)); | ||
const consequent_id = context.state.scope.generate('consequent'); | ||
statements.push(b.var(b.id(consequent_id), b.arrow([b.id('$$anchor')], consequent))); | ||
let alternate_id; | ||
if (node.alternate) { | ||
const alternate = /** @type {BlockStatement} */ (context.visit(node.alternate)); | ||
alternate_id = context.state.scope.generate('alternate'); | ||
statements.push(b.var(b.id(alternate_id), b.arrow([b.id('$$anchor')], alternate))); | ||
} | ||
/** @type {Expression[]} */ | ||
const args = [ | ||
context.state.node, | ||
b.thunk(/** @type {Expression} */ (context.visit(node.test))), | ||
b.arrow([b.id('$$anchor')], consequent) | ||
b.arrow( | ||
[b.id('$$render')], | ||
b.block([ | ||
b.if( | ||
/** @type {Expression} */ (context.visit(node.test)), | ||
b.stmt(b.call(b.id('$$render'), b.id(consequent_id))), | ||
alternate_id | ||
? b.stmt( | ||
b.call( | ||
b.id('$$render'), | ||
b.id(alternate_id), | ||
node.alternate ? b.literal(false) : undefined | ||
) | ||
) | ||
: undefined | ||
) | ||
]) | ||
) | ||
]; | ||
if (node.alternate || node.elseif) { | ||
args.push( | ||
node.alternate | ||
? b.arrow([b.id('$$anchor')], /** @type {BlockStatement} */ (context.visit(node.alternate))) | ||
: b.literal(null) | ||
); | ||
} | ||
if (node.elseif) { | ||
@@ -55,3 +76,5 @@ // We treat this... | ||
context.state.init.push(b.stmt(b.call('$.if', ...args))); | ||
statements.push(b.stmt(b.call('$.if', ...args))); | ||
context.state.init.push(b.block(statements)); | ||
} |
@@ -16,9 +16,7 @@ /** @import { Effect, TemplateNode } from '#client' */ | ||
* @param {TemplateNode} node | ||
* @param {() => boolean} get_condition | ||
* @param {(anchor: Node) => void} consequent_fn | ||
* @param {null | ((anchor: Node) => void)} [alternate_fn] | ||
* @param {(branch: (fn: (anchor: Node) => void, flag?: boolean) => void) => void} 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(node, get_condition, consequent_fn, alternate_fn = null, elseif = false) { | ||
export function if_block(node, fn, elseif = false) { | ||
if (hydrating) { | ||
@@ -41,5 +39,15 @@ hydrate_next(); | ||
block(() => { | ||
if (condition === (condition = !!get_condition())) return; | ||
var has_branch = false; | ||
const set_branch = (/** @type {(anchor: Node) => void} */ fn, flag = true) => { | ||
has_branch = true; | ||
update_branch(flag, fn); | ||
}; | ||
const update_branch = ( | ||
/** @type {boolean | null} */ new_condition, | ||
/** @type {null | ((anchor: Node) => void)} */ fn | ||
) => { | ||
if (condition === (condition = new_condition)) return; | ||
/** Whether or not there was a hydration mismatch. Needs to be a `let` or else it isn't treeshaken out */ | ||
@@ -65,4 +73,4 @@ let mismatch = false; | ||
resume_effect(consequent_effect); | ||
} else { | ||
consequent_effect = branch(() => consequent_fn(anchor)); | ||
} else if (fn) { | ||
consequent_effect = branch(() => fn(anchor)); | ||
} | ||
@@ -78,4 +86,4 @@ | ||
resume_effect(alternate_effect); | ||
} else if (alternate_fn) { | ||
alternate_effect = branch(() => alternate_fn(anchor)); | ||
} else if (fn) { | ||
alternate_effect = branch(() => fn(anchor)); | ||
} | ||
@@ -94,2 +102,10 @@ | ||
} | ||
}; | ||
block(() => { | ||
has_branch = false; | ||
fn(set_branch); | ||
if (!has_branch) { | ||
update_branch(null, null); | ||
} | ||
}, flags); | ||
@@ -96,0 +112,0 @@ |
@@ -9,3 +9,3 @@ // generated during release, do not modify | ||
*/ | ||
export const VERSION = '5.6.1'; | ||
export const VERSION = '5.6.2'; | ||
export const PUBLIC_VERSION = '5'; |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2366570
52276