All files / TRANSPILE/1-Analyze/helpers EnumMemberSuggestion.ts

100% Statements 8/8
100% Branches 2/2
100% Functions 3/3
100% Lines 6/6

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                          316x 316x 58x   316x         10x 9x          
/**
 * E0424's suggestion: which enums declare a member of this name, and the
 * "did you mean" text that names them.
 *
 * #1322: three codegen sites built this list three times, with two wordings
 * for the several-enums case. One builder, one wording, used by the bare
 * member rule and by the switch analyzer's case-label check.
 */
import ICodeGenSymbols from "../../../types/ICodeGenSymbols";
 
class EnumMemberSuggestion {
  /** The enums that declare `member`, in declaration order. */
  static enumsDeclaring(member: string, symbols: ICodeGenSymbols): string[] {
    const found: string[] = [];
    for (const [enumName, members] of symbols.enumMembers) {
      if (members.has(member)) found.push(enumName);
    }
    return found;
  }
 
  /** `'X' is not defined; did you mean 'A.X' or 'B.X'?` */
  static message(member: string, enums: readonly string[]): string {
    const spelled = enums.map((e) => `'${e}.${member}'`).join(" or ");
    return `'${member}' is not defined; did you mean ${spelled}?`;
  }
}
 
export default EnumMemberSuggestion;