All files / src/rules _structure_path.ts

100% Statements 16/16
100% Branches 7/7
100% Functions 1/1
100% Lines 16/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 171x 1x 1x 1296x 1296x 2283x 106x 2283x 1190x 1190x 409x 409x 1190x 2283x 781x 781x  
import {StatementNode, StructureNode} from "../abap/nodes";
 
/** The structures from the root down to the direct parent of the statement, undefined if it is not in the root */
export function structurePath(root: StructureNode, statement: StatementNode): StructureNode[] | undefined {
  for (const child of root.getChildren()) {
    if (child === statement) {
      return [root];
    } else if (child instanceof StructureNode) {
      const found = structurePath(child, statement);
      if (found !== undefined) {
        return [root, ...found];
      }
    }
  }
  return undefined;
}