static fromScan()

in packages/babel-plugin-fbt/src/translate/FbtSite.js [106:136]


  static fromScan(json: CollectFbtOutputPhrase): FbtSite {
    const textAndDescToHash: TextAndDescToHash = {};
    const {hashToLeaf, jsfbt} = json;
    invariant(hashToLeaf != null, 'Expected hashToLeaf to be defined');
    invariant(jsfbt != null, 'Expect a non-void jsfbt table');
    for (const hash in hashToLeaf) {
      const textAndDesc = this._serializeTextAndDesc(
        hashToLeaf[hash].text,
        hashToLeaf[hash].desc,
      );
      invariant(
        textAndDescToHash[textAndDesc] == null,
        "Duplicate text+desc pairs pointing to different hashes shouldn't be possible",
      );
      textAndDescToHash[textAndDesc] = hash;
    }
    const tableData = {
      t: FbtSite._hashifyLeaves(jsfbt.t, textAndDescToHash),
      m: jsfbt.m,
    };
    const hashToTokenAliases = {};
    onEachLeaf({jsfbt}, leaf => {
      const hash =
        textAndDescToHash[this._serializeTextAndDesc(leaf.text, leaf.desc)];
      if (leaf.tokenAliases != null) {
        hashToTokenAliases[hash] = leaf.tokenAliases;
      }
    });

    return new FbtSite(hashToLeaf, tableData, json.project, hashToTokenAliases);
  }