Ver Fonte

fix v-on handler with whitespaces (fix #3893)

Evan You há 9 anos atrás
pai
commit
74e4e11b44

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

@@ -1,6 +1,6 @@
 /* @flow */
 
-const simplePathRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['.*?'\]|\[".*?"\]|\[\d+\]|\[[A-Za-z_$][\w$]*\])*$/
+const simplePathRE = /^\s*[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['.*?'\]|\[".*?"\]|\[\d+\]|\[[A-Za-z_$][\w$]*\])*\s*$/
 
 // keyCode aliases
 const keyCodes = {

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

@@ -244,6 +244,14 @@ describe('codegen', () => {
     )
   })
 
+  // #3893
+  it('should not treat handler with unexpected whitespace as inline statement', () => {
+    assertCodegen(
+      '<input @input=" onInput ">',
+      `with(this){return _h('input',{on:{"input": onInput }})}`
+    )
+  })
+
   it('generate unhandled events', () => {
     assertCodegen(
       '<input @input="curent++">',