Skip to content

Commit bc4bb04

Browse files
committed
move more stuff
1 parent 0a1b9d6 commit bc4bb04

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ export function RegularElement(node, context) {
105105
break;
106106

107107
case 'Attribute':
108+
// `is` attributes need to be part of the template, otherwise they break
109+
if (attribute.name === 'is' && context.state.metadata.namespace === 'html') {
110+
const { value } = build_attribute_value(attribute.value, context);
111+
112+
if (value.type === 'Literal' && typeof value.value === 'string') {
113+
context.state.template.push(` is="${escape_html(value.value, true)}"`);
114+
continue;
115+
}
116+
}
117+
108118
attributes.push(attribute);
109119
lookup.set(attribute.name, attribute);
110120
break;
@@ -243,7 +253,7 @@ export function RegularElement(node, context) {
243253
attribute.name !== 'autofocus' &&
244254
(attribute.value === true || is_text_attribute(attribute))
245255
) {
246-
const name = get_attribute_name(node, attribute, context);
256+
const name = get_attribute_name(node, attribute);
247257
const value = is_text_attribute(attribute) ? attribute.value[0].data : true;
248258

249259
if (name !== 'class' || value) {
@@ -479,15 +489,6 @@ function build_element_spread_attributes(attributes, context, element, element_i
479489
if (attribute.type === 'Attribute') {
480490
const { value } = build_attribute_value(attribute.value, context);
481491

482-
if (
483-
attribute.name === 'is' &&
484-
value.type === 'Literal' &&
485-
context.state.metadata.namespace === 'html'
486-
) {
487-
context.state.template.push(` is="${escape_html(value.value, true)}"`);
488-
continue;
489-
}
490-
491492
if (
492493
is_event_attribute(attribute) &&
493494
(get_attribute_expression(attribute).type === 'ArrowFunctionExpression' ||
@@ -568,7 +569,7 @@ function build_element_spread_attributes(attributes, context, element, element_i
568569
*/
569570
function build_element_attribute_update_assignment(element, node_id, attribute, context) {
570571
const state = context.state;
571-
const name = get_attribute_name(element, attribute, context);
572+
const name = get_attribute_name(element, attribute);
572573
const is_svg = context.state.metadata.namespace === 'svg' || element.name === 'svg';
573574
const is_mathml = context.state.metadata.namespace === 'mathml';
574575
let { has_call, value } = build_attribute_value(attribute.value, context);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export function build_class_directives(
101101
/**
102102
* @param {AST.Attribute['value']} value
103103
* @param {ComponentContext} context
104+
* @returns {{ value: Expression, has_state: boolean, has_call: boolean }}
104105
*/
105106
export function build_attribute_value(value, context) {
106107
if (value === true) {
@@ -127,9 +128,8 @@ export function build_attribute_value(value, context) {
127128
/**
128129
* @param {AST.RegularElement | AST.SvelteElement} element
129130
* @param {AST.Attribute} attribute
130-
* @param {{ state: { metadata: { namespace: Namespace }}}} context
131131
*/
132-
export function get_attribute_name(element, attribute, context) {
132+
export function get_attribute_name(element, attribute) {
133133
if (!element.metadata.svg && !element.metadata.mathml) {
134134
return normalize_attribute(attribute.name);
135135
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export function get_states_and_calls(values) {
3636
* @param {Array<AST.Text | AST.ExpressionTag>} values
3737
* @param {(node: SvelteNode, state: any) => any} visit
3838
* @param {ComponentClientTransformState} state
39+
* @returns {{ value: Expression, has_state: boolean, has_call: boolean }}
3940
*/
4041
export function build_template_literal(values, visit, state) {
4142
/** @type {Expression[]} */

packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/element.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ export function build_element_attributes(node, context) {
217217
} else {
218218
for (const attribute of /** @type {AST.Attribute[]} */ (attributes)) {
219219
if (attribute.value === true || is_text_attribute(attribute)) {
220-
const name = get_attribute_name(node, attribute, context);
220+
const name = get_attribute_name(node, attribute);
221221
const literal_value = /** @type {Literal} */ (
222222
build_attribute_value(
223223
attribute.value,
@@ -239,7 +239,7 @@ export function build_element_attributes(node, context) {
239239
continue;
240240
}
241241

242-
const name = get_attribute_name(node, attribute, context);
242+
const name = get_attribute_name(node, attribute);
243243
const value = build_attribute_value(
244244
attribute.value,
245245
context,
@@ -264,9 +264,8 @@ export function build_element_attributes(node, context) {
264264
/**
265265
* @param {AST.RegularElement | AST.SvelteElement} element
266266
* @param {AST.Attribute} attribute
267-
* @param {{ state: { namespace: Namespace }}} context
268267
*/
269-
function get_attribute_name(element, attribute, context) {
268+
function get_attribute_name(element, attribute) {
270269
let name = attribute.name;
271270
if (!element.metadata.svg && !element.metadata.mathml) {
272271
name = name.toLowerCase();
@@ -334,7 +333,7 @@ function build_element_spread_attributes(
334333
const object = b.object(
335334
attributes.map((attribute) => {
336335
if (attribute.type === 'Attribute') {
337-
const name = get_attribute_name(element, attribute, context);
336+
const name = get_attribute_name(element, attribute);
338337
const value = build_attribute_value(
339338
attribute.value,
340339
context,

0 commit comments

Comments
 (0)