diff --git a/packages/compiler-sfc/__tests__/__snapshots__/compileScriptPropsTransform.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/compileScriptPropsTransform.spec.ts.snap index 7105dfe3..8a735942 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/compileScriptPropsTransform.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/compileScriptPropsTransform.spec.ts.snap @@ -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) { diff --git a/packages/compiler-sfc/__tests__/compileScriptPropsTransform.spec.ts b/packages/compiler-sfc/__tests__/compileScriptPropsTransform.spec.ts index 140dbec2..e7fbb31c 100644 --- a/packages/compiler-sfc/__tests__/compileScriptPropsTransform.spec.ts +++ b/packages/compiler-sfc/__tests__/compileScriptPropsTransform.spec.ts @@ -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) }) diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index f70faeaf..3a3a2603 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -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})` } }