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

fix(babel-plugin-fbt): detect fbt JS callsites from FbtCollector [master] #263

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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