Skip to content

Commit 79ecf1e

Browse files
authored
Fix wrong AST for asycn function in v-on (#227)
* Fix wrong AST for asycn function in v-on * chore: add comment * chore: fix comment
1 parent ae61e8d commit 79ecf1e

File tree

9 files changed

+2011
-2
lines changed

9 files changed

+2011
-2
lines changed

Diff for: src/script/index.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,15 @@ const PARENS = /^(\s*\()([\s\S]*?)(\)\s*)$/u
7575
const DUMMY_PARENT: any = {}
7676

7777
// Like Vue, it judges whether it is a function expression or not.
78-
// https://github.com/vuejs/vue/blob/0948d999f2fddf9f90991956493f976273c5da1f/src/compiler/codegen/events.js#L3
79-
const IS_FUNCTION_EXPRESSION = /^\s*([\w$_]+|\([^)]*?\))\s*=>|^function\s*\(/u
78+
// https://github.com/vuejs/core/blob/fef2acb2049fce3407dff17fe8af1836b97dfd73/packages/compiler-core/src/transforms/vOn.ts#L19
79+
const IS_FUNCTION_EXPRESSION =
80+
/^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/u
81+
// ^^^^^^^ omit paren argument ^^^^^^^^ function keyword
82+
// ^^^^^ <--- async keyword (optional) ---> ^^^^^
83+
// ^^------^^ arguments with parens ^^^^^^ named function (optional)
84+
// ^^^^^^^^^ return types (optional)
85+
// ^^ arrow ^^ opening paren
86+
8087
const IS_SIMPLE_PATH =
8188
/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?'\]|\["[^"]*?"\]|\[\d+\]|\[[A-Za-z_$][\w$]*\])*$/u
8289

0 commit comments

Comments
 (0)