Skip to content

Assignment context

AssignmentContext provides the symbol that is the target of the current assignment.

const AssignmentContext: ComponentContext<AssignmentContext>
const myContext = useContext(AssignmentContext);
isAssignedbooleanWhether the symbol has had a value assigned to it. Once the symbol has been assigned, subsequent assignments will have no effect.
targetOutputSymbolThe symbol that is the target of the current assignment.
import { createAssignmentContext } from "@alloy-js/core";
function createAssignmentContext(target: OutputSymbol): AssignmentContext;

Creates a new Assignment context interface.

targetOutputSymbol

When a variable is declared, the symbol for the variable doesn’t yet know what value it will hold, because that depends on the assignment to the variable in the variable declaration’s initializer. This context provides the symbol that is the target of the current assignment, so that children of an assignment or initializer can provide additional symbol information.

For example, when assigning an object value expression to a variable, the object value expression should use assignment context to provide the member symbols for the object value’s properties.