@@ -22,12 +22,7 @@ import {
2222 build_set_style
2323} from './shared/element.js' ;
2424import { process_children } from './shared/fragment.js' ;
25- import {
26- build_render_statement ,
27- build_template_chunk ,
28- get_expression_id ,
29- memoize_expression
30- } from './shared/utils.js' ;
25+ import { build_render_statement , build_template_chunk , get_expression_id } from './shared/utils.js' ;
3126import { visit_event_attribute } from './shared/events.js' ;
3227
3328/**
@@ -199,24 +194,23 @@ export function RegularElement(node, context) {
199194
200195 const node_id = context . state . node ;
201196
197+ /** If true, needs `__value` for inputs */
198+ const needs_special_value_handling =
199+ node . name === 'option' ||
200+ node . name === 'select' ||
201+ bindings . has ( 'group' ) ||
202+ bindings . has ( 'checked' ) ;
203+
202204 if ( has_spread ) {
203205 build_attribute_effect ( attributes , class_directives , style_directives , context , node , node_id ) ;
204206 } else {
205- /** If true, needs `__value` for inputs */
206- const needs_special_value_handling =
207- node . name === 'option' ||
208- node . name === 'select' ||
209- bindings . has ( 'group' ) ||
210- bindings . has ( 'checked' ) ;
211-
212207 for ( const attribute of /** @type {AST.Attribute[] } */ ( attributes ) ) {
213208 if ( is_event_attribute ( attribute ) ) {
214209 visit_event_attribute ( attribute , context ) ;
215210 continue ;
216211 }
217212
218213 if ( needs_special_value_handling && attribute . name === 'value' ) {
219- build_element_special_value_attribute ( node . name , node_id , attribute , context ) ;
220214 continue ;
221215 }
222216
@@ -391,6 +385,15 @@ export function RegularElement(node, context) {
391385 context . state . update . push ( b . stmt ( b . assignment ( '=' , dir , dir ) ) ) ;
392386 }
393387
388+ if ( ! has_spread && needs_special_value_handling ) {
389+ for ( const attribute of /** @type {AST.Attribute[] } */ ( attributes ) ) {
390+ if ( attribute . name === 'value' ) {
391+ build_element_special_value_attribute ( node . name , node_id , attribute , context ) ;
392+ break ;
393+ }
394+ }
395+ }
396+
394397 context . state . template . pop_element ( ) ;
395398}
396399
@@ -621,12 +624,7 @@ function build_element_special_value_attribute(element, node_id, attribute, cont
621624 element === 'select' && attribute . value !== true && ! is_text_attribute ( attribute ) ;
622625
623626 const { value, has_state } = build_attribute_value ( attribute . value , context , ( value , metadata ) =>
624- metadata . has_call
625- ? // if is a select with value we will also invoke `init_select` which need a reference before the template effect so we memoize separately
626- is_select_with_value
627- ? memoize_expression ( state , value )
628- : get_expression_id ( state . expressions , value )
629- : value
627+ metadata . has_call ? get_expression_id ( state . expressions , value ) : value
630628 ) ;
631629
632630 const evaluated = context . state . scope . evaluate ( value ) ;
@@ -651,10 +649,6 @@ function build_element_special_value_attribute(element, node_id, attribute, cont
651649 : inner_assignment
652650 ) ;
653651
654- if ( is_select_with_value ) {
655- state . init . push ( b . stmt ( b . call ( '$.init_select' , node_id , b . thunk ( value ) ) ) ) ;
656- }
657-
658652 if ( has_state ) {
659653 const id = b . id ( state . scope . generate ( `${ node_id . name } _value` ) ) ;
660654
@@ -668,4 +662,8 @@ function build_element_special_value_attribute(element, node_id, attribute, cont
668662 } else {
669663 state . init . push ( update ) ;
670664 }
665+
666+ if ( is_select_with_value ) {
667+ state . init . push ( b . stmt ( b . call ( '$.init_select' , node_id ) ) ) ;
668+ }
671669}
0 commit comments