Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ linters:
main:
deny:
- pkg: 'encoding/json$'
desc: 'Use "github.com/microsoft/typescript-go/internal/json" instead.'
desc: 'Use "github.com/go-json-experiment/json" instead.'

exclusions:
rules:
Expand Down
2 changes: 1 addition & 1 deletion internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"fmt"
"sync"

"github.com/go-json-experiment/json"
"github.com/microsoft/typescript-go/internal/api/encoder"
"github.com/microsoft/typescript-go/internal/ast"
"github.com/microsoft/typescript-go/internal/astnav"
"github.com/microsoft/typescript-go/internal/checker"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/json"
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
"github.com/microsoft/typescript-go/internal/project"
"github.com/microsoft/typescript-go/internal/tsoptions"
Expand Down
5 changes: 3 additions & 2 deletions internal/api/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
"strconv"
"strings"

"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"github.com/microsoft/typescript-go/internal/ast"
"github.com/microsoft/typescript-go/internal/checker"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/json"
"github.com/microsoft/typescript-go/internal/project"
)

Expand Down Expand Up @@ -200,7 +201,7 @@ type GetSourceFileParams struct {
FileName string `json:"fileName"`
}

func unmarshalPayload(method string, payload json.Value) (any, error) {
func unmarshalPayload(method string, payload jsontext.Value) (any, error) {
unmarshaler, ok := unmarshalers[Method(method)]
if !ok {
return nil, fmt.Errorf("unknown API method %q", method)
Expand Down
2 changes: 1 addition & 1 deletion internal/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"strconv"
"sync"

"github.com/go-json-experiment/json"
"github.com/microsoft/typescript-go/internal/bundled"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/json"
"github.com/microsoft/typescript-go/internal/project"
"github.com/microsoft/typescript-go/internal/vfs"
"github.com/microsoft/typescript-go/internal/vfs/osvfs"
Expand Down
2 changes: 1 addition & 1 deletion internal/collections/ordered_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"slices"
"strconv"

"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"github.com/microsoft/typescript-go/internal/json"
)

// OrderedMap is an insertion ordered map.
Expand Down
2 changes: 1 addition & 1 deletion internal/collections/ordered_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"slices"
"testing"

"github.com/go-json-experiment/json"
"github.com/microsoft/typescript-go/internal/collections"
"github.com/microsoft/typescript-go/internal/json"
"gotest.tools/v3/assert"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
"strings"
"sync"

"github.com/go-json-experiment/json"
"github.com/microsoft/typescript-go/internal/ast"
"github.com/microsoft/typescript-go/internal/binder"
"github.com/microsoft/typescript-go/internal/checker"
"github.com/microsoft/typescript-go/internal/collections"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/diagnostics"
"github.com/microsoft/typescript-go/internal/json"
"github.com/microsoft/typescript-go/internal/module"
"github.com/microsoft/typescript-go/internal/modulespecifiers"
"github.com/microsoft/typescript-go/internal/outputpaths"
Expand Down
4 changes: 2 additions & 2 deletions internal/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"unicode"
"unicode/utf8"

"github.com/microsoft/typescript-go/internal/json"
"github.com/microsoft/typescript-go/internal/jsonutil"
"github.com/microsoft/typescript-go/internal/stringutil"
"github.com/microsoft/typescript-go/internal/tspath"
)
Expand Down Expand Up @@ -427,7 +427,7 @@ func FirstResult[T1 any](t1 T1, _ ...any) T1 {
}

func StringifyJson(input any, prefix string, indent string) (string, error) {
output, err := json.MarshalIndent(input, prefix, indent)
output, err := jsonutil.MarshalIndent(input, prefix, indent)
return string(output), err
}

Expand Down
2 changes: 1 addition & 1 deletion internal/diagnostics/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"strings"
"unicode"

"github.com/microsoft/typescript-go/internal/json"
"github.com/go-json-experiment/json"
"github.com/microsoft/typescript-go/internal/repo"
)

