File tree 3 files changed +17
-8
lines changed
3 files changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -50,11 +50,17 @@ export default __default__"
50
50
`;
51
51
52
52
exports[`CSS vars injection codegen should ignore comments 1`] = `
53
- "export default {
53
+ "import { useCssVars as _useCssVars , unref as _unref } from 'vue'
54
+
55
+ export default {
54
56
setup (__props , { expose }) {
55
57
expose()
56
- const color = 'red'
57
- return { color }
58
+
59
+ _useCssVars(_ctx = > ({
60
+ \\" xxxxxxxx-width\\ " : (width )
61
+ }))
62
+ const color = 'red';const width = 100
63
+ return { color , width }
58
64
}
59
65
60
66
}"
Original file line number Diff line number Diff line change @@ -164,13 +164,17 @@ describe('CSS vars injection', () => {
164
164
//#4185
165
165
test ( 'should ignore comments' , ( ) => {
166
166
const { content } = compileSFCScript (
167
- `<script setup>const color = 'red'</script>\n` +
167
+ `<script setup>const color = 'red';const width = 100 </script>\n` +
168
168
`<style>
169
+ /* comment **/
169
170
div{ /* color: v-bind(color); */ width:20; }
171
+ div{ width: v-bind(width); }
172
+ /* comment */
170
173
</style>`
171
174
)
172
175
173
- expect ( content ) . not . toMatch ( `_useCssVars` )
176
+ expect ( content ) . not . toMatch ( `"${ mockId } -color": (color)` )
177
+ expect ( content ) . toMatch ( `"${ mockId } -width": (width)` )
174
178
assertCode ( content )
175
179
} )
176
180
Original file line number Diff line number Diff line change @@ -12,8 +12,7 @@ import { PluginCreator } from 'postcss'
12
12
import hash from 'hash-sum'
13
13
14
14
export const CSS_VARS_HELPER = `useCssVars`
15
- export const cssVarRE =
16
- / \b v - b i n d \( \s * (?: ' ( [ ^ ' ] + ) ' | " ( [ ^ " ] + ) " | ( [ ^ ' " ] [ ^ ) ] * ) ) \s * \) / g
15
+ export const cssVarRE = / \b v - b i n d \( \s * (?: ' ( [ ^ ' ] + ) ' | " ( [ ^ " ] + ) " | ( [ ^ ' " ] [ ^ ) ] * ) ) \s * \) / g
17
16
18
17
export function genCssVarsFromList (
19
18
vars : string [ ] ,
@@ -38,7 +37,7 @@ export function parseCssVars(sfc: SFCDescriptor): string[] {
38
37
sfc . styles . forEach ( style => {
39
38
let match
40
39
// ignore v-bind() in comments /* ... */
41
- const content = style . content . replace ( / \/ \* [ \s \S ] * \* \/ / g, '' )
40
+ const content = style . content . replace ( / \/ \* ( [ \s \S ] * ? ) \* \/ / g, '' )
42
41
while ( ( match = cssVarRE . exec ( content ) ) ) {
43
42
const variable = match [ 1 ] || match [ 2 ] || match [ 3 ]
44
43
if ( ! vars . includes ( variable ) ) {
You can’t perform that action at this time.
0 commit comments