Skip to content

Commit

Permalink
fix: svelte:element with dynamic this and spread attributes throws error
Browse files Browse the repository at this point in the history
  • Loading branch information
teobgeno committed Aug 17, 2023
1 parent e135d44 commit 49a6c21
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/silly-shrimps-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 1,5 @@
---
'svelte': patch
---

fix: svelte:element with dynamic this and spread attributes throws error
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 37,7 @@ import {
import create_debugging_comment from '../shared/create_debugging_comment.js';
import { push_array } from '../../../../utils/push_array.js';
import CommentWrapper from '../Comment.js';
import flatten_reference from '../../../../compile/utils/flatten_reference.js';

const regex_contains_radio_or_checkbox_or_file = /radio|checkbox|file/;
const regex_contains_radio_or_checkbox_or_range_or_file = /radio|checkbox|range|file/;
Expand Down Expand Up @@ -990,7 991,9 @@ export default class ElementWrapper extends Wrapper {
const static_attributes = [];
this.attributes.forEach((attr) => {
if (attr instanceof SpreadAttributeWrapper) {
static_attributes.push({ type: 'SpreadElement', argument: attr.node.expression.node });
const { name } = flatten_reference(attr.node.expression.node);
const snippet = { type: 'SpreadElement', argument: attr.node.expression.manipulate(block) };
static_attributes.push(p`${name}: {${snippet}}`);
} else {
const name = attr.property_name || attr.name;
static_attributes.push(p`${name}: ${attr.get_value(block)}`);
Expand Down
14 changes: 12 additions & 2 deletions packages/svelte/test/js/samples/svelte-element/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 21,12 @@ function create_dynamic_element_3(ctx) {
return {
c() {
svelte_element = element(static_value);
set_dynamic_element_data(static_value)(svelte_element, { static_value, ...static_obj });

set_dynamic_element_data(static_value)(svelte_element, {
static_value,
static_obj: { .../*static_obj*/ ctx[2] }
});

toggle_class(svelte_element, "foo", static_value);
},
m(target, anchor) {
Expand All @@ -43,7 48,12 @@ function create_dynamic_element_2(ctx) {
return {
c() {
svelte_element = element(/*dynamic_value*/ ctx[0]);
set_dynamic_element_data(/*dynamic_value*/ ctx[0])(svelte_element, { static_value, ...static_obj });

set_dynamic_element_data(/*dynamic_value*/ ctx[0])(svelte_element, {
static_value,
static_obj: { .../*static_obj*/ ctx[2] }
});

toggle_class(svelte_element, "foo", static_value);
},
m(target, anchor) {
Expand Down

0 comments on commit 49a6c21

Please sign in to comment.