fix: align numeric placeholder generation in <Plural> with babel#241
Open
mogelbrod wants to merge 2 commits into
Open
fix: align numeric placeholder generation in <Plural> with babel#241mogelbrod wants to merge 2 commits into
<Plural> with babel#241mogelbrod wants to merge 2 commits into
Conversation
Contributor
Author
|
@timofei-iatsenko fix for second bug in #239 🙏 I agree that the babel behaviour which this PR mimics isn't ideal. Changing the babel version would be considered a breaking change since it would invalidate translations - which is why I opted to simply mirror it here. I'm open to both approaches though. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #241 +/- ##
==========================================
+ Coverage 94.96% 94.99% +0.02%
==========================================
Files 10 10
Lines 2603 2637 +34
==========================================
+ Hits 2472 2505 +33
- 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:
|
Collaborator
|
FYI, i'm working on my attempt on fixing this. I discovered that there is also another issue related to |
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.
For
<Plural>/<Select>/<SelectOrdinal>, the SWC plugin always allocated thevalueexpression's index first, before processing the option attributes (one,other, …). While this is probably more intuitive, the JS implementation instead iterates attributes in source order and allocates the value's index at the position where thevalueattribute actually appears.This only diverges when a non-identifier
valueis not the first attribute and an earlier option contains a numeric-indexed expression — but when it does, the numbers differ:{0, plural, one {{1} glass} other {many}}{1, plural, one {{0} glass} other {many}}With the conventional value-first ordering both implementations already agreed (
value→{0}), so existing snapshots were unaffected.Fix
value_pos: the position of thevalueattribute among the cases in source order (0for theplural(value, { … })call form, where the value is always first).push_icuallocates the value's index atvalue_poswhile iterating the cases, so indices are consumed in source order. The value placeholder is still emitted first in the ICU string by rendering each case body into a buffer (viaString::split_off) and assembling{value, format, …cases}at the end.Index allocation (
numeric_index/values_indexed) persists across the split, so only the output position is decoupled from the allocation order.