Skip to content

fix(@formatjs/icu-messageformat-parser): fix flatten, fix #4202#5784

Closed
longlho wants to merge 1 commit intomainfrom
01-01-fix_formatjs_icu-messageformat-parser_fix_flatten_fix_4202
Closed

fix(@formatjs/icu-messageformat-parser): fix flatten, fix #4202#5784
longlho wants to merge 1 commit intomainfrom
01-01-fix_formatjs_icu-messageformat-parser_fix_flatten_fix_4202

Conversation

@longlho
Copy link
Member

@longlho longlho commented Jan 2, 2026

TL;DR

Fix handling of pound symbols (#) in nested plural messages by replacing them with explicit variable references to avoid ambiguity.

What changed?

  • Added a new replacePoundWithArgument function that transforms pound elements (#) into explicit number elements ({variableName, number}) when needed
  • Modified the hoisting logic to detect when plural elements are followed by other plural/select elements
  • When multiple plurals are present, the outer plural's pound symbols are replaced with explicit variable references
  • Implemented the same fix in both TypeScript and Rust versions of the parser

How to test?

The PR includes test cases that verify the correct behavior:

  • Test with two plurals: {topicCount, plural, one {# topic} other {# topics}} and {noteCount, plural, one {# note} other {# notes}}
  • Test with three plurals: {a, plural, one {# a} other {# as}}, {b, plural, one {# b} other {# bs}}, and {c, plural, one {# c} other {# cs}}

Why make this change?

Fixes issue #4202 where nested plural messages with pound symbols (#) could be ambiguous. When multiple plurals are present in a message, the pound symbol in each plural should refer to its own variable. By replacing outer plural's pound symbols with explicit variable references, we ensure correct variable substitution when messages are hoisted and nested.

@longlho longlho marked this pull request as ready for review January 2, 2026 03:52
Copy link
Member Author

longlho commented Jan 2, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • main - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has required the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@graphite-app
Copy link

graphite-app bot commented Jan 2, 2026

Merge activity

  • Jan 2, 3:54 AM UTC: longlho added this pull request to the Graphite merge queue.
  • Jan 2, 3:55 AM UTC: CI is running for this pull request on a draft pull request (#5786) due to your merge queue CI optimization settings.
  • Jan 2, 3:57 AM UTC: The Graphite merge queue couldn't merge this PR because it was not satisfying all requirements (Failed CI (verify-hooks)).
  • Jan 2, 3:59 AM UTC: longlho added this pull request to the Graphite merge queue.
  • Jan 2, 3:59 AM UTC: CI is running for this pull request on a draft pull request (#5787) due to your merge queue CI optimization settings.
  • Jan 2, 4:02 AM UTC: Merged by the Graphite merge queue via draft PR: #5787.

graphite-app bot pushed a commit that referenced this pull request Jan 2, 2026
### TL;DR

Fix handling of pound symbols (`#`) in nested plural messages by replacing them with explicit variable references to avoid ambiguity.

### What changed?

- Added a new `replacePoundWithArgument` function that transforms pound elements (`#`) into explicit number elements (`{variableName, number}`) when needed
- Modified the hoisting logic to detect when plural elements are followed by other plural/select elements
- When multiple plurals are present, the outer plural's pound symbols are replaced with explicit variable references
- Implemented the same fix in both TypeScript and Rust versions of the parser

### How to test?

The PR includes test cases that verify the correct behavior:
- Test with two plurals: `{topicCount, plural, one {# topic} other {# topics}} and {noteCount, plural, one {# note} other {# notes}}`
- Test with three plurals: `{a, plural, one {# a} other {# as}}, {b, plural, one {# b} other {# bs}}, and {c, plural, one {# c} other {# cs}}`

### Why make this change?

Fixes issue #4202 where nested plural messages with pound symbols (`#`) could be ambiguous. When multiple plurals are present in a message, the pound symbol in each plural should refer to its own variable. By replacing outer plural's pound symbols with explicit variable references, we ensure correct variable substitution when messages are hoisted and nested.
graphite-app bot pushed a commit that referenced this pull request Jan 2, 2026
### TL;DR

Fix handling of pound symbols (`#`) in nested plural messages by replacing them with explicit variable references to avoid ambiguity.

### What changed?

- Added a new `replacePoundWithArgument` function that transforms pound elements (`#`) into explicit number elements (`{variableName, number}`) when needed
- Modified the hoisting logic to detect when plural elements are followed by other plural/select elements
- When multiple plurals are present, the outer plural's pound symbols are replaced with explicit variable references
- Implemented the same fix in both TypeScript and Rust versions of the parser

### How to test?

The PR includes test cases that verify the correct behavior:
- Test with two plurals: `{topicCount, plural, one {# topic} other {# topics}} and {noteCount, plural, one {# note} other {# notes}}`
- Test with three plurals: `{a, plural, one {# a} other {# as}}, {b, plural, one {# b} other {# bs}}, and {c, plural, one {# c} other {# cs}}`

### Why make this change?

Fixes issue #4202 where nested plural messages with pound symbols (`#`) could be ambiguous. When multiple plurals are present in a message, the pound symbol in each plural should refer to its own variable. By replacing outer plural's pound symbols with explicit variable references, we ensure correct variable substitution when messages are hoisted and nested.
@graphite-app graphite-app bot closed this Jan 2, 2026
@graphite-app graphite-app bot deleted the 01-01-fix_formatjs_icu-messageformat-parser_fix_flatten_fix_4202 branch January 2, 2026 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant