@@ -9,7 +9,6 @@ import sortedIndexBy from "lodash/sortedIndexBy"
9
9
import {
10
10
traverseNodes ,
11
11
ESLintArrayPattern ,
12
- ESLintBlockStatement ,
13
12
ESLintCallExpression ,
14
13
ESLintExpression ,
15
14
ESLintExpressionStatement ,
@@ -132,24 +131,6 @@ function normalizeLeft(
132
131
return [ id ]
133
132
}
134
133
135
- /**
136
- * Remove references by name.
137
- * @param references The array of references to remove.
138
- * @param name The name of target references.
139
- */
140
- function removeByName ( references : Reference [ ] , name : string ) : void {
141
- let i = 0
142
- while ( i < references . length ) {
143
- const reference = references [ i ]
144
-
145
- if ( reference . id . name === name ) {
146
- references . splice ( i , 1 )
147
- } else {
148
- i += 1
149
- }
150
- }
151
- }
152
-
153
134
/**
154
135
* Get the comma token before a given node.
155
136
* @param tokens The token list.
@@ -500,20 +481,23 @@ export function parseVOnExpression(
500
481
locationCalculator : LocationCalculator ,
501
482
parserOptions : any ,
502
483
) : ExpressionParseResult {
503
- debug ( '[script] parse v-on expression: "{%s}"' , code )
484
+ debug ( '[script] parse v-on expression: "void function($event) {%s}"' , code )
504
485
505
486
if ( code . trim ( ) === "" ) {
506
487
throwEmptyError ( locationCalculator , "statements" )
507
488
}
508
489
509
490
try {
510
491
const ast = parseScriptFragment (
511
- `{${ code } }` ,
512
- locationCalculator . getSubCalculatorAfter ( - 1 ) ,
492
+ `void function($event) {${ code } }` ,
493
+ locationCalculator . getSubCalculatorAfter ( - 22 ) ,
513
494
parserOptions ,
514
495
) . ast
515
496
const references = analyzeExternalReferences ( ast , parserOptions )
516
- const block = ast . body [ 0 ] as ESLintBlockStatement
497
+ const outermostStatement = ast . body [ 0 ] as ESLintExpressionStatement
498
+ const functionDecl = ( outermostStatement . expression as ESLintUnaryExpression )
499
+ . argument as ESLintFunctionExpression
500
+ const block = functionDecl . body
517
501
const body = block . body
518
502
const firstStatement = first ( body )
519
503
const lastStatement = last ( body )
@@ -548,13 +532,10 @@ export function parseVOnExpression(
548
532
b . parent = expression
549
533
}
550
534
551
- // Remvoe braces.
552
- tokens . shift ( )
535
+ // Remove braces.
536
+ tokens . splice ( 0 , 6 )
553
537
tokens . pop ( )
554
538
555
- // Remove $event: https://vuejs.org/v2/api/#v-on
556
- removeByName ( references , "$event" )
557
-
558
539
return { expression, tokens, comments, references, variables : [ ] }
559
540
} catch ( err ) {
560
541
return throwErrorAsAdjustingOutsideOfCode ( err , code , locationCalculator )
0 commit comments