diff --git a/packages/compiler-sfc/__tests__/cssVars.spec.ts b/packages/compiler-sfc/__tests__/cssVars.spec.ts index ffa5d4e798b..05e5f689ac9 100644 --- a/packages/compiler-sfc/__tests__/cssVars.spec.ts +++ b/packages/compiler-sfc/__tests__/cssVars.spec.ts @@ -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( + ` + ` + ) + expect(content).toMatch( + `export default {\n setup(__props, { expose }) {\n expose();\n\n_useCssVars(_ctx => ({\n "xxxxxxxx-background": (_unref(background))\n}))` + ) + }) }) }) diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index b7e4c0ea778..0f5a18952e5 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -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` )