# core/plugins/syntax.branch.plugin.ts

> 26 lines of code and 5 definitions.

Tree: GovLab Docs
Language: typescript
Layer: infrastructure
Canonical: https://banes-lab.com/anatomy/docs#file-docs-core-plugins-syntax-branch-plugin-ts
Source text: https://banes-lab.com/source/docs/core/plugins/syntax.branch.plugin.ts.txt

Listed in [core/plugins](https://banes-lab.com/api/source/docs/core/plugins.md), after [core/plugins/manifest.surface.plugin.ts](https://banes-lab.com/source/docs/core/plugins/manifest.surface.plugin.ts.md) and before [core/plugins/syntax.event.plugin.ts](https://banes-lab.com/source/docs/core/plugins/syntax.event.plugin.ts.md).

## Definitions

- `decisionLabel` (lexical_declaration, line 4)
- `recognizer` (lexical_declaration, line 14, exported)
- `classify` (method_definition, line 15, exported)
- `kind` (lexical_declaration, line 16, exported)
- `id` (lexical_declaration, line 20, exported)

## Contained in

- [core/plugins](https://banes-lab.com/anatomy/docs/folder-docs-core-plugins.md)

## Source

```typescript
import type { Recognizer } from "#types/code.types";
import ts from "typescript";

const decisionLabel = function decisionLabel(node: ts.Node): string | null {
    if (ts.isIfStatement(node)) {
        return "if";
    }
    if (ts.isSwitchStatement(node)) {
        return "switch";
    }
    return ts.isConditionalExpression(node) ? "ternary" : null;
};

export const recognizer: Recognizer = {
    classify(node, context) {
        const kind = decisionLabel(node);
        if (kind === null) {
            return null;
        }
        const id = context.mkNodeId(node);
        return {
            edges: [{ from: context.currentId, kind: "branch", to: id }],
            nodes: [{ id, kind: "decision", label: kind, source: context.sourceOf(node) }],
        };
    },
    emits: { edges: ["branch"], nodes: ["decision"] },
    name: "decision",
};
```
