Skip to content

Commit db030f9

Browse files
committed
DRY
1 parent bc4bb04 commit db030f9

File tree

1 file changed

+13
-30
lines changed

1 file changed

+13
-30
lines changed

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

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -196,25 +196,21 @@ function build_dynamic_element_attributes(element, attributes, context, element_
196196
attribute.type === 'SpreadAttribute' && attribute.metadata.expression.has_call;
197197
}
198198

199+
const call = b.call(
200+
'$.set_attributes',
201+
element_id,
202+
is_reactive ? attributes_id : b.literal(null),
203+
b.object(values),
204+
context.state.analysis.css.hash !== '' && b.literal(context.state.analysis.css.hash),
205+
b.binary('!==', b.member(element_id, 'namespaceURI'), b.id('$.NAMESPACE_SVG')),
206+
is_ignored(element, 'hydration_attribute_changed') && b.true,
207+
b.call(b.member(b.member(element_id, 'nodeName'), 'includes'), b.literal('-'))
208+
);
209+
199210
if (is_reactive) {
200211
context.state.init.push(b.let(attributes_id));
201212

202-
const update = b.stmt(
203-
b.assignment(
204-
'=',
205-
attributes_id,
206-
b.call(
207-
'$.set_attributes',
208-
element_id,
209-
attributes_id,
210-
b.object(values),
211-
context.state.analysis.css.hash !== '' && b.literal(context.state.analysis.css.hash),
212-
b.binary('!==', b.member(element_id, 'namespaceURI'), b.id('$.NAMESPACE_SVG')),
213-
is_ignored(element, 'hydration_attribute_changed') && b.true,
214-
b.call(b.member(b.member(element_id, 'nodeName'), 'includes'), b.literal('-'))
215-
)
216-
)
217-
);
213+
const update = b.stmt(b.assignment('=', attributes_id, call));
218214

219215
if (needs_isolation) {
220216
context.state.init.push(build_update(update));
@@ -225,19 +221,6 @@ function build_dynamic_element_attributes(element, attributes, context, element_
225221
return true;
226222
}
227223

228-
context.state.init.push(
229-
b.stmt(
230-
b.call(
231-
'$.set_attributes',
232-
element_id,
233-
b.literal(null),
234-
b.object(values),
235-
context.state.analysis.css.hash !== '' && b.literal(context.state.analysis.css.hash),
236-
b.binary('!==', b.member(element_id, 'namespaceURI'), b.id('$.NAMESPACE_SVG')),
237-
is_ignored(element, 'hydration_attribute_changed') && b.true,
238-
b.call(b.member(b.member(element_id, 'nodeName'), 'includes'), b.literal('-'))
239-
)
240-
)
241-
);
224+
context.state.init.push(b.stmt(call));
242225
return false;
243226
}

0 commit comments

Comments
 (0)