File tree Expand file tree Collapse file tree 3 files changed +47
-1
lines changed Expand file tree Collapse file tree 3 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,27 @@ return { color, width }
6666}"
6767`;
6868
69+ exports[`CSS vars injection codegen should work with w/ complex expression 1`] = `
70+ "import { useCssVars as _useCssVars , unref as _unref } from 'vue'
71+
72+ export default {
73+ setup (__props , { expose }) {
74+ expose();
75+
76+ _useCssVars(_ctx = > ({
77+ \\" xxxxxxxx-_a___b____2____px__\\ " : ((_unref (a ) + _unref (b )) / 2 + ' px' ),
78+ \\" xxxxxxxx-__a___b______2___a_\\ " : (((_unref (a ) + _unref (b ))) / (2 * _unref (a )))
79+ }))
80+
81+ let a = 100
82+ let b = 200
83+
84+ return { a , b }
85+ }
86+
87+ } "
88+ `;
89+
6990exports[`CSS vars injection codegen w/ <script setup > 1`] = `
7091"import { useCssVars as _useCssVars , unref as _unref } from 'vue'
7192
Original file line number Diff line number Diff line change @@ -195,6 +195,31 @@ describe('CSS vars injection', () => {
195195 // color should only be injected once, even if it is twice in style
196196 expect ( content ) . toMatch ( `_useCssVars(_ctx => ({
197197 "${ mockId } -color": (color)
198+ })` )
199+ assertCode ( content )
200+ } )
201+
202+ test ( 'should work with w/ complex expression' , ( ) => {
203+ const { content } = compileSFCScript (
204+ `<script setup>
205+ let a = 100
206+ let b = 200
207+ </script>\n` +
208+ `<style>
209+ div {
210+ color: v-bind((a + b) / 2 + 'px' );
211+ }
212+ div {
213+ color: v-bind ((a + b) / 2 + 'px' );
214+ }
215+ p {
216+ color: v-bind(((a + b)) / (2 * a));
217+ }
218+ </style>`
219+ )
220+ expect ( content ) . toMatch ( `_useCssVars(_ctx => ({
221+ "${ mockId } -_a___b____2____px__": ((_unref(a) + _unref(b)) / 2 + 'px' ),
222+ "${ mockId } -__a___b______2___a_": (((_unref(a) + _unref(b))) / (2 * _unref(a)))
198223})` )
199224 assertCode ( content )
200225 } )
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ import hash from 'hash-sum'
1313
1414export const CSS_VARS_HELPER = `useCssVars`
1515export const cssVarRE =
16- / \b v - b i n d \( \s * (?: ' ( [ ^ ' ] + ) ' | " ( [ ^ " ] + ) " | ( [ ^ ' " ] [ ^ ) ] * ) ) \s * \) / g
16+ / \b v - b i n d \s * \ (\s * (?: ' ( [ ^ ' ] + ) ' | " ( [ ^ " ] + ) " | ( [ ^ ' " ] [ ^ ; ] * ) ) \s * \) / g
1717
1818export function genCssVarsFromList (
1919 vars : string [ ] ,
You can’t perform that action at this time.
0 commit comments