Repository navigation
fix: transform JSX macros nested inside expression placeholders - #279
Merged
Merged
Conversation
fold_jsx_element returned transform_jsx_macro(el) for Trans and ICU
choice elements without folding the produced element's children, so
macro elements captured inside values/components expressions (e.g.
{cond ? <Trans/> : <Trans/>} or {cond && <Trans/>}) were emitted
untransformed after the macro import had been removed.
Fold the produced element with self so nested macros inside those
expressions are transformed recursively, matching how every other
fold_* method in the file recurses after transforming.
Fixes lingui#16
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #279 +/- ##
=======================================
Coverage 94.44% 94.44%
=======================================
Files 11 11
Lines 2518 2518
=======================================
Hits 2378 2378
Misses 140 140
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
timofei-iatsenko
approved these changes
Oct 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #16
<Trans>,<Plural>,<Select>and<SelectOrdinal>inside a JSX expression placeholder are now transformed. Before this change, they were emitted as-is, for example in{cond ? <Trans>a</Trans> : <Trans>b</Trans>},{cond && <Trans>a</Trans>}or{items.map(i => <Trans>{i}</Trans>)}. The macro import was still removed, so the output referenced an element with no import.Cause
fold_jsx_elementreturned the result oftransform_jsx_macrowithout folding it again.transform_jsx_macrocopies placeholder expressions verbatim intovaluesandcomponents, so the folder never visited macros inside them. The otherfold_*methods in the sameimpl Foldcallfold_children_with(self)after they transform.Fix
Both macro branches in
fold_jsx_elementnow callfold_children_with(self)on the produced element. The fold runs after the message is built, so a direct child macro such as<Trans>You have <Plural .../></Trans>is still inlined into the parent message. The produced element uses the runtimeTransidentifier, so the fold does not match it again.Before:
After:
The nested descriptors keep their
/*i18n*/comments, so the extractor can find these messages too.Scope
<Plural>or<Trans>into a runtime element, and it would no longer be inlined into the parent message.valuesandcomponents. This also fixes macros in the preservedrenderandcomponentattributes, for examplerender={() => <Trans>x</Trans>}. I can limit it to the descriptor if you prefer a narrower change.Tests
jsx_macros_inside_expression_are_transformedcovers the repro from the issue and the&&form. Without the fix, it shows the untransformed<Trans>invalues.lingui_macroandlingui_extractorsnapshots are unchanged.cargo fmt --checkandcargo clippy -p lingui_macro --all-targets --all-features -- -D warningspass.