1
- import { ComponentNode , findProp , NodeTypes } from '@vue/compiler-dom'
1
+ import {
2
+ AttributeNode ,
3
+ buildProps ,
4
+ ComponentNode ,
5
+ createCallExpression ,
6
+ DirectiveNode ,
7
+ findProp ,
8
+ JSChildNode ,
9
+ NodeTypes ,
10
+ TransformContext
11
+ } from '@vue/compiler-dom'
12
+ import { SSR_RENDER_ATTRS } from '../runtimeHelpers'
2
13
import { processChildren , SSRTransformContext } from '../ssrCodegenTransform'
14
+ import { buildSSRProps } from './ssrTransformElement'
3
15
16
+ const wipMap = new WeakMap < ComponentNode , WIPEntry > ( )
17
+
18
+ interface WIPEntry {
19
+ tag : AttributeNode | DirectiveNode
20
+ propsExp : string | JSChildNode | null
21
+ }
22
+
23
+ // phase 1: build props
24
+ export function ssrTransformTransitionGroup (
25
+ node : ComponentNode ,
26
+ context : TransformContext
27
+ ) {
28
+ return ( ) => {
29
+ const tag = findProp ( node , 'tag' )
30
+ if ( tag ) {
31
+ const otherProps = node . props . filter ( p => p !== tag )
32
+ const { props, directives } = buildProps (
33
+ node ,
34
+ context ,
35
+ otherProps ,
36
+ true , /* isComponent */
37
+ false , /* isDynamicComponent */
38
+ true /* ssr (skip event listeners) */
39
+ )
40
+ let propsExp = null
41
+ if ( props || directives . length ) {
42
+ propsExp = createCallExpression ( context . helper ( SSR_RENDER_ATTRS ) , [
43
+ buildSSRProps ( props , directives , context )
44
+ ] )
45
+ }
46
+ wipMap . set ( node , {
47
+ tag,
48
+ propsExp
49
+ } )
50
+ }
51
+ }
52
+ }
53
+
54
+ // phase 2: process children
4
55
export function ssrProcessTransitionGroup (
5
56
node : ComponentNode ,
6
57
context : SSRTransformContext
7
58
) {
8
- const tag = findProp ( node , 'tag' )
9
- if ( tag ) {
59
+ const entry = wipMap . get ( node )
60
+ if ( entry ) {
61
+ const { tag, propsExp } = entry
10
62
if ( tag . type === NodeTypes . DIRECTIVE ) {
11
63
// dynamic :tag
12
64
context . pushStringPart ( `<` )
13
65
context . pushStringPart ( tag . exp ! )
66
+ if ( propsExp ) {
67
+ context . pushStringPart ( propsExp )
68
+ }
14
69
context . pushStringPart ( `>` )
15
70
16
71
processChildren (
@@ -30,7 +85,11 @@ export function ssrProcessTransitionGroup(
30
85
context . pushStringPart ( `>` )
31
86
} else {
32
87
// static tag
33
- context . pushStringPart ( `<${ tag . value ! . content } >` )
88
+ context . pushStringPart ( `<${ tag . value ! . content } ` )
89
+ if ( propsExp ) {
90
+ context . pushStringPart ( propsExp )
91
+ }
92
+ context . pushStringPart ( `>` )
34
93
processChildren ( node , context , false , true )
35
94
context . pushStringPart ( `</${ tag . value ! . content } >` )
36
95
}
0 commit comments