Skip to content

Commit fe34f96

Browse files
committed
fix(compiler): allow inline async functions in event handlers
1 parent d40b7dd commit fe34f96

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/compiler/codegen/events.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* @flow */
22

3-
const fnExpRE = /^([\w$_]+|\([^)]*?\))\s*=>|^function(?:\s+[\w$]+)?\s*\(/
3+
const fnExpRE = /^((?:async )?[\w$_]+|(?:async ?)?\([^)]*?\))\s*=>|^(?:async )?function(?:\s+[\w$]+)?\s*\(/
44
const fnInvokeRE = /\([^)]*?\);*$/
55
const simplePathRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*$/
66

test/unit/modules/compiler/codegen.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,5 +701,30 @@ describe('codegen', () => {
701701
`with(this){return _c('div',[(ok)?_l((1),function(i){return _c('foo',{key:i})}):_e()],2)}`
702702
)
703703
})
704+
705+
it('should allow async arrow functions in event handlers', () => {
706+
assertCodegen(
707+
`<button @click="async () => a += await 2"></button>`,
708+
`with(this){return _c('button',{on:{"click":async () => a += await 2}})}`
709+
)
710+
assertCodegen(
711+
`<button @click="async() => a += await 2"></button>`,
712+
`with(this){return _c('button',{on:{"click":async() => a += await 2}})}`
713+
)
714+
})
715+
716+
it('should allow async arrow functions with parameters in event handlers', () => {
717+
assertCodegen(
718+
`<button @click="async n => n += await 2"></button>`,
719+
`with(this){return _c('button',{on:{"click":async n => n += await 2}})}`
720+
)
721+
})
722+
723+
it('should allow async functions in event handlers', () => {
724+
assertCodegen(
725+
`<button @click="async function () { a += await 2}"></button>`,
726+
`with(this){return _c('button',{on:{"click":async function () { a += await 2}}})}`
727+
)
728+
})
704729
})
705730
/* eslint-enable quotes */

0 commit comments

Comments
 (0)