Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cssVars): work with calc complex expression #5306

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -74,14 +74,16 @@ export default {
expose();

_useCssVars(_ctx => ({
\\"xxxxxxxx-foo\\": (_unref(foo)),
\\"xxxxxxxx-_a___b____2____px__\\": ((_unref(a) + _unref(b)) / 2 + 'px' ),
\\"xxxxxxxx-__a___b______2___a_\\": (((_unref(a) + _unref(b))) / (2 * _unref(a)))
}))

let a = 100
let b = 200
let foo = 300

return { a, b }
return { a, b, foo }
}

}"
Expand Down
6 changes: 6 additions & 0 deletions packages/compiler-sfc/__tests__/cssVars.spec.ts
Expand Up @@ -204,8 +204,13 @@ describe('CSS vars injection', () => {
`<script setup>
let a = 100
let b = 200
let foo = 300
</script>\n` +
`<style>
p{
width: calc(v-bind(foo) - 3px);
height: calc(v-bind('foo') - 3px);
}
div {
color: v-bind((a + b) / 2 + 'px' );
}
Expand All @@ -218,6 +223,7 @@ describe('CSS vars injection', () => {
</style>`
)
expect(content).toMatch(`_useCssVars(_ctx => ({
"${mockId}-foo": (_unref(foo)),
"${mockId}-_a___b____2____px__": ((_unref(a) + _unref(b)) / 2 + 'px' ),
"${mockId}-__a___b______2___a_": (((_unref(a) + _unref(b))) / (2 * _unref(a)))
})`)
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-sfc/src/cssVars.ts
Expand Up @@ -13,7 +13,7 @@ import hash from 'hash-sum'

export const CSS_VARS_HELPER = `useCssVars`
export const cssVarRE =
/\bv-bind\s*\(\s*(?:'([^']+)'|"([^"]+)"|([^'"][^;]*))\s*\)/g
/\bv-bind\s*\(\s*(?:'([^']+)'|"([^"]+)"|([^'"]|[\w]*|[^;]*))\s*\)/g
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would fail on calc(v-bind(foo + 123))


export function genCssVarsFromList(
vars: string[],
Expand Down