Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/codegen/events.js
Original file line number Diff line number Diff line change
@@ -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$]*])*$/

Expand Down
25 changes: 25 additions & 0 deletions test/unit/modules/compiler/codegen.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */