@@ -42,6 +42,7 @@ import {
42
42
processChildrenAsStatement
43
43
} from '../ssrCodegenTransform'
44
44
import { isSymbol , isObject , isArray } from '@vue/shared'
45
+ import { createSSRCompilerError , SSRErrorCodes } from '../errors'
45
46
46
47
// We need to construct the slot functions in the 1st pass to ensure proper
47
48
// scope tracking, but the children of each slot cannot be processed until
@@ -136,35 +137,7 @@ export function ssrProcessComponent(
136
137
const component = componentTypeMap . get ( node ) !
137
138
138
139
if ( component === PORTAL ) {
139
- const targetProp = findProp ( node , 'target' )
140
- if ( ! targetProp ) return
141
-
142
- let target : JSChildNode
143
- if ( targetProp . type === NodeTypes . ATTRIBUTE && targetProp . value ) {
144
- target = createSimpleExpression ( targetProp . value . content , true )
145
- } else if ( targetProp . type === NodeTypes . DIRECTIVE && targetProp . exp ) {
146
- target = targetProp . exp
147
- } else {
148
- return
149
- }
150
-
151
- const contentRenderFn = createFunctionExpression (
152
- [ `_push` ] ,
153
- undefined , // Body is added later
154
- true , // newline
155
- false , // isSlot
156
- node . loc
157
- )
158
- contentRenderFn . body = processChildrenAsStatement ( node . children , context )
159
- context . pushStatement (
160
- createCallExpression ( context . helper ( SSR_RENDER_PORTAL ) , [
161
- contentRenderFn ,
162
- target ,
163
- `_parent`
164
- ] )
165
- )
166
-
167
- return
140
+ return ssrProcessPortal ( node , context )
168
141
}
169
142
170
143
const needFragmentWrapper =
@@ -194,6 +167,47 @@ export function ssrProcessComponent(
194
167
}
195
168
}
196
169
170
+ function ssrProcessPortal ( node : ComponentNode , context : SSRTransformContext ) {
171
+ const targetProp = findProp ( node , 'target' )
172
+ if ( ! targetProp ) {
173
+ context . onError (
174
+ createSSRCompilerError ( SSRErrorCodes . X_SSR_NO_PORTAL_TARGET , node . loc )
175
+ )
176
+ return
177
+ }
178
+
179
+ let target : JSChildNode
180
+ if ( targetProp . type === NodeTypes . ATTRIBUTE && targetProp . value ) {
181
+ target = createSimpleExpression ( targetProp . value . content , true )
182
+ } else if ( targetProp . type === NodeTypes . DIRECTIVE && targetProp . exp ) {
183
+ target = targetProp . exp
184
+ } else {
185
+ context . onError (
186
+ createSSRCompilerError (
187
+ SSRErrorCodes . X_SSR_NO_PORTAL_TARGET ,
188
+ targetProp . loc
189
+ )
190
+ )
191
+ return
192
+ }
193
+
194
+ const contentRenderFn = createFunctionExpression (
195
+ [ `_push` ] ,
196
+ undefined , // Body is added later
197
+ true , // newline
198
+ false , // isSlot
199
+ node . loc
200
+ )
201
+ contentRenderFn . body = processChildrenAsStatement ( node . children , context )
202
+ context . pushStatement (
203
+ createCallExpression ( context . helper ( SSR_RENDER_PORTAL ) , [
204
+ contentRenderFn ,
205
+ target ,
206
+ `_parent`
207
+ ] )
208
+ )
209
+ }
210
+
197
211
export const rawOptionsMap = new WeakMap < RootNode , CompilerOptions > ( )
198
212
199
213
const [ baseNodeTransforms , baseDirectiveTransforms ] = getBaseTransformPreset (
0 commit comments