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): missing keywords of method property #6972

Merged
merged 2 commits into from Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -1744,12 +1744,14 @@ export default /*#__PURE__*/_defineComponent({
bar: { type: Number, required: false },
baz: { type: Boolean, required: true },
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') } },
fred: { type: String, required: false, get default() { return 'fred' } }
},
setup(__props: any, { expose }) {
expose();

const props = __props as { foo: string, bar?: number, baz: boolean, qux(): number, quux(): void };
const props = __props as { foo: string, bar?: number, baz: boolean, qux(): number, quux(): void, quuxx: Promise<string>, fred: string };



Expand Down
16 changes: 14 additions & 2 deletions packages/compiler-sfc/__tests__/compileScript.spec.ts
Expand Up @@ -1041,10 +1041,14 @@ const emit = defineEmits(['a', 'b'])
baz: boolean;
qux?(): number;
quux?(): void
quuxx?: Promise<string>;
fred?: string
}>(), {
foo: 'hi',
qux() { return 1 },
['quux']() { }
['quux']() { },
async quuxx() { return await Promise.resolve('hi') },
get fred() { return 'fred' }
})
</script>
`)
Expand All @@ -1061,7 +1065,13 @@ const emit = defineEmits(['a', 'b'])
`quux: { type: Function, required: false, default() { } }`
)
expect(content).toMatch(
`{ foo: string, bar?: number, baz: boolean, qux(): number, quux(): void }`
`quuxx: { type: Promise, required: false, async default() { return await Promise.resolve('hi') } }`
)
expect(content).toMatch(
`fred: { type: String, required: false, get default() { return 'fred' } }`
)
expect(content).toMatch(
`{ foo: string, bar?: number, baz: boolean, qux(): number, quux(): void, quuxx: Promise<string>, fred: string }`
)
expect(content).toMatch(`const props = __props`)
expect(bindings).toStrictEqual({
Expand All @@ -1070,6 +1080,8 @@ const emit = defineEmits(['a', 'b'])
baz: BindingTypes.PROPS,
qux: BindingTypes.PROPS,
quux: BindingTypes.PROPS,
quuxx: BindingTypes.PROPS,
fred: BindingTypes.PROPS,
props: BindingTypes.SETUP_CONST
})
})
Expand Down
4 changes: 3 additions & 1 deletion packages/compiler-sfc/src/compileScript.ts
Expand Up @@ -805,7 +805,9 @@ export function compileScript(
prop.value.end!
)}`
} else {
defaultString = `default() ${scriptSetupSource.slice(
defaultString = `${prop.async ? 'async ' : ''}${
prop.kind !== 'method' ? `${prop.kind} ` : ''
}default() ${scriptSetupSource.slice(
prop.body.start!,
prop.body.end!
)}`
Expand Down