提交 66527fa0 编写于 作者: fxy060608's avatar fxy060608

fix(mp): init parent with scoped slots

上级 6380bda2
......@@ -35,6 +35,17 @@ describe('mp:compiler-mp-weixin', () => {
expect(res.generic[0]).toBe('test-foo-default')
}
)
assertCodegen(
'<uni-clientdb v-slot:default="{data}"><uni-table><uni-tr><uni-th align="center">日期</uni-th></uni-tr></uni-table></uni-clientdb>',
'<uni-clientdb generic:scoped-slots-default="test-uni-clientdb-default" data-vue-generic="scoped" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'default\']}}"></uni-clientdb>',
function (res) {
expect(res.generic[0]).toBe('test-uni-clientdb-default')
const wxmlKey = Object.keys(res.files)[0]
expect(res.files[wxmlKey]).toBe(
'<uni-table vue-id="551070e6-2" bind:__l="__l" vue-slots="{{[\'default\']}}"><uni-tr vue-id="{{(\'551070e6-3\')+\',\'+(\'551070e6-2\')}}" bind:__l="__l" vue-slots="{{[\'default\']}}"><uni-th vue-id="{{(\'551070e6-4\')+\',\'+(\'551070e6-3\')}}" align="center" bind:__l="__l" vue-slots="{{[\'default\']}}">日期</uni-th></uni-tr></uni-table>'
)
}
)
})
it('generate named scoped slot', () => {
......@@ -130,8 +141,11 @@ describe('mp:compiler-mp-weixin', () => {
'<template v-for="(item, key) in { list1, list2 }"></template>',
'<block wx:for="{{({list1,list2})}}" wx:for-item="item" wx:for-index="key"></block>'
)
assertCodegen('<test :obj="{x:0}"></test>', '<test vue-id="551070e6-1" obj="{{({x:0})}}" bind:__l="__l"></test>')
assertCodegen('<test :obj="{\'x\':0}"></test>', '<test vue-id="551070e6-1" obj="{{$root.a0}}" bind:__l="__l"></test>', 'with(this){var a0={"x":0};$mp.data=Object.assign({},{$root:{a0:a0}})}')
assertCodegen('<test :obj="{x:0}"></test>',
'<test vue-id="551070e6-1" obj="{{({x:0})}}" bind:__l="__l"></test>')
assertCodegen('<test :obj="{\'x\':0}"></test>',
'<test vue-id="551070e6-1" obj="{{$root.a0}}" bind:__l="__l"></test>',
'with(this){var a0={"x":0};$mp.data=Object.assign({},{$root:{a0:a0}})}')
assertCodegen(
'<test :obj="{x:{x:0}}"></test>', '<test vue-id="551070e6-1" obj="{{$root.a0}}" bind:__l="__l"></test>',
'with(this){var a0={x:{x:0}};$mp.data=Object.assign({},{$root:{a0:a0}})}'
......@@ -144,4 +158,4 @@ describe('mp:compiler-mp-weixin', () => {
'<test data-custom-hidden="{{!(shown)}}" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'default\']}}">hello world</test>'
)
})
})
})
......@@ -22,7 +22,7 @@ const res = compiler.compile(
<custom data-a="1" :data-b="b"></custom>
`, {
miniprogram: true,
resourcePath: '/User/fxy/Documents/test.wxml',
resourcePath: 'test.wxml',
isReservedTag: function (tag) {
return true
},
......
......@@ -369,7 +369,11 @@ function traverseResolveScopedSlots (callExprNode, state) {
resourcePath,
paramExprNode,
returnExprNodes,
traverseExpr,
traverseExpr: function (exprNode, state) {
const ast = traverseExpr(exprNode, state)
initParent(ast)
return ast
},
normalizeChildren
},
state
......@@ -416,7 +420,8 @@ function traverseRenderList (callExprNode, state) {
const children = traverseExpr(forReturnStatementArgument, state)
// 支付宝小程序在 block 标签上使用 key 时顺序不能保障
if (state.options.platform.name === 'mp-alipay' && t.isCallExpression(forReturnStatementArgument) && children && children.type) {
if (state.options.platform.name === 'mp-alipay' && t.isCallExpression(forReturnStatementArgument) && children &&
children.type) {
children.attr = children.attr || {}
Object.assign(children.attr, attr)
return children
......@@ -483,4 +488,4 @@ function traverseCreateTextVNode (callExprNode, state) {
function traverseCreateEmptyVNode (callExprNode, state) {
return ''
}
}
......@@ -67,6 +67,9 @@ export function initEntryPage () {
}
if (!entryPagePath || entryPagePath === __uniConfig.entryPagePath) {
if (entryPageQuery) {
__uniConfig.entryPageQuery = entryPageQuery
}
return
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册