fix(sfc/style-vars): should ignore style variable bindings in comments (#4188)

fix #4185
This commit is contained in:
edison
2021-07-26 23:19:56 +08:00
committed by GitHub
parent 1c7f5d3fce
commit 3a75d5d694
3 changed files with 27 additions and 1 deletions

View File

@@ -49,6 +49,17 @@ __default__.setup = __setup__
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'

View File

@@ -161,6 +161,19 @@ describe('CSS vars injection', () => {
)
})
//#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>