mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-23 06:10:02 +08:00
- 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.
18 lines
928 B
TypeScript
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);
|