static flattenUnusedSegments(segments) {
    const done = Object.create(null);
    const retv = [];

    for (let i = 0; i < segments.length; ++i) {
      const segment = segments[i];

      // Ignores duplicated.
      if (done[segment.id]) {
        continue;
      }

      // Use previous segments if unused.
      if (!segment.internal.used) {
        for (let j = 0; j < segment.allPrevSegments.length; ++j) {
          const prevSegment = segment.allPrevSegments[j];

          if (!done[prevSegment.id]) {
            done[prevSegment.id] = true;
            retv.push(prevSegment);
          }
        }
      } else {
        done[segment.id] = true;
        retv.push(segment);
      }
    }

    return retv;
  }
Replaces unused segments with the previous segments of each unused segment.
@param {CodePathSegment[]} segments An array of segments to replace.
@returns {CodePathSegment[]} The replaced array.