Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for bind getter/setters #14307

Merged
merged 28 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
simplify
  • Loading branch information
Rich-Harris committed Nov 19, 2024
commit f00a403cb1a5deb710e10a5e70b8c9bac2ebc8fd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @import { CallExpression, Expression, MemberExpression, Pattern, SequenceExpression } from 'estree' */
/** @import { CallExpression, Expression, MemberExpression, Pattern } from 'estree' */
/** @import { AST, SvelteNode } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import { dev, is_ignored } from '../../../../state.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,16 @@ export function build_element_attributes(node, context) {
const binding = binding_properties[attribute.name];
if (binding?.omit_in_ssr) continue;

const get =
attribute.expression.type === 'SequenceExpression'
? b.call(/** @type {Expression} */ (context.visit(attribute.expression.expressions[0])))
: /** @type {Expression} */ (context.visit(attribute.expression));
let expression = /** @type {Expression} */ (context.visit(attribute.expression));

if (expression.type === 'SequenceExpression') {
expression = b.call(expression.expressions[0]);
}

if (is_content_editable_binding(attribute.name)) {
content = get;
content = expression;
} else if (attribute.name === 'value' && node.name === 'textarea') {
content = b.call('$.escape', get);
content = b.call('$.escape', expression);
} else if (attribute.name === 'group' && attribute.expression.type !== 'SequenceExpression') {
const value_attribute = /** @type {AST.Attribute | undefined} */ (
node.attributes.find((attr) => attr.type === 'Attribute' && attr.name === 'value')
Expand Down Expand Up @@ -163,7 +164,7 @@ export function build_element_attributes(node, context) {
start: -1,
end: -1,
parent: attribute,
expression: get,
expression,
metadata: {
expression: create_expression_metadata()
}
Expand Down
Loading