Skip to content

createAccessExpression

Create a language-specific access/member expression component pair.

Returns { Expression, Part } where:

  • Expression is the main component that collects Part children and renders the chain
  • Part is 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 />
canUseCallChains(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(TPartProps, OutputSymbol | undefined, 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(TPart, TPart, 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(TPart) => Children

Extract the base content from the first part (the leftmost identifier).

isCallPart(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(Children, TPart, number, 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).