chore: simplify accessor return (#10520)

Return `pop` directly by returning the component from it; gets rid of extraneous variable declaration

---------

Co-authored-by: Rich Harris <rich.harris@vercel.com>
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
pull/10535/head
Rich Harris 2 years ago committed by GitHub
parent 8feb86583a
commit fbb8839aba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -288,17 +288,12 @@ export function client_component(source, analysis, options) {
)
: () => {};
if (properties.length > 0) {
append_styles();
component_block.body.push(
b.var('$$accessors', b.object(properties)),
b.stmt(b.call('$.pop', b.id('$$accessors')))
properties.length > 0
? b.return(b.call('$.pop', b.object(properties)))
: b.stmt(b.call('$.pop'))
);
append_styles();
component_block.body.push(b.return(b.id('$$accessors')));
} else {
component_block.body.push(b.stmt(b.call('$.pop')));
append_styles();
}
if (analysis.uses_rest_props) {
/** @type {string[]} */

@ -1906,14 +1906,15 @@ export function push(props, runes = false) {
}
/**
* @param {Record<string, any>} [accessors]
* @returns {void}
* @template {Record<string, any>} T
* @param {T} [component]
* @returns {T}
*/
export function pop(accessors) {
export function pop(component) {
const context_stack_item = current_component_context;
if (context_stack_item !== null) {
if (accessors !== undefined) {
context_stack_item.a = accessors;
if (component !== undefined) {
context_stack_item.a = component;
}
const effects = context_stack_item.e;
if (effects !== null) {
@ -1925,6 +1926,9 @@ export function pop(accessors) {
current_component_context = context_stack_item.p;
context_stack_item.m = true;
}
// Micro-optimization: Don't set .a above to the empty object
// so it can be garbage-collected when the return here is unused
return component || /** @type {T} */ ({});
}
/**

Loading…
Cancel
Save