@ -29,7 +29,8 @@ import {
build _render _statement ,
build _template _chunk ,
build _update _assignment ,
get _expression _id
get _expression _id ,
memoize _expression
} from './shared/utils.js' ;
import { visit _event _attribute } from './shared/events.js' ;
@ -532,20 +533,32 @@ function build_element_attribute_update_assignment(
const is _svg = context . state . metadata . namespace === 'svg' || element . name === 'svg' ;
const is _mathml = context . state . metadata . namespace === 'mathml' ;
const is _autofocus = name === 'autofocus' ;
let { value , has _state } = build _attribute _value ( attribute . value , context , ( value , metadata ) =>
metadata . has _call ? get _expression _id ( state , value ) : value
metadata . has _call
? // if it's autofocus we will not add this to a template effect so we don't want to get the expression id
// but separately memoize the expression
is _autofocus
? memoize _expression ( state , value )
: get _expression _id ( state , value )
: value
) ;
if ( name === 'autofocus' ) {
if ( is_autofocus ) {
state . init . push ( b . stmt ( b . call ( '$.autofocus' , node _id , value ) ) ) ;
return false ;
}
// Special case for Firefox who needs it set as a property in order to work
if ( name === 'muted' ) {
if ( ! has _state ) {
state . init . push ( b . stmt ( b . assignment ( '=' , b . member ( node _id , b . id ( 'muted' ) ) , value ) ) ) ;
return false ;
}
state . update . push ( b . stmt ( b . assignment ( '=' , b . member ( node _id , b . id ( 'muted' ) ) , value ) ) ) ;
return false ;
}
/** @type {Statement} */
let update ;
@ -660,8 +673,18 @@ 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 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
element === 'select' && attribute . value !== true && ! is _text _attribute ( attribute ) ;
const { value , has _state } = build _attribute _value ( attribute . value , context , ( value , metadata ) =>
metadata . has _call ? get _expression _id ( state , value ) : value
metadata . has _call
? // if is a select with value we will also invoke `init_select` which need a reference before the template effect so we memoize separately
is _select _with _value
? memoize _expression ( context . state , value )
: get _expression _id ( state , value )
: value
) ;
const inner _assignment = b . assignment (
@ -674,11 +697,6 @@ function build_element_special_value_attribute(element, node_id, attribute, cont
)
) ;
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
element === 'select' && attribute . value !== true && ! is _text _attribute ( attribute ) ;
const update = b . stmt (
is _select _with _value
? b . sequence ( [