File tree 3 files changed +47
-1
lines changed
3 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,27 @@ return { color, width }
66
66
}"
67
67
`;
68
68
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
+
69
90
exports[`CSS vars injection codegen w/ <script setup > 1`] = `
70
91
"import { useCssVars as _useCssVars , unref as _unref } from 'vue'
71
92
Original file line number Diff line number Diff line change @@ -195,6 +195,31 @@ describe('CSS vars injection', () => {
195
195
// color should only be injected once, even if it is twice in style
196
196
expect ( content ) . toMatch ( `_useCssVars(_ctx => ({
197
197
"${ 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)))
198
223
})` )
199
224
assertCode ( content )
200
225
} )
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ import hash from 'hash-sum'
13
13
14
14
export const CSS_VARS_HELPER = `useCssVars`
15
15
export const cssVarRE =
16
- / \b v - b i n d \( \s * (?: ' ( [ ^ ' ] + ) ' | " ( [ ^ " ] + ) " | ( [ ^ ' " ] [ ^ ) ] * ) ) \s * \) / g
16
+ / \b v - b i n d \s * \ (\s * (?: ' ( [ ^ ' ] + ) ' | " ( [ ^ " ] + ) " | ( [ ^ ' " ] [ ^ ; ] * ) ) \s * \) / g
17
17
18
18
export function genCssVarsFromList (
19
19
vars : string [ ] ,
You can’t perform that action at this time.
0 commit comments