@@ -58,9 +58,9 @@ describe('compiler: transform v-slot', () => {
5858 )
5959 assert (
6060 `<uni-list-item class="item"><template v-slot:body v-if="ok"><view class="item"></view></template></uni-list-item>` ,
61- `<uni-list-item u-s="{{['body'] }}" class="item" u-i="2a9ec0b0-0"><view wx:if="{{a}}" class="item" slot="body"></view></uni-list-item>` ,
61+ `<uni-list-item u-s="{{b }}" class="item" u-i="2a9ec0b0-0"><view wx:if="{{a}}" class="item" slot="body"></view></uni-list-item>` ,
6262 `(_ctx, _cache) => {
63- return _e({ a: _ctx.ok }, _ctx.ok ? {} : {})
63+ return _e({ a: _ctx.ok }, _ctx.ok ? {} : {}, { b: [_ctx.ok ? 'body' : ''] } )
6464}`
6565 )
6666 } )
@@ -88,9 +88,9 @@ describe('compiler: transform v-slot', () => {
8888 test ( 'v-if + scoped slots' , ( ) => {
8989 assert (
9090 `<custom><template v-if="ok" v-slot:default="slotProps"><view>{{ slotProps.item }}</view></template></custom>` ,
91- `<custom u-s="{{['d'] }}" u-i="2a9ec0b0-0"><block wx:if="{{a}}"><view wx:for="{{b}}" wx:for-item="slotProps" wx:key="b" slot="{{slotProps.c}}"><view>{{slotProps.a}}</view></view></block></custom>` ,
91+ `<custom u-s="{{c }}" u-i="2a9ec0b0-0"><block wx:if="{{a}}"><view wx:for="{{b}}" wx:for-item="slotProps" wx:key="b" slot="{{slotProps.c}}"><view>{{slotProps.a}}</view></view></block></custom>` ,
9292 `(_ctx, _cache) => {
93- return _e({ a: _ctx.ok }, _ctx.ok ? { b: _w((slotProps, s0, i0) => { return { a: _t(slotProps.item), b: i0, c: s0 }; }, { name: 'd', path: 'b', vueId: '2a9ec0b0-0' }) } : {})
93+ return _e({ a: _ctx.ok }, _ctx.ok ? { b: _w((slotProps, s0, i0) => { return { a: _t(slotProps.item), b: i0, c: s0 }; }, { name: 'd', path: 'b', vueId: '2a9ec0b0-0' }) } : {}, { c: [_ctx.ok ? 'd' : ''] } )
9494}`
9595 )
9696 } )
@@ -183,3 +183,117 @@ describe('should remove template when it has no any child nodes or all of its ch
183183}`
184184 )
185185} )
186+
187+ describe ( 'v-slot + v-if / v-else-if / v-else' , ( ) => {
188+ assert (
189+ `<custom><template v-if="a" #header>hello</template></custom>` ,
190+ `<custom u-s="{{b}}" u-i="2a9ec0b0-0"><view wx:if="{{a}}" slot="header">hello</view></custom>` ,
191+ `(_ctx, _cache) => {
192+ return _e({ a: _ctx.a }, _ctx.a ? {} : {}, { b: [_ctx.a ? 'header' : ''] })
193+ }`
194+ )
195+
196+ assert (
197+ `<custom><template v-if="a">hello</template></custom>` ,
198+ `<custom u-s="{{b}}" u-i="2a9ec0b0-0"><block wx:if="{{a}}">hello</block></custom>` ,
199+ `(_ctx, _cache) => {
200+ return _e({ a: _ctx.a }, _ctx.a ? {} : {}, { b: [_ctx.a ? 'd' : ''] })
201+ }`
202+ )
203+
204+ assert (
205+ `<custom><template v-if="a">hello</template><template v-else #footer>hello</template></custom>` ,
206+ `<custom u-s="{{b}}" u-i="2a9ec0b0-0"><block wx:if="{{a}}">hello</block><view wx:else slot="footer">hello</view></custom>` ,
207+ `(_ctx, _cache) => {
208+ return _e({ a: _ctx.a }, _ctx.a ? {} : {}, { b: [!_ctx.a ? 'footer' : '', _ctx.a ? 'd' : ''] })
209+ }`
210+ )
211+
212+ assert (
213+ `<custom><template v-if="a" #header>hello</template><template v-if="b" #footer>hello</template></custom>` ,
214+ `<custom u-s="{{c}}" u-i="2a9ec0b0-0"><view wx:if="{{a}}" slot="header">hello</view><view wx:if="{{b}}" slot="footer">hello</view></custom>` ,
215+ `(_ctx, _cache) => {
216+ return _e({ a: _ctx.a }, _ctx.a ? {} : {}, { b: _ctx.b }, _ctx.b ? {} : {}, { c: [_ctx.a ? 'header' : '', _ctx.b ? 'footer' : ''] })
217+ }`
218+ )
219+
220+ assert (
221+ `<custom><template v-if="a" #header>hello</template><template v-if="b">hello</template></custom>` ,
222+ `<custom u-s="{{c}}" u-i="2a9ec0b0-0"><view wx:if="{{a}}" slot="header">hello</view><block wx:if="{{b}}">hello</block></custom>` ,
223+ `(_ctx, _cache) => {
224+ return _e({ a: _ctx.a }, _ctx.a ? {} : {}, { b: _ctx.b }, _ctx.b ? {} : {}, { c: [_ctx.a ? 'header' : '', _ctx.b ? 'd' : ''] })
225+ }`
226+ )
227+
228+ assert (
229+ `<custom><template v-if="a" #header>hello</template><template v-else #footer>hello</template></custom>` ,
230+ `<custom u-s="{{b}}" u-i="2a9ec0b0-0"><view wx:if="{{a}}" slot="header">hello</view><view wx:else slot="footer">hello</view></custom>` ,
231+ `(_ctx, _cache) => {
232+ return _e({ a: _ctx.a }, _ctx.a ? {} : {}, { b: [_ctx.a ? 'header' : '', !_ctx.a ? 'footer' : ''] })
233+ }`
234+ )
235+
236+ assert (
237+ `<custom><template v-if="a" #header>hello</template><template v-else>hello</template></custom>` ,
238+ `<custom u-s="{{b}}" u-i="2a9ec0b0-0"><view wx:if="{{a}}" slot="header">hello</view><block wx:else>hello</block></custom>` ,
239+ `(_ctx, _cache) => {
240+ return _e({ a: _ctx.a }, _ctx.a ? {} : {}, { b: [_ctx.a ? 'header' : '', !_ctx.a ? 'd' : ''] })
241+ }`
242+ )
243+
244+ assert (
245+ `<custom><template v-if="a" #header>hello</template><template v-else-if="b" #footer>hello</template></custom>` ,
246+ `<custom u-s="{{c}}" u-i="2a9ec0b0-0"><view wx:if="{{a}}" slot="header">hello</view><view wx:elif="{{b}}" slot="footer">hello</view></custom>` ,
247+ `(_ctx, _cache) => {
248+ return _e({ a: _ctx.a }, _ctx.a ? {} : _ctx.b ? {} : {}, { b: _ctx.b, c: [_ctx.a ? 'header' : '', !_ctx.a && _ctx.b ? 'footer' : ''] })
249+ }`
250+ )
251+
252+ assert (
253+ `<custom><template v-if="a" #header>hello</template><template v-else-if="b" #footer>hello</template><template v-else-if="c" #header2>hello</template></custom>` ,
254+ `<custom u-s="{{d}}" u-i="2a9ec0b0-0"><view wx:if="{{a}}" slot="header">hello</view><view wx:elif="{{b}}" slot="footer">hello</view><view wx:elif="{{c}}" slot="header2">hello</view></custom>` ,
255+ `(_ctx, _cache) => {
256+ return _e({ a: _ctx.a }, _ctx.a ? {} : _ctx.b ? {} : _ctx.c ? {} : {}, { b: _ctx.b, c: _ctx.c, d: [_ctx.a ? 'header' : '', !_ctx.a && _ctx.b ? 'footer' : '', !_ctx.a && !_ctx.b && _ctx.c ? 'header2' : ''] })
257+ }`
258+ )
259+
260+ assert (
261+ `<custom><template v-if="a" #header>hello</template><template v-else-if="b" #footer>hello</template><template v-if="c" #header2>hello</template></custom>` ,
262+ `<custom u-s="{{d}}" u-i="2a9ec0b0-0"><view wx:if="{{a}}" slot="header">hello</view><view wx:elif="{{b}}" slot="footer">hello</view><view wx:if="{{c}}" slot="header2">hello</view></custom>` ,
263+ `(_ctx, _cache) => {
264+ return _e({ a: _ctx.a }, _ctx.a ? {} : _ctx.b ? {} : {}, { b: _ctx.b, c: _ctx.c }, _ctx.c ? {} : {}, { d: [_ctx.a ? 'header' : '', !_ctx.a && _ctx.b ? 'footer' : '', _ctx.c ? 'header2' : ''] })
265+ }`
266+ )
267+
268+ assert (
269+ `<custom><template v-if="a" #header>hello</template><template v-else-if="b" #footer>hello</template><template v-else #footer2>hello</template></custom>` ,
270+ `<custom u-s="{{c}}" u-i="2a9ec0b0-0"><view wx:if="{{a}}" slot="header">hello</view><view wx:elif="{{b}}" slot="footer">hello</view><view wx:else slot="footer2">hello</view></custom>` ,
271+ `(_ctx, _cache) => {
272+ return _e({ a: _ctx.a }, _ctx.a ? {} : _ctx.b ? {} : {}, { b: _ctx.b, c: [_ctx.a ? 'header' : '', !_ctx.a && _ctx.b ? 'footer' : '', !_ctx.a && !_ctx.b ? 'footer2' : ''] })
273+ }`
274+ )
275+
276+ assert (
277+ `<custom><template v-if="a" #header>hello</template><template v-else-if="b" #footer>hello</template><template v-else-if="c" #footer3>hello</template><template v-else #footer2>hello</template></custom>` ,
278+ `<custom u-s="{{d}}" u-i="2a9ec0b0-0"><view wx:if="{{a}}" slot="header">hello</view><view wx:elif="{{b}}" slot="footer">hello</view><view wx:elif="{{c}}" slot="footer3">hello</view><view wx:else slot="footer2">hello</view></custom>` ,
279+ `(_ctx, _cache) => {
280+ return _e({ a: _ctx.a }, _ctx.a ? {} : _ctx.b ? {} : _ctx.c ? {} : {}, { b: _ctx.b, c: _ctx.c, d: [_ctx.a ? 'header' : '', !_ctx.a && _ctx.b ? 'footer' : '', !_ctx.a && !_ctx.b && _ctx.c ? 'footer3' : '', !_ctx.a && !_ctx.b && !_ctx.c ? 'footer2' : ''] })
281+ }`
282+ )
283+
284+ assert (
285+ `<custom><template v-if="a" #[header]>hello</template></custom>` ,
286+ `<custom u-s="{{c}}" u-i="2a9ec0b0-0"><view wx:if="{{a}}" slot="{{b}}">hello</view></custom>` ,
287+ `(_ctx, _cache) => {
288+ return _e({ a: _ctx.a }, _ctx.a ? { b: _d(_ctx.header) } : {}, { c: _d([_ctx.a ? _ctx.header : ""]) })
289+ }`
290+ )
291+
292+ assert (
293+ `<custom><template v-if="a" #[header]>hello</template><template v-else>hello</template></custom>` ,
294+ `<custom u-s="{{c}}" u-i="2a9ec0b0-0"><view wx:if="{{a}}" slot="{{b}}">hello</view><block wx:else>hello</block></custom>` ,
295+ `(_ctx, _cache) => {
296+ return _e({ a: _ctx.a }, _ctx.a ? { b: _d(_ctx.header) } : {}, { c: _d([_ctx.a ? _ctx.header : "", !_ctx.a ? "d" : ""]) })
297+ }`
298+ )
299+ } )
0 commit comments