1
1
import {
2
+ type CompilerError ,
2
3
type ComponentNode ,
3
4
ElementTypes ,
4
5
type IfBranchNode ,
@@ -15,40 +16,43 @@ export const transformTransition: NodeTransform = (node, context) => {
15
16
) {
16
17
const component = context . isBuiltInComponent ( node . tag )
17
18
if ( component === TRANSITION ) {
18
- return ( ) => {
19
- if ( ! node . children . length ) {
20
- return
21
- }
19
+ return postTransformTransition ( node , context . onError )
20
+ }
21
+ }
22
+ }
22
23
23
- // warn multiple transition children
24
- if ( hasMultipleChildren ( node ) ) {
25
- context . onError (
26
- createDOMCompilerError (
27
- DOMErrorCodes . X_TRANSITION_INVALID_CHILDREN ,
28
- {
29
- start : node . children [ 0 ] . loc . start ,
30
- end : node . children [ node . children . length - 1 ] . loc . end ,
31
- source : '' ,
32
- } ,
33
- ) ,
34
- )
35
- }
24
+ export function postTransformTransition (
25
+ node : ComponentNode ,
26
+ onError : ( error : CompilerError ) => void ,
27
+ ) : ( ) => void {
28
+ return ( ) => {
29
+ if ( ! node . children . length ) {
30
+ return
31
+ }
32
+
33
+ if ( hasMultipleChildren ( node ) ) {
34
+ onError (
35
+ createDOMCompilerError ( DOMErrorCodes . X_TRANSITION_INVALID_CHILDREN , {
36
+ start : node . children [ 0 ] . loc . start ,
37
+ end : node . children [ node . children . length - 1 ] . loc . end ,
38
+ source : '' ,
39
+ } ) ,
40
+ )
41
+ }
36
42
37
- // check if it's s single child w/ v-show
38
- // if yes, inject "persisted: true" to the transition props
39
- const child = node . children [ 0 ]
40
- if ( child . type === NodeTypes . ELEMENT ) {
41
- for ( const p of child . props ) {
42
- if ( p . type === NodeTypes . DIRECTIVE && p . name === 'show' ) {
43
- node . props . push ( {
44
- type : NodeTypes . ATTRIBUTE ,
45
- name : 'persisted' ,
46
- nameLoc : node . loc ,
47
- value : undefined ,
48
- loc : node . loc ,
49
- } )
50
- }
51
- }
43
+ // check if it's s single child w/ v-show
44
+ // if yes, inject "persisted: true" to the transition props
45
+ const child = node . children [ 0 ]
46
+ if ( child . type === NodeTypes . ELEMENT ) {
47
+ for ( const p of child . props ) {
48
+ if ( p . type === NodeTypes . DIRECTIVE && p . name === 'show' ) {
49
+ node . props . push ( {
50
+ type : NodeTypes . ATTRIBUTE ,
51
+ name : 'persisted' ,
52
+ nameLoc : node . loc ,
53
+ value : undefined ,
54
+ loc : node . loc ,
55
+ } )
52
56
}
53
57
}
54
58
}
0 commit comments