File tree Expand file tree Collapse file tree 3 files changed +17
-8
lines changed Expand file tree Collapse file tree 3 files changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -50,11 +50,17 @@ export default __default__"
5050`;
5151
5252exports[`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 {
5456 setup (__props , { expose }) {
5557 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 }
5864}
5965
6066}"
Original file line number Diff line number Diff line change @@ -164,13 +164,17 @@ describe('CSS vars injection', () => {
164164 //#4185
165165 test ( 'should ignore comments' , ( ) => {
166166 const { content } = compileSFCScript (
167- `<script setup>const color = 'red'</script>\n` +
167+ `<script setup>const color = 'red';const width = 100 </script>\n` +
168168 `<style>
169+ /* comment **/
169170 div{ /* color: v-bind(color); */ width:20; }
171+ div{ width: v-bind(width); }
172+ /* comment */
170173 </style>`
171174 )
172175
173- expect ( content ) . not . toMatch ( `_useCssVars` )
176+ expect ( content ) . not . toMatch ( `"${ mockId } -color": (color)` )
177+ expect ( content ) . toMatch ( `"${ mockId } -width": (width)` )
174178 assertCode ( content )
175179 } )
176180
Original file line number Diff line number Diff line change @@ -12,8 +12,7 @@ import { PluginCreator } from 'postcss'
1212import hash from 'hash-sum'
1313
1414export 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
1716
1817export function genCssVarsFromList (
1918 vars : string [ ] ,
@@ -38,7 +37,7 @@ export function parseCssVars(sfc: SFCDescriptor): string[] {
3837 sfc . styles . forEach ( style => {
3938 let match
4039 // ignore v-bind() in comments /* ... */
41- const content = style . content . replace ( / \/ \* [ \s \S ] * \* \/ / g, '' )
40+ const content = style . content . replace ( / \/ \* ( [ \s \S ] * ? ) \* \/ / g, '' )
4241 while ( ( match = cssVarRE . exec ( content ) ) ) {
4342 const variable = match [ 1 ] || match [ 2 ] || match [ 3 ]
4443 if ( ! vars . includes ( variable ) ) {
You can’t perform that action at this time.
0 commit comments