提交 7c382d6f 编写于 作者: Q qiang

fix: 解决小程序 v-for 中属性值为对象表达式报错的问题 fixed #1450

上级 3226634c
......@@ -126,8 +126,8 @@ describe('mp:compiler-mp-alipay', () => {
it('generate events with v-on directive', () => {
assertCodegen(
'<uni-list-item title="标题文字" note="描述信息" show-extra-icon="true" :extra-icon="{color: \'#4cd964\',size: \'22\',type: \'spinner\'}"></uni-list-item>',
'<uni-list-item vue-id="551070e6-1" title="标题文字" note="描述信息" show-extra-icon="true" extra-icon="{{$root.a0}}" onVueInit="__l"></uni-list-item>',
'with(this){var a0={color:"#4cd964",size:"22",type:"spinner"};$mp.data=Object.assign({},{$root:{a0:a0}})}'
'<uni-list-item vue-id="551070e6-1" title="标题文字" note="描述信息" show-extra-icon="true" extra-icon="{{({color:\'#4cd964\',size:\'22\',type:\'spinner\'})}}" onVueInit="__l"></uni-list-item>',
'with(this){}'
)
assertCodegen(
......
......@@ -130,5 +130,6 @@ 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>')
})
})
const {
IDENTIFIER_ATTR
} = require('../../../constants')
// const {
// IDENTIFIER_ATTR
// } = require('../../../constants')
const getMemberExpr = require('../member-expr')
// const getMemberExpr = require('../member-expr')
module.exports = function processAttrs (paths, path, state, isComponent, tagName) {
const attrsPath = paths.attrs
if (attrsPath) {
attrsPath.get('value.properties').forEach(propertyPath => {
const valuePath = propertyPath.get('value')
if (valuePath.isObjectExpression()) {
valuePath.replaceWith(getMemberExpr(null, IDENTIFIER_ATTR, valuePath.node, state))
}
})
}
// 不再单独处理ObjectExpression,改为在转换temlplte时用()包裹(微信、QQ)
// const attrsPath = paths.attrs
// if (attrsPath) {
// attrsPath.get('value.properties').forEach(propertyPath => {
// const valuePath = propertyPath.get('value')
// if (valuePath.isObjectExpression()) {
// valuePath.replaceWith(getMemberExpr(null, IDENTIFIER_ATTR, valuePath.node, state))
// }
// })
// }
return []
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册