fix: throw on dynamic macro message ids#2553
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2553 +/- ##
===========================================
+ Coverage 77.05% 89.55% +12.50%
===========================================
Files 84 119 +35
Lines 2157 3475 +1318
Branches 555 1036 +481
===========================================
+ Hits 1662 3112 +1450
+ Misses 382 327 -55
+ Partials 113 36 -77 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| name: "Preserve custom ID (dynamic expression)", | ||
| code: ` | ||
| import { Trans } from '@lingui/react/macro'; | ||
| const dynId = "dynamic"; | ||
| <Trans id={dynId}>Hello World</Trans>; | ||
| `, |
There was a problem hiding this comment.
This is a misuse and it should throw. Or maybe i'm missing some valid use case?
There was a problem hiding this comment.
I was careless and misunderstood the intent. The best solution would be to throw an error.
|
As wrote above, passing a dynamic id is acceptable only on the runtime Trans. This is a valid pattern to resolve "lazy" translations. However passing a dynamic id to the Trans macro - break the logic. Extractor would not be able to extract this correctly, and it most likely a misuse. if you have a dynamic id - means you defined a message somewhere else. the message and parameters of Trans macro would be discarded. |
This reverts commit 41ebc0d.
Description
Throw a compile-time error when Lingui macros receive a dynamic message
idin JS or JSX.Note: the SWC plugin has the same gap and should be fixed separately.
Types of changes
Fixes #2523
Checklist