@@ -46,6 +46,11 @@ import {
4646const ALIAS_PARENS = / ^ ( \s * ) \( ( [ \s \S ] + ) \) ( \s * (?: i n | o f ) \b [ \s \S ] + ) $ / u
4747const DUMMY_PARENT : any = { }
4848
49+ // Like Vue, it judges whether it is a function expression or not.
50+ // https://github.com/vuejs/vue/blob/0948d999f2fddf9f90991956493f976273c5da1f/src/compiler/codegen/events.js#L3
51+ const IS_FUNCTION_EXPRESSION = / ^ \s * ( [ \w $ _ ] + | \( [ ^ ) ] * ?\) ) \s * = > | ^ f u n c t i o n \s * \( / u
52+ const IS_SIMPLE_PATH = / ^ [ A - Z a - z _ $ ] [ \w $ ] * (?: \. [ A - Z a - z _ $ ] [ \w $ ] * | \[ ' [ ^ ' ] * ?' \] | \[ " [ ^ " ] * ?" \] | \[ \d + \] | \[ [ A - Z a - z _ $ ] [ \w $ ] * \] ) * $ / u
53+
4954/**
5055 * The interface of ESLint custom parsers.
5156 */
@@ -807,6 +812,24 @@ export function parseVOnExpression(
807812 code : string ,
808813 locationCalculator : LocationCalculator ,
809814 parserOptions : any ,
815+ ) : ExpressionParseResult < ESLintExpression | VOnExpression > {
816+ if ( IS_FUNCTION_EXPRESSION . test ( code ) || IS_SIMPLE_PATH . test ( code ) ) {
817+ return parseExpressionBody ( code , locationCalculator , parserOptions )
818+ }
819+ return parseVOnExpressionBody ( code , locationCalculator , parserOptions )
820+ }
821+
822+ /**
823+ * Parse the source code of inline scripts.
824+ * @param code The source code of inline scripts.
825+ * @param locationCalculator The location calculator for the inline script.
826+ * @param parserOptions The parser options.
827+ * @returns The result of parsing.
828+ */
829+ function parseVOnExpressionBody (
830+ code : string ,
831+ locationCalculator : LocationCalculator ,
832+ parserOptions : any ,
810833) : ExpressionParseResult < VOnExpression > {
811834 debug ( '[script] parse v-on expression: "void function($event){%s}"' , code )
812835
0 commit comments