export default __default__"
`;
+exports[`CSS vars injection codegen should ignore comments 1`] = `
+"export default {
+ setup(__props, { expose }) {
+ expose()
+const color = 'red'
+return { color }
+}
+
+}"
+`;
+
exports[`CSS vars injection codegen w/ <script setup> 1`] = `
"import { useCssVars as _useCssVars, unref as _unref } from 'vue'
)
})
+ //#4185
+ test('should ignore comments', () => {
+ const { content } = compileSFCScript(
+ `<script setup>const color = 'red'</script>\n` +
+ `<style>
+ div{ /* color: v-bind(color); */ width:20; }
+ </style>`
+ )
+
+ expect(content).not.toMatch(`_useCssVars`)
+ assertCode(content)
+ })
+
test('w/ <script setup> using the same var multiple times', () => {
const { content } = compileSFCScript(
`<script setup>
const vars: string[] = []
sfc.styles.forEach(style => {
let match
- while ((match = cssVarRE.exec(style.content))) {
+ // ignore v-bind() in comments /* ... */
+ const content = style.content.replace(/\/\*[\s\S]*\*\//g, '')
+ while ((match = cssVarRE.exec(content))) {
const variable = match[1] || match[2] || match[3]
if (!vars.includes(variable)) {
vars.push(variable)