All files / transpiler/output/codegen/helpers SetMapHelper.ts

100% Statements 17/17
100% Branches 4/4
100% Functions 4/4
100% Lines 17/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64                          5x 5x 8x 3x     5x               75x 75x 75x                       28x 28x 33x 31x     28x             27x 27x 28x   27x          
/**
 * SetMapHelper
 *
 * Helper class for Set and Map manipulation utilities.
 * Used for const inference and parameter tracking operations.
 */
 
class SetMapHelper {
  /**
   * Find items that are in source set but not in target set.
   * Useful for finding new modifications not yet in cross-file data.
   */
  static findNewItems<T>(source: Set<T>, target: ReadonlySet<T>): Set<T> {
    const newItems = new Set<T>();
    for (const item of source) {
      if (!target.has(item)) {
        newItems.add(item);
      }
    }
    return newItems;
  }
 
  /**
   * Restore a map's state by clearing and repopulating from saved data.
   * Used for rollback scenarios in code generation.
   */
  static restoreMapState<K, V>(target: Map<K, V>, saved: Map<K, V>): void {
    target.clear();
    for (const [k, v] of saved) {
      target.set(k, v);
    }
  }
 
  /**
   * Filter map entries to only include keys not present in exclude map.
   * Returns new map with filtered entries.
   */
  static filterExclude<K, V>(
    source: Map<K, V>,
    exclude: ReadonlyMap<K, unknown> | undefined,
  ): Map<K, V> {
    const result = new Map<K, V>();
    for (const [key, value] of source) {
      if (!exclude?.has(key)) {
        result.set(key, value);
      }
    }
    return result;
  }
 
  /**
   * Convert map values that are arrays to new arrays (defensive copy).
   */
  static copyArrayValues<K, V>(source: Map<K, V[]>): Map<K, V[]> {
    const result = new Map<K, V[]>();
    for (const [key, value] of source) {
      result.set(key, [...value]);
    }
    return result;
  }
}
 
export default SetMapHelper;