visit() function
This API is provided as a beta preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Apply visitor functions to message nodes.
Signature:
export declare function visit(msg: Message, visitors: {
annotation?: (annotation: FunctionAnnotation | UnsupportedAnnotation, context: 'declaration' | 'selector' | 'placeholder', argument: Literal | VariableRef | undefined) => (() => void) | void;
attribute?: (attr: Attribute, index: number, attributes: Attribute[], context: 'declaration' | 'selector' | 'placeholder') => (() => void) | void;
declaration?: (declaration: Declaration) => (() => void) | void;
expression?: (expression: Expression, context: 'declaration' | 'selector' | 'placeholder') => (() => void) | void;
key?: (key: Literal | CatchallKey, index: number, keys: (Literal | CatchallKey)[]) => void;
markup?: (markup: Markup, context: 'declaration' | 'placeholder') => (() => void) | void;
node?: (node: MessageNode, ...rest: unknown[]) => void;
option?: (option: Option, index: number, options: Option[], context: 'declaration' | 'selector' | 'placeholder') => (() => void) | void;
pattern?: (pattern: Pattern) => (() => void) | void;
value?: (value: Literal | VariableRef, context: 'declaration' | 'selector' | 'placeholder', position: 'arg' | 'option' | 'attribute') => void;
variant?: (variant: Variant) => (() => void) | void;
}): void;
Parameters
Parameter | Type | Description |
---|---|---|
msg | Message | |
visitors | { annotation?: (annotation: FunctionAnnotation | UnsupportedAnnotation, context: ‘declaration’ | ‘selector’ | ‘placeholder’, argument: Literal | VariableRef | undefined) => (() => void) | void; attribute?: (attr: Attribute, index: number, attributes: Attribute[], context: ‘declaration’ | ‘selector’ | ‘placeholder’) => (() => void) | void; declaration?: (declaration: Declaration) => (() => void) | void; expression?: (expression: Expression, context: ‘declaration’ | ‘selector’ | ‘placeholder’) => (() => void) | void; key?: (key: Literal | CatchallKey, index: number, keys: (Literal | CatchallKey)[]) => void; markup?: (markup: Markup, context: ‘declaration’ | ‘placeholder’) => (() => void) | void; node?: (node: MessageNode, …rest: unknown[]) => void; option?: (option: Option, index: number, options: Option[], context: ‘declaration’ | ‘selector’ | ‘placeholder’) => (() => void) | void; pattern?: (pattern: Pattern) => (() => void) | void; value?: (value: Literal | VariableRef, context: ‘declaration’ | ‘selector’ | ‘placeholder’, position: ‘arg’ | ‘option’ | ‘attribute’) => void; variant?: (variant: Variant) => (() => void) | void; } |
Returns:
void
Remarks
The visitors are applied in source order, starting from the root. Visitors for nodes that contain other nodes may return a callback function that will be called with no arguments when exiting the node.
If set, the node
visitor is called for all MessageNode values for which an explicit visitor is not defined.
Many visitors will be called with additional arguments identifying some of the context for the visited node.