@@ -38,6 +38,38 @@ export const ssrTransformModel: DirectiveTransform = (dir, node, context) => {
38
38
}
39
39
}
40
40
41
+ function processOption ( plainNode : PlainElementNode ) {
42
+ if ( plainNode . tag === 'option' ) {
43
+ if ( plainNode . props . findIndex ( p => p . name === 'selected' ) === - 1 ) {
44
+ const value = findValueBinding ( plainNode )
45
+ plainNode . ssrCodegenNode ! . elements . push (
46
+ createConditionalExpression (
47
+ createCallExpression ( context . helper ( SSR_INCLUDE_BOOLEAN_ATTR ) , [
48
+ createConditionalExpression (
49
+ createCallExpression ( `Array.isArray` , [ model ] ) ,
50
+ createCallExpression ( context . helper ( SSR_LOOSE_CONTAIN ) , [
51
+ model ,
52
+ value
53
+ ] ) ,
54
+ createCallExpression ( context . helper ( SSR_LOOSE_EQUAL ) , [
55
+ model ,
56
+ value
57
+ ] )
58
+ )
59
+ ] ) ,
60
+ createSimpleExpression ( ' selected' , true ) ,
61
+ createSimpleExpression ( '' , true ) ,
62
+ false /* no newline */
63
+ )
64
+ )
65
+ }
66
+ } else if ( plainNode . tag === 'optgroup' ) {
67
+ plainNode . children . forEach ( option =>
68
+ processOption ( option as PlainElementNode )
69
+ )
70
+ }
71
+ }
72
+
41
73
if ( node . tagType === ElementTypes . ELEMENT ) {
42
74
const res : DirectiveTransformResult = { props : [ ] }
43
75
const defaultProps = [
@@ -130,32 +162,9 @@ export const ssrTransformModel: DirectiveTransform = (dir, node, context) => {
130
162
checkDuplicatedValue ( )
131
163
node . children = [ createInterpolation ( model , model . loc ) ]
132
164
} else if ( node . tag === 'select' ) {
133
- node . children . forEach ( option => {
134
- if ( option . type === NodeTypes . ELEMENT ) {
135
- const plainNode = option as PlainElementNode
136
- if ( plainNode . props . findIndex ( p => p . name === 'selected' ) === - 1 ) {
137
- const value = findValueBinding ( plainNode )
138
- plainNode . ssrCodegenNode ! . elements . push (
139
- createConditionalExpression (
140
- createCallExpression ( context . helper ( SSR_INCLUDE_BOOLEAN_ATTR ) , [
141
- createConditionalExpression (
142
- createCallExpression ( `Array.isArray` , [ model ] ) ,
143
- createCallExpression ( context . helper ( SSR_LOOSE_CONTAIN ) , [
144
- model ,
145
- value
146
- ] ) ,
147
- createCallExpression ( context . helper ( SSR_LOOSE_EQUAL ) , [
148
- model ,
149
- value
150
- ] )
151
- )
152
- ] ) ,
153
- createSimpleExpression ( ' selected' , true ) ,
154
- createSimpleExpression ( '' , true ) ,
155
- false /* no newline */
156
- )
157
- )
158
- }
165
+ node . children . forEach ( child => {
166
+ if ( child . type === NodeTypes . ELEMENT ) {
167
+ processOption ( child as PlainElementNode )
159
168
}
160
169
} )
161
170
} else {
0 commit comments