Parse in engine

pull/300/head
Anton Medvedev 3 months ago
parent 1bb2803186
commit 8ca74b870d
No known key found for this signature in database

@ -10,6 +10,8 @@ import (
"github.com/dop251/goja"
"github.com/goccy/go-yaml"
"github.com/antonmedv/fx/internal/jsonx"
)
//go:embed stdlib.js
@ -74,7 +76,12 @@ func Reduce(args []string) {
os.Exit(1)
}
} else {
node, err := jsonx.Parse(data)
if err != nil {
println(err.Error())
os.Exit(1)
}
data = []byte(node.String())
}
var code strings.Builder

@ -0,0 +1,30 @@
package jsonx
import (
"strings"
)
func (n *Node) String() string {
var out strings.Builder
it := n
for it != nil {
if it.Key != nil {
out.Write(it.Key)
out.WriteByte(':')
}
if it.Value != nil {
out.Write(it.Value)
}
if it.Comma {
out.WriteByte(',')
}
if it.IsCollapsed() {
it = it.Collapsed
} else {
it = it.Next
}
}
return out.String()
}
Loading…
Cancel
Save