unified-latex-util-visit
What is this?
Functions to traverse a unified-latex
Abstract Syntax Tree (AST). visit
is
very similar to estree-util-visit.
When should I use this?
If you want to recursively replace particular AST nodes.
Install
npm install @unified-latex/unified-latex-util-visit
This package contains both esm and commonjs exports. To explicitly access the esm export,
import the .js
file. To explicitly access the commonjs export, import the .cjs
file.
Functions
visit(tree, visitor, options)
Visit children of tree which pass a test
function visit<Opts extends VisitOptions>(
tree: Ast.Ast,
visitor:
| Visitor<NarrowArraysBasedOnOptions<GuardFromOptions<Opts, Ast.Ast>, Opts>>
| Visitors<
NarrowArraysBasedOnOptions<GuardFromOptions<Opts, Ast.Ast>, Opts>
>,
options: VisitOptions
): void;
Parameters
Param | Type | Description |
---|
tree | Ast.Ast | Abstract syntax tree to walk |
visitor | Omitted | Function to run for each node |
options | VisitOptions | see below |
where
type VisitOptions = {
startingContext?: VisitorContext;
test?: (node: Ast.Ast, info: VisitInfo) => boolean;
includeArrays?: boolean;
};
Constants
Name | Type | Description |
---|
CONTINUE | Symbol | Continue traversing as normal |
EXIT | Symbol | Stop traversing immediately |
SKIP | Symbol | Do not traverse this node’s children |
Types
VisitInfo
export type VisitInfo = {
readonly key: string | undefined;
readonly index: number | undefined;
readonly parents: (Ast.Node | Ast.Argument)[];
readonly containingArray: (Ast.Node | Ast.Argument)[] | undefined;
readonly context: VisitorContext;
};
VisitorContext
export type VisitorContext = {
inMathMode?: boolean;
hasMathModeAncestor?: boolean;
};