Skip to content
This repository has been archived by the owner on Nov 18, 2024. It is now read-only.

Commit

Permalink
fix(babel-plugin-fbt): detect fbt JS callsites from FbtCollector
Browse files Browse the repository at this point in the history
  • Loading branch information
kayhadrin committed Sep 2, 2021
1 parent 8ac3e66 commit 761a1d5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/babel-plugin-fbt/src/bin/FbtCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -101,7 +102,7 @@ class FbtCollector implements IFbtCollector {
options.filename = filename;
}

if (!/<[Ff]bt|fbt(\.c)?\s*\(/.test(source)) {
if (!FbtUtil.textContainsFbtLikeModule(source)) {
return;
}

Expand Down
17 changes: 16 additions & 1 deletion packages/babel-plugin-fbt/src/bin/__tests__/collectFBT-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('collectFbt', () => {
}
}

it('should extract strings', () => {
it('should extract fbt strings', () => {
var res = collect('const fbt = require(\'fbt\');<fbt desc="foo">bar</fbt>');

var expected = {
Expand All @@ -75,6 +75,21 @@ describe('collectFbt', () => {
expect(actual).toEqual(expected);
});

it('should extract fbs strings', () => {
var res = collect('const fbs = require(\'fbs\');<fbs desc="foo">bar</fbs>');

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(
[
Expand Down

0 comments on commit 761a1d5

Please # to comment.