@@ -46,6 +46,11 @@ import {
46
46
const ALIAS_PARENS = /^(\s*)\(([\s\S]+)\)(\s*(?:in|of)\b[\s\S]+)$/u
47
47
const DUMMY_PARENT: any = {}
48
48
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*=>|^function\s*\(/u
52
+ const IS_SIMPLE_PATH = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?'\]|\["[^"]*?"\]|\[\d+\]|\[[A-Za-z_$][\w$]*\])*$/u
53
+
49
54
/**
50
55
* The interface of ESLint custom parsers.
51
56
*/
@@ -807,6 +812,24 @@ export function parseVOnExpression(
807
812
code: string,
808
813
locationCalculator: LocationCalculator,
809
814
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,
810
833
): ExpressionParseResult<VOnExpression> {
811
834
debug('[script] parse v-on expression: "void function($event){%s}"', code)
812
835
0 commit comments