@ -22,12 +22,7 @@ import {
build _set _style
} from './shared/element.js' ;
import { process _children } from './shared/fragment.js' ;
import {
build _render _statement ,
build _template _chunk ,
get _expression _id ,
memoize _expression
} from './shared/utils.js' ;
import { build _render _statement , build _template _chunk , get _expression _id } from './shared/utils.js' ;
import { visit _event _attribute } from './shared/events.js' ;
/ * *
@ -199,16 +194,16 @@ export function RegularElement(node, context) {
const node _id = context . state . node ;
/** If true, needs `__value` for inputs */
const needs _special _value _handling =
node . name === 'option' ||
node . name === 'select' ||
bindings . has ( 'group' ) ||
bindings . has ( 'checked' ) ;
if ( has _spread ) {
build _attribute _effect ( attributes , class _directives , style _directives , context , node , node _id ) ;
} else {
/** If true, needs `__value` for inputs */
const needs _special _value _handling =
node . name === 'option' ||
node . name === 'select' ||
bindings . has ( 'group' ) ||
bindings . has ( 'checked' ) ;
for ( const attribute of /** @type {AST.Attribute[]} */ ( attributes ) ) {
if ( is _event _attribute ( attribute ) ) {
visit _event _attribute ( attribute , context ) ;
@ -216,7 +211,6 @@ export function RegularElement(node, context) {
}
if ( needs _special _value _handling && attribute . name === 'value' ) {
build _element _special _value _attribute ( node . name , node _id , attribute , context ) ;
continue ;
}
@ -391,6 +385,15 @@ export function RegularElement(node, context) {
context . state . update . push ( b . stmt ( b . assignment ( '=' , dir , dir ) ) ) ;
}
if ( ! has _spread && needs _special _value _handling ) {
for ( const attribute of /** @type {AST.Attribute[]} */ ( attributes ) ) {
if ( attribute . name === 'value' ) {
build _element _special _value _attribute ( node . name , node _id , attribute , context ) ;
break ;
}
}
}
context . state . template . pop _element ( ) ;
}
@ -621,12 +624,7 @@ function build_element_special_value_attribute(element, node_id, attribute, cont
element === 'select' && attribute . value !== true && ! is _text _attribute ( attribute ) ;
const { value , has _state } = build _attribute _value ( attribute . value , context , ( value , metadata ) =>
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 ( state , value )
: get _expression _id ( state . expressions , value )
: value
metadata . has _call ? get _expression _id ( state . expressions , value ) : value
) ;
const evaluated = context . state . scope . evaluate ( value ) ;
@ -651,10 +649,6 @@ function build_element_special_value_attribute(element, node_id, attribute, cont
: inner _assignment
) ;
if ( is _select _with _value ) {
state . init . push ( b . stmt ( b . call ( '$.init_select' , node _id , b . thunk ( value ) ) ) ) ;
}
if ( has _state ) {
const id = b . id ( state . scope . generate ( ` ${ node _id . name } _value ` ) ) ;
@ -668,4 +662,8 @@ function build_element_special_value_attribute(element, node_id, attribute, cont
} else {
state . init . push ( update ) ;
}
if ( is _select _with _value ) {
state . init . push ( b . stmt ( b . call ( '$.init_select' , node _id ) ) ) ;
}
}