Files
scriptc/tests/corpus/generic-record-index.ts
Chris Tate 3af05d9fbc feat(compiler): lower the complete frontend statically
- Complete frontend lowering with zero rejected statements, dynamic islands, or skipped functions.
- Support contextual construction, presence guards, and union record copies used by the compiler.
- Add native CommonJS resolution and cross-platform file URL handling while preserving Node host behavior.
2026-09-28 23:49:13 -05:00

18 lines
928 B
TypeScript

function own<T>(table: Record<string, T | undefined>, key: string): T | undefined {
return Object.hasOwn(table, key) ? table[key] : undefined;
}
const scalars: Record<string, number | string | boolean | undefined> = {
number: 3, string: "text", boolean: false, empty: undefined,
};
for (const key of ["number", "string", "boolean", "empty", "missing", "constructor", "toString"]) {
console.log(key, own(scalars, key));
}
type Value = { kind: "number"; value: number } | { kind: "list"; values: Value[] };
const child: Value = { kind: "number", value: 4 };
const values: Record<string, Value | undefined> = { child, tree: { kind: "list", values: [child] } };
const found = own(values, "child");
console.log("identity", found === child);
const tree = own(values, "tree");
if (tree?.kind === "list") console.log("nested", tree.values[0] === child, tree.values.length);
console.log("absent", own(values, "no") === undefined);