fix(compiler): allow inline async functions in event handlers

This commit is contained in:
Eduardo San Martin Morote
2019-08-07 11:47:42 +02:00
parent d40b7ddb81
commit fe34f96a3e
2 changed files with 26 additions and 1 deletions

View File

@@ -1,6 +1,6 @@
/* @flow */
const fnExpRE = /^([\w$_]+|\([^)]*?\))\s*=>|^function(?:\s+[\w$]+)?\s*\(/
const fnExpRE = /^((?:async )?[\w$_]+|(?:async ?)?\([^)]*?\))\s*=>|^(?:async )?function(?:\s+[\w$]+)?\s*\(/
const fnInvokeRE = /\([^)]*?\);*$/
const simplePathRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*$/

View File

@@ -701,5 +701,30 @@ describe('codegen', () => {
`with(this){return _c('div',[(ok)?_l((1),function(i){return _c('foo',{key:i})}):_e()],2)}`
)
})
it('should allow async arrow functions in event handlers', () => {
assertCodegen(
`<button @click="async () => a += await 2"></button>`,
`with(this){return _c('button',{on:{"click":async () => a += await 2}})}`
)
assertCodegen(
`<button @click="async() => a += await 2"></button>`,
`with(this){return _c('button',{on:{"click":async() => a += await 2}})}`
)
})
it('should allow async arrow functions with parameters in event handlers', () => {
assertCodegen(
`<button @click="async n => n += await 2"></button>`,
`with(this){return _c('button',{on:{"click":async n => n += await 2}})}`
)
})
it('should allow async functions in event handlers', () => {
assertCodegen(
`<button @click="async function () { a += await 2}"></button>`,
`with(this){return _c('button',{on:{"click":async function () { a += await 2}}})}`
)
})
})
/* eslint-enable quotes */