From 8b0510ac9198fb5ed82eae11d9627aa99ecf9e9f Mon Sep 17 00:00:00 2001 From: GU Yiling Date: Mon, 18 Mar 2019 16:19:41 +0800 Subject: [PATCH] fix(codegen): support named function expression in v-on (#9709) fix #9707 --- src/compiler/codegen/events.js | 2 +- test/unit/modules/compiler/codegen.spec.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/compiler/codegen/events.js b/src/compiler/codegen/events.js index 8ce9e1b58e1..44657e38cd8 100644 --- a/src/compiler/codegen/events.js +++ b/src/compiler/codegen/events.js @@ -1,6 +1,6 @@ /* @flow */ -const fnExpRE = /^([\w$_]+|\([^)]*?\))\s*=>|^function\s*\(/ +const fnExpRE = /^([\w$_]+|\([^)]*?\))\s*=>|^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 e56b25766f2..e946e218491 100644 --- a/test/unit/modules/compiler/codegen.spec.js +++ b/test/unit/modules/compiler/codegen.spec.js @@ -500,6 +500,11 @@ describe('codegen', () => { '', `with(this){return _c('input',{on:{"input":function () { current++ }}})}` ) + // normal named function + assertCodegen( + '', + `with(this){return _c('input',{on:{"input":function fn () { current++ }}})}` + ) // arrow with no args assertCodegen( '',