Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: microsoft/typescript-go
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: microsoft/typescript-go
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: jabaile/tinygo
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 2 commits
  • 12 files changed
  • 1 contributor

Commits on Mar 26, 2025

  1. Remove jsonv2

    jakebailey committed Mar 26, 2025
    Copy the full SHA
    c46a92e View commit details
  2. Hack it to work in tinygo

    jakebailey committed Mar 26, 2025
    Copy the full SHA
    f05ae14 View commit details
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ go 1.24.0

require (
github.com/dlclark/regexp2 v1.11.5
github.com/go-json-experiment/json v0.0.0-20250223041408-d3c622f1b874
github.com/google/go-cmp v0.7.0
github.com/pkg/diff v0.0.0-20241224192749-4e6772a4315c
golang.org/x/sys v0.31.0
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
github.com/dlclark/regexp2 v1.11.5 h1:Q/sSnsKerHeCkc/jSTNq1oCm7KiVgUMZRDUoRu0JQZQ=
github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/go-json-experiment/json v0.0.0-20250223041408-d3c622f1b874 h1:F8d1AJ6M9UQCavhwmO6ZsrYLfG8zVFWfEfMS2MXPkSY=
github.com/go-json-experiment/json v0.0.0-20250223041408-d3c622f1b874/go.mod h1:TiCD2a1pcmjd7YnhGH0f/zKNcCD06B029pHhzV23c2M=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/pkg/diff v0.0.0-20241224192749-4e6772a4315c h1:8TRxBMS/YsupXoOiGKHr9ZOXo+5DezGWPgBAhBHEHto=
39 changes: 1 addition & 38 deletions internal/collections/ordered_map.go
Original file line number Diff line number Diff line change
@@ -11,9 +11,6 @@ import (
"reflect"
"slices"
"strconv"

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

// OrderedMap is an insertion ordered map.
@@ -244,10 +241,7 @@ func resolveKeyName(k reflect.Value) (string, error) {
panic("unexpected map key type")
}

var (
_ json.Unmarshaler = (*OrderedMap[string, string])(nil)
_ json2.UnmarshalerFrom = (*OrderedMap[string, string])(nil)
)
var _ json.Unmarshaler = (*OrderedMap[string, string])(nil)

func (m *OrderedMap[K, V]) UnmarshalJSON(data []byte) error {
if string(data) == "null" {
@@ -288,34 +282,3 @@ func (m *OrderedMap[K, V]) UnmarshalJSON(data []byte) error {
}
return nil
}

func (m *OrderedMap[K, V]) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
token, err := dec.ReadToken()
if err != nil {
return err
}
if token.Kind() == 'n' { // jsontext.Null.Kind()
// By convention, to approximate the behavior of Unmarshal itself,
// Unmarshalers implement UnmarshalJSON([]byte("null")) as a no-op.
// https://pkg.go.dev/encoding/json#Unmarshaler
return nil
}
if token.Kind() != '{' { // jsontext.ObjectStart.Kind()
return errors.New("cannot unmarshal non-object JSON value into Map")
}
for dec.PeekKind() != '}' { // jsontext.ObjectEnd.Kind()
var key K
var value V
if err := json2.UnmarshalDecode(dec, &key); err != nil {
return err
}
if err := json2.UnmarshalDecode(dec, &value); err != nil {
return err
}
m.Set(key, value)
}
if _, err := dec.ReadToken(); err != nil {
return err
}
return nil
}
5 changes: 0 additions & 5 deletions internal/collections/ordered_map_test.go
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@ import (
"slices"
"testing"

json2 "github.com/go-json-experiment/json"
"github.com/microsoft/typescript-go/internal/collections"
"gotest.tools/v3/assert"
)
@@ -166,10 +165,6 @@ func TestOrderedMapUnmarshalJSON(t *testing.T) {
t.Parallel()
testOrderedMapUnmarshalJSON(t, json.Unmarshal)
})
t.Run("UnmarshalJSONV2", func(t *testing.T) {
t.Parallel()
testOrderedMapUnmarshalJSON(t, func(in []byte, out any) error { return json2.Unmarshal(in, out) })
})
}

