Skip to content

Commit 228dd4d

Browse files
teobgenogtm-nayandummdidumm
authored
fix: svelte:element with dynamic this and spread attributes throws error (#9112)
fixes #9092 --------- Co-authored-by: gtmnayan <50981692+gtm-nayan@users.noreply.github.com> Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
1 parent 3191147 commit 228dd4d

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

.changeset/khaki-wolves-dream.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: handle `svelte:element` with dynamic this and spread attributes

packages/svelte/src/compiler/compile/render_dom/wrappers/Element/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,8 @@ export default class ElementWrapper extends Wrapper {
990990
const static_attributes = [];
991991
this.attributes.forEach((attr) => {
992992
if (attr instanceof SpreadAttributeWrapper) {
993-
static_attributes.push({ type: 'SpreadElement', argument: attr.node.expression.node });
993+
const snippet = { type: 'SpreadElement', argument: attr.node.expression.manipulate(block) };
994+
static_attributes.push(snippet);
994995
} else {
995996
const name = attr.property_name || attr.name;
996997
static_attributes.push(p`${name}: ${attr.get_value(block)}`);

packages/svelte/test/js/samples/svelte-element/expected.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function create_dynamic_element_3(ctx) {
2121
return {
2222
c() {
2323
svelte_element = element(static_value);
24-
set_dynamic_element_data(static_value)(svelte_element, { static_value, ...static_obj });
24+
set_dynamic_element_data(static_value)(svelte_element, { static_value, .../*static_obj*/ ctx[2] });
2525
toggle_class(svelte_element, "foo", static_value);
2626
},
2727
m(target, anchor) {
@@ -43,7 +43,7 @@ function create_dynamic_element_2(ctx) {
4343
return {
4444
c() {
4545
svelte_element = element(/*dynamic_value*/ ctx[0]);
46-
set_dynamic_element_data(/*dynamic_value*/ ctx[0])(svelte_element, { static_value, ...static_obj });
46+
set_dynamic_element_data(/*dynamic_value*/ ctx[0])(svelte_element, { static_value, .../*static_obj*/ ctx[2] });
4747
toggle_class(svelte_element, "foo", static_value);
4848
},
4949
m(target, anchor) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
html: '<div id="element" class="element-handler">this is div</div>'
3+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script>
2+
let props = {
3+
id: "element",
4+
class: "element-handler"
5+
}
6+
</script>
7+
<svelte:element this={"div"} {...props}>this is div</svelte:element>

0 commit comments

Comments
 (0)