From 72dc637526cf4441aab09b72541d28b91e706bf2 Mon Sep 17 00:00:00 2001 From: qiang Date: Wed, 12 Jan 2022 15:40:52 +0800 Subject: [PATCH] fix(mp): TemplateElement with quote --- .../__tests__/compiler-mp-weixin.spec.js | 14 ++++++++++++++ packages/uni-template-compiler/lib/util.js | 6 ++++++ 2 files changed, 20 insertions(+) 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 4e39263a5..b2a2da1d3 100644 --- a/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js @@ -60,11 +60,25 @@ describe('mp:compiler-mp-weixin', () => { '', `with(this){var a0=text+"'";$mp.data=Object.assign({},{$root:{a0:a0}})}` ) + assertCodegen( + '', + '', + 'with(this){var a0=`${text}\'`;$mp.data=Object.assign({},{$root:{a0:a0}})}' + ) assertCodegen( `{{text+'\\''}}`, '{{$root.t0}}', `with(this){var t0=text+"'";$mp.data=Object.assign({},{$root:{t0:t0}})}` ) + assertCodegen( + '{{`${text}\'`}}', + '{{$root.t0}}', + 'with(this){var t0=`${text}\'`;$mp.data=Object.assign({},{$root:{t0:t0}})}' + ) + assertCodegen( + '{{`${text}"`}}', + `{{text+'"'}}` + ) assertCodegen( `{{text+"\\""}}`, '{{$root.t0}}', diff --git a/packages/uni-template-compiler/lib/util.js b/packages/uni-template-compiler/lib/util.js index 081c12589..a25958200 100644 --- a/packages/uni-template-compiler/lib/util.js +++ b/packages/uni-template-compiler/lib/util.js @@ -255,6 +255,12 @@ function hasEscapeQuote (path) { has = true path.stop() } + }, + TemplateElement (path) { + if (path.node.value.cooked.includes('\'')) { + has = true + path.stop() + } } }) } -- GitLab