createAccessExpression
Create a language-specific access/member expression component pair.
Returns { Expression, Part } where:
Expressionis the main component that collects Part children and renders the chainPartis a no-op component whose props are consumed by Expression
The factory handles:
- Children collection and Part filtering
- Symbol resolution (refkey → symbol via binder, single computed per part)
- Reactive optimization (getter delegation over single computed per part)
- Flattening nested Expression instances
takeSymbols()to prevent symbol leakage- Call chain detection and chunked formatting algorithm
Configuration for creating a language-specific access expression component.
import { createAccessExpression } from "@alloy-js/core";
<createAccessExpression />import { createAccessExpression } from "@alloy-js/core/stc";
createAccessExpression({ canUseCallChains: undefined, createDescriptor: undefined, formatPart: undefined, getBase: undefined, isCallPart: undefined, wrapPartResult: undefined,}).children(children)| canUseCallChains | (parts: TPart[]) => boolean | Additional check for whether call chain formatting should be used. Called only when isCallPart is provided and more than one call is detected. Return false to force linear formatting (e.g., TypeScript disables call chains when any part has await). Defaults to () => true. |
| createDescriptor | (props: TPartProps, symbol: OutputSymbol | undefined, first: boolean) => TPart | Convert Part props + resolved symbol into a plain descriptor object. Called once per Part during children processing. The returned descriptor is wrapped in a computed + getter delegation for reactive optimization. |
| formatPart | (part: TPart, prevPart: TPart, inCallChain: boolean) => Children | Format a non-first part given its descriptor and the previous part. Returns JSX children for that segment (e.g., .foo, ?.bar, [idx], (args)). inCallChain is true when rendering inside a chunked call chain. |
| getBase | (part: TPart) => Children | Extract the base content from the first part (the leftmost identifier). |
| isCallPart | (part: TPart) => boolean | Identify which parts are function calls, for call chain detection. When provided, the factory uses the chunked call chain algorithm (line breaks after each call group) when more than one call is detected. When omitted, the expression is always formatted linearly. |
| wrapPartResult | (expression: Children, part: TPart, index: number, isLast: boolean) => Children | Post-process the accumulated expression after each part in linear (non-call-chain) mode. Use this for language-specific wrapping like TypeScript’s await which wraps the entire expression so far. Defaults to identity (returns expression unchanged). |