fix bind:group

pull/16607/head
Jack Goodall 4 weeks ago
parent 805ca34a96
commit 4c3c658bfa

@ -14,6 +14,11 @@ import { init_spread_bindings } from '../../shared/spread_bindings.js';
* @param {ComponentContext} context * @param {ComponentContext} context
*/ */
export function BindDirective(node, context) { export function BindDirective(node, context) {
const expression = /** @type {Expression} */ (context.visit(node.expression));
const property = binding_properties[node.name];
const parent = /** @type {AST.SvelteNode} */ (context.path.at(-1));
let get, set; let get, set;
// Handle SpreadElement by creating a variable declaration before visiting // Handle SpreadElement by creating a variable declaration before visiting
@ -21,53 +26,45 @@ export function BindDirective(node, context) {
const { get: getter, set: setter } = init_spread_bindings(node.expression, context); const { get: getter, set: setter } = init_spread_bindings(node.expression, context);
get = getter; get = getter;
set = setter; set = setter;
} else if (expression.type === 'SequenceExpression') {
[get, set] = expression.expressions;
} else { } else {
const expression = /** @type {Expression} */ (context.visit(node.expression)); if (
dev &&
if (expression.type === 'SequenceExpression') { context.state.analysis.runes &&
[get, set] = expression.expressions; expression.type === 'MemberExpression' &&
} else { (node.name !== 'this' ||
if ( context.path.some(
dev && ({ type }) =>
context.state.analysis.runes && type === 'IfBlock' ||
expression.type === 'MemberExpression' && type === 'EachBlock' ||
(node.name !== 'this' || type === 'AwaitBlock' ||
context.path.some( type === 'KeyBlock'
({ type }) => )) &&
type === 'IfBlock' || !is_ignored(node, 'binding_property_non_reactive')
type === 'EachBlock' || ) {
type === 'AwaitBlock' || validate_binding(context.state, node, expression);
type === 'KeyBlock' }
)) &&
!is_ignored(node, 'binding_property_non_reactive')
) {
validate_binding(context.state, node, expression);
}
get = b.thunk(expression); get = b.thunk(expression);
/** @type {Expression | undefined} */ /** @type {Expression | undefined} */
set = b.unthunk( set = b.unthunk(
b.arrow( b.arrow(
[b.id('$$value')], [b.id('$$value')],
/** @type {Expression} */ ( /** @type {Expression} */ (
context.visit( context.visit(
b.assignment('=', /** @type {Pattern} */ (node.expression), b.id('$$value')) b.assignment('=', /** @type {Pattern} */ (node.expression), b.id('$$value'))
)
) )
) )
); )
);
if (get === set) { if (get === set) {
set = undefined; set = undefined;
}
} }
} }
const property = binding_properties[node.name];
const parent = /** @type {AST.SvelteNode} */ (context.path.at(-1));
/** @type {CallExpression} */ /** @type {CallExpression} */
let call; let call;
@ -231,7 +228,7 @@ export function BindDirective(node, context) {
if (value !== undefined) { if (value !== undefined) {
group_getter = b.thunk( group_getter = b.thunk(
b.block([b.stmt(build_attribute_value(value, context).value), b.return(get)]) b.block([b.stmt(build_attribute_value(value, context).value), b.return(b.call(get))])
); );
} }
} }

Loading…
Cancel
Save