Skip to content

Commit b298b3c

Browse files
edison1105yyx990803
authored andcommitted
fix(cssVars): cssVarName should keep backslashe in ssr dev mode
1 parent 9845f1d commit b298b3c

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap

+3-1
Original file line numberDiff line numberDiff line change
@@ -1003,10 +1003,12 @@ export default {
10031003
setup(__props) {
10041004
10051005
const count = ref(0)
1006+
const style = { color: 'red' }
10061007
10071008
return (_ctx, _push, _parent, _attrs) => {
10081009
const _cssVars = { style: {
1009-
\\"--xxxxxxxx-count\\": (count.value)
1010+
\\"--xxxxxxxx-count\\": (count.value),
1011+
\\"--xxxxxxxx-style\\\\\\\\.color\\": (style.color)
10101012
}}
10111013
_push(\`<!--[--><div\${
10121014
_ssrRenderAttrs(_cssVars)

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

+3
Original file line numberDiff line numberDiff line change
@@ -778,13 +778,15 @@ describe('SFC compile <script setup>', () => {
778778
<script setup>
779779
import { ref } from 'vue'
780780
const count = ref(0)
781+
const style = { color: 'red' }
781782
</script>
782783
<template>
783784
<div>{{ count }}</div>
784785
<div>static</div>
785786
</template>
786787
<style>
787788
div { color: v-bind(count) }
789+
span { color: v-bind(style.color) }
788790
</style>
789791
`,
790792
{
@@ -799,6 +801,7 @@ describe('SFC compile <script setup>', () => {
799801
expect(content).toMatch(`ssrInterpolate`)
800802
expect(content).not.toMatch(`useCssVars`)
801803
expect(content).toMatch(`"--${mockId}-count": (count.value)`)
804+
expect(content).toMatch(`"--${mockId}-style\\\\.color": (style.color)`)
802805
assertCode(content)
803806
})
804807

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ export function genCssVarsFromList(
2121
isSSR = false
2222
): string {
2323
return `{\n ${vars
24-
.map(
25-
key => `"${isSSR ? `--` : ``}${genVarName(id, key, isProd)}": (${key})`
26-
)
24+
.map(key => {
25+
const varName = genVarName(id, key, isProd)
26+
return `"${isSSR ? `--` : ``}${
27+
isSSR && !isProd ? varName.replace(/\\/g, '\\\\') : varName
28+
}": (${key})`
29+
})
2730
.join(',\n ')}\n}`
2831
}
2932

0 commit comments

Comments
 (0)