Expand Down
4 changes: 2 additions & 2 deletions internal/execute/tsc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/microsoft/typescript-go/internal/diagnostics"
"github.com/microsoft/typescript-go/internal/format"
"github.com/microsoft/typescript-go/internal/incremental"
"github.com/microsoft/typescript-go/internal/json"
"github.com/microsoft/typescript-go/internal/jsonutil"
"github.com/microsoft/typescript-go/internal/parser"
"github.com/microsoft/typescript-go/internal/pprof"
"github.com/microsoft/typescript-go/internal/tsoptions"
Expand Down Expand Up @@ -413,7 +413,7 @@ func emitFilesAndReportErrors(

func showConfig(sys System, config *core.CompilerOptions) {
// !!!
_ = json.MarshalIndentWrite(sys.Writer(), config, "", " ")
_ = jsonutil.MarshalIndentWrite(sys.Writer(), config, "", " ")
}

func listFiles(sys System, program compiler.ProgramLike) {
Expand Down
2 changes: 1 addition & 1 deletion internal/fourslash/fourslash.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
"unicode"
"unicode/utf8"

"github.com/go-json-experiment/json"
"github.com/google/go-cmp/cmp"
"github.com/microsoft/typescript-go/internal/ast"
"github.com/microsoft/typescript-go/internal/bundled"
"github.com/microsoft/typescript-go/internal/collections"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/json"
"github.com/microsoft/typescript-go/internal/ls"
"github.com/microsoft/typescript-go/internal/lsp"
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
Expand Down
2 changes: 1 addition & 1 deletion internal/fourslash/test_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"testing"
"unicode/utf8"

"github.com/go-json-experiment/json"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/json"
"github.com/microsoft/typescript-go/internal/ls"
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
"github.com/microsoft/typescript-go/internal/stringutil"
Expand Down
5 changes: 3 additions & 2 deletions internal/incremental/buildInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package incremental
import (
"fmt"

"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"github.com/microsoft/typescript-go/internal/collections"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/diagnostics"
"github.com/microsoft/typescript-go/internal/json"
"github.com/microsoft/typescript-go/internal/tsoptions"
"github.com/microsoft/typescript-go/internal/tspath"
)
Expand Down Expand Up @@ -213,7 +214,7 @@ func (b *BuildInfoDiagnosticsOfFile) MarshalJSON() ([]byte, error) {
}

func (b *BuildInfoDiagnosticsOfFile) UnmarshalJSON(data []byte) error {
var fileIdAndDiagnostics []json.Value
var fileIdAndDiagnostics []jsontext.Value
if err := json.Unmarshal(data, &fileIdAndDiagnostics); err != nil {
return fmt.Errorf("invalid BuildInfoDiagnosticsOfFile: %s", data)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/incremental/incremental.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package incremental

import (
"github.com/go-json-experiment/json"
"github.com/microsoft/typescript-go/internal/compiler"
"github.com/microsoft/typescript-go/internal/json"
"github.com/microsoft/typescript-go/internal/outputpaths"
"github.com/microsoft/typescript-go/internal/tsoptions"
"github.com/microsoft/typescript-go/internal/tspath"
Expand Down
2 changes: 1 addition & 1 deletion internal/incremental/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"fmt"
"slices"

"github.com/go-json-experiment/json"
"github.com/microsoft/typescript-go/internal/ast"
"github.com/microsoft/typescript-go/internal/compiler"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/diagnostics"
"github.com/microsoft/typescript-go/internal/json"
"github.com/microsoft/typescript-go/internal/outputpaths"
"github.com/microsoft/typescript-go/internal/tspath"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/jsnum/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"unicode"
"unicode/utf8"

"github.com/microsoft/typescript-go/internal/json"
"github.com/go-json-experiment/json"
"github.com/microsoft/typescript-go/internal/stringutil"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/jsnum/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"slices"
"testing"

"github.com/microsoft/typescript-go/internal/json"
"github.com/go-json-experiment/json"
"github.com/microsoft/typescript-go/internal/testutil/jstest"
"gotest.tools/v3/assert"
)
Expand Down
52 changes: 0 additions & 52 deletions internal/json/json.go

This file was deleted.

24 changes: 24 additions & 0 deletions internal/jsonutil/jsonutil.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package jsonutil

import (
"io"

"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
)

func MarshalIndent(in any, prefix, indent string) (out []byte, err error) {
if prefix == "" && indent == "" {
// WithIndentPrefix and WithIndent imply multiline output, so skip them.
return json.Marshal(in)
}
return json.Marshal(in, jsontext.WithIndentPrefix(prefix), jsontext.WithIndent(indent))
}

func MarshalIndentWrite(out io.Writer, in any, prefix, indent string) (err error) {
if prefix == "" && indent == "" {
// WithIndentPrefix and WithIndent imply multiline output, so skip them.
return json.MarshalWrite(out, in)
}
return json.MarshalWrite(out, in, jsontext.WithIndentPrefix(prefix), jsontext.WithIndent(indent))
}
2 changes: 1 addition & 1 deletion internal/ls/completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (
"unicode"
"unicode/utf8"

"github.com/go-json-experiment/json"
"github.com/microsoft/typescript-go/internal/ast"
"github.com/microsoft/typescript-go/internal/astnav"
"github.com/microsoft/typescript-go/internal/checker"
"github.com/microsoft/typescript-go/internal/collections"
"github.com/microsoft/typescript-go/internal/compiler"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/jsnum"
"github.com/microsoft/typescript-go/internal/json"
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
"github.com/microsoft/typescript-go/internal/lsutil"
"github.com/microsoft/typescript-go/internal/scanner"
Expand Down
7 changes: 4 additions & 3 deletions internal/lsp/lsproto/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"fmt"
"strconv"

"github.com/microsoft/typescript-go/internal/json"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
)

type JSONRPCVersion struct{}
Expand Down Expand Up @@ -103,7 +104,7 @@ func (m *Message) UnmarshalJSON(data []byte) error {
JSONRPC JSONRPCVersion `json:"jsonrpc"`
Method Method `json:"method"`
ID *ID `json:"id,omitzero"`
Params json.Value `json:"params"`
Params jsontext.Value `json:"params"`
Result any `json:"result,omitzero"`
Error *ResponseError `json:"error,omitzero"`
}
Expand Down Expand Up @@ -185,7 +186,7 @@ func (r *RequestMessage) UnmarshalJSON(data []byte) error {
JSONRPC JSONRPCVersion `json:"jsonrpc"`
ID *ID `json:"id"`
Method Method `json:"method"`
Params json.Value `json:"params"`
Params jsontext.Value `json:"params"`
}
if err := json.Unmarshal(data, &raw); err != nil {
return fmt.Errorf("%w: %w", ErrInvalidRequest, err)
Expand Down
2 changes: 1 addition & 1 deletion internal/lsp/lsproto/lsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package lsproto
import (
"fmt"

"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"github.com/microsoft/typescript-go/internal/json"
)

type DocumentUri string // !!!
Expand Down
2 changes: 1 addition & 1 deletion internal/lsp/lsproto/lsp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package lsproto
import (
"testing"

"github.com/microsoft/typescript-go/internal/json"
"github.com/go-json-experiment/json"
"gotest.tools/v3/assert"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/lsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"sync/atomic"
"syscall"

"github.com/go-json-experiment/json"
"github.com/microsoft/typescript-go/internal/collections"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/json"
"github.com/microsoft/typescript-go/internal/ls"
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
"github.com/microsoft/typescript-go/internal/project"
Expand Down
5 changes: 3 additions & 2 deletions internal/module/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
"sync"
"testing"

"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/json"
"github.com/microsoft/typescript-go/internal/jsonutil"
"github.com/microsoft/typescript-go/internal/module"
"github.com/microsoft/typescript-go/internal/repo"
"github.com/microsoft/typescript-go/internal/testutil/baseline"
Expand Down Expand Up @@ -326,7 +327,7 @@ func runTraceBaseline(t *testing.T, test traceTestCase) {

if test.trace {
t.Run("trace", func(t *testing.T) {
output, err := json.MarshalIndent(resolver, "", " ")
output, err := jsonutil.MarshalIndent(resolver, "", " ")
if err != nil {
t.Fatal(err)
}
Expand Down
Loading
Loading