提交 c78bf406 编写于 作者: Q qiang

fix(mp-weixin): array.length with multiple logicalExpression #1827

上级 f3fde1b1
......@@ -376,6 +376,11 @@ describe('mp:compiler-mp-weixin', () => {
'<button disabled="{{$root.g0===0}}">hello world</button>',
'with(this){var g0=array.length;$mp.data=Object.assign({},{$root:{g0:g0}})}'
)
assertCodegen(
'<button :disabled="array.test&&test(array.test.test).length===0">hello world</button>',
'<button disabled="{{$root.g0}}">hello world</button>',
'with(this){var g0=array.test&&test(array.test.test).length===0;$mp.data=Object.assign({},{$root:{g0:g0}})}'
)
assertCodegen(
'<view :class="\'c\'+array.length">hello world</view>',
'<view class="{{[\'c\'+$root.g0]}}">hello world</view>',
......@@ -391,6 +396,16 @@ describe('mp:compiler-mp-weixin', () => {
'<block wx:if="{{$root.g0}}"><view>hello</view></block>',
'with(this){var g0=array.length;$mp.data=Object.assign({},{$root:{g0:g0}})}'
)
assertCodegen(
'<view v-if="array&&array.length">hello</view>',
'<block wx:if="{{$root.g0}}"><view>hello</view></block>',
'with(this){var g0=array&&array.length;$mp.data=Object.assign({},{$root:{g0:g0}})}'
)
assertCodegen(
'<view v-if="test1&&!test2&&array&&array.length">hello</view>',
'<block wx:if="{{$root.g0}}"><view>hello</view></block>',
'with(this){var g0=test1&&!test2&&array&&array.length;$mp.data=Object.assign({},{$root:{g0:g0}})}'
)
assertCodegen(
'<view v-show="array.length">hello</view>',
'<view hidden="{{!($root.g0)}}">hello</view>',
......
......@@ -151,6 +151,15 @@ module.exports = {
}
// 微信小程序平台无法观测 Array length 访问:https://developers.weixin.qq.com/community/develop/doc/000c8ee47d87a0d5b6685a8cb57000
if (this.options.platform.name === 'mp-weixin' && hasLengthProperty(path)) {
let newPath = path
while (newPath) {
path = newPath
newPath = path.findParent((path) => path.isLogicalExpression())
}
path.skip()
if (path.findParent((path) => path.shouldSkip)) {
return
}
path.replaceWith(getMemberExpr(path, IDENTIFIER_GLOBAL, path.node, this))
}
},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册