1
1
/* @flow */
2
2
3
3
const fnExpRE = / ^ ( [ \w $ _ ] + | \( [ ^ ) ] * ?\) ) \s * = > | ^ f u n c t i o n \s * \( /
4
+ const fnInvokeRE = / \( [ ^ ) ] * ?\) $ /
4
5
const simplePathRE = / ^ [ A - Z a - z _ $ ] [ \w $ ] * (?: \. [ A - Z a - z _ $ ] [ \w $ ] * | \[ ' [ ^ ' ] * ?' ] | \[ " [ ^ " ] * ?" ] | \[ \d + ] | \[ [ A - Z a - z _ $ ] [ \w $ ] * ] ) * $ /
5
6
6
7
// KeyboardEvent.keyCode aliases
@@ -94,6 +95,7 @@ function genHandler (
94
95
95
96
const isMethodPath = simplePathRE . test ( handler . value )
96
97
const isFunctionExpression = fnExpRE . test ( handler . value )
98
+ const isFunctionInvocation = fnInvokeRE . test ( handler . value )
97
99
98
100
if ( ! handler . modifiers ) {
99
101
if ( isMethodPath || isFunctionExpression ) {
@@ -103,7 +105,9 @@ function genHandler (
103
105
if ( __WEEX__ && handler . params ) {
104
106
return genWeexHandler ( handler . params , handler . value )
105
107
}
106
- return `function($event){${ handler . value } }` // inline statement
108
+ return `function($event){${
109
+ isFunctionInvocation ? `return (${ handler . value } )` : handler . value
110
+ } }` // inline statement
107
111
} else {
108
112
let code = ''
109
113
let genModifierCode = ''
@@ -138,7 +142,9 @@ function genHandler (
138
142
? `return ${ handler . value } ($event)`
139
143
: isFunctionExpression
140
144
? `return (${ handler . value } )($event)`
141
- : handler . value
145
+ : isFunctionInvocation
146
+ ? `return (${ handler . value } )`
147
+ : handler . value
142
148
/* istanbul ignore if */
143
149
if ( __WEEX__ && handler . params ) {
144
150
return genWeexHandler ( handler . params , code + handlerCode )
0 commit comments