Skip to content

Commit 18a9fd8

Browse files
committed
feat: Support default values for v-bind in CSS
1 parent 97f45f3 commit 18a9fd8

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

packages/compiler-sfc/__tests__/cssVars.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ describe('CSS vars injection', () => {
103103
const { content } = compileSFCScript(
104104
`<script>const a = 1</script>\n` +
105105
`<style>div{
106-
color: v-bind(color);
107-
font-size: v-bind('font.size');
106+
color: v-bind(color, blue);
107+
font-size: v-bind('font.size', 14px);
108108
}</style>`,
109109
{ isProd: true },
110110
)
@@ -115,7 +115,7 @@ describe('CSS vars injection', () => {
115115

116116
const { code } = compileStyle({
117117
source: `.foo {
118-
color: v-bind(color);
118+
color: v-bind(color, blue);
119119
font-size: v-bind('font.size');
120120
}`,
121121
filename: 'test.css',
@@ -124,7 +124,7 @@ describe('CSS vars injection', () => {
124124
})
125125
expect(code).toMatchInlineSnapshot(`
126126
".foo {
127-
color: var(--4003f1a6);
127+
color: var(--4003f1a6, blue);
128128
font-size: var(--41b6490a);
129129
}"
130130
`)

packages/compiler-sfc/src/style/cssVars.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ function lexBinding(content: string, start: number): number | null {
9898
state = LexerState.inDoubleQuoteString
9999
} else if (char === `(`) {
100100
parenDepth++
101-
} else if (char === `)`) {
101+
} else if (char === `)` || char === ',') {
102102
if (parenDepth > 0) {
103-
parenDepth--
103+
char === `)` && parenDepth--
104104
} else {
105105
return i
106106
}
@@ -146,8 +146,8 @@ export const cssVarsPlugin: PluginCreator<CssVarsPluginOptions> = opts => {
146146
const variable = normalizeExpression(value.slice(start, end))
147147
transformed +=
148148
value.slice(lastIndex, match.index) +
149-
`var(--${genVarName(id, variable, isProd)})`
150-
lastIndex = end + 1
149+
`var(--${genVarName(id, variable, isProd)}`
150+
lastIndex = end
151151
}
152152
}
153153
decl.value = transformed + value.slice(lastIndex)

0 commit comments

Comments
 (0)