Skip to content

Commit 7219b9e

Browse files
committed
simplify
1 parent 8c11e70 commit 7219b9e

File tree

2 files changed

+19
-42
lines changed
  • packages/svelte
    • src/compiler/phases/3-transform/client/visitors
    • tests/snapshot/samples/dynamic-attributes-casing/_expected/client

2 files changed

+19
-42
lines changed

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

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -477,66 +477,43 @@ function serialize_element_attribute_update_assignment(element, node_id, attribu
477477
const assign = (grouped, singular) => {
478478
if (name === 'class') {
479479
if (singular) {
480-
return {
481-
singular: b.stmt(
482-
b.call(
483-
is_svg ? '$.svg_class_name_effect' : '$.class_name_effect',
484-
node_id,
485-
b.thunk(singular)
486-
)
487-
),
488-
grouped: b.stmt(b.call(is_svg ? '$.svg_class_name' : '$.class_name', node_id, singular))
489-
};
480+
return b.stmt(b.call(is_svg ? '$.svg_class_name' : '$.class_name', node_id, singular));
490481
}
491-
return {
492-
grouped: b.stmt(b.call(is_svg ? '$.svg_class_name' : '$.class_name', node_id, value))
493-
};
482+
return b.stmt(b.call(is_svg ? '$.svg_class_name' : '$.class_name', node_id, value));
494483
} else if (!DOMProperties.includes(name)) {
495484
if (singular) {
496-
return {
497-
singular: b.stmt(
498-
b.call(
499-
name.startsWith('xlink') ? '$.xlink_attr_effect' : '$.attr_effect',
500-
node_id,
501-
b.literal(name),
502-
b.thunk(singular)
503-
)
504-
),
505-
grouped: b.stmt(
506-
b.call(
507-
name.startsWith('xlink') ? '$.xlink_attr' : '$.attr',
508-
node_id,
509-
b.literal(name),
510-
grouped
511-
)
512-
)
513-
};
514-
}
515-
return {
516-
grouped: b.stmt(
485+
return b.stmt(
517486
b.call(
518487
name.startsWith('xlink') ? '$.xlink_attr' : '$.attr',
519488
node_id,
520489
b.literal(name),
521490
grouped
522491
)
492+
);
493+
}
494+
return b.stmt(
495+
b.call(
496+
name.startsWith('xlink') ? '$.xlink_attr' : '$.attr',
497+
node_id,
498+
b.literal(name),
499+
grouped
523500
)
524-
};
501+
);
525502
} else {
526-
return { grouped: b.stmt(b.assignment('=', b.member(node_id, b.id(name)), grouped)) };
503+
return b.stmt(b.assignment('=', b.member(node_id, b.id(name)), grouped));
527504
}
528505
};
529506

530507
if (attribute.metadata.dynamic) {
531-
const { grouped, singular } = assign(grouped_value, value);
532-
if (contains_call_expression && singular) {
533-
state.init.push(singular);
508+
const grouped = assign(grouped_value, value);
509+
if (contains_call_expression) {
510+
state.init.push(serialize_update(grouped));
534511
} else {
535512
state.update.push(grouped);
536513
}
537514
return true;
538515
} else {
539-
state.init.push(assign(grouped_value).grouped);
516+
state.init.push(assign(grouped_value));
540517
return false;
541518
}
542519
}

packages/svelte/tests/snapshot/samples/dynamic-attributes-casing/_expected/client/main.svelte.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ export default function Main($$anchor, $$props) {
1818
var custom_element_fooBar;
1919
var div_1 = $.sibling($.sibling(custom_element, true));
2020

21-
$.attr_effect(div_1, "foobar", y);
21+
$.render_effect(() => $.attr(div_1, "foobar", y()));
2222

2323
var svg_1 = $.sibling($.sibling(div_1, true));
2424

25-
$.attr_effect(svg_1, "viewBox", y);
25+
$.render_effect(() => $.attr(svg_1, "viewBox", y()));
2626

2727
var custom_element_1 = $.sibling($.sibling(svg_1, true));
2828

0 commit comments

Comments
 (0)