Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler-sfc): no params were generated when using withDefaults #12823

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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,6 +517,7 @@ 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') } },
quuux: { type: Number, required: false, default(a, [b, ...c], {d, ...e}, ...f) { return 1 } },
fred: { type: String, required: false, get default() { return 'fred' } }
},
setup(__props: any, { expose: __expose }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,14 @@ const props = defineProps({ foo: String })
qux?(): number;
quux?(): void
quuxx?: Promise<string>;
quuux?: number;
fred?: string
}>(), {
foo: 'hi',
qux() { return 1 },
['quux']() { },
async quuxx() { return await Promise.resolve('hi') },
quuux(a, [b, ...c], {d, ...e}, ...f) { return 1 },
get fred() { return 'fred' }
})
</script>
Expand All @@ -412,6 +414,9 @@ const props = defineProps({ foo: String })
expect(content).toMatch(
`quuxx: { type: Promise, required: false, async default() { return await Promise.resolve('hi') } }`,
)
expect(content).toMatch(
`quuux: { type: Number, required: false, default(a, [b, ...c], {d, ...e}, ...f) { return 1 } }`,
)
expect(content).toMatch(
`fred: { type: String, required: false, get default() { return 'fred' } }`,
)
Expand All @@ -423,6 +428,7 @@ const props = defineProps({ foo: String })
qux: BindingTypes.PROPS,
quux: BindingTypes.PROPS,
quuxx: BindingTypes.PROPS,
quuux: BindingTypes.PROPS,
fred: BindingTypes.PROPS,
props: BindingTypes.SETUP_CONST,
})
Expand Down
8 changes: 7 additions & 1 deletion packages/compiler-sfc/src/script/defineProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,15 @@ function genRuntimePropFromType(
// prop has corresponding static default value
defaultString = `default: ${ctx.getString(prop.value)}`
} else {
let paramsString = ''
if (prop.params.length) {
const start = prop.params[0].start
edison1105 marked this conversation as resolved.
Show resolved Hide resolved
const end = prop.params[prop.params.length - 1].end
paramsString = ctx.getString({ start, end } as Node)
}
defaultString = `${prop.async ? 'async ' : ''}${
prop.kind !== 'method' ? `${prop.kind} ` : ''
}default() ${ctx.getString(prop.body)}`
}default(${paramsString}) ${ctx.getString(prop.body)}`
}
}
}
Expand Down