Commit 478bf45
fix(parser): inject params into one-line non-async arrow scenarios
parse-function@5.6.10 decides whether its input is an ES6 object method with
`/^\*?.+\([\S\W]*\)\s*{/`. The greedy `.+` combined with `[\S\W]*` matches any
source containing a `) {` sequence, so a non-async arrow whose body holds an
`if`, `for`, `while` or `switch` gets wrapped in braces as a fake object method
and acorn throws. getParams() then returns undefined and nothing is injected —
`I`, page objects and `current` are all undefined when the test runs.
Async arrows escape through the library's own isAsyncArrow check, and in plain
JavaScript a multi-line arrow escapes as well, because `.` does not cross a
newline so the greedy `.+` cannot reach past the first line. That second escape
does not exist under TypeScript: tsx/esbuild emit every function on one line, so
fn.toString() returns the one-line form however the source was written, and
every non-async scenario with destructured params and a conditional fails.
normalizeArrowFn() asks acorn whether the source really is an
ArrowFunctionExpression and, if so, hands parse-function `async <source>` so it
takes the isAsyncArrow branch. Anything acorn does not confirm as an arrow —
class methods, generators, function expressions, strings, unparseable input — is
returned untouched, so only input that fails today is affected. The prefix cannot
change a parameter list, and default values stay correct because their offsets
are sliced from the same prefixed string.
ecmaVersion becomes a shared const so the parse and the arrow check cannot drift
apart; its value is unchanged, so no syntax gains or loses parseability.
Fixes #5679
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>1 parent 8b91815 commit 478bf45
2 files changed
Lines changed: 28 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
20 | | - | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
41 | 53 | | |
42 | 54 | | |
43 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
43 | 57 | | |
44 | 58 | | |
0 commit comments