From 447def37871275bf9a16861c708efa00a991034b Mon Sep 17 00:00:00 2001 From: qiang Date: Sat, 15 Aug 2020 14:41:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E8=A1=A8=E8=BE=BE=E5=BC=8F=E7=BC=96=E8=AF=91?= =?UTF-8?q?=20question/104101?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__tests__/compiler-mp-weixin.spec.js | 4 ++++ .../uni-template-compiler/lib/script/traverse/data/attrs.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js b/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js index d0d8214b94..4f9a3016be 100644 --- a/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js @@ -132,6 +132,10 @@ describe('mp:compiler-mp-weixin', () => { ) assertCodegen('', '') assertCodegen('', '', 'with(this){var a0={"x":0};$mp.data=Object.assign({},{$root:{a0:a0}})}') + assertCodegen( + '', '', + 'with(this){var a0={x:{x:0}};$mp.data=Object.assign({},{$root:{a0:a0}})}' + ) }) it('generate v-show directive', () => { diff --git a/packages/uni-template-compiler/lib/script/traverse/data/attrs.js b/packages/uni-template-compiler/lib/script/traverse/data/attrs.js index 644986879e..394b88bf93 100644 --- a/packages/uni-template-compiler/lib/script/traverse/data/attrs.js +++ b/packages/uni-template-compiler/lib/script/traverse/data/attrs.js @@ -12,7 +12,7 @@ module.exports = function processAttrs (paths, path, state, isComponent, tagName attrsPath.get('value.properties').forEach(propertyPath => { const valuePath = propertyPath.get('value') // 对于普通的ObjectExpression不再单独处理,改为在转换temlplte时用()包裹(微信、QQ) - if (valuePath.isObjectExpression() && valuePath.node.properties.find(({ key }) => !t.isIdentifier(key))) { + if (valuePath.isObjectExpression() && valuePath.node.properties.find(({ key, value }) => !t.isIdentifier(key) || !(t.isIdentifier(value) || t.isStringLiteral(value) || t.isBooleanLiteral(value) || t.isNumericLiteral(value) || t.isNullLiteral(value)))) { valuePath.replaceWith(getMemberExpr(path, IDENTIFIER_ATTR, valuePath.node, state)) } }) -- GitLab