fix(formatjs): scope static evaluation to formatjs descriptor keys only#591
Conversation
Two bugs caused valid JSX outside formatjs calls to trigger the
"must be statically evaluate-able" error:
1. `visit_mut_jsx_opening_element` only guarded against `JSXElementName::Ident`
names. Member expressions like `React.Suspense` fell through the guard and
had their attributes (e.g. `fallback={<Loading />}`) evaluated, causing
spurious errors.
2. `JSXAttrOrSpread::get_key_value_with_visitor` called `evaluate_expr` for
ALL JSXExprContainer attribute values regardless of the attribute key.
Attributes like `values` or `fallback` that contain JSX expressions would
trigger the error even inside legitimate `FormattedMessage` components.
Fix: return early for non-Ident JSX element names, and only call `evaluate_expr`
for known formatjs descriptor keys (`id`, `defaultMessage`, `description`).
Fixes #588
Co-authored-by: Donny/강동윤 <kdy1@users.noreply.github.com>
|
|
|
PR Review: fix(formatjs): scope static evaluation to formatjs descriptor keys onlyThis PR fixes two related bugs that caused spurious "must be statically evaluate-able" errors on valid JSX outside of formatjs calls. The fixes are well-targeted and minimal. Bug Fix 1:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d1a0294c82
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| match name { | ||
| JSXElementName::Ident(ident) => { | ||
| if !self.component_names.contains(&*ident.sym) { | ||
| return; | ||
| } | ||
| } | ||
| _ => return, |
There was a problem hiding this comment.
Support member-expression message components
visit_mut_jsx_opening_element now returns for every non-Ident tag, which fixes React.Suspense but also skips valid message components written as member expressions, e.g. import * as ReactIntl from 'react-intl'; <ReactIntl.FormattedMessage defaultMessage="..." />. Before this change those nodes still reached create_message_descriptor_from_extractor; with the new early return they never get IDs generated, descriptions removed, or messages extracted. This affects projects that use namespace imports or object-qualified wrapper components.
Useful? React with 👍 / 👎.
## Summary - Addressed `chatgpt-codex-connector[bot]` review follow-ups across merged PRs: #585, #591, #592, #593, #594, #595, #597, #598, #599. - Applied the fixes as 9 separate commits (one commit per original PR) in a single follow-up branch. ## What Changed - #585 / #592 (`loadable-components`) - Fixed source-less default-import matching to honor the configured local name. - Updated `ssr: false` detection to respect final object-literal override order. - Added/updated fixtures for both behaviors. - #591 / #594 (`formatjs`) - Added JSX member-expression message component support (e.g. `ReactIntl.FormattedMessage`). - Updated #532 regression coverage to validate the `ast: true` path. - #593 / #595 (`graphql-codegen-client-preset`) - Extended `namingConvention` parsing to accept string/object forms. - Preserved names for `keep`/unknown conventions instead of forcing PascalCase. - Fixed Windows absolute `filename` path handling in WASM runtime path resolution. - Added unit coverage for the new config/path behaviors. - #597 / #599 (`emotion`) - Ensured tagged-template labels are terminated before sourcemap comments. - Added css-prop rewrite support for namespace imports (`emotionReact.css`). - Attached PURE comments to the generated call site span. - Updated emotion fixtures accordingly. - #598 (docs) - Corrected capability descriptions in `packages/jest/README.tmpl.md` and `packages/swc-sdk/README.tmpl.md`. ## Validation - `cargo test -p swc_plugin_loadable_components --test fixture -- --ignored` - `cargo test -p swc_plugin_graphql_codegen_client_preset` - `cargo test -p swc_emotion --test fixture -- --ignored` - `pnpm -C /Users/kdy1/.codex/worktrees/17e6/plugins/packages/formatjs test` All passed (formatjs has an existing non-blocking Vitest warning about an un-awaited rejects assertion).
Two bugs caused valid JSX outside formatjs calls to trigger the "must be statically evaluate-able" error:
visit_mut_jsx_opening_elementonly guarded againstJSXElementName::Identnames. Member expressions likeReact.Suspensefell through the guard and had their attributes (e.g.fallback={<Loading />}) evaluated, causing spurious errors.JSXAttrOrSpread::get_key_value_with_visitorcalledevaluate_exprfor ALLJSXExprContainerattribute values regardless of the attribute key. Attributes likevaluesorfallbackthat contain JSX expressions would trigger the error even inside legitimateFormattedMessagecomponents.Fixes #588
Generated with Claude Code