]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-sfc): fix object default values for reactive props destructure
authorEvan You <yyx990803@gmail.com>
Tue, 10 May 2022 00:39:27 +0000 (08:39 +0800)
committerEvan You <yyx990803@gmail.com>
Tue, 10 May 2022 00:39:27 +0000 (08:39 +0800)
packages/compiler-sfc/__tests__/__snapshots__/compileScriptPropsTransform.spec.ts.snap
packages/compiler-sfc/__tests__/compileScriptPropsTransform.spec.ts
packages/compiler-sfc/src/compileScript.ts

index 7105dfe38643b52acd9d9213b4c3ff03f05ced96..8a7359420bb799adf3676f8a8ad63a742d8c5e25 100644 (file)
@@ -65,7 +65,7 @@ exports[`sfc props transform default values w/ runtime declaration 1`] = `
 export default {
   props: _mergeDefaults(['foo', 'bar'], {
   foo: 1,
-  bar: () => {}
+  bar: () => ({})
 }),
   setup(__props) {
 
@@ -83,7 +83,7 @@ exports[`sfc props transform default values w/ type declaration 1`] = `
 export default /*#__PURE__*/_defineComponent({
   props: {
     foo: { type: Number, required: false, default: 1 },
-    bar: { type: Object, required: false, default: () => {} }
+    bar: { type: Object, required: false, default: () => ({}) }
   },
   setup(__props: any) {
 
@@ -101,11 +101,11 @@ exports[`sfc props transform default values w/ type declaration, prod mode 1`] =
 export default /*#__PURE__*/_defineComponent({
   props: {
     foo: { default: 1 },
-    bar: { default: () => {} },
+    bar: { default: () => ({}) },
     baz: null,
     boola: { type: Boolean },
     boolb: { type: [Boolean, Number] },
-    func: { type: Function, default: () => () => {} }
+    func: { type: Function, default: () => (() => {}) }
   },
   setup(__props: any) {
 
index 140dbec2e6be20ad1468b54d298ec28c7944e17f..e7fbb31c344eff19e78f41179c184e23197dd5d9 100644 (file)
@@ -59,7 +59,7 @@ describe('sfc props transform', () => {
     // function
     expect(content).toMatch(`props: _mergeDefaults(['foo', 'bar'], {
   foo: 1,
-  bar: () => {}
+  bar: () => ({})
 })`)
     assertCode(content)
   })
@@ -74,7 +74,7 @@ describe('sfc props transform', () => {
     // function
     expect(content).toMatch(`props: {
     foo: { type: Number, required: false, default: 1 },
-    bar: { type: Object, required: false, default: () => {} }
+    bar: { type: Object, required: false, default: () => ({}) }
   }`)
     assertCode(content)
   })
@@ -92,11 +92,11 @@ describe('sfc props transform', () => {
     // function
     expect(content).toMatch(`props: {
     foo: { default: 1 },
-    bar: { default: () => {} },
+    bar: { default: () => ({}) },
     baz: null,
     boola: { type: Boolean },
     boolb: { type: [Boolean, Number] },
-    func: { type: Function, default: () => () => {} }
+    func: { type: Function, default: () => (() => {}) }
   }`)
     assertCode(content)
   })
index f70faeaf02b2956be67d8ab58aa33007b2c0f92e..3a3a260332e528faa820ac458b66dd9eaa37e245 100644 (file)
@@ -735,7 +735,7 @@ export function compileScript(
         destructured.default.end!
       )
       const isLiteral = destructured.default.type.endsWith('Literal')
-      return isLiteral ? value : `() => ${value}`
+      return isLiteral ? value : `() => (${value})`
     }
   }