File tree Expand file tree Collapse file tree 2 files changed +51
-1
lines changed
Expand file tree Collapse file tree 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', () => {
271271 } )
272272 } )
273273
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+
274324 test ( 'should NOT wrap as function if expression is complex member expression' , ( ) => {
275325 const { node } = parseWithVOn ( `<div @click="a['b' + c]"/>` )
276326 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'
1616import { isMemberExpression , hasScopeRef } from '../utils'
1717import { CAPITALIZE } from '../runtimeHelpers'
1818
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 * \( /
2020
2121export interface VOnDirectiveNode extends DirectiveNode {
2222 // 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