UNPKG

harmonyc

Version:

Harmony Code - model-driven BDD for Vitest

20 lines (19 loc) 796 B
import { Label, Section, Step } from "../../model/model.js"; export function autoLabel(b) { const forks = b.children.filter((c, i) => c.isFork || i === 0); if (forks.length > 1) { forks .filter((child) => child instanceof Step) .forEach((step) => { const label = step.action.toSingleLineString(); const autoLabel = new Label(label); autoLabel.atSameAs(step.action); const autoSection = new Section(autoLabel, [], step.isFork); // todo this is some redundancy with both section and label storing the position autoSection.atSameAs(step); step.replaceWith(autoSection); autoSection.addChild(step); }); } b.children.forEach((c) => autoLabel(c)); }