+32
-2
lines changedFilter options
+32
-2
lines changed Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
1
1
/* @flow */
2
2
3
3
const fnExpRE = /^([\w$_]+|\([^)]*?\))\s*=>|^function\s*\(/
4
+
const fnInvokeRE = /\([^)]*?\)$/
4
5
const simplePathRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[A-Za-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)
Original file line number Diff line number Diff line change
@@ -923,4 +923,28 @@ describe('Directive v-on', () => {
923
923
expect(spy.calls.count()).toBe(0)
924
924
}).then(done)
925
925
})
926
+
927
+
// #7628
928
+
it('handler should return the return value of inline function invocation', () => {
929
+
let value
930
+
new Vue({
931
+
template: `<test @foo="bar()"></test>`,
932
+
methods: {
933
+
bar() {
934
+
return 1
935
+
}
936
+
},
937
+
components: {
938
+
test: {
939
+
created() {
940
+
value = this.$listeners.foo()
941
+
},
942
+
render(h) {
943
+
return h('div')
944
+
}
945
+
}
946
+
}
947
+
}).$mount()
948
+
expect(value).toBe(1)
949
+
})
926
950
})
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4