@@ -7,12 +7,11 @@ import { is_void } from '../../../../../utils.js';
77import { dev , locator } from '../../../../state.js' ;
88import * as b from '#compiler/builders' ;
99import { clean_nodes , determine_namespace_for_children } from '../../utils.js' ;
10- import { is_custom_element_node } from '../../../nodes.js' ;
1110import {
12- ELEMENT_IS_NAMESPACED ,
13- ELEMENT_PRESERVE_ATTRIBUTE_CASE
14- } from '../../../../../constants.js' ;
15- import { build_element_attributes , build_spread_object } from './shared/element.js' ;
11+ build_element_attributes ,
12+ build_spread_object ,
13+ prepare_element_spread
14+ } from './shared/element.js' ;
1615import {
1716 process_children ,
1817 build_template ,
@@ -43,8 +42,24 @@ export function RegularElement(node, context) {
4342 const optimiser = new PromiseOptimiser ( ) ;
4443
4544 state . template . push ( b . literal ( `<${ node . name } ` ) ) ;
46- const body = build_element_attributes ( node , { ...context , state } , optimiser . transform ) ;
47- state . template . push ( b . literal ( node_is_void ? '/>' : '>' ) ) ; // add `/>` for XHTML compliance
45+
46+ // If this element needs special handling (like <select value>),
47+ // avoid calling build_element_attributes here to prevent evaluating/awaiting
48+ // attribute expressions twice. We'll handle attributes in the special branch.
49+ const is_select_special =
50+ node . name === 'select' &&
51+ node . attributes . some (
52+ ( attribute ) =>
53+ ( ( attribute . type === 'Attribute' || attribute . type === 'BindDirective' ) &&
54+ attribute . name === 'value' ) ||
55+ attribute . type === 'SpreadAttribute'
56+ ) ;
57+
58+ let body = /** @type {Expression | null } */ ( null ) ;
59+ if ( ! is_select_special ) {
60+ body = build_element_attributes ( node , { ...context , state } , optimiser . transform ) ;
61+ state . template . push ( b . literal ( node_is_void ? '/>' : '>' ) ) ; // add `/>` for XHTML compliance
62+ }
4863
4964 if ( ( node . name === 'script' || node . name === 'style' ) && node . fragment . nodes . length === 1 ) {
5065 state . template . push (
@@ -100,15 +115,7 @@ export function RegularElement(node, context) {
100115 ) ;
101116 }
102117
103- if (
104- node . name === 'select' &&
105- node . attributes . some (
106- ( attribute ) =>
107- ( ( attribute . type === 'Attribute' || attribute . type === 'BindDirective' ) &&
108- attribute . name === 'value' ) ||
109- attribute . type === 'SpreadAttribute'
110- )
111- ) {
118+ if ( is_select_special ) {
112119 /** @type {Array<AST.Attribute | AST.SpreadAttribute | AST.BindDirective> } */
113120 const select_attributes = [ ] ;
114121 /** @type {AST.ClassDirective[] } */
@@ -130,58 +137,15 @@ export function RegularElement(node, context) {
130137 }
131138 }
132139
133- const attributes_expression = build_spread_object (
140+ const { object , css_hash , classes , styles , flags } = prepare_element_spread (
134141 node ,
135142 select_attributes ,
143+ style_directives ,
144+ class_directives ,
136145 context ,
137146 optimiser . transform
138147 ) ;
139148
140- /** @type {ObjectExpression | undefined } */
141- let classes ;
142- if ( class_directives . length ) {
143- const properties = class_directives . map ( ( directive ) =>
144- b . init (
145- directive . name ,
146- directive . expression . type === 'Identifier' && directive . expression . name === directive . name
147- ? b . id ( directive . name )
148- : /** @type {Expression } */ ( context . visit ( directive . expression ) )
149- )
150- ) ;
151-
152- classes = b . object ( properties ) ;
153- }
154-
155- /** @type {ObjectExpression | undefined } */
156- let styles ;
157- if ( style_directives . length > 0 ) {
158- const properties = style_directives . map ( ( directive ) =>
159- b . init (
160- directive . name ,
161- directive . value === true
162- ? b . id ( directive . name )
163- : build_attribute_value ( directive . value , context , optimiser . transform , true )
164- )
165- ) ;
166-
167- styles = b . object ( properties ) ;
168- }
169-
170- let flags = 0 ;
171-
172- if ( node . metadata . svg || node . metadata . mathml ) {
173- flags |= ELEMENT_IS_NAMESPACED | ELEMENT_PRESERVE_ATTRIBUTE_CASE ;
174- } else if ( is_custom_element_node ( node ) ) {
175- flags |= ELEMENT_PRESERVE_ATTRIBUTE_CASE ;
176- }
177-
178- const css_hash =
179- node . metadata . scoped && context . state . analysis . css . hash
180- ? b . literal ( context . state . analysis . css . hash )
181- : undefined ;
182-
183- const flag_literal = flags ? b . literal ( flags ) : undefined ;
184-
185149 const inner_state = { ...state , template : [ ] , init : [ ] } ;
186150 process_children ( trimmed , { ...context , state : inner_state } ) ;
187151
@@ -191,15 +155,7 @@ export function RegularElement(node, context) {
191155 ) ;
192156
193157 const statement = b . stmt (
194- b . call (
195- '$$renderer.select' ,
196- attributes_expression ,
197- css_hash ,
198- classes ,
199- styles ,
200- flag_literal ,
201- fn
202- )
158+ b . call ( '$$renderer.select' , object , fn , css_hash , classes , styles , flags )
203159 ) ;
204160
205161 if ( optimiser . expressions . length > 0 ) {
0 commit comments