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 (#263)
Browse files Browse the repository at this point in the history
Summary:
Running string extraction from JS files containing only `<fbs>` or `fbs()` callsites doesn't work.
This PR should fix it.

Pull Request resolved: #263

Test Plan: `yarn clean-test`

Reviewed By: pkqinys

Differential Revision: D30744411

Pulled By: kayhadrin

fbshipit-source-id: cb563d7cbfad047176db127a7395e187e060ec09
  • Loading branch information
kayhadrin authored and facebook-github-bot committed Sep 7, 2021
1 parent a1df470 commit ec2a5ee
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 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 @@ -13,6 +13,7 @@

const {extractEnumsAndFlattenPhrases} = require('../FbtShiftEnums');
const fbt = require('../index');
const FbtUtil = require('../FbtUtil');
const fs = require('graceful-fs');

export type ExternalTransform = (
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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\');<fbt desc="foo">bar</fbt>');
expect(res).toMatchSnapshot();
});

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

it('should extract the author from Docblock', () => {
var res = collect(
[
Expand Down

0 comments on commit ec2a5ee

Please # to comment.