From 0fd4972f3bacdd464f46c8b76312a37bb260f357 Mon Sep 17 00:00:00 2001 From: qiang Date: Tue, 29 Mar 2022 19:40:00 +0800 Subject: [PATCH] =?UTF-8?q?fix(mp-alipay):=20=E4=BF=AE=E5=A4=8D=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E6=94=AF=E4=BB=98=E5=AE=9D=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=EF=BC=88=E6=9C=AA=E4=BD=BF=E7=94=A8=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=EF=BC=89=E6=8A=A5=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__tests__/compiler-mp-alipay.spec.js | 9 ++++++ .../lib/script/traverse/data/index.js | 29 +++++++++++-------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js b/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js index 47a77a431..75d0c1f22 100644 --- a/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js @@ -45,6 +45,15 @@ describe('mp:compiler-mp-alipay', () => { '', '' ) + assertCodegen( + 'text', + 'text', + undefined, + undefined, + { + wxComponents: { component1: '/mycomponents/component1' } + } + ) assertCodegen( 'text', 'text', diff --git a/packages/uni-template-compiler/lib/script/traverse/data/index.js b/packages/uni-template-compiler/lib/script/traverse/data/index.js index 1f78c491f..d4ca8e3bf 100644 --- a/packages/uni-template-compiler/lib/script/traverse/data/index.js +++ b/packages/uni-template-compiler/lib/script/traverse/data/index.js @@ -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 -- GitLab