func testOrderedMapUnmarshalJSON(t *testing.T, unmarshal func([]byte, any) error) {
5 changes: 3 additions & 2 deletions internal/compiler/module/resolver.go
Original file line number Diff line number Diff line change
@@ -1504,8 +1504,9 @@ func (r *resolutionState) getPackageJsonInfo(packageDirectory string, onlyRecord
directoryExists := r.resolver.host.FS().DirectoryExists(packageDirectory)
if directoryExists && r.resolver.host.FS().FileExists(packageJsonPath) {
// Ignore error
contents, _ := r.resolver.host.FS().ReadFile(packageJsonPath)
packageJsonContent, _ := packagejson.Parse([]byte(contents))
// contents, _ := r.resolver.host.FS().ReadFile(packageJsonPath)
// packageJsonContent, _ := packagejson.Parse([]byte(contents))
var packageJsonContent packagejson.Fields
if r.resolver.traceEnabled() {
r.resolver.host.Trace(diagnostics.Found_package_json_at_0.Format(packageJsonPath))
}
11 changes: 1 addition & 10 deletions internal/compiler/packagejson/exportsorimports.go
Original file line number Diff line number Diff line change
@@ -3,8 +3,6 @@ package packagejson
import (
"encoding/json"

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

@@ -23,19 +21,12 @@ type ExportsOrImports struct {
objectKind objectKind
}

var (
_ json.Unmarshaler = (*ExportsOrImports)(nil)
_ json2.UnmarshalerFrom = (*ExportsOrImports)(nil)
)
var _ json.Unmarshaler = (*ExportsOrImports)(nil)

func (e *ExportsOrImports) UnmarshalJSON(data []byte) error {
return unmarshalJSONValue[ExportsOrImports](&e.JSONValue, data)
}

func (e *ExportsOrImports) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
return unmarshalJSONValueV2[ExportsOrImports](&e.JSONValue, dec)
}

func (e ExportsOrImports) AsObject() *collections.OrderedMap[string, ExportsOrImports] {
if e.Type != JSONValueTypeObject {
panic("expected object")
5 changes: 0 additions & 5 deletions internal/compiler/packagejson/exportsorimports_test.go
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ import (
"encoding/json"
"testing"

json2 "github.com/go-json-experiment/json"
"github.com/microsoft/typescript-go/internal/compiler/packagejson"
"gotest.tools/v3/assert"
)
@@ -16,10 +15,6 @@ func TestExports(t *testing.T) {
t.Parallel()
testExports(t, json.Unmarshal)
})
t.Run("UnmarshalJSONV2", func(t *testing.T) {
t.Parallel()
testExports(t, func(in []byte, out any) error { return json2.Unmarshal(in, out) })
})
}

func testExports(t *testing.T, unmarshal func([]byte, any) error) {
63 changes: 1 addition & 62 deletions internal/compiler/packagejson/jsonvalue.go
Original file line number Diff line number Diff line change
@@ -4,8 +4,6 @@ import (
"encoding/json"
"fmt"

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

@@ -74,19 +72,12 @@ func (v JSONValue) AsArray() []JSONValue {
return v.Value.([]JSONValue)
}

var (
_ json.Unmarshaler = (*JSONValue)(nil)
_ json2.UnmarshalerFrom = (*JSONValue)(nil)
)
var _ json.Unmarshaler = (*JSONValue)(nil)

func (v *JSONValue) UnmarshalJSON(data []byte) error {
return unmarshalJSONValue[JSONValue](v, data)
}

func (v *JSONValue) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
return unmarshalJSONValueV2[JSONValue](v, dec)
}

func unmarshalJSONValue[T any](v *JSONValue, data []byte) error {
if string(data) == "null" {
*v = JSONValue{Type: JSONValueTypeNull}
@@ -119,55 +110,3 @@ func unmarshalJSONValue[T any](v *JSONValue, data []byte) error {
}
return nil
}

func unmarshalJSONValueV2[T any](v *JSONValue, dec *jsontext.Decoder) error {
switch dec.PeekKind() {
case 'n': // jsontext.Null.Kind()
if _, err := dec.ReadToken(); err != nil {
return err
}
v.Value = nil
v.Type = JSONValueTypeNull
return nil
case '"':
v.Type = JSONValueTypeString
if err := json2.UnmarshalDecode(dec, &v.Value); err != nil {
return err
}
case '[':
if _, err := dec.ReadToken(); err != nil {
return err
}
var elements []T
for dec.PeekKind() != jsontext.EndArray.Kind() {
var element T
if err := json2.UnmarshalDecode(dec, &element); err != nil {
return err
}
elements = append(elements, element)
}
if _, err := dec.ReadToken(); err != nil {
return err
}
v.Type = JSONValueTypeArray
v.Value = elements
case '{':
var object collections.OrderedMap[string, T]
if err := json2.UnmarshalDecode(dec, &object); err != nil {
return err
}
v.Type = JSONValueTypeObject
v.Value = &object
case 't', 'f': // jsontext.True.Kind(), jsontext.False.Kind()
v.Type = JSONValueTypeBoolean
if err := json2.UnmarshalDecode(dec, &v.Value); err != nil {
return err
}
default:
v.Type = JSONValueTypeNumber
if err := json2.UnmarshalDecode(dec, &v.Value); err != nil {
return err
}
}
return nil
}
5 changes: 0 additions & 5 deletions internal/compiler/packagejson/jsonvalue_test.go
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ import (
"encoding/json"
"testing"

json2 "github.com/go-json-experiment/json"
"github.com/microsoft/typescript-go/internal/compiler/packagejson"
"gotest.tools/v3/assert"
)
@@ -16,10 +15,6 @@ func TestJSONValue(t *testing.T) {
t.Parallel()
testJSONValue(t, json.Unmarshal)
})
t.Run("UnmarshalJSONV2", func(t *testing.T) {
t.Parallel()
testJSONValue(t, func(in []byte, out any) error { return json2.Unmarshal(in, out) })
})
}

func testJSONValue(t *testing.T, unmarshal func([]byte, any) error) {
6 changes: 2 additions & 4 deletions internal/compiler/packagejson/packagejson.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package packagejson

import (
json2 "github.com/go-json-experiment/json"
)
import "encoding/json"

type HeaderFields struct {
Name Expected[string] `json:"name"`
@@ -34,7 +32,7 @@ type Fields struct {

func Parse(data []byte) (Fields, error) {
var f Fields
if err := json2.Unmarshal(data, &f); err != nil {
if err := json.Unmarshal(data, &f); err != nil {
return f, err
}
return f, nil
12 changes: 0 additions & 12 deletions internal/compiler/packagejson/packagejson_test.go
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ import (
"path/filepath"
"testing"

json2 "github.com/go-json-experiment/json"
"github.com/microsoft/typescript-go/internal/compiler/packagejson"
"github.com/microsoft/typescript-go/internal/parser"
"github.com/microsoft/typescript-go/internal/repo"
@@ -33,17 +32,6 @@ func BenchmarkPackageJSON(b *testing.B) {
})
})

b.Run("UnmarshalJSONV2", func(b *testing.B) {
b.Run(f.Name(), func(b *testing.B) {
for b.Loop() {
var p packagejson.Fields
if err := json2.Unmarshal(content, &p); err != nil {
b.Fatal(err)
}
}
})
})

b.Run("ParseJSONText", func(b *testing.B) {
b.Run(f.Name(), func(b *testing.B) {
fileName := "/" + f.Name()
7 changes: 4 additions & 3 deletions internal/jsnum/string.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package jsnum

import (
"encoding/json"
"errors"
"math"
"math/big"
@@ -32,9 +31,11 @@ func (n Number) String() string {
}
}

return strconv.FormatFloat(float64(n), 'g', -1, 64)

// Otherwise, the Go json package handles this correctly.
b, _ := json.Marshal(float64(n)) //nolint:errchkjson
return string(b)
// b, _ := json.Marshal(float64(n)) //nolint:errchkjson
// return string(b)
}

// https://tc39.es/ecma262/2024/multipage/abstract-operations.html#sec-stringtonumber