Make it work even if no spread props are used

pull/16140/head
Matei-Paul Trandafir 3 months ago
parent 3b9fdf982e
commit d546f1967d
No known key found for this signature in database
GPG Key ID: BC96CA77836E14F8

@ -54,8 +54,7 @@ export function SlotElement(node, context) {
// Let bindings first, they can be used on attributes // Let bindings first, they can be used on attributes
context.state.init.push(...lets); context.state.init.push(...lets);
const props_expression = const props_expression = b.call('$.props', b.object(props), ...spreads);
spreads.length === 0 ? b.object(props) : b.call('$.spread_props', b.object(props), ...spreads);
const fallback = const fallback =
node.fragment.nodes.length === 0 node.fragment.nodes.length === 0

@ -4,8 +4,8 @@
import { dev, is_ignored } from '../../../../../state.js'; import { dev, is_ignored } from '../../../../../state.js';
import { get_attribute_chunks, object } from '../../../../../utils/ast.js'; import { get_attribute_chunks, object } from '../../../../../utils/ast.js';
import * as b from '#compiler/builders'; import * as b from '#compiler/builders';
import { build_bind_this, memoize_expression, validate_binding } from '../shared/utils.js'; import { build_bind_this, memoize_expression, validate_binding } from './utils.js';
import { build_attribute_value } from '../shared/element.js'; import { build_attribute_value } from './element.js';
import { build_event_handler } from './events.js'; import { build_event_handler } from './events.js';
import { determine_slot } from '../../../../../utils/slot.js'; import { determine_slot } from '../../../../../utils/slot.js';
@ -399,14 +399,10 @@ export function build_component(node, component_name, context) {
push_prop(b.init('$$legacy', b.true)); push_prop(b.init('$$legacy', b.true));
} }
const props_expression = const props_expression = b.call(
props_and_spreads.length === 0 || '$.props',
(props_and_spreads.length === 1 && Array.isArray(props_and_spreads[0])) ...props_and_spreads.map((p) => (Array.isArray(p) ? b.object(p) : p))
? b.object(/** @type {Property[]} */ (props_and_spreads[0]) || []) );
: b.call(
'$.spread_props',
...props_and_spreads.map((p) => (Array.isArray(p) ? b.object(p) : p))
);
/** @param {Expression} node_id */ /** @param {Expression} node_id */
let fn = (node_id) => { let fn = (node_id) => {

@ -114,7 +114,7 @@ export {
prop, prop,
rest_props, rest_props,
legacy_rest_props, legacy_rest_props,
spread_props, props,
update_pre_prop, update_pre_prop,
update_prop update_prop
} from './reactivity/props.js'; } from './reactivity/props.js';

@ -239,7 +239,7 @@ const spread_props_handler = {
* @param {Array<Record<string, unknown> | (() => Record<string, unknown>)>} props * @param {Array<Record<string, unknown> | (() => Record<string, unknown>)>} props
* @returns {any} * @returns {any}
*/ */
export function spread_props(...props) { export function props(...props) {
let destroyed = false; let destroyed = false;
teardown(() => (destroyed = true)); teardown(() => (destroyed = true));
return new Proxy( return new Proxy(

Loading…
Cancel
Save