Skip to content

Commit e5a500a

Browse files
committed
simplify
1 parent acbd5cf commit e5a500a

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

packages/svelte/src/compiler/phases/3-transform/client/visitors/BindDirective.js

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @import { CallExpression, Expression, MemberExpression, SequenceExpression } from 'estree' */
1+
/** @import { CallExpression, Expression, MemberExpression, Pattern, SequenceExpression } from 'estree' */
22
/** @import { AST, SvelteNode } from '#compiler' */
33
/** @import { ComponentContext } from '../types' */
44
import { dev, is_ignored } from '../../../../state.js';
@@ -13,15 +13,15 @@ import { build_bind_this, validate_binding } from './shared/utils.js';
1313
* @param {ComponentContext} context
1414
*/
1515
export function BindDirective(node, context) {
16-
const expression = node.expression;
16+
const expression = /** @type {Expression} */ (context.visit(node.expression));
1717
const property = binding_properties[node.name];
1818

1919
const parent = /** @type {SvelteNode} */ (context.path.at(-1));
2020

2121
let get, set;
2222

2323
if (expression.type === 'SequenceExpression') {
24-
[get, set] = /** @type {SequenceExpression} */ (context.visit(expression)).expressions;
24+
[get, set] = expression.expressions;
2525
} else {
2626
if (
2727
dev &&
@@ -37,20 +37,20 @@ export function BindDirective(node, context) {
3737
)) &&
3838
!is_ignored(node, 'binding_property_non_reactive')
3939
) {
40-
validate_binding(
41-
context.state,
42-
node,
43-
/**@type {MemberExpression} */ (context.visit(expression))
44-
);
40+
validate_binding(context.state, node, expression);
4541
}
4642

47-
get = b.thunk(/** @type {Expression} */ (context.visit(expression)));
43+
get = b.thunk(expression);
4844

4945
/** @type {Expression | undefined} */
5046
set = b.unthunk(
5147
b.arrow(
5248
[b.id('$$value')],
53-
/** @type {Expression} */ (context.visit(b.assignment('=', expression, b.id('$$value'))))
49+
/** @type {Expression} */ (
50+
context.visit(
51+
b.assignment('=', /** @type {Pattern} */ (node.expression), b.id('$$value'))
52+
)
53+
)
5454
)
5555
);
5656

@@ -171,7 +171,7 @@ export function BindDirective(node, context) {
171171
break;
172172

173173
case 'this':
174-
call = build_bind_this(expression, context.state.node, context);
174+
call = build_bind_this(node.expression, context.state.node, context);
175175
break;
176176

177177
case 'textContent':
@@ -221,21 +221,8 @@ export function BindDirective(node, context) {
221221
);
222222

223223
if (value !== undefined) {
224-
let group_expression;
225-
if (Array.isArray(expression)) {
226-
const get_id = b.id(context.state.scope.generate('bind_get'));
227-
228-
context.state.init.push(b.var(get_id, get));
229-
group_expression = b.call(get_id);
230-
} else {
231-
group_expression = /** @type {Expression} */ (context.visit(expression));
232-
}
233-
234224
group_getter = b.thunk(
235-
b.block([
236-
b.stmt(build_attribute_value(value, context).value),
237-
b.return(group_expression)
238-
])
225+
b.block([b.stmt(build_attribute_value(value, context).value), b.return(expression)])
239226
);
240227
}
241228
}

0 commit comments

Comments
 (0)