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 4e39263a5359a4c33ee3f6c29707f74de7cb120c..b2a2da1d35a02dec2fef920792c7b7778d8604d3 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 081c12589b0f97ab154a045636d08683e5d1dcab..a25958200644d33f3ba2c500766d8420b95baa00 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() + } } }) }