|
|
|
@ -229,17 +229,16 @@ export function RegularElement(node, context) {
|
|
|
|
|
(attribute.value === true || is_text_attribute(attribute))
|
|
|
|
|
) {
|
|
|
|
|
const name = get_attribute_name(node, attribute, context);
|
|
|
|
|
const literal_value = /** @type {Literal} */ (
|
|
|
|
|
build_attribute_value(attribute.value, context)[1]
|
|
|
|
|
).value;
|
|
|
|
|
if (name !== 'class' || literal_value) {
|
|
|
|
|
const value = is_text_attribute(attribute) ? attribute.value[0].data : true;
|
|
|
|
|
|
|
|
|
|
if (name !== 'class' || value) {
|
|
|
|
|
// TODO namespace=foreign probably doesn't want to do template stuff at all and instead use programmatic methods
|
|
|
|
|
// to create the elements it needs.
|
|
|
|
|
context.state.template.push(
|
|
|
|
|
` ${attribute.name}${
|
|
|
|
|
is_boolean_attribute(name) && literal_value === true
|
|
|
|
|
is_boolean_attribute(name) && value === true
|
|
|
|
|
? ''
|
|
|
|
|
: `="${literal_value === true ? '' : escape_html(literal_value, true)}"`
|
|
|
|
|
: `="${value === true ? '' : escape_html(value, true)}"`
|
|
|
|
|
}`
|
|
|
|
|
);
|
|
|
|
|
continue;
|
|
|
|
@ -440,7 +439,7 @@ function build_element_spread_attributes(
|
|
|
|
|
if (attribute.type === 'Attribute') {
|
|
|
|
|
const name = get_attribute_name(element, attribute, context);
|
|
|
|
|
// TODO: handle has_call
|
|
|
|
|
const [, value] = build_attribute_value(attribute.value, context);
|
|
|
|
|
const { value } = build_attribute_value(attribute.value, context);
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
name === 'is' &&
|
|
|
|
@ -554,7 +553,7 @@ function build_element_attribute_update_assignment(element, node_id, attribute,
|
|
|
|
|
const name = get_attribute_name(element, attribute, context);
|
|
|
|
|
const is_svg = context.state.metadata.namespace === 'svg' || element.name === 'svg';
|
|
|
|
|
const is_mathml = context.state.metadata.namespace === 'mathml';
|
|
|
|
|
let [has_call, value] = build_attribute_value(attribute.value, context);
|
|
|
|
|
let { has_call, value } = build_attribute_value(attribute.value, context);
|
|
|
|
|
|
|
|
|
|
// The foreign namespace doesn't have any special handling, everything goes through the attr function
|
|
|
|
|
if (context.state.metadata.namespace === 'foreign') {
|
|
|
|
@ -636,7 +635,7 @@ function build_element_attribute_update_assignment(element, node_id, attribute,
|
|
|
|
|
function build_custom_element_attribute_update_assignment(node_id, attribute, context) {
|
|
|
|
|
const state = context.state;
|
|
|
|
|
const name = attribute.name; // don't lowercase, as we set the element's property, which might be case sensitive
|
|
|
|
|
let [has_call, value] = build_attribute_value(attribute.value, context);
|
|
|
|
|
let { has_call, value } = build_attribute_value(attribute.value, context);
|
|
|
|
|
|
|
|
|
|
const update = b.stmt(b.call('$.set_custom_element_data', node_id, b.literal(name), value));
|
|
|
|
|
|
|
|
|
@ -665,7 +664,7 @@ function build_custom_element_attribute_update_assignment(node_id, attribute, co
|
|
|
|
|
*/
|
|
|
|
|
function build_element_special_value_attribute(element, node_id, attribute, context) {
|
|
|
|
|
const state = context.state;
|
|
|
|
|
const [, value] = build_attribute_value(attribute.value, context);
|
|
|
|
|
const { value } = build_attribute_value(attribute.value, context);
|
|
|
|
|
|
|
|
|
|
const inner_assignment = b.assignment(
|
|
|
|
|
'=',
|
|
|
|
@ -676,7 +675,7 @@ function build_element_special_value_attribute(element, node_id, attribute, cont
|
|
|
|
|
value
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
const is_reactive = attribute.metadata.expression.has_state;
|
|
|
|
|
|
|
|
|
|
const is_select_with_value =
|
|
|
|
|
// attribute.metadata.dynamic would give false negatives because even if the value does not change,
|
|
|
|
|
// the inner options could still change, so we need to always treat it as reactive
|
|
|
|
@ -699,7 +698,7 @@ function build_element_special_value_attribute(element, node_id, attribute, cont
|
|
|
|
|
state.init.push(b.stmt(b.call('$.init_select', node_id, b.thunk(value))));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (is_reactive) {
|
|
|
|
|
if (attribute.metadata.expression.has_state) {
|
|
|
|
|
const id = state.scope.generate(`${node_id.name}_value`);
|
|
|
|
|
build_update_assignment(
|
|
|
|
|
state,
|
|
|
|
|