From fe34f96a3ead6f841601cd36517391caa2a51780 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 7 Aug 2019 11:47:42 +0200 Subject: [PATCH] fix(compiler): allow inline async functions in event handlers --- src/compiler/codegen/events.js | 2 +- test/unit/modules/compiler/codegen.spec.js | 25 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/compiler/codegen/events.js b/src/compiler/codegen/events.js index fc817c03d52..2bd64172534 100644 --- a/src/compiler/codegen/events.js +++ b/src/compiler/codegen/events.js @@ -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$]*])*$/ diff --git a/test/unit/modules/compiler/codegen.spec.js b/test/unit/modules/compiler/codegen.spec.js index 10c65618a58..608d8dceee3 100644 --- a/test/unit/modules/compiler/codegen.spec.js +++ b/test/unit/modules/compiler/codegen.spec.js @@ -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( + ``, + `with(this){return _c('button',{on:{"click":async () => a += await 2}})}` + ) + assertCodegen( + ``, + `with(this){return _c('button',{on:{"click":async() => a += await 2}})}` + ) + }) + + it('should allow async arrow functions with parameters in event handlers', () => { + assertCodegen( + ``, + `with(this){return _c('button',{on:{"click":async n => n += await 2}})}` + ) + }) + + it('should allow async functions in event handlers', () => { + assertCodegen( + ``, + `with(this){return _c('button',{on:{"click":async function () { a += await 2}}})}` + ) + }) }) /* eslint-enable quotes */