Skip to content

Commit 0a1b9d6

Browse files
committed
getting closer
1 parent dbc1e54 commit 0a1b9d6

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,17 @@ export function SvelteElement(node, context) {
9090
);
9191
}
9292
} else {
93+
const attributes_id = b.id(context.state.scope.generate('attributes'));
94+
9395
// Always use spread because we don't know whether the element is a custom element or not,
9496
// therefore we need to do the "how to set an attribute" logic at runtime.
95-
is_attributes_reactive =
96-
build_dynamic_element_attributes(node, attributes, inner_context, element_id) !== null;
97+
is_attributes_reactive = build_dynamic_element_attributes(
98+
node,
99+
attributes,
100+
inner_context,
101+
element_id,
102+
attributes_id
103+
);
97104
}
98105

99106
// class/style directives must be applied last since they could override class/style attributes
@@ -151,9 +158,10 @@ export function SvelteElement(node, context) {
151158
* @param {Array<AST.Attribute | AST.SpreadAttribute>} attributes
152159
* @param {ComponentContext} context
153160
* @param {Identifier} element_id
161+
* @param {Identifier} attributes_id
154162
* @returns {boolean}
155163
*/
156-
function build_dynamic_element_attributes(element, attributes, context, element_id) {
164+
function build_dynamic_element_attributes(element, attributes, context, element_id, attributes_id) {
157165
let needs_isolation = false;
158166
let is_reactive = false;
159167

@@ -189,17 +197,16 @@ function build_dynamic_element_attributes(element, attributes, context, element_
189197
}
190198

191199
if (is_reactive) {
192-
const id = b.id(context.state.scope.generate('attributes'));
193-
context.state.init.push(b.let(id));
200+
context.state.init.push(b.let(attributes_id));
194201

195202
const update = b.stmt(
196203
b.assignment(
197204
'=',
198-
id,
205+
attributes_id,
199206
b.call(
200207
'$.set_attributes',
201208
element_id,
202-
id,
209+
attributes_id,
203210
b.object(values),
204211
context.state.analysis.css.hash !== '' && b.literal(context.state.analysis.css.hash),
205212
b.binary('!==', b.member(element_id, 'namespaceURI'), b.id('$.NAMESPACE_SVG')),

0 commit comments

Comments
 (0)