This commit is contained in:
郝晨光 2025-07-01 14:11:30 +01:00 committed by GitHub
commit b7d2467311
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 3 deletions

View File

@ -517,7 +517,9 @@ export default /*@__PURE__*/_defineComponent({
qux: { type: Function, required: false, default() { return 1 } }, qux: { type: Function, required: false, default() { return 1 } },
quux: { type: Function, required: false, default() { } }, quux: { type: Function, required: false, default() { } },
quuxx: { type: Promise, required: false, async default() { return await Promise.resolve('hi') } }, 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 }) { setup(__props: any, { expose: __expose }) {
__expose(); __expose();

View File

@ -388,12 +388,16 @@ const props = defineProps({ foo: String })
quux?(): void quux?(): void
quuxx?: Promise<string>; quuxx?: Promise<string>;
fred?: string fred?: string
toLowerCase: (str: string) => string
toUpperCase: (str: string) => string
}>(), { }>(), {
foo: 'hi', foo: 'hi',
qux() { return 1 }, qux() { return 1 },
['quux']() { }, ['quux']() { },
async quuxx() { return await Promise.resolve('hi') }, 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> </script>
`) `)
@ -415,6 +419,12 @@ const props = defineProps({ foo: String })
expect(content).toMatch( expect(content).toMatch(
`fred: { type: String, required: false, get default() { return 'fred' } }`, `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(content).toMatch(`const props = __props`)
expect(bindings).toStrictEqual({ expect(bindings).toStrictEqual({
foo: BindingTypes.PROPS, foo: BindingTypes.PROPS,
@ -424,6 +434,8 @@ const props = defineProps({ foo: String })
quux: BindingTypes.PROPS, quux: BindingTypes.PROPS,
quuxx: BindingTypes.PROPS, quuxx: BindingTypes.PROPS,
fred: BindingTypes.PROPS, fred: BindingTypes.PROPS,
toLowerCase: BindingTypes.PROPS,
toUpperCase: BindingTypes.PROPS,
props: BindingTypes.SETUP_CONST, props: BindingTypes.SETUP_CONST,
}) })
}) })

View File

@ -262,7 +262,7 @@ function genRuntimePropFromType(
} else { } else {
defaultString = `${prop.async ? 'async ' : ''}${ defaultString = `${prop.async ? 'async ' : ''}${
prop.kind !== 'method' ? `${prop.kind} ` : '' prop.kind !== 'method' ? `${prop.kind} ` : ''
}default() ${ctx.getString(prop.body)}` }default(${prop.params.map(node => ctx.getString(node)).join(',')}) ${ctx.getString(prop.body)}`
} }
} }
} }