Skip to content

Commit 8bafc73

Browse files
committed
simplify
1 parent 4e079b5 commit 8bafc73

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ function build_dynamic_element_attributes(attributes, context, element_id) {
200200
element_id,
201201
b.id(id),
202202
b.object(values),
203-
b.literal(context.state.analysis.css.hash)
203+
context.state.analysis.css.hash !== '' && b.literal(context.state.analysis.css.hash)
204204
)
205205
)
206206
);
@@ -221,7 +221,7 @@ function build_dynamic_element_attributes(attributes, context, element_id) {
221221
element_id,
222222
b.literal(null),
223223
b.object(values),
224-
b.literal(context.state.analysis.css.hash)
224+
context.state.analysis.css.hash !== '' && b.literal(context.state.analysis.css.hash)
225225
)
226226
)
227227
);

packages/svelte/src/internal/client/dom/elements/attributes.js

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,15 @@ export function set_xlink_attribute(dom, attribute, value) {
129129
* @param {any} node
130130
* @param {string} prop
131131
* @param {any} value
132-
* @param {string} [css_hash]
133132
*/
134-
export function set_custom_element_data(node, prop, value, css_hash) {
133+
export function set_custom_element_data(node, prop, value) {
135134
if (prop in node) {
136135
var curr_val = node[prop];
137136
var next_val = typeof curr_val === 'boolean' && value === '' ? true : value;
138137
if (typeof curr_val !== 'object' || curr_val !== next_val) {
139138
node[prop] = next_val;
140139
}
141140
} else {
142-
if (css_hash && css_hash.length !== 0 && prop === 'class') {
143-
if (value) value += ' ';
144-
value += css_hash;
145-
}
146141
set_attribute(node, prop, value);
147142
}
148143
}
@@ -158,7 +153,6 @@ export function set_custom_element_data(node, prop, value, css_hash) {
158153
* @returns {Record<string, any>}
159154
*/
160155
export function set_attributes(element, prev, next, lowercase_attributes, css_hash, skip_warning) {
161-
var has_hash = css_hash.length !== 0;
162156
var current = prev || {};
163157
var is_option_element = element.tagName === 'OPTION';
164158

@@ -168,8 +162,8 @@ export function set_attributes(element, prev, next, lowercase_attributes, css_ha
168162
}
169163
}
170164

171-
if (has_hash && !next.class) {
172-
next.class = '';
165+
if (css_hash !== '') {
166+
next.class = next.class ? next.class + ' ' + css_hash : css_hash;
173167
}
174168

175169
var setters = setters_cache.get(element.nodeName);
@@ -284,11 +278,6 @@ export function set_attributes(element, prev, next, lowercase_attributes, css_ha
284278
element[name] = value;
285279
}
286280
} else if (typeof value !== 'function') {
287-
if (has_hash && name === 'class') {
288-
if (value) value += ' ';
289-
value += css_hash;
290-
}
291-
292281
set_attribute(element, name, value);
293282
}
294283
}
@@ -314,18 +303,22 @@ export function set_attributes(element, prev, next, lowercase_attributes, css_ha
314303
* @param {Element} node
315304
* @param {Record<string, any> | undefined} prev
316305
* @param {Record<string, any>} next The new attributes - this function mutates this object
317-
* @param {string} css_hash
306+
* @param {string} [css_hash]
318307
*/
319-
export function set_dynamic_element_attributes(node, prev, next, css_hash) {
308+
export function set_dynamic_element_attributes(node, prev, next, css_hash = '') {
320309
if (node.tagName.includes('-')) {
321310
for (var key in prev) {
322311
if (!(key in next)) {
323312
next[key] = null;
324313
}
325314
}
326315

316+
if (css_hash !== '') {
317+
next.class = next.class ? next.class + ' ' + css_hash : css_hash;
318+
}
319+
327320
for (key in next) {
328-
set_custom_element_data(node, key, next[key], css_hash);
321+
set_custom_element_data(node, key, next[key]);
329322
}
330323

331324
return next;

0 commit comments

Comments
 (0)