Przeglądaj źródła

fix: fix function expression regex (#9922)

fix #9920
GU Yiling 7 lat temu
rodzic
commit
569b728ab1

+ 1 - 1
src/compiler/codegen/events.js

@@ -1,6 +1,6 @@
 /* @flow */
 /* @flow */
 
 
-const fnExpRE = /^([\w$_]+|\([^)]*?\))\s*=>|^function\s*(?:[\w$]+)?\s*\(/
+const fnExpRE = /^([\w$_]+|\([^)]*?\))\s*=>|^function(?:\s+[\w$]+)?\s*\(/
 const fnInvokeRE = /\([^)]*?\);*$/
 const fnInvokeRE = /\([^)]*?\);*$/
 const simplePathRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*$/
 const simplePathRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*$/
 
 

+ 5 - 0
test/unit/modules/compiler/codegen.spec.js

@@ -345,6 +345,11 @@ describe('codegen', () => {
       `<input @input="onInput(');[\\'());');">`,
       `<input @input="onInput(');[\\'());');">`,
       `with(this){return _c('input',{on:{"input":function($event){onInput(');[\\'());');}}})}`
       `with(this){return _c('input',{on:{"input":function($event){onInput(');[\\'());');}}})}`
     )
     )
+    // function name including a `function` part (#9920)
+    assertCodegen(
+      '<input @input="functionName()">',
+      `with(this){return _c('input',{on:{"input":function($event){return functionName()}}})}`
+    )
   })
   })
 
 
   it('generate events with multiple statements', () => {
   it('generate events with multiple statements', () => {