Skip to content

Instantly share code, notes, and snippets.

@kayhadrin
Created May 29, 2020 11:20
Show Gist options
  • Save kayhadrin/0429148128d1042f808666301c423c99 to your computer and use it in GitHub Desktop.
Save kayhadrin/0429148128d1042f808666301c423c99 to your computer and use it in GitHub Desktop.
diff --git a/babel.config.js b/babel.config.js
index 56ee9e1..694d1fc 100644
--- a/babel.config.js
+++ b/babel.config.js
@@ -7,7 +7,13 @@ module.exports = function(api) {
'module:metro-react-native-babel-preset',
],
plugins: [
- 'babel-plugin-fbt', 'babel-plugin-fbt-runtime',
+ [
+ 'babel-plugin-fbt',
+ {
+ extraOptions: {__self: true},
+ },
+ ],
+ 'babel-plugin-fbt-runtime',
],
};
};
diff --git a/i18n/fbt/.source_strings.json b/i18n/fbt/.source_strings.json
index e69de29..f03f958 100644
--- a/i18n/fbt/.source_strings.json
+++ b/i18n/fbt/.source_strings.json
@@ -0,0 +1 @@
+{"phrases":[{"hashToText":{"dad697a0606b40c4fdf8fed3d3358838":"foo"},"filepath":"src/App.tsx","line_beg":10,"col_beg":0,"line_end":10,"col_end":17,"desc":"bar","project":"","type":"text","jsfbt":"foo"},{"hashToText":{"165e015d5652e69bae99c7e2c6dc6d87":"foo"},"filepath":"src/App.tsx","line_beg":11,"col_beg":10,"line_end":11,"col_end":36,"desc":"test","project":"","__self":{"type":"ThisExpression"},"type":"text","jsfbt":"foo"}],"childParentMappings":{}}
diff --git a/i18n/fbt/.src_manifest.json b/i18n/fbt/.src_manifest.json
index b25eafa..1a319a1 100644
--- a/i18n/fbt/.src_manifest.json
+++ b/i18n/fbt/.src_manifest.json
@@ -1 +1 @@
-{"i18n/fbt/.enum_manifest.json":[""]}
\ No newline at end of file
+{"i18n/fbt/.enum_manifest.json":["src/App.tsx"]}
\ No newline at end of file
diff --git a/package.json b/package.json
index 5388f4f..8b65341 100644
--- a/package.json
+++ b/package.json
@@ -13,7 +13,7 @@
"test": "node node_modules/jest/bin/jest.js",
"lint": "eslint src --ext .ts,.tsx,.js,.jsx",
"manifest": "babel-node ./node_modules/babel-plugin-fbt/bin/manifest --src src/ --enum-manifest i18n/fbt/.enum_manifest.json --src-manifest i18n/fbt/.src_manifest.json",
- "collect-fbts": "babel-node ./node_modules/babel-plugin-fbt/bin/collectFBT --hash-module 'fb-tiger-hash/src/hashPhrases' --react-native-mode --manifest < i18n/fbt/.src_manifest.json > i18n/fbt/.source_strings.json",
+ "collect-fbts": "babel-node ./node_modules/babel-plugin-fbt/bin/collectFBT --hash-module 'fb-tiger-hash/src/hashPhrases' --react-native-mode --manifest --options __self < i18n/fbt/.src_manifest.json > i18n/fbt/.source_strings.json",
"translate-fbts": "babel-node ./node_modules/babel-plugin-fbt/bin/translate.js --jenkins --source-strings i18n/fbt/.source_strings.json --translations i18n/fbt/translationScriptInput/*.json > i18n/fbt/translatedFbts.json"
},
"private": true,
@@ -60,14 +60,14 @@
"@types/styled-components": "^5.1.0",
"abort-controller": "^3.0.0",
"babel-jest": "^26.0.1",
- "babel-plugin-fbt": "^0.14.1",
+ "babel-plugin-fbt": "^0.14.2",
"babel-plugin-fbt-runtime": "^0.9.11",
"babel-preset-expo": "^8.2.1",
"babel-preset-react-native": "^4.0.1",
"codecov": "^3.7.0",
"eslint": "^7.1.0",
"fb-tiger-hash": "^0.1.6",
- "fbt": "^0.14.0",
+ "fbt": "^0.15.0",
"jest": "^26.0.1",
"jest-expo": "^37.0.0",
"jest-expo-ts": "^22.0.1",
diff --git a/src/App.tsx b/src/App.tsx
index f8adbbf..4aec5dc 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -6,6 +6,10 @@ import { Image } from 'react-native';
import RootNavigator from './components/navigation/RootStackNavigator';
import RootProvider from './providers';
+import fbt from 'fbt';
+fbt('foo', 'bar');
+const f = <fbt desc="test">foo</fbt>;
+
function cacheImages(images: Image[]): Image[] {
return images.map((image: Image) => {
if (typeof image === 'string') {
diff --git a/yarn.lock b/yarn.lock
index aac91a0..1d8b10c 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -4641,10 +4641,10 @@ babel-plugin-fbt-runtime@^0.9.11:
"@babel/core" "^7.0.0"
fbjs "^1.0.0"
-babel-plugin-fbt@^0.14.1:
- version "0.14.1"
- resolved "https://registry.yarnpkg.com/babel-plugin-fbt/-/babel-plugin-fbt-0.14.1.tgz#e6b35d34d05e1b3ffc46ea0136958b426ad5b534"
- integrity sha512-7J7raQMRcKTPZLCey1MZJaoYHDPLNHzgrzZaL8u6JP6VB1g2rMAR+Gy2ljiLkNDC7+Q8JwTYtUYTSEJ9+kxhiw==
+babel-plugin-fbt@^0.14.2:
+ version "0.14.2"
+ resolved "https://registry.yarnpkg.com/babel-plugin-fbt/-/babel-plugin-fbt-0.14.2.tgz#27ecd52b130b58efab853c3646a6b9b5c7840838"
+ integrity sha512-bcUzZZ9jhVolYYYP1MarxgdtucCc2li7ZXUCiDUBD3ZX8hgKgXDSVaTKnAJ4PUhtIMgqVyQlzphxs5AGQyTVVA==
dependencies:
"@babel/core" ">=7.0.0"
"@babel/generator" ">=7.0.0"
@@ -7420,10 +7420,10 @@ fbjs@^1.0.0:
setimmediate "^1.0.5"
ua-parser-js "^0.7.18"
-fbt@^0.14.0:
- version "0.14.0"
- resolved "https://registry.yarnpkg.com/fbt/-/fbt-0.14.0.tgz#86454eb0e76fbea6aa8d65f7f3d7c7e1b994016c"
- integrity sha512-GK9cM210SR4AL2RyCYAoo0xlWbwAboTeDUmyIweHXOwt0iAAuQlk9V8klET+hQ4H6F3FN6FWkBS7ny8Y/ZdOlA==
+fbt@^0.15.0:
+ version "0.15.0"
+ resolved "https://registry.yarnpkg.com/fbt/-/fbt-0.15.0.tgz#e7aff024bdfde871b98f90c0fe7697ce7667009d"
+ integrity sha512-d/Zlg0VspTJQjHc6epHn5DnZKN4EjrqwpCbX7UiTzpqQ4VO/h0LdQDxbyVSDTvQUcQ0MWMMe4aUAtlEFxW9s9g==
dependencies:
invariant "^2.2.4"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment