refactor: only rewrite css varaiable in <style scoped> when vars is present

This commit is contained in:
Evan You
2020-07-10 17:10:48 -04:00
parent f3cc41f0c8
commit 73bfce3706
5 changed files with 66 additions and 44 deletions

View File

@@ -1,15 +1,23 @@
import { compileStyle, compileStyleAsync } from '../src/compileStyle'
import {
compileStyle,
compileStyleAsync,
SFCStyleCompileOptions
} from '../src/compileStyle'
import { mockWarn } from '@vue/shared'
describe('SFC scoped CSS', () => {
mockWarn()
function compileScoped(source: string): string {
function compileScoped(
source: string,
options?: Partial<SFCStyleCompileOptions>
): string {
const res = compileStyle({
source,
filename: 'test.css',
id: 'test',
scoped: true
scoped: true,
...options
})
if (res.errors.length) {
res.errors.forEach(err => {
@@ -254,10 +262,15 @@ describe('SFC scoped CSS', () => {
describe('<style vars>', () => {
test('should rewrite CSS vars in scoped mode', () => {
const code = compileScoped(`.foo {
const code = compileScoped(
`.foo {
color: var(--color);
font-size: var(--global:font);
}`)
}`,
{
vars: true
}
)
expect(code).toMatchInlineSnapshot(`
".foo[test] {
color: var(--test-color);