function extractEnumsAndFlattenPhrases()

in packages/babel-plugin-fbt/src/FbtShiftEnums.js [20:43]


function extractEnumsAndFlattenPhrases(
  phrases: $ReadOnlyArray<Phrase>,
): Array<Phrase> {
  return _flatMap<Phrase, Phrase>(phrases, phrase => {
    const {jsfbt} = phrase;
    const {enums, metadata} = _extractEnumsFromMetadata(jsfbt.m);
    return _buildTablesWithoutEnums(jsfbt.t, enums, []).map(table => {
      const leaf = coerceToTableJSFBTTreeLeaf(table);
      invariant(
        (metadata.length === 0) === (leaf != null),
        'If the JSFBT table depth is 1, then the metadata array should be empty; ' +
          'otherwise, when the depth is greater than 1, the metadata array should not be empty. Metadata length: %s, ',
        metadata.length,
      );
      return {
        ...phrase,
        jsfbt: {
          t: table,
          m: metadata,
        },
      };
    });
  });
}