Skip to content

Commit 7dfe146

Browse files
committed
fix(compiler-sfc): fix object default values for reactive props destructure
1 parent 0683a02 commit 7dfe146

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

packages/compiler-sfc/__tests__/__snapshots__/compileScriptPropsTransform.spec.ts.snap

+4-4
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ exports[`sfc props transform default values w/ runtime declaration 1`] = `
6565
export default {
6666
props: _mergeDefaults(['foo', 'bar'], {
6767
foo: 1,
68-
bar: () => {}
68+
bar: () => ({})
6969
}),
7070
setup(__props) {
7171
@@ -83,7 +83,7 @@ exports[`sfc props transform default values w/ type declaration 1`] = `
8383
export default /*#__PURE__*/_defineComponent({
8484
props: {
8585
foo: { type: Number, required: false, default: 1 },
86-
bar: { type: Object, required: false, default: () => {} }
86+
bar: { type: Object, required: false, default: () => ({}) }
8787
},
8888
setup(__props: any) {
8989
@@ -101,11 +101,11 @@ exports[`sfc props transform default values w/ type declaration, prod mode 1`] =
101101
export default /*#__PURE__*/_defineComponent({
102102
props: {
103103
foo: { default: 1 },
104-
bar: { default: () => {} },
104+
bar: { default: () => ({}) },
105105
baz: null,
106106
boola: { type: Boolean },
107107
boolb: { type: [Boolean, Number] },
108-
func: { type: Function, default: () => () => {} }
108+
func: { type: Function, default: () => (() => {}) }
109109
},
110110
setup(__props: any) {
111111

packages/compiler-sfc/__tests__/compileScriptPropsTransform.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe('sfc props transform', () => {
5959
// function
6060
expect(content).toMatch(`props: _mergeDefaults(['foo', 'bar'], {
6161
foo: 1,
62-
bar: () => {}
62+
bar: () => ({})
6363
})`)
6464
assertCode(content)
6565
})
@@ -74,7 +74,7 @@ describe('sfc props transform', () => {
7474
// function
7575
expect(content).toMatch(`props: {
7676
foo: { type: Number, required: false, default: 1 },
77-
bar: { type: Object, required: false, default: () => {} }
77+
bar: { type: Object, required: false, default: () => ({}) }
7878
}`)
7979
assertCode(content)
8080
})
@@ -92,11 +92,11 @@ describe('sfc props transform', () => {
9292
// function
9393
expect(content).toMatch(`props: {
9494
foo: { default: 1 },
95-
bar: { default: () => {} },
95+
bar: { default: () => ({}) },
9696
baz: null,
9797
boola: { type: Boolean },
9898
boolb: { type: [Boolean, Number] },
99-
func: { type: Function, default: () => () => {} }
99+
func: { type: Function, default: () => (() => {}) }
100100
}`)
101101
assertCode(content)
102102
})

packages/compiler-sfc/src/compileScript.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ export function compileScript(
735735
destructured.default.end!
736736
)
737737
const isLiteral = destructured.default.type.endsWith('Literal')
738-
return isLiteral ? value : `() => ${value}`
738+
return isLiteral ? value : `() => (${value})`
739739
}
740740
}
741741

0 commit comments

Comments
 (0)