From 04acf78993c3fec6e1f9ec12f57f578945a822bd Mon Sep 17 00:00:00 2001 From: yintyuan Date: Mon, 30 Oct 2023 11:06:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20style=E5=8A=A8=E6=80=81=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E8=BD=AC=E6=8D=A2=E5=90=8E=E6=A0=B7=E5=BC=8F=E5=A4=B1?= =?UTF-8?q?=E6=95=88=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taroize/__tests__/wxml.test.ts | 6 ++++++ packages/taroize/src/wxml.ts | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/taroize/__tests__/wxml.test.ts b/packages/taroize/__tests__/wxml.test.ts index 5287f2142ce..049f657889b 100644 --- a/packages/taroize/__tests__/wxml.test.ts +++ b/packages/taroize/__tests__/wxml.test.ts @@ -397,4 +397,10 @@ describe('style属性的解析', () => { contentInput = convertStyleUnit(contentInput) expect(contentInput).toBe(``) }) + + test('style="height: calc(100vh - {{xxx}}rem)",内联样式使用calc计算,包含变量,变量前有空格,转换后空格保留',() => { + let contentInput = `` + contentInput = convertStyleUnit(contentInput) + expect(contentInput).toBe('') + }) }) diff --git a/packages/taroize/src/wxml.ts b/packages/taroize/src/wxml.ts index a3f2e78aade..faa0effa986 100644 --- a/packages/taroize/src/wxml.ts +++ b/packages/taroize/src/wxml.ts @@ -128,9 +128,9 @@ function convertStyleAttrs (styleAttrsMap: any[]) { const attrValueReg = /([^{}]*)\{\{([^{}]*)\}\}([^{}]*)/ const matchs = attrValueReg.exec(attr.value) if (matchs !== null) { - const tempLeftValue = matchs[1]?.trim() || '' - const tempMidValue = matchs[2]?.trim() || '' - const tempRightValue = matchs[3]?.trim() || '' + const tempLeftValue = matchs[1] || '' + const tempMidValue = matchs[2] || '' + const tempRightValue = matchs[3] || '' // 将模版中的内容转换为 ast 节点 const tempMidValueAst = parseFile(tempMidValue).program.body[0] as any attr.value = t.templateLiteral(