Skip to content

Commit

Permalink
Fix wrong AST for asycn function in v-on (#227)
Browse files Browse the repository at this point in the history
* Fix wrong AST for asycn function in v-on

* chore: add comment

* chore: fix comment
  • Loading branch information
ota-meshi authored Jun 1, 2024
1 parent ae61e8d commit 79ecf1e
Show file tree
Hide file tree
Showing 9 changed files with 2,011 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,15 @@ const PARENS = /^(\s*\()([\s\S]*?)(\)\s*)$/u
const DUMMY_PARENT: any = {}

// Like Vue, it judges whether it is a function expression or not.
// https://github.com/vuejs/vue/blob/0948d999f2fddf9f90991956493f976273c5da1f/src/compiler/codegen/events.js#L3
const IS_FUNCTION_EXPRESSION = /^\s*([\w$_]+|\([^)]*?\))\s*=>|^function\s*\(/u
// https://github.com/vuejs/core/blob/fef2acb2049fce3407dff17fe8af1836b97dfd73/packages/compiler-core/src/transforms/vOn.ts#L19
const IS_FUNCTION_EXPRESSION =
/^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/u
// ^^^^^^^ omit paren argument ^^^^^^^^ function keyword
// ^^^^^ <--- async keyword (optional) ---> ^^^^^
// ^^------^^ arguments with parens ^^^^^^ named function (optional)
// ^^^^^^^^^ return types (optional)
// ^^ arrow ^^ opening paren

const IS_SIMPLE_PATH =
/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?'\]|\["[^"]*?"\]|\[\d+\]|\[[A-Za-z_$][\w$]*\])*$/u

Expand Down
Loading

0 comments on commit 79ecf1e

Please sign in to comment.