1 | /**
|
2 | * Copyright 2004-present Facebook. All Rights Reserved.
|
3 | *
|
4 | * This file is shared between www and fbsource and www is the source of truth.
|
5 | * When you make change to this file on www, please make sure you test it on
|
6 | * fbsource and send a diff to update the files too so that the 2 versions are
|
7 | * kept in sync.
|
8 | *
|
9 | * Run the following command to sync the change from www to fbsource.
|
10 | * js1 upgrade www-shared -p babel_plugin_fbt --remote localhost:~/www
|
11 | *
|
12 | * @emails oncall+internationalization
|
13 | * @format
|
14 | * @flow
|
15 | */
|
16 |
|
17 | ;
|
18 |
|
19 | const {FBT_ENUM_MODULE_SUFFIX} = require('./FbtConstants');
|
20 | const invariant = require('fbjs/lib/invariant');
|
21 |
|
22 | const fbtEnumMapping /*: {[string]: ?string} */ = {};
|
23 |
|
24 | const FbtEnumRegistrar = {
|
25 | /**
|
26 | * Associate a JS variable name to an Fbt enum module name
|
27 | * If the module name is invalid, then it's a no-op.
|
28 | */
|
29 | setModuleAlias(
|
30 | name /*: string */,
|
31 | fbtEnumModuleName /*: string */,
|
32 | ) /*: void */ {
|
33 | invariant(
|
34 | fbtEnumModuleName.trim() !== '',
|
35 | 'JS module name must not be empty',
|
36 | );
|
37 | if (fbtEnumModuleName.endsWith(FBT_ENUM_MODULE_SUFFIX)) {
|
38 | fbtEnumMapping[name] = fbtEnumModuleName;
|
39 | }
|
40 | },
|
41 |
|
42 | /**
|
43 | * Returns the Fbt enum module name for a given variable name (if any)
|
44 | */
|
45 | getModuleName(name /*: string */) /*: ?string */ {
|
46 | return fbtEnumMapping[name];
|
47 | },
|
48 | };
|
49 |
|
50 | module.exports = FbtEnumRegistrar;
|