@@ -20,6 +20,7 @@ import { ssrProcessFor } from './transforms/ssrVFor'
20
20
import { ssrProcessSlotOutlet } from './transforms/ssrTransformSlotOutlet'
21
21
import { ssrProcessComponent } from './transforms/ssrTransformComponent'
22
22
import { ssrProcessElement } from './transforms/ssrTransformElement'
23
+ import { createSSRCompilerError , SSRErrorCodes } from './errors'
23
24
24
25
// Because SSR codegen output is completely different from client-side output
25
26
// (e.g. multiple elements can be concatenated into a single template literal
@@ -115,24 +116,70 @@ export function processChildren(
115
116
}
116
117
for ( let i = 0 ; i < children . length ; i ++ ) {
117
118
const child = children [ i ]
118
- if ( child . type === NodeTypes . ELEMENT ) {
119
- if ( child . tagType === ElementTypes . ELEMENT ) {
120
- ssrProcessElement ( child , context )
121
- } else if ( child . tagType === ElementTypes . COMPONENT ) {
122
- ssrProcessComponent ( child , context )
123
- } else if ( child . tagType === ElementTypes . SLOT ) {
124
- ssrProcessSlotOutlet ( child , context )
125
- }
126
- } else if ( child . type === NodeTypes . TEXT ) {
127
- context . pushStringPart ( escapeHtml ( child . content ) )
128
- } else if ( child . type === NodeTypes . INTERPOLATION ) {
129
- context . pushStringPart (
130
- createCallExpression ( context . helper ( SSR_INTERPOLATE ) , [ child . content ] )
131
- )
132
- } else if ( child . type === NodeTypes . IF ) {
133
- ssrProcessIf ( child , context )
134
- } else if ( child . type === NodeTypes . FOR ) {
135
- ssrProcessFor ( child , context )
119
+ switch ( child . type ) {
120
+ case NodeTypes . ELEMENT :
121
+ switch ( child . tagType ) {
122
+ case ElementTypes . ELEMENT :
123
+ ssrProcessElement ( child , context )
124
+ break
125
+ case ElementTypes . COMPONENT :
126
+ ssrProcessComponent ( child , context )
127
+ break
128
+ case ElementTypes . SLOT :
129
+ ssrProcessSlotOutlet ( child , context )
130
+ break
131
+ case ElementTypes . TEMPLATE :
132
+ // TODO
133
+ break
134
+ default :
135
+ context . onError (
136
+ createSSRCompilerError (
137
+ SSRErrorCodes . X_SSR_INVALID_AST_NODE ,
138
+ ( child as any ) . loc
139
+ )
140
+ )
141
+ // make sure we exhaust all possible types
142
+ const exhaustiveCheck : never = child
143
+ return exhaustiveCheck
144
+ }
145
+ break
146
+ case NodeTypes . TEXT :
147
+ context . pushStringPart ( escapeHtml ( child . content ) )
148
+ break
149
+ case NodeTypes . COMMENT :
150
+ // no need to escape comment here because the AST can only
151
+ // contain valid comments.
152
+ context . pushStringPart ( `<!--${ child . content } -->` )
153
+ break
154
+ case NodeTypes . INTERPOLATION :
155
+ context . pushStringPart (
156
+ createCallExpression ( context . helper ( SSR_INTERPOLATE ) , [ child . content ] )
157
+ )
158
+ break
159
+ case NodeTypes . IF :
160
+ ssrProcessIf ( child , context )
161
+ break
162
+ case NodeTypes . FOR :
163
+ ssrProcessFor ( child , context )
164
+ break
165
+ case NodeTypes . IF_BRANCH :
166
+ // no-op - handled by ssrProcessIf
167
+ break
168
+ case NodeTypes . TEXT_CALL :
169
+ case NodeTypes . COMPOUND_EXPRESSION :
170
+ // no-op - these two types can never appear as template child node since
171
+ // `transformText` is not used during SSR compile.
172
+ break
173
+ default :
174
+ context . onError (
175
+ createSSRCompilerError (
176
+ SSRErrorCodes . X_SSR_INVALID_AST_NODE ,
177
+ ( child as any ) . loc
178
+ )
179
+ )
180
+ // make sure we exhaust all possible types
181
+ const exhaustiveCheck : never = child
182
+ return exhaustiveCheck
136
183
}
137
184
}
138
185
if ( asFragment ) {
0 commit comments