From ff07613215004c9f1fbd463d3566ceae57e1f792 Mon Sep 17 00:00:00 2001 From: daiwei Date: Sat, 22 Jan 2022 14:20:31 +0800 Subject: [PATCH 1/5] fix(cssVars): work with calc complex expression --- .../__tests__/__snapshots__/cssVars.spec.ts.snap | 2 ++ packages/compiler-sfc/__tests__/cssVars.spec.ts | 6 ++++++ packages/compiler-sfc/src/cssVars.ts | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/compiler-sfc/__tests__/__snapshots__/cssVars.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/cssVars.spec.ts.snap index b44f584b206..f3180f45214 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/cssVars.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/cssVars.spec.ts.snap @@ -74,6 +74,8 @@ export default { expose(); _useCssVars(_ctx => ({ + \\"xxxxxxxx-a\\": (_unref(a)), + \\"xxxxxxxx-b\\": (_unref(b)), \\"xxxxxxxx-_a___b____2____px__\\": ((_unref(a) + _unref(b)) / 2 + 'px' ), \\"xxxxxxxx-__a___b______2___a_\\": (((_unref(a) + _unref(b))) / (2 * _unref(a))) })) diff --git a/packages/compiler-sfc/__tests__/cssVars.spec.ts b/packages/compiler-sfc/__tests__/cssVars.spec.ts index 965c9a5202b..e79bbd6daf2 100644 --- a/packages/compiler-sfc/__tests__/cssVars.spec.ts +++ b/packages/compiler-sfc/__tests__/cssVars.spec.ts @@ -206,6 +206,10 @@ describe('CSS vars injection', () => { let b = 200 \n` + `` ) expect(content).toMatch(`_useCssVars(_ctx => ({ + "${mockId}-a": (_unref(a)), + "${mockId}-b": (_unref(b)), "${mockId}-_a___b____2____px__": ((_unref(a) + _unref(b)) / 2 + 'px' ), "${mockId}-__a___b______2___a_": (((_unref(a) + _unref(b))) / (2 * _unref(a))) })`) diff --git a/packages/compiler-sfc/src/cssVars.ts b/packages/compiler-sfc/src/cssVars.ts index da3e164aeaf..9031237fa20 100644 --- a/packages/compiler-sfc/src/cssVars.ts +++ b/packages/compiler-sfc/src/cssVars.ts @@ -13,7 +13,7 @@ import hash from 'hash-sum' export const CSS_VARS_HELPER = `useCssVars` export const cssVarRE = - /\bv-bind\s*\(\s*(?:'([^']+)'|"([^"]+)"|([^'"][^;]*))\s*\)/g + /\bv-bind\s*\(\s*(?:'([^']+)'|"([^"]+)"|([^'"]|[^;]*))\s*\)/g export function genCssVarsFromList( vars: string[], From 4f716cef1118651c9f815983e6d4b89fcc2c957c Mon Sep 17 00:00:00 2001 From: daiwei Date: Sun, 23 Jan 2022 16:36:25 +0800 Subject: [PATCH 2/5] chore: improve code --- .../__tests__/__snapshots__/cssVars.spec.ts.snap | 4 +++- packages/compiler-sfc/__tests__/cssVars.spec.ts | 6 ++++++ packages/compiler-sfc/src/cssVars.ts | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/compiler-sfc/__tests__/__snapshots__/cssVars.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/cssVars.spec.ts.snap index f3180f45214..e252e122621 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/cssVars.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/cssVars.spec.ts.snap @@ -76,14 +76,16 @@ export default { _useCssVars(_ctx => ({ \\"xxxxxxxx-a\\": (_unref(a)), \\"xxxxxxxx-b\\": (_unref(b)), + \\"xxxxxxxx-foo\\": (_unref(foo)), \\"xxxxxxxx-_a___b____2____px__\\": ((_unref(a) + _unref(b)) / 2 + 'px' ), \\"xxxxxxxx-__a___b______2___a_\\": (((_unref(a) + _unref(b))) / (2 * _unref(a))) })) let a = 100 let b = 200 + let foo = 300 -return { a, b } +return { a, b, foo } } }" diff --git a/packages/compiler-sfc/__tests__/cssVars.spec.ts b/packages/compiler-sfc/__tests__/cssVars.spec.ts index e79bbd6daf2..c9e0c7ab0fd 100644 --- a/packages/compiler-sfc/__tests__/cssVars.spec.ts +++ b/packages/compiler-sfc/__tests__/cssVars.spec.ts @@ -204,12 +204,17 @@ describe('CSS vars injection', () => { `\n` + `` ) expect(content).toMatch(`_useCssVars(_ctx => ({ - "${mockId}-a": (_unref(a)), - "${mockId}-b": (_unref(b)), "${mockId}-foo": (_unref(foo)), "${mockId}-_a___b____2____px__": ((_unref(a) + _unref(b)) / 2 + 'px' ), "${mockId}-__a___b______2___a_": (((_unref(a) + _unref(b))) / (2 * _unref(a))) From 998cf37e1b0e7d83c9302bfdd26e231ced5da293 Mon Sep 17 00:00:00 2001 From: daiwei Date: Sun, 23 Jan 2022 17:01:18 +0800 Subject: [PATCH 5/5] trigger ci