@@ -5,12 +5,22 @@ import {
5
5
transformChildren ,
6
6
transformElement ,
7
7
transformTemplateRef ,
8
+ transformVFor ,
9
+ transformVIf ,
10
+ type ForIRNode ,
11
+ type IfIRNode ,
8
12
} from '../../src'
9
13
10
14
import { makeCompile } from './_utils'
11
15
12
16
const compileWithTransformRef = makeCompile ( {
13
- nodeTransforms : [ transformTemplateRef , transformElement , transformChildren ] ,
17
+ nodeTransforms : [
18
+ transformVIf ,
19
+ transformVFor ,
20
+ transformTemplateRef ,
21
+ transformElement ,
22
+ transformChildren ,
23
+ ] ,
14
24
} )
15
25
16
26
describe ( 'compiler: template ref transform' , ( ) => {
@@ -72,49 +82,49 @@ describe('compiler: template ref transform', () => {
72
82
expect ( code ) . contains ( '_setTemplateRef(n0, foo, r0)' )
73
83
} )
74
84
75
- // test('ref + v-if', () => {
76
- // const { ir, code } = compileWithTransformRef(
77
- // `<div ref="foo" v-if="true" />`,
78
- // )
85
+ test ( 'ref + v-if' , ( ) => {
86
+ const { ir, code } = compileWithTransformRef (
87
+ `<div ref={foo} v-if={true} />` ,
88
+ )
89
+ expect ( code ) . toMatchSnapshot ( )
79
90
80
- // expect( ir.block.operation).lengthOf(1)
81
- // expect(ir.block.operation[0] .type).toBe(IRNodeTypes.IF)
91
+ const op = ir . block . dynamic . children [ 0 ] . operation as IfIRNode
92
+ expect ( op . type ) . toBe ( IRNodeTypes . IF )
82
93
83
- // const { positive } = ir.block.operation[0] as IfIRNode
84
- // expect(positive.operation).toMatchObject([
85
- // {
86
- // type: IRNodeTypes.SET_TEMPLATE_REF,
87
- // element: 2,
88
- // value: {
89
- // content: 'foo',
90
- // isStatic: true,
91
- // },
92
- // effect: false,
93
- // },
94
- // ])
95
- // expect(code).matchSnapshot()
96
- // expect(code).contains('_setRef(n2, "foo")')
97
- // })
94
+ const { positive } = op
95
+ expect ( positive . effect [ 0 ] . operations ) . toMatchObject ( [
96
+ {
97
+ type : IRNodeTypes . SET_TEMPLATE_REF ,
98
+ element : 2 ,
99
+ value : {
100
+ content : 'foo' ,
101
+ isStatic : false ,
102
+ } ,
103
+ effect : true ,
104
+ } ,
105
+ ] )
106
+ expect ( code ) . contains ( '_setTemplateRef(n2, foo, r2)' )
107
+ } )
98
108
99
- // test('ref + v-for', () => {
100
- // const { ir, code } = compileWithTransformRef(
101
- // `<div ref="foo" v-for="item in [1,2,3]" />`,
102
- // )
109
+ test ( 'ref + v-for' , ( ) => {
110
+ const { ir, code } = compileWithTransformRef (
111
+ `<div ref={foo} v-for={item in [1,2,3]} />` ,
112
+ )
113
+ expect ( code ) . toMatchSnapshot ( )
103
114
104
- // const { render } = ir.block.operation[0] as ForIRNode
105
- // expect(render.operation).toMatchObject([
106
- // {
107
- // type: IRNodeTypes.SET_TEMPLATE_REF,
108
- // element: 2,
109
- // value: {
110
- // content: 'foo',
111
- // isStatic: true,
112
- // },
113
- // refFor: true,
114
- // effect: false,
115
- // },
116
- // ])
117
- // expect(code).matchSnapshot()
118
- // expect(code).contains('_setRef(n2, "foo", void 0, true)')
119
- // })
115
+ const { render } = ir . block . dynamic . children [ 0 ] . operation as ForIRNode
116
+ expect ( render . effect [ 0 ] . operations ) . toMatchObject ( [
117
+ {
118
+ type : IRNodeTypes . SET_TEMPLATE_REF ,
119
+ element : 2 ,
120
+ value : {
121
+ content : 'foo' ,
122
+ isStatic : false ,
123
+ } ,
124
+ refFor : true ,
125
+ effect : true ,
126
+ } ,
127
+ ] )
128
+ expect ( code ) . contains ( '_setTemplateRef(n2, foo, r2, true)' )
129
+ } )
120
130
} )
0 commit comments