Skip to content

Commit

Permalink
compile
Browse files Browse the repository at this point in the history
  • Loading branch information
alixander committed Sep 29, 2023
1 parent cad4856 commit e56f9c0
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions d2js/js.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type jsObjOrder struct {
func jsGetObjOrder(this js.Value, args []js.Value) interface{} {
dsl := args[0].String()

g, err := d2compiler.Compile("", strings.NewReader(dsl), &d2compiler.CompileOptions{
g, _, err := d2compiler.Compile("", strings.NewReader(dsl), &d2compiler.CompileOptions{
UTF16: true,
})
if err != nil {
Expand All @@ -46,8 +46,14 @@ func jsGetObjOrder(this js.Value, args []js.Value) interface{} {
return string(str)
}

objOrder, err := d2oracle.GetObjOrder(g, nil)
if err != nil {
ret := jsObjOrder{Error: err.Error()}
str, _ := json.Marshal(ret)
return string(str)
}
resp := jsObjOrder{
Order: d2oracle.GetObjOrder(g),
Order: objOrder,
}

str, _ := json.Marshal(resp)
Expand All @@ -72,7 +78,7 @@ func jsGetRefRanges(this js.Value, args []js.Value) interface{} {
return string(str)
}

g, err := d2compiler.Compile("", strings.NewReader(dsl), &d2compiler.CompileOptions{
g, _, err := d2compiler.Compile("", strings.NewReader(dsl), &d2compiler.CompileOptions{
UTF16: true,
})
var pe *d2parser.ParseError
Expand All @@ -91,7 +97,7 @@ func jsGetRefRanges(this js.Value, args []js.Value) interface{} {

var ranges []d2ast.Range
if len(mk.Edges) == 1 {
edge := d2oracle.GetEdge(g, key)
edge := d2oracle.GetEdge(g, nil, key)
if edge == nil {
ret := jsRefRanges{D2Error: "edge not found"}
str, _ := json.Marshal(ret)
Expand All @@ -102,7 +108,7 @@ func jsGetRefRanges(this js.Value, args []js.Value) interface{} {
ranges = append(ranges, ref.MapKey.Range)
}
} else {
obj := d2oracle.GetObj(g, key)
obj := d2oracle.GetObj(g, nil, key)
if obj == nil {
ret := jsRefRanges{D2Error: "obj not found"}
str, _ := json.Marshal(ret)
Expand Down Expand Up @@ -164,7 +170,7 @@ func jsParse(this js.Value, args []js.Value) interface{} {

detectFS := detectFS{}

g, err := d2compiler.Compile("", strings.NewReader(dsl), &d2compiler.CompileOptions{
g, _, err := d2compiler.Compile("", strings.NewReader(dsl), &d2compiler.CompileOptions{
UTF16: true,
FS: detectFS,
})
Expand Down Expand Up @@ -221,7 +227,7 @@ func jsParse(this js.Value, args []js.Value) interface{} {
func jsCompile(this js.Value, args []js.Value) interface{} {
script := args[0].String()

g, err := d2compiler.Compile("", strings.NewReader(script), &d2compiler.CompileOptions{
g, _, err := d2compiler.Compile("", strings.NewReader(script), &d2compiler.CompileOptions{
UTF16: true,
})
var pe *d2parser.ParseError
Expand Down

0 comments on commit e56f9c0

Please sign in to comment.