clean up diff

pull/16607/head
Jack Goodall 3 weeks ago
parent 9c9a1a841c
commit d4417cb245

@ -818,9 +818,8 @@ function read_sequence(parser, done, location) {
parser.allow_whitespace(); parser.allow_whitespace();
const has_spread = parser.match('...'); const has_spread = parser.eat('...');
if (has_spread) { if (has_spread) {
parser.eat('...', true);
parser.allow_whitespace(); parser.allow_whitespace();
} }

@ -253,7 +253,7 @@ export function BindDirective(node, context) {
node.metadata = { node.metadata = {
binding_group_name: group_name, binding_group_name: group_name,
parent_each_blocks: each_blocks, parent_each_blocks: each_blocks,
spread_binding: false spread_binding: node.metadata.spread_binding
}; };
} }

@ -197,27 +197,16 @@ export function build_component(node, component_name, context) {
push_prop(b.init(attribute.name, value)); push_prop(b.init(attribute.name, value));
} }
} else if (attribute.type === 'BindDirective') { } else if (attribute.type === 'BindDirective') {
if (attribute.metadata.spread_binding) {
const { get, set } = init_spread_bindings(attribute.expression, context);
if (attribute.name === 'this') {
bind_this = {
type: 'SpreadElement',
argument: attribute.expression
};
} else {
push_prop(b.get(attribute.name, [b.return(b.call(get))]), true);
push_prop(b.set(attribute.name, [b.stmt(b.call(set, b.id('$$value')))]), true);
}
} else {
const expression = /** @type {Expression} */ (context.visit(attribute.expression)); const expression = /** @type {Expression} */ (context.visit(attribute.expression));
if ( if (
dev && dev &&
attribute.name !== 'this' && attribute.name !== 'this' &&
!is_ignored(node, 'ownership_invalid_binding') && !is_ignored(node, 'ownership_invalid_binding') &&
// bind:x={() => x.y, y => x.y = y} will be handled by the assignment expression binding validation // bind:x={() => x.y, y => x.y = y} and bind:x={...[() => x.y, y => x.y = y]}
attribute.expression.type !== 'SequenceExpression' // will be handled by the assignment expression binding validation
attribute.expression.type !== 'SequenceExpression' &&
!attribute.metadata.spread_binding
) { ) {
const left = object(attribute.expression); const left = object(attribute.expression);
const binding = left && context.state.scope.get(left.name); const binding = left && context.state.scope.get(left.name);
@ -237,7 +226,19 @@ export function build_component(node, component_name, context) {
} }
} }
if (expression.type === 'SequenceExpression') { if (attribute.metadata.spread_binding) {
const { get, set } = init_spread_bindings(attribute.expression, context);
if (attribute.name === 'this') {
bind_this = {
type: 'SpreadElement',
argument: attribute.expression
};
} else {
push_prop(b.get(attribute.name, [b.return(b.call(get))]), true);
push_prop(b.set(attribute.name, [b.stmt(b.call(set, b.id('$$value')))]), true);
}
} else if (expression.type === 'SequenceExpression') {
if (attribute.name === 'this') { if (attribute.name === 'this') {
bind_this = attribute.expression; bind_this = attribute.expression;
} else { } else {
@ -271,10 +272,7 @@ export function build_component(node, component_name, context) {
// Delay prop pushes so bindings come at the end, to avoid spreads overwriting them // Delay prop pushes so bindings come at the end, to avoid spreads overwriting them
if (is_store_sub) { if (is_store_sub) {
push_prop( push_prop(
b.get(attribute.name, [ b.get(attribute.name, [b.stmt(b.call('$.mark_store_binding')), b.return(expression)]),
b.stmt(b.call('$.mark_store_binding')),
b.return(expression)
]),
true true
); );
} else { } else {
@ -288,14 +286,11 @@ export function build_component(node, component_name, context) {
); );
push_prop( push_prop(
b.set(attribute.name, [ b.set(attribute.name, [b.stmt(/** @type {Expression} */ (context.visit(assignment)))]),
b.stmt(/** @type {Expression} */ (context.visit(assignment)))
]),
true true
); );
} }
} }
}
} else if (attribute.type === 'AttachTag') { } else if (attribute.type === 'AttachTag') {
const evaluated = context.state.scope.evaluate(attribute.expression); const evaluated = context.state.scope.evaluate(attribute.expression);

@ -15,8 +15,7 @@ import type {
Program, Program,
ChainExpression, ChainExpression,
SimpleCallExpression, SimpleCallExpression,
SequenceExpression, SequenceExpression
SpreadElement
} from 'estree'; } from 'estree';
import type { Scope } from '../phases/scope'; import type { Scope } from '../phases/scope';
import type { _CSS } from './css'; import type { _CSS } from './css';

Loading…
Cancel
Save