Skip to content

Commit 5ea150a

Browse files
committed
test: add test for async function with no bracket
1 parent 051407d commit 5ea150a

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

packages/compiler-core/__tests__/transforms/vOn.spec.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,21 @@ describe('compiler: transform v-on', () => {
271271
})
272272
})
273273

274+
test('should NOT wrap as function if expression is already function expression (async)', () => {
275+
const { node } = parseWithVOn(`<div @click="async $event => await foo($event)"/>`)
276+
expect((node.codegenNode as VNodeCall).props).toMatchObject({
277+
properties: [
278+
{
279+
key: { content: `onClick` },
280+
value: {
281+
type: NodeTypes.SIMPLE_EXPRESSION,
282+
content: `async $event => await foo($event)`
283+
}
284+
}
285+
]
286+
})
287+
})
288+
274289
test('should NOT wrap as function if expression is already function expression (with newlines)', () => {
275290
const { node } = parseWithVOn(
276291
`<div @click="
@@ -613,6 +628,39 @@ describe('compiler: transform v-on', () => {
613628
})
614629
})
615630

631+
test('inline async arrow function with no bracket expression handler', () => {
632+
const { root, node } = parseWithVOn(
633+
`<div v-on:click="async e => await foo(e)" />`,
634+
{
635+
prefixIdentifiers: true,
636+
cacheHandlers: true
637+
}
638+
)
639+
640+
expect(root.cached).toBe(1)
641+
const vnodeCall = node.codegenNode as VNodeCall
642+
// should not treat cached handler as dynamicProp, so no flags
643+
expect(vnodeCall.patchFlag).toBeUndefined()
644+
expect(
645+
(vnodeCall.props as ObjectExpression).properties[0].value
646+
).toMatchObject({
647+
type: NodeTypes.JS_CACHE_EXPRESSION,
648+
index: 0,
649+
value: {
650+
type: NodeTypes.COMPOUND_EXPRESSION,
651+
children: [
652+
`async `,
653+
{ content: `e` },
654+
` => await `,
655+
{ content: `_ctx.foo` },
656+
`(`,
657+
{ content: `e` },
658+
`)`
659+
]
660+
}
661+
})
662+
})
663+
616664
test('inline async function expression handler', () => {
617665
const { root, node } = parseWithVOn(
618666
`<div v-on:click="async function () { await foo() } " />`,

0 commit comments

Comments
 (0)