@@ -41,9 +41,7 @@ export function RegularElement(node, context) {
41
41
42
42
const optimiser = new PromiseOptimiser ( ) ;
43
43
44
- state . template . push ( b . literal ( `<${ node . name } ` ) ) ;
45
-
46
- // If this element needs special handling (like <select value>),
44
+ // If this element needs special handling (like <select value> / <option>),
47
45
// avoid calling build_element_attributes here to prevent evaluating/awaiting
48
46
// attribute expressions twice. We'll handle attributes in the special branch.
49
47
const is_select_special =
@@ -54,9 +52,13 @@ export function RegularElement(node, context) {
54
52
attribute . name === 'value' ) ||
55
53
attribute . type === 'SpreadAttribute'
56
54
) ;
55
+ const is_option_special = node . name === 'option' ;
56
+ const is_special = is_select_special || is_option_special ;
57
57
58
58
let body = /** @type {Expression | null } */ ( null ) ;
59
- if ( ! is_select_special ) {
59
+ if ( ! is_special ) {
60
+ // only open the tag in the non-special path
61
+ state . template . push ( b . literal ( `<${ node . name } ` ) ) ;
60
62
body = build_element_attributes ( node , { ...context , state } , optimiser . transform ) ;
61
63
state . template . push ( b . literal ( node_is_void ? '/>' : '>' ) ) ; // add `/>` for XHTML compliance
62
64
}
@@ -170,14 +172,32 @@ export function RegularElement(node, context) {
170
172
}
171
173
172
174
if ( node . name === 'option' ) {
173
- const attributes = build_spread_object (
175
+ /** @type {Array<AST.Attribute | AST.SpreadAttribute | AST.BindDirective> } */
176
+ const option_attributes = [ ] ;
177
+ /** @type {AST.ClassDirective[] } */
178
+ const class_directives = [ ] ;
179
+ /** @type {AST.StyleDirective[] } */
180
+ const style_directives = [ ] ;
181
+
182
+ for ( const attribute of node . attributes ) {
183
+ if (
184
+ attribute . type === 'Attribute' ||
185
+ attribute . type === 'BindDirective' ||
186
+ attribute . type === 'SpreadAttribute'
187
+ ) {
188
+ option_attributes . push ( attribute ) ;
189
+ } else if ( attribute . type === 'ClassDirective' ) {
190
+ class_directives . push ( attribute ) ;
191
+ } else if ( attribute . type === 'StyleDirective' ) {
192
+ style_directives . push ( attribute ) ;
193
+ }
194
+ }
195
+
196
+ const { object, css_hash, classes, styles, flags } = prepare_element_spread (
174
197
node ,
175
- node . attributes . filter (
176
- ( attribute ) =>
177
- attribute . type === 'Attribute' ||
178
- attribute . type === 'BindDirective' ||
179
- attribute . type === 'SpreadAttribute'
180
- ) ,
198
+ option_attributes ,
199
+ style_directives ,
200
+ class_directives ,
181
201
context ,
182
202
optimiser . transform
183
203
) ;
@@ -199,7 +219,9 @@ export function RegularElement(node, context) {
199
219
) ;
200
220
}
201
221
202
- const statement = b . stmt ( b . call ( '$$renderer.option' , attributes , body ) ) ;
222
+ const statement = b . stmt (
223
+ b . call ( '$$renderer.option' , object , body , css_hash , classes , styles , flags )
224
+ ) ;
203
225
204
226
if ( optimiser . expressions . length > 0 ) {
205
227
context . state . template . push (
0 commit comments