Skip to content

Commit

Permalink
fix(compiler-sfc): fix object default values for reactive props destr…
Browse files Browse the repository at this point in the history
…ucture
  • Loading branch information
yyx990803 committed May 10, 2022
1 parent 0683a02 commit 7dfe146
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('sfc props transform', () => {
// function
expect(content).toMatch(`props: _mergeDefaults(['foo', 'bar'], {
foo: 1,
bar: () => {}
bar: () => ({})
})`)
assertCode(content)
})
Expand All @@ -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)
})
Expand All @@ -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)
})
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-sfc/src/compileScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})`
}
}

Expand Down

0 comments on commit 7dfe146

Please sign in to comment.