Function annotateProgram

Returns a deep annotated copy of the input node with annotations if it is a valid estree-sentry program. Throws a EstreeSentrySyntaxError if the input node is not a valid estree-sentry program. See guard for a failing example.

import { ROOT_PATH, annotateProgram } from "estree-sentry";
// returns: {
// type: "Program",
// sourceType: "script",
// body: [{
// type: "EmptyStatement",
// path: "$.body.0",
// kind: "Statement",
// }],
// path: "$",
// kind: "Program"
// }
annotateProgram(
{
type: "Program",
sourceType: "script",
body: [
{
type: "EmptyStatement",
},
],
},
ROOT_PATH,
(_node, path, kind) => ({ path, kind }),
);

An EstreeSentrySyntaxError if the input root node is not a valid estree-sentry program.

  • Type Parameters

    • A

      The type of the annotation.

    Parameters

    • root: object

      The input root node.

    • path: Path

      The root path to which segments will be appended.

    • annotate: Annotate<A>

      Annotation function that will be called on each visited node.

    Returns Program<A>

    A deep copy of the input root node that is a valid estree-sentry program.