forked from vuejs/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssrTransformTransitionGroup.ts
77 lines (74 loc) · 2.06 KB
/
ssrTransformTransitionGroup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import {
ComponentNode,
findProp,
NodeTypes,
createCallExpression,
buildProps,
createTemplateLiteral,
DirectiveNode,
AttributeNode,
createTransformContext
} from '@vue/compiler-dom'
import { processChildren, SSRTransformContext } from '../ssrCodegenTransform'
import { SSR_RENDER_ATTRS } from '../runtimeHelpers'
function injectProp(
node: ComponentNode,
context: SSRTransformContext,
tag: AttributeNode | DirectiveNode
) {
const { props } = buildProps(
node,
createTransformContext(context.root, context.options),
node.props.filter(p => p !== tag),
true /* ssr */
)
if (props) {
context.pushStatement(
createCallExpression(`_push`, [
createTemplateLiteral([
createCallExpression(context.helper(SSR_RENDER_ATTRS), [props])
])
])
)
}
}
export function ssrProcessTransitionGroup(
node: ComponentNode,
context: SSRTransformContext
) {
const tag = findProp(node, 'tag')
if (tag) {
if (tag.type === NodeTypes.DIRECTIVE) {
// dynamic :tag
context.pushStringPart(`<`)
context.pushStringPart(tag.exp!)
injectProp(node, context, tag)
context.pushStringPart(`>`)
processChildren(
node.children,
context,
false,
/**
* TransitionGroup has the special runtime behavior of flattening and
* concatenating all children into a single fragment (in order for them to
* be patched using the same key map) so we need to account for that here
* by disabling nested fragment wrappers from being generated.
*/
true
)
context.pushStringPart(`</`)
context.pushStringPart(tag.exp!)
context.pushStringPart(`>`)
} else {
// static tag
context.pushStringPart(`<${tag.value!.content}`)
injectProp(node, context, tag)
context.pushStringPart(`>`)
processChildren(node.children, context, false, true)
context.pushStringPart(`</${tag.value!.content}>`)
}
} else {
// fragment
processChildren(node.children, context, true, true)
}
}