diff --git a/d2js/js.go b/d2js/js.go index 7aa664abcd..186567719d 100644 --- a/d2js/js.go +++ b/d2js/js.go @@ -11,7 +11,6 @@ import ( "oss.terrastruct.com/d2/d2ast" "oss.terrastruct.com/d2/d2compiler" "oss.terrastruct.com/d2/d2format" - "oss.terrastruct.com/d2/d2graph" "oss.terrastruct.com/d2/d2oracle" "oss.terrastruct.com/d2/d2parser" "oss.terrastruct.com/d2/d2target" @@ -45,38 +44,8 @@ func jsGetObjOrder(this js.Value, args []js.Value) interface{} { return string(str) } - var order []string - - queue := []string{""} - for len(queue) > 0 { - curr := queue[0] - queue = queue[1:] - var obj *d2graph.Object - if curr == "" { - obj = g.Root - } else { - mk, err := d2parser.ParseMapKey(curr) - if err != nil { - ret := jsObjOrder{Error: err.Error()} - str, _ := json.Marshal(ret) - return string(str) - } - var ok bool - obj, ok = g.Root.HasChild(d2graph.Key(mk.Key)) - if !ok { - ret := jsObjOrder{Error: "not found"} - str, _ := json.Marshal(ret) - return string(str) - } - } - order = append(order, obj.AbsID()) - for _, ch := range obj.ChildrenArray { - queue = append(queue, ch.AbsID()) - } - } - resp := jsObjOrder{ - Order: order, + Order: d2oracle.GetObjOrder(g), } str, _ := json.Marshal(resp)