update format

This commit is contained in:
Alexander Wang 2023-06-14 14:57:43 -07:00
parent 3fd9964129
commit 5445e5e0de
No known key found for this signature in database
GPG key ID: BE3937D0D52D8927

View file

@ -14,7 +14,6 @@ import (
"oss.terrastruct.com/d2/d2format" "oss.terrastruct.com/d2/d2format"
"oss.terrastruct.com/d2/d2oracle" "oss.terrastruct.com/d2/d2oracle"
"oss.terrastruct.com/d2/d2parser" "oss.terrastruct.com/d2/d2parser"
"oss.terrastruct.com/d2/d2target"
"oss.terrastruct.com/d2/lib/urlenc" "oss.terrastruct.com/d2/lib/urlenc"
) )
@ -128,11 +127,10 @@ type jsObject struct {
} }
type jsParseResponse struct { type jsParseResponse struct {
DSL string `json:"dsl"` DSL string `json:"dsl"`
Texts []*d2target.MText `json:"texts"` ParseError string `json:"parseError"`
ParseError string `json:"parseError"` UserError string `json:"userError"`
UserError string `json:"userError"` D2Error string `json:"d2Error"`
D2Error string `json:"d2Error"`
} }
type blockFS struct{} type blockFS struct{}
@ -177,11 +175,14 @@ func jsParse(this js.Value, args []js.Value) interface{} {
return string(str) return string(str)
} }
resp := jsParseResponse{ m, err := d2parser.Parse("", strings.NewReader(dsl), nil)
Texts: g.Texts(), if err != nil {
return err
} }
newDSL := d2format.Format(g.AST) resp := jsParseResponse{}
newDSL := d2format.Format(m)
if dsl != newDSL { if dsl != newDSL {
resp.DSL = newDSL resp.DSL = newDSL
} }