docs: function compressToDAWG(trie, name) {
    const nodesByHash = new Map();
    const replaceNodes = new Map();
  
    (function groupNodesByHash(node) {
      // Get a sorted list of next labels from this node
      const nexts = Object.keys(node)
        .filter(n => n !== '$')
        .sort();
  
      // Create a setter which can be used later to replace the value of a node.
      // Each node is associated with a lambda function accepting one argument:
      // the new value of the node. Because the context of the node (parent and
      // label) is captured in the closure, it allows to just call it later, in a
      // different context, to change the value of a given node in-place.
      nexts.forEach((n) => {
        replaceNodes.set(
          node[n],
          (newNode) => {
            // eslint-disable-next-line no-param-reassign
            node[n] = newNode;
          },
        );
      });
  
      // Compute a unique hash for this node recursively.
      const hash = `(${node.$},${[
        ...nexts.map(c => `${c},${groupNodesByHash(node[c])}`),
      ].join('|')})`;
  
      // Keep track of all node's hashes
      if (!nodesByHash.has(hash)) {
        nodesByHash.set(hash, []);
      }
      nodesByHash.get(hash).push(node);
  
      return hash;
    }(trie));
  
    // Given `nodesByHash`, which associates a list of nodes to each hash
    // encountered in the previous step, we will detect all the sub-trees being
    // seen more than once and store them in a variable to allow sharing with
    // different parts in the DAWG.
    const variables = [];
    nodesByHash.forEach((nodes) => {
      if (nodes.length > 1) {
        // Dump one of the nodes (they are all the same so it does not matter which one)
        variables.push(`_${nextId}=${JSON.stringify(nodes[0])}`);
  
        // Replace all the other ones by the name of this new variable
        nodes.forEach((node) => {
          replaceNodes.get(node)(`_${nextId}`);
        });
  
        nextId += 1;
      }
    });
  
    const output = [];
  
    // Create TypeScript source code to declare all of these variables. Because
    // the value of nodes has been set to a value of the form '"_id"', we need to
    // replace this on the fly to '_id'. We use a RegExp for this.
    if (variables.length !== 0) {
      let variablesSourceCode = `const ${variables.join(',')};`;
      for (let i = 0; i < nextId; i += 1) {
        variablesSourceCode = variablesSourceCode.replace(
          new RegExp(`"_${i}"`, 'g'),
          `_${i}`,
        );
      }
      output.push(variablesSourceCode);
    }
  
    // Dump the root of the DAWG as well, and perform the same replacement of _id
    // parts than for the variables above.
    let serializedTrie = JSON.stringify(trie);
    for (let i = 0; i < nextId; i += 1) {
      serializedTrie = serializedTrie.replace(
        new RegExp(`"_${i}"`, 'g'),
        `_${i}`,
      );
    }
    output.push(`export const ${name} = ${serializedTrie};`);
  
    return output.join('\n');
  }