@@ -22,12 +22,7 @@ import {
22
22
build_set_style
23
23
} from './shared/element.js' ;
24
24
import { 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' ;
31
26
import { visit_event_attribute } from './shared/events.js' ;
32
27
33
28
/**
@@ -199,24 +194,23 @@ export function RegularElement(node, context) {
199
194
200
195
const node_id = context . state . node ;
201
196
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
+
202
204
if ( has_spread ) {
203
205
build_attribute_effect ( attributes , class_directives , style_directives , context , node , node_id ) ;
204
206
} 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
-
212
207
for ( const attribute of /** @type {AST.Attribute[] } */ ( attributes ) ) {
213
208
if ( is_event_attribute ( attribute ) ) {
214
209
visit_event_attribute ( attribute , context ) ;
215
210
continue ;
216
211
}
217
212
218
213
if ( needs_special_value_handling && attribute . name === 'value' ) {
219
- build_element_special_value_attribute ( node . name , node_id , attribute , context ) ;
220
214
continue ;
221
215
}
222
216
@@ -391,6 +385,15 @@ export function RegularElement(node, context) {
391
385
context . state . update . push ( b . stmt ( b . assignment ( '=' , dir , dir ) ) ) ;
392
386
}
393
387
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
+
394
397
context . state . template . pop_element ( ) ;
395
398
}
396
399
@@ -621,12 +624,7 @@ function build_element_special_value_attribute(element, node_id, attribute, cont
621
624
element === 'select' && attribute . value !== true && ! is_text_attribute ( attribute ) ;
622
625
623
626
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
630
628
) ;
631
629
632
630
const evaluated = context . state . scope . evaluate ( value ) ;
@@ -651,10 +649,6 @@ function build_element_special_value_attribute(element, node_id, attribute, cont
651
649
: inner_assignment
652
650
) ;
653
651
654
- if ( is_select_with_value ) {
655
- state . init . push ( b . stmt ( b . call ( '$.init_select' , node_id , b . thunk ( value ) ) ) ) ;
656
- }
657
-
658
652
if ( has_state ) {
659
653
const id = b . id ( state . scope . generate ( `${ node_id . name } _value` ) ) ;
660
654
@@ -668,4 +662,8 @@ function build_element_special_value_attribute(element, node_id, attribute, cont
668
662
} else {
669
663
state . init . push ( update ) ;
670
664
}
665
+
666
+ if ( is_select_with_value ) {
667
+ state . init . push ( b . stmt ( b . call ( '$.init_select' , node_id ) ) ) ;
668
+ }
671
669
}
0 commit comments