Skip to main content

kcl_api/ast/
node_path.rs

1use serde::Serialize;
2
3/// A traversal path through the AST to a node.
4///
5/// Similar to the idea of a `NodeId`, a `NodePath` uniquely identifies a node,
6/// assuming you know the root node.
7///
8/// The implementation doesn't cover all parts of the tree. It currently only
9/// works on parts of the tree that the frontend uses.
10#[derive(Debug, Default, Clone, Serialize, PartialEq, Eq, Hash, ts_rs::TS)]
11#[ts(export_to = "NodePath.ts")]
12pub struct NodePath {
13    pub steps: Vec<Step>,
14}
15
16#[derive(Debug, Clone, Serialize, PartialEq, Eq, Hash, ts_rs::TS)]
17#[ts(export_to = "NodePath.ts")]
18#[serde(tag = "type")]
19pub enum Step {
20    ProgramBodyItem { index: usize },
21    CallCallee,
22    CallArg { index: usize },
23    CallKwCallee,
24    CallKwUnlabeledArg,
25    CallKwArg { index: usize },
26    BinaryLeft,
27    BinaryRight,
28    UnaryArg,
29    PipeBodyItem { index: usize },
30    ArrayElement { index: usize },
31    ArrayRangeStart,
32    ArrayRangeEnd,
33    ObjectProperty { index: usize },
34    ObjectPropertyKey,
35    ObjectPropertyValue,
36    ExpressionStatementExpr,
37    VariableDeclarationDeclaration,
38    VariableDeclarationInit,
39    FunctionExpressionName,
40    FunctionExpressionParam { index: usize },
41    FunctionExpressionBody,
42    FunctionExpressionBodyItem { index: usize },
43    ReturnStatementArg,
44    MemberExpressionObject,
45    MemberExpressionProperty,
46    IfExpressionCondition,
47    IfExpressionThen,
48    IfExpressionElseIf { index: usize },
49    IfExpressionElseIfCond,
50    IfExpressionElseIfBody,
51    IfExpressionElse,
52    ImportStatementItem { index: usize },
53    ImportStatementItemName,
54    ImportStatementItemAlias,
55    LabeledExpressionExpr,
56    LabeledExpressionLabel,
57    AscribedExpressionExpr,
58    SketchBlockArgs,
59    SketchBlockBody,
60    SketchBlockBodyItem { index: usize },
61    SketchVar,
62}