fix: align numeric placeholder generation with babel#239
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #239 +/- ##
==========================================
+ Coverage 94.95% 94.99% +0.03%
==========================================
Files 10 10
Lines 2597 2637 +40
==========================================
+ Hits 2466 2505 +39
- Misses 131 132 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
TODO: we need to add the same test cases for the babel plugin, so the implementation will not diverge in a future. The first fix is looks good to me. The second is bothering me, because it think the original implementation of the named placeholders went wrong, and now fixes on top of this implementation making everethying quite complicated and not straightforward. Could you may be split this into 2 PRs, and i happily approve fix for the first one, and think a bit for the solution for the second one. |
e08f777 to
5ffbfd5
Compare
|
@timofei-iatsenko: I've extracted the second bug fix into #241 |
The SWC plugin assigned auto-generated numeric placeholder indices (
{0},{1}, …) differently from the reference Babel/JS macro (@lingui/babel-plugin-lingui-macro). Because message IDs andvalueskeys are derived from these indices, the two toolchains could extract different catalogs for identical source, and thus break translation lookups in projects that mix the JS and SWC tooling.ph({ name }),{label: value}and bare identifiers carry an explicit name and, in the babel macro, never advance the counter. The SWC plugin derived the next numeric index fromvalues_indexed.len(), which also counted named placeholders, so any unnamed expression following a named one was numbered one too high.{available} of {1, plural, one {# zone} other {# zones}} available{available} of {0, plural, one {# zone} other {# zones}} availableFix
Replaced the
values_indexed.len()-based index with a dedicatednumeric_indexcounter (next_numeric_index) that is advanced only when an auto-numeric placeholder is actually assigned — never for named placeholders. This mirrorsgetExpressionIndex.