From bdf56966217e5ce13286cf373d29db0563c34e0e Mon Sep 17 00:00:00 2001
From: baiwusanyu-c <740132583@qq.com>
Date: Mon, 20 Feb 2023 13:17:14 +0800
Subject: [PATCH 1/8] fix(compiler-sfc): use prependLeft to handle CSSVars
---
packages/compiler-sfc/src/compileScript.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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`
)
From c2efb654b74bd665f9c62e2866a27d5960029cbf Mon Sep 17 00:00:00 2001
From: baiwusanyu-c <740132583@qq.com>
Date: Mon, 20 Feb 2023 13:32:07 +0800
Subject: [PATCH 2/8] fix(compiler-sfc): added a unit test
---
.../__tests__/compileScript.spec.ts | 3 +--
.../compiler-sfc/__tests__/cssVars.spec.ts | 23 +++++++++++++++++++
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/packages/compiler-sfc/__tests__/compileScript.spec.ts b/packages/compiler-sfc/__tests__/compileScript.spec.ts
index 3ea7632f68b..b091b8b5fcc 100644
--- a/packages/compiler-sfc/__tests__/compileScript.spec.ts
+++ b/packages/compiler-sfc/__tests__/compileScript.spec.ts
@@ -1136,7 +1136,7 @@ const emit = defineEmits(['a', 'b'])
`)
assertCode(content)
})
-
+
// #7111
test('withDefaults (static) w/ production mode', () => {
const { content } = compile(
@@ -1277,7 +1277,6 @@ const emit = defineEmits(['a', 'b'])
expect(content).toMatch(`emits: ["foo", "bar"]`)
})
-
test('defineEmits w/ type from normal script', () => {
const { content } = compile(`
+`
+ )
+ console.log(content)
+ expect(content).toMatch(`export default {
+ setup(__props, { expose }) {
+ expose();
+
+_useCssVars(_ctx => ({
+ "xxxxxxxx-background": (_unref(background))
+}))
+`)
+ })
})
})
From 10cc4e61d65489d8e72d12575bc2309b8f73fdad Mon Sep 17 00:00:00 2001
From: baiwusanyu-c <740132583@qq.com>
Date: Mon, 20 Feb 2023 13:35:36 +0800
Subject: [PATCH 3/8] fix(compiler-sfc): rollback format
---
packages/compiler-sfc/__tests__/compileScript.spec.ts | 1 +
1 file changed, 1 insertion(+)
diff --git a/packages/compiler-sfc/__tests__/compileScript.spec.ts b/packages/compiler-sfc/__tests__/compileScript.spec.ts
index b091b8b5fcc..00558e225ce 100644
--- a/packages/compiler-sfc/__tests__/compileScript.spec.ts
+++ b/packages/compiler-sfc/__tests__/compileScript.spec.ts
@@ -1277,6 +1277,7 @@ const emit = defineEmits(['a', 'b'])
expect(content).toMatch(`emits: ["foo", "bar"]`)
})
+
test('defineEmits w/ type from normal script', () => {
const { content } = compile(`
-`
+ let background = _ref('red')
+
+ `
)
console.log(content)
- expect(content).toMatch(`export default {
- setup(__props, { expose }) {
- expose();
-
-_useCssVars(_ctx => ({
- "xxxxxxxx-background": (_unref(background))
-}))
-`)
+ expect(content).toMatch(
+ `export default {\n setup(__props, { expose }) {\n expose();\n\n_useCssVars(_ctx => ({\n "xxxxxxxx-background": (_unref(background))\n}))`
+ )
})
})
})
From 69493a5b01dc3fbc094911480d0418941fbbb67f Mon Sep 17 00:00:00 2001
From: baiwusanyu-c <740132583@qq.com>
Date: Mon, 20 Feb 2023 13:52:57 +0800
Subject: [PATCH 8/8] fix(compiler-sfc): format code
---
packages/compiler-sfc/__tests__/cssVars.spec.ts | 1 -
1 file changed, 1 deletion(-)
diff --git a/packages/compiler-sfc/__tests__/cssVars.spec.ts b/packages/compiler-sfc/__tests__/cssVars.spec.ts
index cc8c2f0dcda..05e5f689ac9 100644
--- a/packages/compiler-sfc/__tests__/cssVars.spec.ts
+++ b/packages/compiler-sfc/__tests__/cssVars.spec.ts
@@ -268,7 +268,6 @@ describe('CSS vars injection', () => {
}
`
)
- console.log(content)
expect(content).toMatch(
`export default {\n setup(__props, { expose }) {\n expose();\n\n_useCssVars(_ctx => ({\n "xxxxxxxx-background": (_unref(background))\n}))`
)