Skip to content

Commit f8a0046

Browse files
committed
refactor(mp): 优化编译产物
1 parent 2a1e55a commit f8a0046

File tree

4 files changed

+164
-151
lines changed

4 files changed

+164
-151
lines changed

packages/uni-mp-alipay/__tests__/vSlot.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ describe('mp-alipay: transform v-slot', () => {
5757
test('v-if + scoped slots', () => {
5858
assert(
5959
`<custom><template v-if="ok" v-slot:default="slotProps"><view>{{ slotProps.item }}</view></template></custom>`,
60-
`<custom u-s="{{['d']}}" u-i="2a9ec0b0-0" onVI="__l"><block a:if="{{a}}"><view a:for="{{b}}" a:for-item="slotProps" a:key="b" slot="{{slotProps.c}}"><view>{{slotProps.a}}</view></view></block></custom>`,
60+
`<custom u-s="{{c}}" u-i="2a9ec0b0-0" onVI="__l"><block a:if="{{a}}"><view a:for="{{b}}" a:for-item="slotProps" a:key="b" slot="{{slotProps.c}}"><view>{{slotProps.a}}</view></view></block></custom>`,
6161
`(_ctx, _cache) => {
62-
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' }) } : {})
62+
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' : ''] })
6363
}`
6464
)
6565
})

packages/uni-mp-baidu/__tests__/vSlot.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ describe('compiler: transform v-slot', () => {
5757
test('v-if + scoped slots', () => {
5858
assert(
5959
`<custom><template v-if="ok" v-slot:default="slotProps"><view>{{ slotProps.item }}</view></template></custom>`,
60-
`<custom u-s="{{['d']}}" u-i="2a9ec0b0-0"><view s-if="{{a}}"><block s-for="slotProps in b trackBy slotProps.a"><view>{{slotProps.b}}</view></block></view></custom>`,
60+
`<custom u-s="{{c}}" u-i="2a9ec0b0-0"><view s-if="{{a}}"><block s-for="slotProps in b trackBy slotProps.a"><view>{{slotProps.b}}</view></block></view></custom>`,
6161
`(_ctx, _cache) => {
62-
return _e({ a: _ctx.ok }, _ctx.ok ? { b: _w((slotProps, s0, i0) => { return { a: i0, b: _t(slotProps.item) }; }, { name: 'd', path: 'b', vueId: '2a9ec0b0-0' }) } : {})
62+
return _e({ a: _ctx.ok }, _ctx.ok ? { b: _w((slotProps, s0, i0) => { return { a: i0, b: _t(slotProps.item) }; }, { name: 'd', path: 'b', vueId: '2a9ec0b0-0' }) } : {}, { c: [_ctx.ok ? 'd' : ''] })
6363
}`
6464
)
6565
})

packages/uni-mp-compiler/__tests__/vSlot.spec.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ describe('compiler: transform v-slot', () => {
4141
)
4242
assert(
4343
`<unicloud-db v-slot:default="{data, loading, error, options}"><view v-if="error">{{error.message}}</view><view v-else></view></unicloud-db>`,
44-
`<unicloud-db u-s="{{b}}" u-i="2a9ec0b0-0"><view wx:for="{{a}}" wx:for-item="v0" wx:key="c" slot="{{v0.d}}"><view wx:if="{{v0.a}}">{{v0.b}}</view><view wx:else></view></view></unicloud-db>`,
44+
`<unicloud-db u-s="{{['d']}}" u-i="2a9ec0b0-0"><view wx:for="{{a}}" wx:for-item="v0" wx:key="c" slot="{{v0.d}}"><view wx:if="{{v0.a}}">{{v0.b}}</view><view wx:else></view></view></unicloud-db>`,
4545
`(_ctx, _cache) => {
46-
return { a: _w(({ data, loading, error, options }, s0, i0) => { return _e({ a: error }, error ? { b: _t(error.message) } : {}, { c: i0, d: s0 }); }, { name: 'd', path: 'a', vueId: '2a9ec0b0-0' }), b: [_ctx.error ? "d" : "true" ? "d" : "" ? 'd' : ''] }
46+
return { a: _w(({ data, loading, error, options }, s0, i0) => { return _e({ a: error }, error ? { b: _t(error.message) } : {}, { c: i0, d: s0 }); }, { name: 'd', path: 'a', vueId: '2a9ec0b0-0' }) }
4747
}`
4848
)
4949
})
@@ -201,6 +201,14 @@ describe('v-slot + v-if / v-else-if / v-else', () => {
201201
}`
202202
)
203203

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 ? "d" : "true" ? 'footer' : '', _ctx.a ? 'd' : ''] })
209+
}`
210+
)
211+
204212
assert(
205213
`<custom><template v-if="a" #header>hello</template><template v-if="b" #footer>hello</template></custom>`,
206214
`<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>`,
@@ -221,47 +229,55 @@ describe('v-slot + v-if / v-else-if / v-else', () => {
221229
`<custom><template v-if="a" #header>hello</template><template v-else #footer>hello</template></custom>`,
222230
`<custom u-s="{{b}}" u-i="2a9ec0b0-0"><view wx:if="{{a}}" slot="header">hello</view><view wx:else slot="footer">hello</view></custom>`,
223231
`(_ctx, _cache) => {
224-
return _e({ a: _ctx.a }, _ctx.a ? {} : {}, { b: [_ctx.a ? 'header' : '', _ctx.a ? "header" : "true" ? "footer" : "" ? 'footer' : ''] })
232+
return _e({ a: _ctx.a }, _ctx.a ? {} : {}, { b: [_ctx.a ? 'header' : '', _ctx.a ? "header" : "true" ? 'footer' : ''] })
225233
}`
226234
)
227235

228236
assert(
229237
`<custom><template v-if="a" #header>hello</template><template v-else>hello</template></custom>`,
230238
`<custom u-s="{{b}}" u-i="2a9ec0b0-0"><view wx:if="{{a}}" slot="header">hello</view><block wx:else>hello</block></custom>`,
231239
`(_ctx, _cache) => {
232-
return _e({ a: _ctx.a }, _ctx.a ? {} : {}, { b: [_ctx.a ? 'header' : '', _ctx.a ? "header" : "true" ? "d" : "" ? 'd' : ''] })
240+
return _e({ a: _ctx.a }, _ctx.a ? {} : {}, { b: [_ctx.a ? 'header' : '', _ctx.a ? "header" : "true" ? 'd' : ''] })
233241
}`
234242
)
235243

236244
assert(
237245
`<custom><template v-if="a" #header>hello</template><template v-else-if="b" #footer>hello</template></custom>`,
238246
`<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>`,
239247
`(_ctx, _cache) => {
240-
return _e({ a: _ctx.a }, _ctx.a ? {} : _ctx.b ? {} : {}, { b: _ctx.b, c: [_ctx.a ? 'header' : '', _ctx.a ? "header" : _ctx.b ? "footer" : "" ? 'footer' : ''] })
248+
return _e({ a: _ctx.a }, _ctx.a ? {} : _ctx.b ? {} : {}, { b: _ctx.b, c: [_ctx.a ? 'header' : '', _ctx.a ? "header" : _ctx.b ? 'footer' : ''] })
241249
}`
242250
)
243251

244252
assert(
245253
`<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>`,
246254
`<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>`,
247255
`(_ctx, _cache) => {
248-
return _e({ a: _ctx.a }, _ctx.a ? {} : _ctx.b ? {} : _ctx.c ? {} : {}, { b: _ctx.b, c: _ctx.c, d: [_ctx.a ? 'header' : '', _ctx.a ? "header" : _ctx.b ? "footer" : "" ? 'footer' : '', _ctx.a ? "header" : _ctx.b ? "footer" : "" ? "footer" : _ctx.c ? "header2" : "" ? 'header2' : ''] })
256+
return _e({ a: _ctx.a }, _ctx.a ? {} : _ctx.b ? {} : _ctx.c ? {} : {}, { b: _ctx.b, c: _ctx.c, d: [_ctx.a ? 'header' : '', _ctx.a ? "header" : _ctx.b ? 'footer' : '', _ctx.a ? "header" : _ctx.b ? "footer" : "" ? "footer" : _ctx.c ? 'header2' : ''] })
249257
}`
250258
)
251259

252260
assert(
253261
`<custom><template v-if="a" #header>hello</template><template v-else-if="b" #footer>hello</template><template v-if="c" #header2>hello</template></custom>`,
254262
`<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>`,
255263
`(_ctx, _cache) => {
256-
return _e({ a: _ctx.a }, _ctx.a ? {} : _ctx.b ? {} : {}, { b: _ctx.b, c: _ctx.c }, _ctx.c ? {} : {}, { d: [_ctx.a ? 'header' : '', _ctx.a ? "header" : _ctx.b ? "footer" : "" ? 'footer' : '', _ctx.c ? 'header2' : ''] })
264+
return _e({ a: _ctx.a }, _ctx.a ? {} : _ctx.b ? {} : {}, { b: _ctx.b, c: _ctx.c }, _ctx.c ? {} : {}, { d: [_ctx.a ? 'header' : '', _ctx.a ? "header" : _ctx.b ? 'footer' : '', _ctx.c ? 'header2' : ''] })
257265
}`
258266
)
259267

260268
assert(
261269
`<custom><template v-if="a" #header>hello</template><template v-else-if="b" #footer>hello</template><template v-else #footer2>hello</template></custom>`,
262270
`<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>`,
263271
`(_ctx, _cache) => {
264-
return _e({ a: _ctx.a }, _ctx.a ? {} : _ctx.b ? {} : {}, { b: _ctx.b, c: [_ctx.a ? 'header' : '', _ctx.a ? "header" : _ctx.b ? "footer" : "" ? 'footer' : '', _ctx.a ? "header" : _ctx.b ? "footer" : "" ? "footer" : "true" ? "footer2" : "" ? 'footer2' : ''] })
272+
return _e({ a: _ctx.a }, _ctx.a ? {} : _ctx.b ? {} : {}, { b: _ctx.b, c: [_ctx.a ? 'header' : '', _ctx.a ? "header" : _ctx.b ? 'footer' : '', _ctx.a ? "header" : _ctx.b ? "footer" : "" ? "footer" : "true" ? '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 ? "header" : _ctx.b ? 'footer' : '', _ctx.a ? "header" : _ctx.b ? "footer" : "" ? "footer" : _ctx.c ? 'footer3' : '', _ctx.a ? "header" : _ctx.b ? "footer" : "" ? "footer" : _ctx.c ? "footer3" : "" ? "footer3" : "true" ? 'footer2' : ''] })
265281
}`
266282
)
267283

@@ -277,7 +293,7 @@ describe('v-slot + v-if / v-else-if / v-else', () => {
277293
`<custom><template v-if="a" #[header]>hello</template><template v-else>hello</template></custom>`,
278294
`<custom u-s="{{c}}" u-i="2a9ec0b0-0"><view wx:if="{{a}}" slot="{{b}}">hello</view><block wx:else>hello</block></custom>`,
279295
`(_ctx, _cache) => {
280-
return _e({ a: _ctx.a }, _ctx.a ? { b: _d(_ctx.header) } : {}, { c: _d([_ctx.a ? _ctx.header : "", _ctx.a ? _ctx.header : "true" ? "d" : "" ? "d" : ""]) })
296+
return _e({ a: _ctx.a }, _ctx.a ? { b: _d(_ctx.header) } : {}, { c: _d([_ctx.a ? _ctx.header : "", _ctx.a ? _ctx.header : "true" ? "d" : ""]) })
281297
}`
282298
)
283299
})

0 commit comments

Comments
 (0)