Commit 5368dff
committed
feat(code-action): convert arrow function to closure
Add a refactor.rewrite code action that converts arrow functions to
anonymous closures: `fn($x) => $x * 2` becomes
`function($x) { return $x * 2; }`.
Variables from the outer scope used in the expression are automatically
detected and captured via a `use()` clause. `$this` is excluded since
closures bind it automatically (unless static). Nested arrow functions
are handled by extending the parameter exclusion set.
Preserves:
- static keyword
- Return type hints
- Parameter type hints
Includes 10 unit tests covering: simple expressions, type hints,
static arrows, single/multiple variable capture, $this exclusion,
parameter exclusion, method calls with captures, and deduplication.
Closes #1481 parent 399b2b1 commit 5368dff
4 files changed
Lines changed: 689 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3585 | 3585 | | |
3586 | 3586 | | |
3587 | 3587 | | |
| 3588 | + | |
| 3589 | + | |
| 3590 | + | |
| 3591 | + | |
| 3592 | + | |
| 3593 | + | |
| 3594 | + | |
| 3595 | + | |
| 3596 | + | |
| 3597 | + | |
| 3598 | + | |
| 3599 | + | |
| 3600 | + | |
| 3601 | + | |
| 3602 | + | |
| 3603 | + | |
| 3604 | + | |
| 3605 | + | |
| 3606 | + | |
| 3607 | + | |
| 3608 | + | |
| 3609 | + | |
| 3610 | + | |
| 3611 | + | |
3588 | 3612 | | |
3589 | 3613 | | |
3590 | 3614 | | |
| |||
0 commit comments