/
fbs.js
42 lines (37 loc) · 1.28 KB
/
fbs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @flow
* @format
*
* Wrapper module for fbt.js (the implementation)
*/
const FbtHooks = require('FbtHooks');
const FbtPureStringResult = require('FbtPureStringResult');
const fbt = require('fbt');
const invariant = require('invariant');
const FbsImpl = {
...fbt,
/**
* @see fbt._param()
*/
_param(label: string, value: $FbsParamInput, variations: [number, number]) {
// TODO(T36305131) Returning implicit Flow type until fbt.js is typed properly
invariant(
typeof value === 'string' || value instanceof FbtPureStringResult,
'Expected fbs parameter value to be the result of fbs(), <fbs/>, or a string; ' +
'instead we got `%s` (type: %s)',
value,
typeof value,
);
// $FlowFixMe TODO(T36305131) Add accurate flow types to fbt.js
return fbt._param(...arguments);
},
_wrapContent(fbtContent, translation, hash) {
const contents = typeof fbtContent === 'string' ? [fbtContent] : fbtContent;
// TODO T59083776: Pass in errorListener and update constructor arguments
const errorListener = FbtHooks.getErrorListener({hash, translation});
return new FbtPureStringResult(contents, errorListener);
},
};
module.exports = ((FbsImpl: $FlowFixMe): $FbsFunctionAPI);