|
|
|
@ -204,6 +204,34 @@ export function build_element_attributes(node, context) {
|
|
|
|
|
|
|
|
|
|
if (has_spread) {
|
|
|
|
|
build_element_spread_attributes(node, attributes, style_directives, class_directives, context);
|
|
|
|
|
if (node.name === 'option') {
|
|
|
|
|
option_has_value = true;
|
|
|
|
|
context.state.template.push(
|
|
|
|
|
b.call(
|
|
|
|
|
'$.maybe_selected',
|
|
|
|
|
b.id('$$payload'),
|
|
|
|
|
b.member(
|
|
|
|
|
b.call(
|
|
|
|
|
'$.spread_attributes',
|
|
|
|
|
build_spread_object(
|
|
|
|
|
node,
|
|
|
|
|
node.attributes.filter(
|
|
|
|
|
(attribute) =>
|
|
|
|
|
attribute.type === 'Attribute' ||
|
|
|
|
|
attribute.type === 'BindDirective' ||
|
|
|
|
|
attribute.type === 'SpreadAttribute'
|
|
|
|
|
),
|
|
|
|
|
context
|
|
|
|
|
),
|
|
|
|
|
b.null
|
|
|
|
|
),
|
|
|
|
|
'value',
|
|
|
|
|
false,
|
|
|
|
|
true
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
const css_hash = node.metadata.scoped ? context.state.analysis.css.hash : null;
|
|
|
|
|
|
|
|
|
@ -302,7 +330,7 @@ export function build_element_attributes(node, context) {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {AST.RegularElement | AST.SvelteElement} element
|
|
|
|
|
* @param {AST.Attribute} attribute
|
|
|
|
|
* @param {AST.Attribute | AST.BindDirective} attribute
|
|
|
|
|
*/
|
|
|
|
|
function get_attribute_name(element, attribute) {
|
|
|
|
|
let name = attribute.name;
|
|
|
|
@ -314,6 +342,36 @@ function get_attribute_name(element, attribute) {
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {AST.RegularElement | AST.SvelteElement} element
|
|
|
|
|
* @param {Array<AST.Attribute | AST.SpreadAttribute | AST.BindDirective>} attributes
|
|
|
|
|
* @param {ComponentContext} context
|
|
|
|
|
*/
|
|
|
|
|
export function build_spread_object(element, attributes, context) {
|
|
|
|
|
return b.object(
|
|
|
|
|
attributes.map((attribute) => {
|
|
|
|
|
if (attribute.type === 'Attribute') {
|
|
|
|
|
const name = get_attribute_name(element, attribute);
|
|
|
|
|
const value = build_attribute_value(
|
|
|
|
|
attribute.value,
|
|
|
|
|
context,
|
|
|
|
|
WHITESPACE_INSENSITIVE_ATTRIBUTES.includes(name)
|
|
|
|
|
);
|
|
|
|
|
return b.prop('init', b.key(name), value);
|
|
|
|
|
} else if (attribute.type === 'BindDirective') {
|
|
|
|
|
const name = get_attribute_name(element, attribute);
|
|
|
|
|
const value =
|
|
|
|
|
attribute.expression.type === 'SequenceExpression'
|
|
|
|
|
? b.call(attribute.expression.expressions[0])
|
|
|
|
|
: /** @type {Expression} */ (context.visit(attribute.expression));
|
|
|
|
|
return b.prop('init', b.key(name), value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return b.spread(/** @type {Expression} */ (context.visit(attribute)));
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param {AST.RegularElement | AST.SvelteElement} element
|
|
|
|
@ -364,21 +422,7 @@ function build_element_spread_attributes(
|
|
|
|
|
flags |= ELEMENT_PRESERVE_ATTRIBUTE_CASE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const object = b.object(
|
|
|
|
|
attributes.map((attribute) => {
|
|
|
|
|
if (attribute.type === 'Attribute') {
|
|
|
|
|
const name = get_attribute_name(element, attribute);
|
|
|
|
|
const value = build_attribute_value(
|
|
|
|
|
attribute.value,
|
|
|
|
|
context,
|
|
|
|
|
WHITESPACE_INSENSITIVE_ATTRIBUTES.includes(name)
|
|
|
|
|
);
|
|
|
|
|
return b.prop('init', b.key(name), value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return b.spread(/** @type {Expression} */ (context.visit(attribute)));
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
const object = build_spread_object(element, attributes, context);
|
|
|
|
|
|
|
|
|
|
const css_hash =
|
|
|
|
|
element.metadata.scoped && context.state.analysis.css.hash
|
|
|
|
|