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(compiler-sfc): use prependLeft to handle CSSVars #7760

Merged
merged 15 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/compiler-sfc/__tests__/cssVars.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,5 +255,22 @@ describe('CSS vars injection', () => {
)
expect(cssVars).toMatchObject([`count.toString(`, `xxx`])
})

// #7759
test('It should correctly parse the case where there is no space after the script tag', () => {
const { content } = compileSFCScript(
`<script setup>import { ref as _ref } from 'vue';
let background = _ref('red')
</script>
<style>
label {
background: v-bind(background);
}
</style>`
)
expect(content).toMatch(
`export default {\n setup(__props, { expose }) {\n expose();\n\n_useCssVars(_ctx => ({\n "xxxxxxxx-background": (_unref(background))\n}))`
)
})
})
})
2 changes: 1 addition & 1 deletion packages/compiler-sfc/src/compileScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,7 @@ export function compileScript(
) {
helperImports.add(CSS_VARS_HELPER)
helperImports.add('unref')
s.prependRight(
s.prependLeft(
startOffset,
`\n${genCssVarsCode(cssVars, bindingMetadata, scopeId, isProd)}\n`
)
Expand Down