All files / cnx/utils FileFacts.ts

100% Statements 9/9
100% Branches 0/0
100% Functions 3/3
100% Lines 9/9

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                              2095x 2095x       2095x         2095x 2095x       2095x         1933x 1933x       1933x          
/**
 * One file's facts, read from where 1.1 Discover and 1.4 Resolve recorded
 * them (#1991). 2.1, 2.2 and the host all look a file up here, so each
 * lookup has one invariant.
 */
import type IFileIncludes from "../PARSE/1-Discover/types/IFileIncludes";
import type IOutputPaths from "../PARSE/1-Discover/types/IOutputPaths";
import type TRunFacts from "../PARSE/2-Parse/types/TRunFacts";
import type ICodeGenSymbols from "../types/ICodeGenSymbols";
import type IProgram from "../types/IProgram";
import invariant from "./invariant";
 
class FileFacts {
  /** 1.4's visible symbol view of one file */
  static symbolsFor(program: IProgram, sourcePath: string): ICodeGenSymbols {
    const symbols = program.codeGenSymbolsFor(sourcePath);
    invariant(
      symbols,
      `1.4 Resolve built every file's visible symbol view, ${sourcePath}'s included`,
    );
    return symbols;
  }
 
  /** What 1.1 learned about one file's includes (#1444) */
  static includesOf(discovery: TRunFacts, sourcePath: string): IFileIncludes {
    const includes = discovery.includes.get(sourcePath);
    invariant(
      includes !== undefined,
      `1.1 Discover records the includes of every file it discovers (missing ${sourcePath})`,
    );
    return includes;
  }
 
  /** Where 3.1 writes one file's outputs, as 1.1 named them */
  static outputsOf(discovery: TRunFacts, sourcePath: string): IOutputPaths {
    const outputs = discovery.outputs.get(sourcePath);
    invariant(
      outputs !== undefined,
      `1.1 Discover names the outputs of every file it discovers (missing ${sourcePath})`,
    );
    return outputs;
  }
}
 
export default FileFacts;