mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-22 05:59:31 +08:00
- Support boolean, bigint, and mixed value keys in native Maps and Sets. - Reuse key hashes and copy collections directly into compact storage. - Preserve collection identity, ordering, iteration, and ownership behavior.
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
// Map support boundaries at lowering. Keep accepted adjacent forms here
|
|
// as well so widening the value domain removes its old diagnostic.
|
|
|
|
// Boolean keys compile alongside the remaining value and method fences.
|
|
const byFlag = new Map<boolean, string>();
|
|
|
|
// Values exclude functions (no closure story in the uniform value slot yet).
|
|
const handlers = new Map<string, () => void>();
|
|
|
|
// Typed nested Maps retain their identity and are supported.
|
|
const nested = new Map<string, Map<string, number>>();
|
|
|
|
// Boolean-keyed parameter slots share the supported key domain.
|
|
function useFlags(m: Map<boolean, number>): number {
|
|
return m.size;
|
|
}
|
|
|
|
// Nullable Map views are supported; no diagnostic should appear here.
|
|
function maybeMap(cond: boolean): Map<string, number> | undefined {
|
|
return undefined;
|
|
}
|
|
|
|
// Maps as array elements now preserve references without a diagnostic.
|
|
const rows: Map<string, number>[] = [];
|
|
|
|
// Maps are not JSON (Node stringifies them as the useless "{}" husk;
|
|
// scriptc rejects instead of shipping that).
|
|
const m = new Map<string, number>();
|
|
console.log(JSON.stringify(m));
|
|
|
|
// Map methods have no bound-value form — call them directly.
|
|
const getter = m.get;
|
|
// Reached: collection defers its diagnostics until a reference makes
|
|
// them relevant; these references are what makes them count.
|
|
useFlags(new Map<boolean, number>());
|
|
maybeMap(true);
|