]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(sfc): ensure consistent dev/prod behavior for non-reactive variables declared...
authorEvan You <yyx990803@gmail.com>
Thu, 10 Nov 2022 09:02:45 +0000 (17:02 +0800)
committerEvan You <yyx990803@gmail.com>
Thu, 10 Nov 2022 09:02:45 +0000 (17:02 +0800)
fix #5655

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

index d553fb04b3b0fdbda149995b29b611de70d5c4f0..e9b5c3fa8837f39f7c53b1279feb121d4e714fd4 100644 (file)
@@ -1280,7 +1280,7 @@ export default {
       function c() {}
       class d {}
       
-return { aa, bb, cc, dd, a, b, c, d, xx, x }
+return { get aa() { return aa }, bb, cc, dd, get a() { return a }, b, c, d, xx, x }
 }
 
 }"
index b7c81a08c8621bc30390410ec950204a85870c77..8df7f2897a696bea896bd24181bb68da88dc2f2d 100644 (file)
@@ -15,7 +15,7 @@ export default {
     let c = () => {}
     let d
     
-return { foo, a, b, c, d, ref, shallowRef }
+return { foo, a, b, get c() { return c }, get d() { return d }, ref, shallowRef }
 }
 
 }"
@@ -36,7 +36,7 @@ export default {
     let c = () => {}
     let d
     
-return { foo, a, b, c, d }
+return { foo, a, b, get c() { return c }, get d() { return d } }
 }
 
 }"
index 4df59cc34286b51448c714aaab62d43133324252..e070087f43b43b2bb12ae21c3256f50cb4e0752d 100644 (file)
@@ -84,7 +84,7 @@ _useCssVars(_ctx => ({
         let b = 200
         let foo = 300
         
-return { a, b, foo }
+return { get a() { return a }, get b() { return b }, get foo() { return foo } }
 }
 
 }"
index b0a6c115e52265f037e799c50caaa618ab691ab0..ea4daa0d71a67466e47b9e3691e283405b9a0100 100644 (file)
@@ -20,7 +20,9 @@ describe('SFC compile <script setup>', () => {
       class dd {}
       </script>
       `)
-    expect(content).toMatch('return { aa, bb, cc, dd, a, b, c, d, xx, x }')
+    expect(content).toMatch(
+      'return { get aa() { return aa }, bb, cc, dd, get a() { return a }, b, c, d, xx, x }'
+    )
     expect(bindings).toStrictEqual({
       x: BindingTypes.SETUP_MAYBE_REF,
       a: BindingTypes.SETUP_LET,
index 88d62f2b47822ba6227692006ef4a4199a7a027d..6d60137974953ae4531f1dacf665bb57d996e27d 100644 (file)
@@ -32,7 +32,9 @@ describe('sfc ref transform', () => {
     // normal declarations left untouched
     expect(content).toMatch(`let c = () => {}`)
     expect(content).toMatch(`let d`)
-    expect(content).toMatch(`return { foo, a, b, c, d, ref, shallowRef }`)
+    expect(content).toMatch(
+      `return { foo, a, b, get c() { return c }, get d() { return d }, ref, shallowRef }`
+    )
     assertCode(content)
     expect(bindings).toStrictEqual({
       foo: BindingTypes.SETUP_REF,
index e944b7647256da8462ab0d35659075992e726ac7..74e3dbd734937b8ac996997322188893419758df 100644 (file)
@@ -1484,7 +1484,15 @@ export function compileScript(
         allBindings[key] = true
       }
     }
-    returned = `{ ${Object.keys(allBindings).join(', ')} }`
+    returned = `{ `
+    for (const key in allBindings) {
+      if (bindingMetadata[key] === BindingTypes.SETUP_LET) {
+        returned += `get ${key}() { return ${key} }, `
+      } else {
+        returned += `${key}, `
+      }
+    }
+    returned = returned.replace(/, $/, '') + ` }`
   } else {
     // inline mode
     if (sfc.template && !sfc.template.src) {