提交 0fd4972f 编写于 作者: Q qiang

fix(mp-alipay): 修复使用支付宝小程序组件(未使用事件)报错的问题

上级 352e8919
......@@ -45,6 +45,15 @@ describe('mp:compiler-mp-alipay', () => {
'<component1 v-for="item in items" :ref="c4"></component1>',
'<component1 vue-id="{{\'551070e6-1-\'+__i0__}}" ref="__r" data-ref-in-for="{{c4}}" a:for="{{items}}" a:for-item="item" a:for-index="__i0__" onVueInit="__l"></component1>'
)
assertCodegen(
'<component1>text</component1>',
'<component1 vue-id="551070e6-1" data-com-type="wx" ref="__r" onVueInit="__l">text</component1>',
undefined,
undefined,
{
wxComponents: { component1: '/mycomponents/component1' }
}
)
assertCodegen(
'<component1 @change="onChange" @cancle="onCancle">text</component1>',
'<component1 onChange="__e" onCancle="__e" vue-id="551070e6-1" data-event-opts="{{[[\'^change\',[[\'onChange\']]],[\'^cancle\',[[\'onCancle\']]]]}}" data-com-type="wx" ref="__r" data-event-list="onChange,onCancle" onVueInit="__l">text</component1>',
......
......@@ -58,20 +58,25 @@ module.exports = function traverseData (path, state, tagName) {
t.stringLiteral('__r')
)
)
const properties = path.node.properties.find(prop => prop.key.name === 'on').value.properties
const list = []
for (let index = 0; index < properties.length; index++) {
const element = properties[index]
if (element.value.value === '__e') {
list.push(element.key.value)
const on = path.node.properties.find(prop => prop.key.name === 'on')
if (on) {
const properties = on.value.properties
const list = []
for (let index = 0; index < properties.length; index++) {
const element = properties[index]
if (element.value.value === '__e') {
list.push(element.key.value)
}
}
if (list.length) {
addAttrProperties.push(
t.objectProperty(
t.stringLiteral(ATTR_DATA_EVENT_LIST),
t.stringLiteral(list.join(','))
)
)
}
}
addAttrProperties.push(
t.objectProperty(
t.stringLiteral(ATTR_DATA_EVENT_LIST),
t.stringLiteral(list.join(','))
)
)
if (wxComponent.startsWith('plugin://')) {
const wrapperTag = 'plugin-wrapper'
const orgPath = path.parentPath
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册