Commit cb7bb23
fix(formatjs_cli): extract formatMessage from callbacks inside optional chains (#6460)
Fixes #6459.
The Rust CLI's chain-expression visitor walked into call expression
arguments, but skipped the callee. As a result, `formatMessage` calls
inside callbacks passed to optional-chain methods (e.g.
`getUsers()?.map(() => intl.formatMessage(...))`) were never extracted.
## Changes
- Walk both the callee and arguments of a `CallExpression` chain element
so nested `formatMessage` calls inside callback bodies are extracted.
- Drop the `StaticMemberExpression` arm — `walk_chain_expression` covers
it via the default case.
- Add fixture case in
`packages/ts-transformer/tests/fixtures/optionalChaining.tsx`.
- Add Rust unit-test expectation in
`crates/formatjs_cli/src/extractor.rs`.
- Add ts-transformer assertion in
`packages/ts-transformer/tests/index.test.ts`.
- Add CLI conformance case `22_callback_in_optional_chain.txt` so both
Rust and TS extractors are guarded.
## Test plan
- [x] `bazel test //crates/formatjs_cli:formatjs_cli_test`
- [x] `bazel test //packages/ts-transformer:ts-transformer_test`
- [x] `bazel test //packages/cli/integration-tests:conformance_test`
---------
Co-authored-by: Long Ho <[email protected]>
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>1 parent c281a36 commit cb7bb23
5 files changed
Lines changed: 64 additions & 10 deletions
File tree
- crates/formatjs_cli/src
- packages
- cli/integration-tests/conformance-tests/test_cases
- ts-transformer/tests
- fixtures
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
591 | 591 | | |
592 | 592 | | |
593 | 593 | | |
594 | | - | |
595 | | - | |
596 | | - | |
| 594 | + | |
| 595 | + | |
597 | 596 | | |
598 | 597 | | |
599 | 598 | | |
600 | 599 | | |
601 | 600 | | |
602 | 601 | | |
603 | | - | |
604 | | - | |
605 | | - | |
606 | | - | |
607 | 602 | | |
608 | 603 | | |
609 | 604 | | |
| |||
1379 | 1374 | | |
1380 | 1375 | | |
1381 | 1376 | | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
1382 | 1385 | | |
1383 | 1386 | | |
1384 | 1387 | | |
| |||
Lines changed: 31 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
Lines changed: 15 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
4 | 8 | | |
5 | | - | |
| 9 | + | |
6 | 10 | | |
7 | 11 | | |
8 | 12 | | |
| |||
33 | 37 | | |
34 | 38 | | |
35 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
36 | 50 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
710 | 710 | | |
711 | 711 | | |
712 | 712 | | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
713 | 718 | | |
714 | 719 | | |
715 | 720 | | |
| |||
0 commit comments