From 569b728ab19d1956bf935a98c9c65a03d92ac85f Mon Sep 17 00:00:00 2001 From: GU Yiling Date: Thu, 25 Apr 2019 21:04:36 +0800 Subject: [PATCH] fix: fix function expression regex (#9922) fix #9920 --- 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 44657e38cd8..fc817c03d52 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 = /^([\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 e946e218491..10c65618a58 100644 --- a/test/unit/modules/compiler/codegen.spec.js +++ b/test/unit/modules/compiler/codegen.spec.js @@ -345,6 +345,11 @@ describe('codegen', () => { ``, `with(this){return _c('input',{on:{"input":function($event){onInput(');[\\'());');}}})}` ) + // function name including a `function` part (#9920) + assertCodegen( + '', + `with(this){return _c('input',{on:{"input":function($event){return functionName()}}})}` + ) }) it('generate events with multiple statements', () => {