childOf

tcmts.core.ir.childOf · #enmaaixp · term · runs anywhere

A node's child at key (its slot: name, initializer, members…), if it has one.

import type { IR } from "#codebase/tcmts/core/hash";

export function childOf(node: IR | undefined, key: string): IR | undefined {
  if (!Array.isArray(node)) return undefined;
  const slot = node.find((c) => Array.isArray(c) && c[0] === key);
  return Array.isArray(slot) ? slot[1] : undefined;
}

uses

used by