import type { VariableType } from "../types.js"; import type { BuiltinSignature } from "./types.js"; /** * Built-in members of primitive Agency types (string, array, …) — analogous * to {@link JS_GLOBALS} but keyed by the *type* of the receiver value rather * than by a name in scope. Consumed by synthValueAccess to resolve property * and method access through chains like `s.length`, `xs.slice(1).join(",")`. * * Two member kinds: * - `property` — `.foo` returns `type` (e.g. `.length` → number). * - `method` — `.foo(args)` validated against `sig`, returns `sig.returnType`. * * `type` / `sig` may be a function of the receiver type for cases where * the result depends on the element type (e.g. `Array.slice` returns * `Array`, `Array.indexOf(T) → number`). * * Phase 1 scope: string + array members that don't take callbacks. * Callback-taking methods (`map`/`filter`/`reduce`/…) need to wire a * functionRefType param — Phase 2. */ type SigOrThunk = BuiltinSignature | ((receiver: VariableType) => BuiltinSignature); type TypeOrThunk = VariableType | ((receiver: VariableType) => VariableType); export type PrimitiveMember = { kind: "property"; type: TypeOrThunk; } | { kind: "method"; sig: SigOrThunk; }; /** * Look up a built-in member on a primitive receiver type. Returns `null` * if `type` isn't a recognized primitive shape or `name` isn't a known * member of it. * * Recognized receiver shapes: * - primitiveType "string" / stringLiteralType → STRING_MEMBERS * - arrayType → ARRAY_MEMBERS * * Other shapes (number, boolean, object, …) return null for now — the * caller falls back to its existing "property does not exist" error. */ export declare function lookupPrimitiveMember(type: VariableType, name: string): PrimitiveMember | null; /** Resolve a `SigOrThunk` against a concrete receiver type. */ export declare function resolveSig(sig: SigOrThunk, receiver: VariableType): BuiltinSignature; /** Resolve a `TypeOrThunk` against a concrete receiver type. */ export declare function resolvePropertyType(type: TypeOrThunk, receiver: VariableType): VariableType; /** * How to compute the return type of a callback-taking array method, given * the receiver `Array` and the callback's own return type `U`. * * "arrayU" — `Array`. e.g. `map`. * "sameArray" — `Array` (callback's return is irrelevant). `filter`/`sort`. * "void" — `void`. `forEach`. * "elementOrNull" — `T | null`. `find`. * "boolean" — boolean. `some`/`every`. * "flatten" — `Array` where the callback's return is `Array` — * we unwrap one level. `flatMap`. * "reduce" — `U` (or accumulator init type if available). `reduce`. * * Methods are not parsed via the BUILTIN_FUNCTION_TYPES path — instead, * `synthValueAccess` consults this table directly when it sees a known * callback method on an `arrayType` receiver. Callback signature * validation (arity, body return type vs. expected slot) is left to a * future phase; today we trust the body and inherit best-effort. */ export declare const ARRAY_CALLBACK_METHOD_KINDS: { readonly map: "arrayU"; readonly filter: "sameArray"; readonly forEach: "void"; readonly find: "elementOrNull"; readonly some: "boolean"; readonly every: "boolean"; readonly sort: "sameArray"; readonly flatMap: "flatten"; readonly reduce: "reduce"; }; export type ArrayCallbackKind = (typeof ARRAY_CALLBACK_METHOD_KINDS)[keyof typeof ARRAY_CALLBACK_METHOD_KINDS]; /** Look up an array callback method, or null if `name` isn't a known one. */ export declare function lookupArrayCallbackMethod(name: string): ArrayCallbackKind | null; export {};