Skip to content

Commit 9bae34c

Browse files
committed
more
1 parent db030f9 commit 9bae34c

File tree

3 files changed

+44
-17
lines changed

3 files changed

+44
-17
lines changed

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

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,15 @@ export function RegularElement(node, context) {
208208
if (has_spread) {
209209
const attributes_id = b.id(context.state.scope.generate('attributes'));
210210

211-
build_element_spread_attributes(attributes, context, node, node_id, attributes_id);
211+
build_element_spread_attributes(
212+
attributes,
213+
context,
214+
node,
215+
node_id,
216+
attributes_id,
217+
(node.metadata.svg || node.metadata.mathml || is_custom_element_node(node)) && b.true,
218+
node.name.includes('-') && b.true
219+
);
212220

213221
// If value binding exists, that one takes care of calling $.init_select
214222
if (node.name === 'select' && !bindings.has('value')) {
@@ -478,8 +486,18 @@ function setup_select_synchronization(value_binding, context) {
478486
* @param {AST.RegularElement} element
479487
* @param {Identifier} element_id
480488
* @param {Identifier} attributes_id
489+
* @param {false | Expression} preserve_attribute_case
490+
* @param {false | Expression} is_custom_element
481491
*/
482-
function build_element_spread_attributes(attributes, context, element, element_id, attributes_id) {
492+
function build_element_spread_attributes(
493+
attributes,
494+
context,
495+
element,
496+
element_id,
497+
attributes_id,
498+
preserve_attribute_case,
499+
is_custom_element
500+
) {
483501
let needs_isolation = false;
484502

485503
/** @type {ObjectExpression['properties']} */
@@ -509,9 +527,6 @@ function build_element_spread_attributes(attributes, context, element, element_i
509527
attribute.type === 'SpreadAttribute' && attribute.metadata.expression.has_call;
510528
}
511529

512-
const preserve_attribute_case =
513-
element.metadata.svg || element.metadata.mathml || is_custom_element_node(element);
514-
515530
const update = b.stmt(
516531
b.assignment(
517532
'=',
@@ -522,9 +537,9 @@ function build_element_spread_attributes(attributes, context, element, element_i
522537
attributes_id,
523538
b.object(values),
524539
context.state.analysis.css.hash !== '' && b.literal(context.state.analysis.css.hash),
525-
preserve_attribute_case && b.true,
526-
is_ignored(element, 'hydration_attribute_changed') && b.true,
527-
element.name.includes('-') && b.true
540+
preserve_attribute_case,
541+
is_custom_element,
542+
is_ignored(element, 'hydration_attribute_changed') && b.true
528543
)
529544
)
530545
);

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ export function SvelteElement(node, context) {
9999
attributes,
100100
inner_context,
101101
element_id,
102-
attributes_id
102+
attributes_id,
103+
b.binary('!==', b.member(element_id, 'namespaceURI'), b.id('$.NAMESPACE_SVG')),
104+
b.call(b.member(b.member(element_id, 'nodeName'), 'includes'), b.literal('-'))
103105
);
104106
}
105107

@@ -159,9 +161,19 @@ export function SvelteElement(node, context) {
159161
* @param {ComponentContext} context
160162
* @param {Identifier} element_id
161163
* @param {Identifier} attributes_id
164+
* @param {false | Expression} preserve_attribute_case
165+
* @param {false | Expression} is_custom_element
162166
* @returns {boolean}
163167
*/
164-
function build_dynamic_element_attributes(element, attributes, context, element_id, attributes_id) {
168+
function build_dynamic_element_attributes(
169+
element,
170+
attributes,
171+
context,
172+
element_id,
173+
attributes_id,
174+
preserve_attribute_case,
175+
is_custom_element
176+
) {
165177
let needs_isolation = false;
166178
let is_reactive = false;
167179

@@ -202,9 +214,9 @@ function build_dynamic_element_attributes(element, attributes, context, element_
202214
is_reactive ? attributes_id : b.literal(null),
203215
b.object(values),
204216
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('-'))
217+
preserve_attribute_case,
218+
is_custom_element,
219+
is_ignored(element, 'hydration_attribute_changed') && b.true
208220
);
209221

210222
if (is_reactive) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ export function set_custom_element_data(node, prop, value) {
149149
* @param {Record<string, any> | undefined} prev
150150
* @param {Record<string, any>} next New attributes - this function mutates this object
151151
* @param {string} [css_hash]
152-
* @param {boolean} preserve_attribute_case
153-
* @param {boolean} [skip_warning]
152+
* @param {boolean} [preserve_attribute_case]
154153
* @param {boolean} [is_custom_element]
154+
* @param {boolean} [skip_warning]
155155
* @returns {Record<string, any>}
156156
*/
157157
export function set_attributes(
@@ -160,8 +160,8 @@ export function set_attributes(
160160
next,
161161
css_hash,
162162
preserve_attribute_case = false,
163-
skip_warning = false,
164-
is_custom_element = false
163+
is_custom_element = false,
164+
skip_warning = false
165165
) {
166166
var current = prev || {};
167167
var is_option_element = element.tagName === 'OPTION';

0 commit comments

Comments
 (0)