提交 570d7b6d 编写于 作者: Q qiang

fix(mp): multiple v-for scope with v-if

上级 e402ded7
......@@ -700,6 +700,11 @@ describe('mp:compiler-extra', () => {
'<view><block wx:for="{{list[$root.m0]}}" wx:for-item="item" wx:for-index="index"><view><view>{{item}}</view></view></block></view>',
'with(this){var m0=get(test);$mp.data=Object.assign({},{$root:{m0:m0}})}'
)
assertCodegen(
'<view v-for="(item,index) in items" :key="index"><view v-if="item"><input v-for="(item1,index1) in item" :key="index1" :placehold="getValue(item1)" :value="getValue(item)"></view></view>',
'<block wx:for="{{$root.l1}}" wx:for-item="item" wx:for-index="index" wx:key="index"><view><block wx:if="{{item.$orig}}"><view><block wx:for="{{item.l0}}" wx:for-item="item1" wx:for-index="index1" wx:key="index1"><input placehold="{{item1.m0}}" value="{{item1.m1}}"/></block></view></block></view></block>',
'with(this){var l1=__map(items,function(item,index){var $orig=__get_orig(item);var l0=item?__map(item,function(item1,index1){var $orig=__get_orig(item1);var m0=getValue(item1);var m1=getValue(item);return{$orig:$orig,m0:m0,m1:m1}}):null;return{$orig:$orig,l0:l0}});$mp.data=Object.assign({},{$root:{l1:l1}})}'
)
})
it('generate TemplateLiteral ', () => {
......
......@@ -5,7 +5,8 @@ const {
VAR_ROOT,
IDENTIFIER_METHOD,
IDENTIFIER_FILTER,
IDENTIFIER_GLOBAL
IDENTIFIER_GLOBAL,
METHOD_RENDER_LIST
} = require('../../constants')
function isMatch (name, forItem, forIndex) {
......@@ -19,8 +20,19 @@ function findScoped (path, test, state) {
const scoped = state.scoped.find(scoped => {
const {
forItem,
forIndex
forIndex,
path: listPath
} = scoped
const funPath = path.findParent(path => path.isFunctionExpression() && path.parentPath.node.callee.name === METHOD_RENDER_LIST)
if (funPath && funPath.parentPath === listPath) {
// TODO 为兼容历史结构仅在当前 list 父级存在 v-if 返回
const parent = listPath.findParent(path => path.isFunctionExpression() || path.isConditionalExpression())
if (parent && parent.isConditionalExpression()) {
return true
}
} else {
return false
}
let match = false
path.traverse({
noScope: true,
......
......@@ -136,7 +136,8 @@ module.exports = function traverseRenderList (path, state) {
forExtra: getForExtra(forItem, forIndex, path, state),
propertyArray: [],
declarationArray: [],
renderSlotStatementArray: []
renderSlotStatementArray: [],
path
}
const forState = {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册