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
context.state.init.push(...lets);
const props_expression =
spreads.length === 0 ? b.object(props) : b.call('$.spread_props', b.object(props), ...spreads);
const props_expression = b.call('$.props', b.object(props), ...spreads);
const fallback =
node.fragment.nodes.length === 0

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

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

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

Loading…
Cancel
Save