@@ -307,7 +307,15 @@ export function RegularElement(node, context) {
307307 } else if ( is_custom_element ) {
308308 build_custom_element_attribute_update_assignment ( node_id , attribute , context ) ;
309309 } else {
310- build_element_attribute_update_assignment ( node , node_id , attribute , attributes , context ) ;
310+ const { value, has_state } = build_attribute_value (
311+ attribute . value ,
312+ context ,
313+ ( value , metadata ) => ( metadata . has_call ? get_expression_id ( context . state , value ) : value )
314+ ) ;
315+
316+ const update = build_element_attribute_update ( node , node_id , name , value , attributes ) ;
317+
318+ ( has_state ? context . state . update : context . state . init ) . push ( b . stmt ( update ) ) ;
311319 }
312320 }
313321 }
@@ -576,37 +584,29 @@ export function build_style_directives_object(style_directives, context) {
576584 * Returns true if attribute is deemed reactive, false otherwise.
577585 * @param {AST.RegularElement } element
578586 * @param {Identifier } node_id
579- * @param {AST.Attribute } attribute
587+ * @param {string } name
588+ * @param {Expression } value
580589 * @param {Array<AST.Attribute | AST.SpreadAttribute> } attributes
581- * @param {ComponentContext } context
582590 */
583- function build_element_attribute_update_assignment (
584- element ,
585- node_id ,
586- attribute ,
587- attributes ,
588- context
589- ) {
590- const state = context . state ;
591- const name = get_attribute_name ( element , attribute ) ;
591+ function build_element_attribute_update ( element , node_id , name , value , attributes ) {
592+ if ( name === 'muted' ) {
593+ // Special case for Firefox who needs it set as a property in order to work
594+ return b . assignment ( '=' , b . member ( node_id , b . id ( 'muted' ) ) , value ) ;
595+ }
592596
593- let { value , has_state } = build_attribute_value ( attribute . value , context , ( value , metadata ) =>
594- metadata . has_call ? get_expression_id ( state , value ) : value
595- ) ;
597+ if ( name === ' value' ) {
598+ return b . call ( '$.set_value' , node_id , value ) ;
599+ }
596600
597- /** @type {Statement } */
598- let update ;
601+ if ( name === 'checked' ) {
602+ return b . call ( '$.set_checked' , node_id , value ) ;
603+ }
599604
600- if ( name === 'muted' ) {
601- // Special case for Firefox who needs it set as a property in order to work
602- update = b . stmt ( b . assignment ( '=' , b . member ( node_id , b . id ( 'muted' ) ) , value ) ) ;
603- } else if ( name === 'value' ) {
604- update = b . stmt ( b . call ( '$.set_value' , node_id , value ) ) ;
605- } else if ( name === 'checked' ) {
606- update = b . stmt ( b . call ( '$.set_checked' , node_id , value ) ) ;
607- } else if ( name === 'selected' ) {
608- update = b . stmt ( b . call ( '$.set_selected' , node_id , value ) ) ;
609- } else if (
605+ if ( name === 'selected' ) {
606+ return b . call ( '$.set_selected' , node_id , value ) ;
607+ }
608+
609+ if (
610610 // If we would just set the defaultValue property, it would override the value property,
611611 // because it is set in the template which implicitly means it's also setting the default value,
612612 // and if one updates the default value while the input is pristine it will also update the
@@ -617,35 +617,34 @@ function build_element_attribute_update_assignment(
617617 ) ||
618618 ( element . name === 'textarea' && element . fragment . nodes . length > 0 ) )
619619 ) {
620- update = b . stmt ( b . call ( '$.set_default_value' , node_id , value ) ) ;
621- } else if (
620+ return b . call ( '$.set_default_value' , node_id , value ) ;
621+ }
622+
623+ if (
622624 // See defaultValue comment
623625 name === 'defaultChecked' &&
624626 attributes . some (
625627 ( attr ) => attr . type === 'Attribute' && attr . name === 'checked' && attr . value === true
626628 )
627629 ) {
628- update = b . stmt ( b . call ( '$.set_default_checked' , node_id , value ) ) ;
629- } else if ( is_dom_property ( name ) ) {
630- update = b . stmt ( b . assignment ( '=' , b . member ( node_id , name ) , value ) ) ;
631- } else {
632- const callee = name . startsWith ( 'xlink' ) ? '$.set_xlink_attribute' : '$.set_attribute' ;
633- update = b . stmt (
634- b . call (
635- callee ,
636- node_id ,
637- b . literal ( name ) ,
638- value ,
639- is_ignored ( element , 'hydration_attribute_changed' ) && b . true
640- )
641- ) ;
630+ return b . call ( '$.set_default_checked' , node_id , value ) ;
642631 }
643632
644- ( has_state ? state . update : state . init ) . push ( update ) ;
633+ if ( is_dom_property ( name ) ) {
634+ return b . assignment ( '=' , b . member ( node_id , name ) , value ) ;
635+ }
636+
637+ return b . call (
638+ name . startsWith ( 'xlink' ) ? '$.set_xlink_attribute' : '$.set_attribute' ,
639+ node_id ,
640+ b . literal ( name ) ,
641+ value ,
642+ is_ignored ( element , 'hydration_attribute_changed' ) && b . true
643+ ) ;
645644}
646645
647646/**
648- * Like `build_element_attribute_update_assignment ` but without any special attribute treatment.
647+ * Like `build_element_attribute_update ` but without any special attribute treatment.
649648 * @param {Identifier } node_id
650649 * @param {AST.Attribute } attribute
651650 * @param {ComponentContext } context
0 commit comments