diff --git a/packages/babel-plugin-fbt/src/bin/FbtCollector.js b/packages/babel-plugin-fbt/src/bin/FbtCollector.js index 490cc0e9..410c4734 100644 --- a/packages/babel-plugin-fbt/src/bin/FbtCollector.js +++ b/packages/babel-plugin-fbt/src/bin/FbtCollector.js @@ -13,6 +13,7 @@ const {extractEnumsAndFlattenPhrases} = require('../FbtShiftEnums'); const fbt = require('../index'); +const FbtUtil = require('../FbtUtil'); const fs = require('graceful-fs'); export type ExternalTransform = ( @@ -107,7 +108,7 @@ class FbtCollector implements IFbtCollector { reactNativeMode: this._config.reactNativeMode, }; - if (!/<[Ff]bt|fbt(\.c)?\s*\(/.test(source)) { + if (!FbtUtil.textContainsFbtLikeModule(source)) { return; } diff --git a/packages/babel-plugin-fbt/src/bin/__tests__/__snapshots__/collectFBT-test.js.snap b/packages/babel-plugin-fbt/src/bin/__tests__/__snapshots__/collectFBT-test.js.snap index 2dd796e4..7e7a3067 100644 --- a/packages/babel-plugin-fbt/src/bin/__tests__/__snapshots__/collectFBT-test.js.snap +++ b/packages/babel-plugin-fbt/src/bin/__tests__/__snapshots__/collectFBT-test.js.snap @@ -1288,30 +1288,29 @@ Object { } `; -exports[`collectFbt should extract fbt.c strings 1`] = ` +exports[`collectFbt should extract fbs strings 1`] = ` Object { "childParentMappings": Object {}, "phrases": Array [ Object { - "col_beg": 6, - "col_end": 23, - "common": true, + "col_beg": 27, + "col_end": 52, "jsfbt": Object { "m": Array [], "t": Object { - "desc": "Indicates an editor field is required.", - "text": "Required", + "desc": "foo", + "text": "bar", }, }, - "line_beg": 3, - "line_end": 3, + "line_beg": 1, + "line_end": 1, "project": "", }, ], } `; -exports[`collectFbt should extract strings 1`] = ` +exports[`collectFbt should extract fbt strings 1`] = ` Object { "childParentMappings": Object {}, "phrases": Array [ @@ -1333,6 +1332,29 @@ Object { } `; +exports[`collectFbt should extract fbt.c strings 1`] = ` +Object { + "childParentMappings": Object {}, + "phrases": Array [ + Object { + "col_beg": 6, + "col_end": 23, + "common": true, + "jsfbt": Object { + "m": Array [], + "t": Object { + "desc": "Indicates an editor field is required.", + "text": "Required", + }, + }, + "line_beg": 3, + "line_end": 3, + "project": "", + }, + ], +} +`; + exports[`collectFbt should extract strings from a custom collector 1`] = ` Object { "childParentMappings": Object { diff --git a/packages/babel-plugin-fbt/src/bin/__tests__/collectFBT-test.js b/packages/babel-plugin-fbt/src/bin/__tests__/collectFBT-test.js index fe9334a1..0b9361c5 100644 --- a/packages/babel-plugin-fbt/src/bin/__tests__/collectFBT-test.js +++ b/packages/babel-plugin-fbt/src/bin/__tests__/collectFBT-test.js @@ -41,11 +41,16 @@ describe('collectFbt', () => { return JSON.parse(JSON.stringify(output)); } - it('should extract strings', () => { + it('should extract fbt strings', () => { var res = collect('const fbt = require(\'fbt\');bar'); expect(res).toMatchSnapshot(); }); + it('should extract fbs strings', () => { + var res = collect('const fbs = require(\'fbs\');bar'); + expect(res).toMatchSnapshot(); + }); + it('should extract the author from Docblock', () => { var res = collect( [