pub enum Node {
Function {
name: String,
kind: String,
line: u32,
body: Vec<Node>,
},
Branch {
test: Vec<Node>,
then: Vec<Node>,
alternate: Option<Box<Node>>,
},
Conditional {
test: Vec<Node>,
then: Vec<Node>,
alternate: Vec<Node>,
},
Loop {
body: Vec<Node>,
},
Switch {
cases: Vec<SwitchCase>,
},
Catch {
body: Vec<Node>,
},
Jump {
labeled: bool,
},
Logical {
op: LogicalOp,
operands: Vec<Node>,
},
Call {
callee: Option<String>,
},
Group(Vec<Node>),
}Expand description
A node of the normalized complexity IR.
Fields that hold sub-expressions or sub-statements are Vec<Node> so the
adapter can drop irrelevant detail and the engine can recurse uniformly.
Variants§
Function
A function-like unit (function, method, arrow, accessor, …). The engine
scores each one independently — nesting resets to 0 at this boundary —
and reports it as a child of the enclosing unit. kind/name are
opaque, adapter-chosen labels (the engine never interprets them).
Branch
An if (with optional else / else if). then is scored with a
nesting bonus; alternate (a nested Branch for else if, or any other
node for a plain else) is scored flat — one cognitive point, no bonus.
Conditional
A ternary ?:. Scored like a branch: +1 plus nesting bonus.
Loop
Any loop (for / for-in / for-of / while / do-while), normalized
to one shape. +1 plus nesting bonus, and a cyclomatic point.
Switch
A switch. +1 plus nesting bonus (but the switch itself is not a McCabe
decision point — each non-default case is, scored via SwitchCase).
Fields
cases: Vec<SwitchCase>Catch
A catch clause. +1 plus nesting bonus, and a cyclomatic point.
Jump
A break / continue. Only a labelled jump adds one cognitive point.
Logical
A run of like logical operators. One cognitive point per node; the
adapter folds a && b && c into a single node with three operands.
Call
A function call. If callee names the nearest enclosing function, the
engine counts it as recursion (one cognitive point).
Group(Vec<Node>)
A transparent container for any construct that holds children but carries no score of its own (statements, expressions, blocks). The engine simply recurses into it.