Skip to content

formatjs_cli extract misses formatMessage() calls nested in callbacks inside optional chains #6459

@walkerburgin

Description

@walkerburgin

Which package?

//crates/formatjs_cli

Describe the bug

The formatjs CLI does not identify messages like this:

  // Case 6: formatMessage nested in a callback inside an optional chain.
  getUsers()?.map(() =>
    intl.formatMessage(
      {
        defaultMessage: 'In a callback inside an optional chain',
        description: 'Test callbacks inside an optional chain',
      },
    ),
  ).join(', ')

To Reproduce

Codesandbox URL

N/A

Reproducible Steps/Repo

Steps to reproduce the behavior:

  1. Go to packages/ts-transformer/tests/fixtures/optionalChaining.tsx
  2. Add the failing test case to the fixture
  3. Go to crates/formatjs_cli/src/extractor.rs
  4. Add the expected message to the test:
            MessageDescriptor {
                id: None,
                default_message: Some("In a callback inside an optional chain".to_string()),
                description: Some(Value::String("Test callbacks inside an optional chain".to_string())),
                file: None,
                start: None,
                end: None,
            },
  5. Run bazel test //crates/formatjs_cli:formatjs_cli_test
  6. Observe that the test fails

Expected behavior

Expected behavior is that the Rust CLI extracts the message.

Screenshots

N/A

Desktop (please complete the following information):

  • OS: [e.g. iOS] MacOS
  • Browser [e.g. chrome, safari] Chrome
  • Version [e.g. 22] master (c281a36db86d4f8e3370010bc568dc9852b59e5e)

Additional context

Initially encountered while using [email protected]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions