File tree 2 files changed +51
-1
lines changed
2 files changed +51
-1
lines changed Original file line number Diff line number Diff line change @@ -271,6 +271,56 @@ describe('compiler: transform v-on', () => {
271
271
} )
272
272
} )
273
273
274
+ test ( 'should NOT wrap as function if expression is already function expression (with newlines)' , ( ) => {
275
+ const { node } = parseWithVOn (
276
+ `<div @click="
277
+ $event => {
278
+ foo($event)
279
+ }
280
+ "/>`
281
+ )
282
+ expect ( ( node . codegenNode as VNodeCall ) . props ) . toMatchObject ( {
283
+ properties : [
284
+ {
285
+ key : { content : `onClick` } ,
286
+ value : {
287
+ type : NodeTypes . SIMPLE_EXPRESSION ,
288
+ content : `
289
+ $event => {
290
+ foo($event)
291
+ }
292
+ `
293
+ }
294
+ }
295
+ ]
296
+ } )
297
+ } )
298
+
299
+ test ( 'should NOT wrap as function if expression is already function expression (with newlines + function keyword)' , ( ) => {
300
+ const { node } = parseWithVOn (
301
+ `<div @click="
302
+ function($event) {
303
+ foo($event)
304
+ }
305
+ "/>`
306
+ )
307
+ expect ( ( node . codegenNode as VNodeCall ) . props ) . toMatchObject ( {
308
+ properties : [
309
+ {
310
+ key : { content : `onClick` } ,
311
+ value : {
312
+ type : NodeTypes . SIMPLE_EXPRESSION ,
313
+ content : `
314
+ function($event) {
315
+ foo($event)
316
+ }
317
+ `
318
+ }
319
+ }
320
+ ]
321
+ } )
322
+ } )
323
+
274
324
test ( 'should NOT wrap as function if expression is complex member expression' , ( ) => {
275
325
const { node } = parseWithVOn ( `<div @click="a['b' + c]"/>` )
276
326
expect ( ( node . codegenNode as VNodeCall ) . props ) . toMatchObject ( {
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ import { validateBrowserExpression } from '../validateExpression'
16
16
import { isMemberExpression , hasScopeRef } from '../utils'
17
17
import { CAPITALIZE } from '../runtimeHelpers'
18
18
19
- const fnExpRE = / ^ ( [ \w $ _ ] + | \( [ ^ ) ] * ?\) ) \s * = > | ^ f u n c t i o n (?: \s + [ \w $ ] + ) ? \s * \( /
19
+ const fnExpRE = / ^ \s * ( [ \w $ _ ] + | \( [ ^ ) ] * ?\) ) \s * = > | ^ \s * f u n c t i o n (?: \s + [ \w $ ] + ) ? \s * \( /
20
20
21
21
export interface VOnDirectiveNode extends DirectiveNode {
22
22
// v-on without arg is handled directly in ./transformElements.ts due to it affecting
You can’t perform that action at this time.
0 commit comments