-
Notifications
You must be signed in to change notification settings - Fork 49.8k
[compiler][repro] Test fixture for fbt plural bug #30432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
de76ed9
[compiler][repro] Test fixture for fbt plural bug
mofeiZ 81180ac
Update on "[compiler][repro] Test fixture for fbt plural bug"
mofeiZ 519cdaf
Update on "[compiler][repro] Test fixture for fbt plural bug"
mofeiZ b06358f
Update on "[compiler][repro] Test fixture for fbt plural bug"
mofeiZ 6467784
Update on "[compiler][repro] Test fixture for fbt plural bug"
mofeiZ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
...-compiler/src/__tests__/fixtures/compiler/fbt/bug-multiple-fbt-plural.expect.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
|
|
||
| ## Input | ||
|
|
||
| ```javascript | ||
| import fbt from 'fbt'; | ||
|
|
||
| /** | ||
| * Forget + fbt inconsistency. Evaluator errors with the following | ||
| * Found differences in evaluator results | ||
| * Non-forget (expected): | ||
| * (kind: ok) 1 rewrite to Rust · 2 months traveling | ||
| * Forget: | ||
| * (kind: ok) 1 rewrites to Rust · 2 months traveling | ||
| * | ||
| * The root issue here is that fbt:plural reads `.start` and `.end` from | ||
| * babel nodes to slice into source strings. (fbt:enum suffers from the same | ||
| * problem). | ||
| * See: | ||
| * - [getRawSource](https://github.com/facebook/fbt/blob/main/packages/babel-plugin-fbt/src/FbtUtil.js#L666-L673) | ||
| * - [getArgCode](https://github.com/facebook/fbt/blob/main/packages/babel-plugin-fbt/src/fbt-nodes/FbtArguments.js#L88-L97) | ||
| * - [_getStringVariationCombinations](https://github.com/facebook/fbt/blob/main/packages/babel-plugin-fbt/src/JSFbtBuilder.js#L297) | ||
| * | ||
| * Specifically, the `count` node requires that a `.start/.end` be attached | ||
| * (see [code in FbtPluralNode](https://github.com/facebook/fbt/blob/main/packages/babel-plugin-fbt/src/fbt-nodes/FbtPluralNode.js#L87-L90)) | ||
| * | ||
| * In this fixture, `count` nodes are the `rewrites` and `months` identifiers. | ||
| */ | ||
| function Foo({rewrites, months}) { | ||
| return ( | ||
| <fbt desc="Test fbt description"> | ||
| <fbt:plural count={rewrites} name="number of rewrites" showCount="yes"> | ||
| rewrite | ||
| </fbt:plural> | ||
| to Rust · | ||
| <fbt:plural count={months} name="number of months" showCount="yes"> | ||
| month | ||
| </fbt:plural> | ||
| traveling | ||
| </fbt> | ||
| ); | ||
| } | ||
|
|
||
| export const FIXTURE_ENTRYPOINT = { | ||
| fn: Foo, | ||
| params: [{rewrites: 1, months: 2}], | ||
| }; | ||
|
|
||
| ``` | ||
|
|
||
| ## Code | ||
|
|
||
| ```javascript | ||
| import { c as _c } from "react/compiler-runtime"; | ||
| import fbt from "fbt"; | ||
|
|
||
| /** | ||
| * Forget + fbt inconsistency. Evaluator errors with the following | ||
| * Found differences in evaluator results | ||
| * Non-forget (expected): | ||
| * (kind: ok) 1 rewrite to Rust · 2 months traveling | ||
| * Forget: | ||
| * (kind: ok) 1 rewrites to Rust · 2 months traveling | ||
| * | ||
| * The root issue here is that fbt:plural reads `.start` and `.end` from | ||
| * babel nodes to slice into source strings. (fbt:enum suffers from the same | ||
| * problem). | ||
| * See: | ||
| * - [getRawSource](https://github.com/facebook/fbt/blob/main/packages/babel-plugin-fbt/src/FbtUtil.js#L666-L673) | ||
| * - [getArgCode](https://github.com/facebook/fbt/blob/main/packages/babel-plugin-fbt/src/fbt-nodes/FbtArguments.js#L88-L97) | ||
| * - [_getStringVariationCombinations](https://github.com/facebook/fbt/blob/main/packages/babel-plugin-fbt/src/JSFbtBuilder.js#L297) | ||
| * | ||
| * Specifically, the `count` node requires that a `.start/.end` be attached | ||
| * (see [code in FbtPluralNode](https://github.com/facebook/fbt/blob/main/packages/babel-plugin-fbt/src/fbt-nodes/FbtPluralNode.js#L87-L90)) | ||
| * | ||
| * In this fixture, `count` nodes are the `rewrites` and `months` identifiers. | ||
| */ | ||
| function Foo(t0) { | ||
| const $ = _c(3); | ||
| const { rewrites, months } = t0; | ||
| let t1; | ||
| if ($[0] !== rewrites || $[1] !== months) { | ||
| t1 = fbt._( | ||
| { | ||
| "*": { | ||
| "*": "{number of rewrites} rewrites to Rust · {number of months} months traveling", | ||
| }, | ||
| _1: { _1: "1 rewrite to Rust · 1 month traveling" }, | ||
| }, | ||
| [ | ||
| fbt._plural(rewrites, "number of rewrites"), | ||
| fbt._plural(months, "number of months"), | ||
| ], | ||
| { hk: "49MfZA" }, | ||
| ); | ||
| $[0] = rewrites; | ||
| $[1] = months; | ||
| $[2] = t1; | ||
| } else { | ||
| t1 = $[2]; | ||
| } | ||
| return t1; | ||
| } | ||
|
|
||
| export const FIXTURE_ENTRYPOINT = { | ||
| fn: Foo, | ||
| params: [{ rewrites: 1, months: 2 }], | ||
| }; | ||
|
|
||
| ``` | ||
|
|
||
42 changes: 42 additions & 0 deletions
42
...bel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/bug-multiple-fbt-plural.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import fbt from 'fbt'; | ||
|
|
||
| /** | ||
| * Forget + fbt inconsistency. Evaluator errors with the following | ||
| * Found differences in evaluator results | ||
| * Non-forget (expected): | ||
| * (kind: ok) 1 rewrite to Rust · 2 months traveling | ||
| * Forget: | ||
| * (kind: ok) 1 rewrites to Rust · 2 months traveling | ||
| * | ||
| * The root issue here is that fbt:plural reads `.start` and `.end` from | ||
| * babel nodes to slice into source strings. (fbt:enum suffers from the same | ||
| * problem). | ||
| * See: | ||
| * - [getRawSource](https://github.com/facebook/fbt/blob/main/packages/babel-plugin-fbt/src/FbtUtil.js#L666-L673) | ||
| * - [getArgCode](https://github.com/facebook/fbt/blob/main/packages/babel-plugin-fbt/src/fbt-nodes/FbtArguments.js#L88-L97) | ||
| * - [_getStringVariationCombinations](https://github.com/facebook/fbt/blob/main/packages/babel-plugin-fbt/src/JSFbtBuilder.js#L297) | ||
| * | ||
| * Specifically, the `count` node requires that a `.start/.end` be attached | ||
| * (see [code in FbtPluralNode](https://github.com/facebook/fbt/blob/main/packages/babel-plugin-fbt/src/fbt-nodes/FbtPluralNode.js#L87-L90)) | ||
| * | ||
| * In this fixture, `count` nodes are the `rewrites` and `months` identifiers. | ||
| */ | ||
| function Foo({rewrites, months}) { | ||
| return ( | ||
| <fbt desc="Test fbt description"> | ||
| <fbt:plural count={rewrites} name="number of rewrites" showCount="yes"> | ||
| rewrite | ||
| </fbt:plural> | ||
| to Rust · | ||
| <fbt:plural count={months} name="number of months" showCount="yes"> | ||
| month | ||
| </fbt:plural> | ||
| traveling | ||
| </fbt> | ||
| ); | ||
| } | ||
|
|
||
| export const FIXTURE_ENTRYPOINT = { | ||
| fn: Foo, | ||
| params: [{rewrites: 1, months: 2}], | ||
| }; |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference, the correct transpilation would be