diff --git a/packages/babel-plugin-fbt/src/bin/FbtCollector.js b/packages/babel-plugin-fbt/src/bin/FbtCollector.js index 1a294f11..08d9341c 100644 --- a/packages/babel-plugin-fbt/src/bin/FbtCollector.js +++ b/packages/babel-plugin-fbt/src/bin/FbtCollector.js @@ -14,6 +14,7 @@ const {extractEnumsAndFlattenPhrases} = require('../FbtShiftEnums'); // eslint-disable-next-line fb-www/no-module-aliasing const fbt = require('../index'); +const FbtUtil = require('../FbtUtil'); const fs = require('graceful-fs'); const path = require('path'); @@ -101,7 +102,7 @@ class FbtCollector implements IFbtCollector { options.filename = filename; } - if (!/<[Ff]bt|fbt(\.c)?\s*\(/.test(source)) { + if (!FbtUtil.textContainsFbtLikeModule(source)) { return; } 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 61f4a6ea..2e6031d8 100644 --- a/packages/babel-plugin-fbt/src/bin/__tests__/collectFBT-test.js +++ b/packages/babel-plugin-fbt/src/bin/__tests__/collectFBT-test.js @@ -60,7 +60,7 @@ describe('collectFbt', () => { } } - it('should extract strings', () => { + it('should extract fbt strings', () => { var res = collect('const fbt = require(\'fbt\');bar'); var expected = { @@ -75,6 +75,21 @@ describe('collectFbt', () => { expect(actual).toEqual(expected); }); + it('should extract fbs strings', () => { + var res = collect('const fbs = require(\'fbs\');bar'); + + var expected = { + type: 'text', + desc: 'foo', + jsfbt: 'bar', + }; + + var actual = {}; + Object.keys(expected).map(key => (actual[key] = res.phrases[0][key])); + + expect(actual).toEqual(expected); + }); + it('should still extract strings if file-level doNotExtract is set to false', () => { var res = collect( [