Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,9 @@ export default /*@__PURE__*/_defineComponent({
qux: { type: Function, required: false, default() { return 1 } },
quux: { type: Function, required: false, default() { } },
quuxx: { type: Promise, required: false, async default() { return await Promise.resolve('hi') } },
fred: { type: String, required: false, get default() { return 'fred' } }
fred: { type: String, required: false, get default() { return 'fred' } },
toLowerCase: { type: Function, required: true, default: (str: string) => str.toLowerCase() },
toUpperCase: { type: Function, required: true, default(str: string) { return str.toUpperCase() } }
},
setup(__props: any, { expose: __expose }) {
__expose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,16 @@ const props = defineProps({ foo: String })
quux?(): void
quuxx?: Promise<string>;
fred?: string
toLowerCase: (str: string) => string
toUpperCase: (str: string) => string
}>(), {
foo: 'hi',
qux() { return 1 },
['quux']() { },
async quuxx() { return await Promise.resolve('hi') },
get fred() { return 'fred' }
get fred() { return 'fred' },
toLowerCase: (str: string) => str.toLowerCase(),
toUpperCase(str: string){ return str.toUpperCase() }
})
</script>
`)
Expand All @@ -415,6 +419,12 @@ const props = defineProps({ foo: String })
expect(content).toMatch(
`fred: { type: String, required: false, get default() { return 'fred' } }`,
)
expect(content).toMatch(
`toLowerCase: { type: Function, required: true, default: (str: string) => str.toLowerCase() }`,
)
expect(content).toMatch(
`toUpperCase: { type: Function, required: true, default(str: string) { return str.toUpperCase() } }`,
)
expect(content).toMatch(`const props = __props`)
expect(bindings).toStrictEqual({
foo: BindingTypes.PROPS,
Expand All @@ -424,6 +434,8 @@ const props = defineProps({ foo: String })
quux: BindingTypes.PROPS,
quuxx: BindingTypes.PROPS,
fred: BindingTypes.PROPS,
toLowerCase: BindingTypes.PROPS,
toUpperCase: BindingTypes.PROPS,
props: BindingTypes.SETUP_CONST,
})
})
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-sfc/src/script/defineProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ function genRuntimePropFromType(
} else {
defaultString = `${prop.async ? 'async ' : ''}${
prop.kind !== 'method' ? `${prop.kind} ` : ''
}default() ${ctx.getString(prop.body)}`
}default(${prop.params.map(node => ctx.getString(node)).join(',')}) ${ctx.getString(prop.body)}`
}
}
}
Expand Down