mirror of https://github.com/vuejs/core.git
fix(compiler-core): add support for arrow aysnc function with unbracketed (#5789)
close #5788
This commit is contained in:
parent
f750c41b51
commit
ca7d421e87
|
@ -286,6 +286,23 @@ describe('compiler: transform v-on', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('should NOT wrap as function if expression is already function expression (async)', () => {
|
||||||
|
const { node } = parseWithVOn(
|
||||||
|
`<div @click="async $event => await foo($event)"/>`,
|
||||||
|
)
|
||||||
|
expect((node.codegenNode as VNodeCall).props).toMatchObject({
|
||||||
|
properties: [
|
||||||
|
{
|
||||||
|
key: { content: `onClick` },
|
||||||
|
value: {
|
||||||
|
type: NodeTypes.SIMPLE_EXPRESSION,
|
||||||
|
content: `async $event => await foo($event)`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
test('should NOT wrap as function if expression is already function expression (with newlines)', () => {
|
test('should NOT wrap as function if expression is already function expression (with newlines)', () => {
|
||||||
const { node } = parseWithVOn(
|
const { node } = parseWithVOn(
|
||||||
`<div @click="
|
`<div @click="
|
||||||
|
@ -630,6 +647,39 @@ describe('compiler: transform v-on', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('inline async arrow function with no bracket expression handler', () => {
|
||||||
|
const { root, node } = parseWithVOn(
|
||||||
|
`<div v-on:click="async e => await foo(e)" />`,
|
||||||
|
{
|
||||||
|
prefixIdentifiers: true,
|
||||||
|
cacheHandlers: true,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(root.cached).toBe(1)
|
||||||
|
const vnodeCall = node.codegenNode as VNodeCall
|
||||||
|
// should not treat cached handler as dynamicProp, so no flags
|
||||||
|
expect(vnodeCall.patchFlag).toBeUndefined()
|
||||||
|
expect(
|
||||||
|
(vnodeCall.props as ObjectExpression).properties[0].value,
|
||||||
|
).toMatchObject({
|
||||||
|
type: NodeTypes.JS_CACHE_EXPRESSION,
|
||||||
|
index: 0,
|
||||||
|
value: {
|
||||||
|
type: NodeTypes.COMPOUND_EXPRESSION,
|
||||||
|
children: [
|
||||||
|
`async `,
|
||||||
|
{ content: `e` },
|
||||||
|
` => await `,
|
||||||
|
{ content: `_ctx.foo` },
|
||||||
|
`(`,
|
||||||
|
{ content: `e` },
|
||||||
|
`)`,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
test('inline async function expression handler', () => {
|
test('inline async function expression handler', () => {
|
||||||
const { root, node } = parseWithVOn(
|
const { root, node } = parseWithVOn(
|
||||||
`<div v-on:click="async function () { await foo() } " />`,
|
`<div v-on:click="async function () { await foo() } " />`,
|
||||||
|
|
|
@ -17,7 +17,7 @@ import { hasScopeRef, isMemberExpression } from '../utils'
|
||||||
import { TO_HANDLER_KEY } from '../runtimeHelpers'
|
import { TO_HANDLER_KEY } from '../runtimeHelpers'
|
||||||
|
|
||||||
const fnExpRE =
|
const fnExpRE =
|
||||||
/^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/
|
/^\s*(async\s*)?(\([^)]*?\)|[\w$_]+)\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/
|
||||||
|
|
||||||
export interface VOnDirectiveNode extends DirectiveNode {
|
export interface VOnDirectiveNode extends DirectiveNode {
|
||||||
// v-on without arg is handled directly in ./transformElements.ts due to it affecting
|
// v-on without arg is handled directly in ./transformElements.ts due to it affecting
|
||||||
|
|
Loading…
Reference in New Issue