提交 cb3bf18e 编写于 作者: Q qiang

fix: 修复小程序端 v-for 中复杂表达式部分条件判断转换错误的问题 question/103466

上级 9b86bb31
......@@ -692,5 +692,10 @@ describe('mp:compiler-extra', () => {
'<block wx:for="{{$root.l0}}" wx:for-item="item" wx:for-index="index" wx:key="index"><view><block wx:if="{{item.$orig}}"><view>{{item.m0}}</view></block></view></block>',
'with(this){var l0=__map(list,function(item,index){var $orig=__get_orig(item);var m0=item?getValue(item):null;return{$orig:$orig,m0:m0}});$mp.data=Object.assign({},{$root:{l0:l0}})}'
)
assertCodegen(
'<view v-for="(item,index) in list" :key="index"><view v-if="item.length">{{getValue(item)}}</view></view>',
'<block wx:for="{{$root.l0}}" wx:for-item="item" wx:for-index="index" wx:key="index"><view><block wx:if="{{item.$orig.length}}"><view>{{item.m0}}</view></block></view></block>',
'with(this){var l0=__map(list,function(item,index){var $orig=__get_orig(item);var m0=item.length?getValue(item):null;return{$orig:$orig,m0:m0}});$mp.data=Object.assign({},{$root:{l0:l0}})}'
)
})
})
......@@ -45,12 +45,12 @@ function findTest (path, state) {
let test = t.arrayExpression([t.clone(path.container.test)])
traverse(test, {
noScope: true,
MemberExpression (path) {
MemberExpression (path_) {
const names = state.scoped.map(scoped => scoped.forItem)
const node = path.node
const node = path_.node
const objectName = node.object.name
if (objectName === VAR_ROOT || names.includes(objectName)) {
path.replaceWith(node.property)
if (objectName === VAR_ROOT || (names.includes(objectName) && path.scope.hasOwnBinding(node.property.name))) {
path_.replaceWith(node.property)
}
}
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册