Răsfoiți Sursa

fix(codegen): support named function expression in v-on (#9709)

fix #9707
GU Yiling 7 ani în urmă
părinte
comite
3433ba5bee

+ 1 - 1
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$]*])*$/
 

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

@@ -500,6 +500,11 @@ describe('codegen', () => {
       '<input @input="function () { current++ }">',
       `with(this){return _c('input',{on:{"input":function () { current++ }}})}`
     )
+    // normal named function
+    assertCodegen(
+      '<input @input="function fn () { current++ }">',
+      `with(this){return _c('input',{on:{"input":function fn () { current++ }}})}`
+    )
     // arrow with no args
     assertCodegen(
       '<input @input="()=>current++">',