How to use babel-plugin-fbt - 2 common examples

To help you get started, we’ve selected a few babel-plugin-fbt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github facebookincubator / fbt / packages / babel-plugin-fbt-runtime / index.js View on Github external
*
 * This is a React Native only transform that runs after the fbt syntax
 * transform. It extracts jsfbt and strip out extra information from the payload
 * produced by the fbt syntax transform.
 *
 * @format
 */

'use strict';

/* eslint consistent-return: 0 */
/* eslint max-len: ["warn", 120] */
/* jslint node: true */

const {fbtHashKey: jenkinsHashKey} = require('babel-plugin-fbt');
const {shiftEnumsToTop} = require('babel-plugin-fbt').FbtShiftEnums;
const invariant = require('fbjs/lib/invariant');

let fbtHashKey = jenkinsHashKey;
module.exports = function fbtRuntime(babel) {
  const t = babel.types;

  function _buildEnumToHashKeyObjectExpression(curLevel, desc, enumsLeft) {
    const properties = [];

    for (const enumKey in curLevel) {
      properties.push(
        t.objectProperty(
          t.identifier(enumKey),
          enumsLeft === 1
            ? t.stringLiteral(fbtHashKey(curLevel[enumKey], desc))
            : _buildEnumToHashKeyObjectExpression(
github facebookincubator / fbt / packages / babel-plugin-fbt-runtime / index.js View on Github external
}

        // Append runtime options - key for runtime dictionary lookup
        if (path.parentPath.node.arguments.length === 1) {
          // Second param 'args' could be omitted sometimes. Use null here
          path.parentPath.node.arguments.push(t.nullLiteral());
        }
        invariant(
          path.parentPath.node.arguments.length === 2,
          'Expecting options to be the third param',
        );

        let shiftedJsfbt;
        let enumCount = 0;
        if (this.opts.reactNativeMode) {
          ({shiftedJsfbt, enumCount} = shiftEnumsToTop(phrase.jsfbt));
        }

        if (enumCount > 0) {
          path.parentPath.node.arguments.push(
            t.ObjectExpression([
              t.objectProperty(
                t.identifier('ehk'), // enumHashKey
                _buildEnumToHashKeyObjectExpression(
                  shiftedJsfbt,
                  phrase.desc,
                  enumCount,
                ),
              ),
            ]),
          );
        } else {

babel-plugin-fbt

The FBT Babel localization transform

MIT
Latest version published 3 years ago

Package Health Score

56 / 100
Full package analysis