facebook / fbt

A JavaScript Internationalization Framework
https://facebook.github.io/fbt
MIT License
3.88k stars 178 forks source link

fbt.plural manifest is wrong in --react-native-mode #401

Open bumbu opened 1 year ago

bumbu commented 1 year ago

🐛 Bug Report

Only reproes with:

Running yarn translate-fbts will throw with

yarn run v1.22.19
$ fbt-translate --translations translations/*.json --jenkins > src/translatedFbts.json
/Users/bumbu/Development/fbt/node_modules/nullthrows/nullthrows.js:9
  throw error;
  ^

Error: Expect `token` to not be null as the metadata has variation mask.
    at nullthrows (/Users/bumbu/Development/fbt/node_modules/nullthrows/nullthrows.js:7:15)
    at new TranslationBuilder (/Users/bumbu/Development/fbt/packages/babel-plugin-fbt/dist/translate/TranslationBuilder.js:109:23)
    at /Users/bumbu/Development/fbt/packages/babel-plugin-fbt/dist/bin/translateUtils.js:113:53
    at Array.map (<anonymous>)
    at processTranslations (/Users/bumbu/Development/fbt/packages/babel-plugin-fbt/dist/bin/translateUtils.js:113:38)
    at /Users/bumbu/Development/fbt/packages/babel-plugin-fbt/dist/bin/translateUtils.js:46:12
    at Array.map (<anonymous>)
    at processFiles (/Users/bumbu/Development/fbt/packages/babel-plugin-fbt/dist/bin/translateUtils.js:44:45)
    at Object.<anonymous> (/Users/bumbu/Development/fbt/packages/babel-plugin-fbt/dist/bin/translate.js:147:15)
    at Module._compile (node:internal/modules/cjs/loader:1254:14) {
  framesToPop: 1
}

Node.js v18.16.0

To Reproduce

Steps to reproduce the behavior:

Expected behavior

Should work

Issue

Running yarn collect-fbts will output following json:

  {
   "hashToLeaf": {
    "7VzaqByBO7Pb/+HbPfOSwg==": {
     "text": "have",
     "desc": "example"
    },
    "AdZhIiwu5YM4eTswNtofDQ==": {
     "text": "has",
     "desc": "example"
    }
   },
   "filepath": "src/example/Example.react.js",
   "line_beg": 332,
   "col_beg": 19,
   "line_end": 338,
   "col_end": 7,
   "project": "fbt-demo-project",
   "jsfbt": {
    "t": {
     "*": {
      "desc": "example",
      "text": "have"
     },
     "_1": {
      "desc": "example",
      "text": "has"
     }
    },
    "m": [
     {
      "type": 2  // <<<<<< this is the issue
     }
    ]
   }
 }

And then inside of TranslationBuilder we expect that if manifest has a type, is should also have the token. Imho in this case the type shouldn't be added at all , so the issue is in the yarn collect-fbts step.