goscript 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiler/gotest/testdata/browserapi/browserapi_test.go +36 -0
- package/compiler/lowering.go +279 -16
- package/compiler/override-registry_test.go +175 -0
- package/compiler/protobuf-ts-binding.go +154 -6
- package/compiler/protobuf-ts-binding_test.go +7 -2
- package/compiler/runtime-contract.go +2 -0
- package/compiler/runtime-contract_test.go +1 -0
- package/compiler/semantic-model.go +16 -0
- package/compiler/semantic-model_test.go +38 -0
- package/compiler/skeleton_test.go +522 -17
- package/compiler/typescript-emitter.go +4 -0
- package/dist/gs/builtin/builtin.js +7 -9
- package/dist/gs/builtin/builtin.js.map +1 -1
- package/dist/gs/builtin/defer.js +2 -2
- package/dist/gs/builtin/hostio.js +5 -5
- package/dist/gs/builtin/hostio.js.map +1 -1
- package/dist/gs/builtin/map.js +2 -1
- package/dist/gs/builtin/map.js.map +1 -1
- package/dist/gs/builtin/slice.d.ts +3 -0
- package/dist/gs/builtin/slice.js +39 -0
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/builtin/type.js +49 -0
- package/dist/gs/builtin/type.js.map +1 -1
- package/dist/gs/compress/gzip/index.d.ts +41 -0
- package/dist/gs/compress/gzip/index.js +235 -0
- package/dist/gs/compress/gzip/index.js.map +1 -0
- package/dist/gs/compress/zlib/index.js +5 -2
- package/dist/gs/compress/zlib/index.js.map +1 -1
- package/dist/gs/crypto/ecdh/index.js +27 -8
- package/dist/gs/crypto/ecdh/index.js.map +1 -1
- package/dist/gs/crypto/ed25519/index.js +3 -3
- package/dist/gs/crypto/ed25519/index.js.map +1 -1
- package/dist/gs/crypto/rand/index.js +6 -3
- package/dist/gs/crypto/rand/index.js.map +1 -1
- package/dist/gs/embed/index.js +9 -3
- package/dist/gs/embed/index.js.map +1 -1
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.d.ts +1 -0
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js +33 -0
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js.map +1 -1
- package/dist/gs/github.com/mr-tron/base58/base58/index.js +4 -1
- package/dist/gs/github.com/mr-tron/base58/base58/index.js.map +1 -1
- package/dist/gs/golang.org/x/crypto/scrypt/index.d.ts +2 -0
- package/dist/gs/golang.org/x/crypto/scrypt/index.js +39 -0
- package/dist/gs/golang.org/x/crypto/scrypt/index.js.map +1 -0
- package/dist/gs/hash/fnv/index.js +13 -5
- package/dist/gs/hash/fnv/index.js.map +1 -1
- package/dist/gs/io/fs/glob.d.ts +3 -3
- package/dist/gs/io/fs/glob.js +9 -9
- package/dist/gs/io/fs/glob.js.map +1 -1
- package/dist/gs/io/fs/readdir.d.ts +2 -2
- package/dist/gs/io/fs/readdir.js +13 -74
- package/dist/gs/io/fs/readdir.js.map +1 -1
- package/dist/gs/io/fs/readlink.d.ts +1 -1
- package/dist/gs/io/fs/readlink.js +2 -2
- package/dist/gs/io/fs/readlink.js.map +1 -1
- package/dist/gs/io/fs/stat.d.ts +4 -2
- package/dist/gs/io/fs/stat.js +12 -73
- package/dist/gs/io/fs/stat.js.map +1 -1
- package/dist/gs/io/fs/sub.d.ts +2 -2
- package/dist/gs/io/fs/sub.js +11 -11
- package/dist/gs/io/fs/sub.js.map +1 -1
- package/dist/gs/io/fs/walk.js +2 -2
- package/dist/gs/io/fs/walk.js.map +1 -1
- package/dist/gs/maps/iter.js.map +1 -1
- package/dist/gs/maps/maps.js.map +1 -1
- package/dist/gs/mime/index.js +5 -2
- package/dist/gs/mime/index.js.map +1 -1
- package/dist/gs/net/http/httptest/index.js +6 -3
- package/dist/gs/net/http/httptest/index.js.map +1 -1
- package/dist/gs/net/http/index.d.ts +34 -18
- package/dist/gs/net/http/index.js +280 -63
- package/dist/gs/net/http/index.js.map +1 -1
- package/dist/gs/net/http/pprof/index.d.ts +5 -5
- package/dist/gs/net/http/pprof/index.js +21 -21
- package/dist/gs/net/http/pprof/index.js.map +1 -1
- package/dist/gs/reflect/iter.js +1 -1
- package/dist/gs/reflect/iter.js.map +1 -1
- package/dist/gs/reflect/type.d.ts +2 -0
- package/dist/gs/reflect/type.js +53 -21
- package/dist/gs/reflect/type.js.map +1 -1
- package/dist/gs/runtime/pprof/index.js.map +1 -1
- package/dist/gs/runtime/runtime.js +2 -2
- package/dist/gs/runtime/runtime.js.map +1 -1
- package/dist/gs/runtime/trace/index.js.map +1 -1
- package/dist/gs/slices/slices.d.ts +1 -1
- package/dist/gs/slices/slices.js +37 -4
- package/dist/gs/slices/slices.js.map +1 -1
- package/gs/builtin/builtin.ts +11 -14
- package/gs/builtin/defer.ts +2 -2
- package/gs/builtin/hostio.ts +5 -5
- package/gs/builtin/map.ts +4 -1
- package/gs/builtin/runtime-contract.test.ts +25 -0
- package/gs/builtin/slice.test.ts +14 -0
- package/gs/builtin/slice.ts +64 -0
- package/gs/builtin/type.ts +72 -0
- package/gs/bytes/bytes.test.ts +14 -13
- package/gs/compress/gzip/index.test.ts +86 -0
- package/gs/compress/gzip/index.ts +297 -0
- package/gs/compress/gzip/meta.json +6 -0
- package/gs/compress/gzip/parity.json +45 -0
- package/gs/compress/zlib/index.test.ts +19 -5
- package/gs/compress/zlib/index.ts +16 -7
- package/gs/context/context.test.ts +3 -1
- package/gs/crypto/ecdh/index.test.ts +6 -2
- package/gs/crypto/ecdh/index.ts +49 -12
- package/gs/crypto/ed25519/index.ts +20 -7
- package/gs/crypto/rand/index.ts +6 -3
- package/gs/embed/index.test.ts +4 -4
- package/gs/embed/index.ts +9 -3
- package/gs/fmt/fmt.test.ts +29 -4
- package/gs/github.com/aperturerobotics/protobuf-go-lite/index.test.ts +126 -0
- package/gs/github.com/aperturerobotics/protobuf-go-lite/index.ts +46 -0
- package/gs/github.com/mr-tron/base58/base58/index.ts +9 -3
- package/gs/github.com/zeebo/blake3/internal/consts/index.test.ts +2 -8
- package/gs/golang.org/x/crypto/scrypt/index.test.ts +81 -0
- package/gs/golang.org/x/crypto/scrypt/index.ts +54 -0
- package/gs/golang.org/x/crypto/scrypt/meta.json +5 -0
- package/gs/hash/fnv/index.test.ts +1 -8
- package/gs/hash/fnv/index.ts +27 -10
- package/gs/io/fs/glob.ts +14 -11
- package/gs/io/fs/meta.json +5 -0
- package/gs/io/fs/readdir.test.ts +63 -2
- package/gs/io/fs/readdir.ts +33 -30
- package/gs/io/fs/readlink.test.ts +2 -2
- package/gs/io/fs/readlink.ts +5 -2
- package/gs/io/fs/stat.test.ts +79 -0
- package/gs/io/fs/stat.ts +24 -10
- package/gs/io/fs/sub.test.ts +93 -0
- package/gs/io/fs/sub.ts +13 -13
- package/gs/io/fs/walk.ts +2 -2
- package/gs/maps/iter.ts +9 -9
- package/gs/maps/maps.ts +4 -4
- package/gs/math/bits/index.test.ts +10 -1
- package/gs/mime/index.test.ts +33 -15
- package/gs/mime/index.ts +9 -2
- package/gs/net/http/httptest/index.test.ts +17 -3
- package/gs/net/http/httptest/index.ts +8 -3
- package/gs/net/http/index.test.ts +851 -124
- package/gs/net/http/index.ts +612 -146
- package/gs/net/http/meta.json +3 -1
- package/gs/net/http/pprof/index.test.ts +4 -4
- package/gs/net/http/pprof/index.ts +43 -22
- package/gs/os/file_unix_js.test.ts +22 -0
- package/gs/reflect/iter.ts +4 -2
- package/gs/reflect/map.test.ts +56 -1
- package/gs/reflect/type.ts +76 -37
- package/gs/runtime/pprof/index.test.ts +7 -1
- package/gs/runtime/pprof/index.ts +5 -1
- package/gs/runtime/runtime.test.ts +7 -0
- package/gs/runtime/runtime.ts +2 -4
- package/gs/runtime/trace/index.test.ts +9 -1
- package/gs/runtime/trace/index.ts +5 -1
- package/gs/slices/meta.json +3 -0
- package/gs/slices/slices.test.ts +59 -21
- package/gs/slices/slices.ts +61 -20
- package/gs/strconv/complex.test.ts +17 -3
- package/gs/sync/atomic/doc_64.test.ts +2 -9
- package/gs/sync/sync.test.ts +18 -8
- package/gs/syscall/js/index.test.ts +9 -4
- package/package.json +5 -4
package/gs/slices/slices.test.ts
CHANGED
|
@@ -22,9 +22,20 @@ import {
|
|
|
22
22
|
MinFunc,
|
|
23
23
|
Replace,
|
|
24
24
|
Sorted,
|
|
25
|
+
SortFunc,
|
|
25
26
|
SortStableFunc,
|
|
26
27
|
} from './slices.js'
|
|
27
28
|
|
|
29
|
+
describe('slices.SortFunc', () => {
|
|
30
|
+
it('awaits async comparison callbacks', async () => {
|
|
31
|
+
const values = $.arrayToSlice([3, 1, 2])
|
|
32
|
+
|
|
33
|
+
await SortFunc(values, async (a, b) => a - b)
|
|
34
|
+
|
|
35
|
+
expect(Array.from(values ?? [])).toEqual([1, 2, 3])
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
|
|
28
39
|
describe('slices.SortStableFunc', () => {
|
|
29
40
|
it('preserves original order for equal elements', () => {
|
|
30
41
|
const values = $.arrayToSlice([
|
|
@@ -43,14 +54,22 @@ describe('slices.SortStableFunc', () => {
|
|
|
43
54
|
describe('slices compatibility helpers', () => {
|
|
44
55
|
it('implements comparison, min/max, compact, replace, clip, and search helpers', () => {
|
|
45
56
|
expect(
|
|
46
|
-
CompareFunc(
|
|
47
|
-
a
|
|
57
|
+
CompareFunc(
|
|
58
|
+
$.arrayToSlice(['a', 'c']),
|
|
59
|
+
$.arrayToSlice(['a', 'b']),
|
|
60
|
+
(a, b) => a.localeCompare(b),
|
|
48
61
|
),
|
|
49
62
|
).toBeGreaterThan(0)
|
|
50
63
|
expect(Min($.arrayToSlice([3, 1, 2]))).toBe(1)
|
|
51
|
-
expect(
|
|
52
|
-
|
|
53
|
-
|
|
64
|
+
expect(
|
|
65
|
+
MaxFunc($.arrayToSlice([{ v: 1 }, { v: 4 }]), (a, b) => a.v - b.v).v,
|
|
66
|
+
).toBe(4)
|
|
67
|
+
expect(
|
|
68
|
+
MinFunc($.arrayToSlice([{ v: 3 }, { v: 2 }]), (a, b) => a.v - b.v).v,
|
|
69
|
+
).toBe(2)
|
|
70
|
+
expect(Array.from(Compact($.arrayToSlice([1, 1, 2, 2, 3])) ?? [])).toEqual([
|
|
71
|
+
1, 2, 3,
|
|
72
|
+
])
|
|
54
73
|
expect(
|
|
55
74
|
Array.from(
|
|
56
75
|
CompactFunc(
|
|
@@ -59,9 +78,9 @@ describe('slices compatibility helpers', () => {
|
|
|
59
78
|
) ?? [],
|
|
60
79
|
),
|
|
61
80
|
).toEqual(['a', 'b'])
|
|
62
|
-
expect(
|
|
63
|
-
1,
|
|
64
|
-
])
|
|
81
|
+
expect(
|
|
82
|
+
Array.from(Replace($.arrayToSlice([1, 2, 3, 4]), 1, 3, 9, 8)) ?? [],
|
|
83
|
+
).toEqual([1, 9, 8, 4])
|
|
65
84
|
expect(Array.from(Clip($.arrayToSlice([1, 2])) ?? [])).toEqual([1, 2])
|
|
66
85
|
expect(BinarySearch($.arrayToSlice([1, 3, 5]), 3)).toEqual([1, true])
|
|
67
86
|
})
|
|
@@ -69,22 +88,37 @@ describe('slices compatibility helpers', () => {
|
|
|
69
88
|
it('concatenates slices and preserves empty concat nilness', () => {
|
|
70
89
|
expect(Concat()).toBeNull()
|
|
71
90
|
expect(Concat($.arrayToSlice<number>([]))).toBeNull()
|
|
72
|
-
expect(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
91
|
+
expect(
|
|
92
|
+
Array.from(
|
|
93
|
+
Concat($.arrayToSlice([1]), null, $.arrayToSlice([2, 3])) ?? [],
|
|
94
|
+
),
|
|
95
|
+
).toEqual([1, 2, 3])
|
|
96
|
+
expect(
|
|
97
|
+
Array.from(Concat(new Uint8Array([1, 2]), new Uint8Array([3])) ?? []),
|
|
98
|
+
).toEqual([1, 2, 3])
|
|
78
99
|
})
|
|
79
100
|
|
|
80
101
|
it('accepts generated possibly-async callback types for sync helpers', () => {
|
|
81
|
-
const compare: (a: number, b: number) => number | Promise<number> = (
|
|
82
|
-
|
|
83
|
-
|
|
102
|
+
const compare: (a: number, b: number) => number | Promise<number> = (
|
|
103
|
+
a,
|
|
104
|
+
b,
|
|
105
|
+
) => a - b
|
|
106
|
+
const keepOdd: (v: number) => boolean | Promise<boolean> = (v) =>
|
|
107
|
+
v % 2 === 0
|
|
108
|
+
const equal: (a: string, b: string) => boolean | Promise<boolean> = (
|
|
109
|
+
a,
|
|
110
|
+
b,
|
|
111
|
+
) => a === b
|
|
84
112
|
|
|
85
|
-
expect(
|
|
86
|
-
|
|
87
|
-
|
|
113
|
+
expect(
|
|
114
|
+
CompareFunc($.arrayToSlice([1]), $.arrayToSlice([2]), compare),
|
|
115
|
+
).toBeLessThan(0)
|
|
116
|
+
expect(
|
|
117
|
+
Array.from(DeleteFunc($.arrayToSlice([1, 2, 3]), keepOdd) ?? []),
|
|
118
|
+
).toEqual([1, 3])
|
|
119
|
+
expect(EqualFunc($.arrayToSlice(['a']), $.arrayToSlice(['a']), equal)).toBe(
|
|
120
|
+
true,
|
|
121
|
+
)
|
|
88
122
|
expect(IndexFunc($.arrayToSlice([1, 2, 3]), keepOdd)).toBe(1)
|
|
89
123
|
expect(IsSortedFunc($.arrayToSlice([1, 2, 3]), compare)).toBe(true)
|
|
90
124
|
expect(BinarySearch($.arrayToSlice([1, 2, 3]), 2)).toEqual([1, true])
|
|
@@ -92,7 +126,11 @@ describe('slices compatibility helpers', () => {
|
|
|
92
126
|
|
|
93
127
|
it('rejects actual async callback results in sync helpers', () => {
|
|
94
128
|
expect(() =>
|
|
95
|
-
CompareFunc(
|
|
129
|
+
CompareFunc(
|
|
130
|
+
$.arrayToSlice([1]),
|
|
131
|
+
$.arrayToSlice([2]),
|
|
132
|
+
async (a, b) => a - b,
|
|
133
|
+
),
|
|
96
134
|
).toThrow('slices: asynchronous callback result is not supported')
|
|
97
135
|
})
|
|
98
136
|
})
|
package/gs/slices/slices.ts
CHANGED
|
@@ -4,9 +4,13 @@ import * as cmp from '../cmp/index.js'
|
|
|
4
4
|
import * as iter from '../iter/index.js'
|
|
5
5
|
|
|
6
6
|
type SyncCallbackResult<T> = T | globalThis.Promise<T>
|
|
7
|
-
type CompareCallback<T, U = T> =
|
|
7
|
+
type CompareCallback<T, U = T> =
|
|
8
|
+
| ((v1: T, v2: U) => SyncCallbackResult<number>)
|
|
9
|
+
| null
|
|
8
10
|
type PredicateCallback<T> = ((value: T) => SyncCallbackResult<boolean>) | null
|
|
9
|
-
type EqualCallback<T, U = T> =
|
|
11
|
+
type EqualCallback<T, U = T> =
|
|
12
|
+
| ((v1: T, v2: U) => SyncCallbackResult<boolean>)
|
|
13
|
+
| null
|
|
10
14
|
|
|
11
15
|
/**
|
|
12
16
|
* Compare compares the elements of s1 and s2 using cmp.Compare.
|
|
@@ -59,9 +63,7 @@ export function CompareFunc<T, U>(
|
|
|
59
63
|
const len2 = $.len(s2)
|
|
60
64
|
const minLen = len1 < len2 ? len1 : len2
|
|
61
65
|
for (let i = 0; i < minLen; i++) {
|
|
62
|
-
const result = syncNumber(
|
|
63
|
-
compare((s1 as any)[i] as T, (s2 as any)[i] as U),
|
|
64
|
-
)
|
|
66
|
+
const result = syncNumber(compare((s1 as any)[i] as T, (s2 as any)[i] as U))
|
|
65
67
|
if (result !== 0) {
|
|
66
68
|
return result
|
|
67
69
|
}
|
|
@@ -131,7 +133,9 @@ export function Concat<T>(...slices: $.Slice<T>[]): $.Slice<T> {
|
|
|
131
133
|
*/
|
|
132
134
|
export function All<T>(
|
|
133
135
|
s: $.Slice<T>,
|
|
134
|
-
): (
|
|
136
|
+
): (
|
|
137
|
+
yieldFunc: (index: number, value: T) => iter.YieldResult,
|
|
138
|
+
) => void | globalThis.Promise<void> {
|
|
135
139
|
return function (
|
|
136
140
|
_yield: (index: number, value: T) => iter.YieldResult,
|
|
137
141
|
): void | globalThis.Promise<void> {
|
|
@@ -228,10 +232,7 @@ export function Min<T extends cmp.Ordered>(x: $.Slice<T>): T {
|
|
|
228
232
|
return min
|
|
229
233
|
}
|
|
230
234
|
|
|
231
|
-
export function MaxFunc<T>(
|
|
232
|
-
x: $.Slice<T>,
|
|
233
|
-
compare: CompareCallback<T>,
|
|
234
|
-
): T {
|
|
235
|
+
export function MaxFunc<T>(x: $.Slice<T>, compare: CompareCallback<T>): T {
|
|
235
236
|
if (compare == null) {
|
|
236
237
|
throw new Error('slices.MaxFunc: nil comparison function')
|
|
237
238
|
}
|
|
@@ -248,10 +249,7 @@ export function MaxFunc<T>(
|
|
|
248
249
|
return max
|
|
249
250
|
}
|
|
250
251
|
|
|
251
|
-
export function MinFunc<T>(
|
|
252
|
-
x: $.Slice<T>,
|
|
253
|
-
compare: CompareCallback<T>,
|
|
254
|
-
): T {
|
|
252
|
+
export function MinFunc<T>(x: $.Slice<T>, compare: CompareCallback<T>): T {
|
|
255
253
|
if (compare == null) {
|
|
256
254
|
throw new Error('slices.MinFunc: nil comparison function')
|
|
257
255
|
}
|
|
@@ -476,7 +474,10 @@ export function Contains<T>(s: $.Slice<T>, v: T): boolean {
|
|
|
476
474
|
return Index(s, v) >= 0
|
|
477
475
|
}
|
|
478
476
|
|
|
479
|
-
export function ContainsFunc<T>(
|
|
477
|
+
export function ContainsFunc<T>(
|
|
478
|
+
s: $.Slice<T>,
|
|
479
|
+
f: PredicateCallback<T>,
|
|
480
|
+
): boolean {
|
|
480
481
|
return IndexFunc(s, f) >= 0
|
|
481
482
|
}
|
|
482
483
|
|
|
@@ -555,18 +556,58 @@ export function Grow<T>(s: $.Slice<T>, n: number): $.Slice<T> {
|
|
|
555
556
|
* @param s The slice to sort in place
|
|
556
557
|
* @param cmp Comparison function
|
|
557
558
|
*/
|
|
558
|
-
export function SortFunc<T>(
|
|
559
|
+
export async function SortFunc<T>(
|
|
559
560
|
s: $.Slice<T>,
|
|
560
561
|
cmp: CompareCallback<T>,
|
|
561
|
-
): void {
|
|
562
|
+
): globalThis.Promise<void> {
|
|
562
563
|
if (cmp == null) {
|
|
563
564
|
throw new Error('slices.SortFunc: nil comparison function')
|
|
564
565
|
}
|
|
565
|
-
if (s === null || s === undefined) {
|
|
566
|
+
if (s === null || s === undefined || $.len(s) < 2) {
|
|
566
567
|
return
|
|
567
568
|
}
|
|
568
|
-
const
|
|
569
|
-
|
|
569
|
+
const sorted = await asyncMergeSort(Array.from(s as any as T[]), cmp)
|
|
570
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
571
|
+
;(s as any)[i] = sorted[i]
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
async function asyncMergeSort<T>(
|
|
576
|
+
values: T[],
|
|
577
|
+
cmp: CompareCallback<T>,
|
|
578
|
+
): globalThis.Promise<T[]> {
|
|
579
|
+
if (values.length < 2) {
|
|
580
|
+
return values
|
|
581
|
+
}
|
|
582
|
+
const mid = Math.floor(values.length / 2)
|
|
583
|
+
const left = await asyncMergeSort(values.slice(0, mid), cmp)
|
|
584
|
+
const right = await asyncMergeSort(values.slice(mid), cmp)
|
|
585
|
+
return asyncMerge(left, right, cmp)
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
async function asyncMerge<T>(
|
|
589
|
+
left: T[],
|
|
590
|
+
right: T[],
|
|
591
|
+
cmp: CompareCallback<T>,
|
|
592
|
+
): globalThis.Promise<T[]> {
|
|
593
|
+
const out: T[] = []
|
|
594
|
+
let li = 0
|
|
595
|
+
let ri = 0
|
|
596
|
+
while (li < left.length && ri < right.length) {
|
|
597
|
+
const order = await cmp!(left[li], right[ri])
|
|
598
|
+
if (order <= 0) {
|
|
599
|
+
out.push(left[li++])
|
|
600
|
+
} else {
|
|
601
|
+
out.push(right[ri++])
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
while (li < left.length) {
|
|
605
|
+
out.push(left[li++])
|
|
606
|
+
}
|
|
607
|
+
while (ri < right.length) {
|
|
608
|
+
out.push(right[ri++])
|
|
609
|
+
}
|
|
610
|
+
return out
|
|
570
611
|
}
|
|
571
612
|
|
|
572
613
|
export function IsSortedFunc<T>(
|
|
@@ -48,10 +48,22 @@ describe('strconv complex helpers', () => {
|
|
|
48
48
|
})
|
|
49
49
|
|
|
50
50
|
it('rejects whitespace and malformed imaginary forms', () => {
|
|
51
|
-
for (const input of [
|
|
51
|
+
for (const input of [
|
|
52
|
+
' 1+2i',
|
|
53
|
+
'1+2i ',
|
|
54
|
+
'1 +2i',
|
|
55
|
+
'i',
|
|
56
|
+
'+i',
|
|
57
|
+
'-i',
|
|
58
|
+
'1++2i',
|
|
59
|
+
'1-+2i',
|
|
60
|
+
'0xp1',
|
|
61
|
+
]) {
|
|
52
62
|
const [, err] = ParseComplex(input, 128)
|
|
53
63
|
|
|
54
|
-
expect(err?.Error(), input).toBe(
|
|
64
|
+
expect(err?.Error(), input).toBe(
|
|
65
|
+
`strconv.ParseComplex: parsing "${input}": invalid syntax`,
|
|
66
|
+
)
|
|
55
67
|
}
|
|
56
68
|
})
|
|
57
69
|
|
|
@@ -60,6 +72,8 @@ describe('strconv complex helpers', () => {
|
|
|
60
72
|
|
|
61
73
|
expect($.real(value)).toBe(Infinity)
|
|
62
74
|
expect($.imag(value)).toBe(0)
|
|
63
|
-
expect(err?.Error()).toBe(
|
|
75
|
+
expect(err?.Error()).toBe(
|
|
76
|
+
'strconv.ParseComplex: parsing "0x1p1025": value out of range',
|
|
77
|
+
)
|
|
64
78
|
})
|
|
65
79
|
})
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { describe, expect, test } from 'vitest'
|
|
2
2
|
|
|
3
3
|
import * as $ from '../../builtin/index.js'
|
|
4
|
-
import {
|
|
5
|
-
AddInt64,
|
|
6
|
-
AddUint64,
|
|
7
|
-
AndUint64,
|
|
8
|
-
OrUint64,
|
|
9
|
-
} from './doc_64.gs.js'
|
|
4
|
+
import { AddInt64, AddUint64, AndUint64, OrUint64 } from './doc_64.gs.js'
|
|
10
5
|
|
|
11
6
|
function asBigInt(value: number): bigint {
|
|
12
7
|
return typeof value === 'bigint' ? value : BigInt(value)
|
|
@@ -23,9 +18,7 @@ describe('sync/atomic 64-bit operations', () => {
|
|
|
23
18
|
test('preserves high uint64 bits for bitwise operations', () => {
|
|
24
19
|
const value = $.varRef($.uint('9223372036854775808', 64))
|
|
25
20
|
|
|
26
|
-
expect(asBigInt(OrUint64(value, $.uint(1, 64)))).toBe(
|
|
27
|
-
9223372036854775808n,
|
|
28
|
-
)
|
|
21
|
+
expect(asBigInt(OrUint64(value, $.uint(1, 64)))).toBe(9223372036854775808n)
|
|
29
22
|
expect(asBigInt(value.value)).toBe(9223372036854775809n)
|
|
30
23
|
|
|
31
24
|
expect(asBigInt(AndUint64(value, $.uint('18446744073709551614', 64)))).toBe(
|
package/gs/sync/sync.test.ts
CHANGED
|
@@ -94,14 +94,24 @@ describe('sync.Map', () => {
|
|
|
94
94
|
|
|
95
95
|
it('matches boxed comparable interface keys', async () => {
|
|
96
96
|
const m = new Map()
|
|
97
|
-
const first = $.namedValueInterfaceValue(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
97
|
+
const first = $.namedValueInterfaceValue(
|
|
98
|
+
8,
|
|
99
|
+
'uint16',
|
|
100
|
+
{},
|
|
101
|
+
{
|
|
102
|
+
kind: $.TypeKind.Basic,
|
|
103
|
+
name: 'uint16',
|
|
104
|
+
},
|
|
105
|
+
)
|
|
106
|
+
const second = $.namedValueInterfaceValue(
|
|
107
|
+
8,
|
|
108
|
+
'uint16',
|
|
109
|
+
{},
|
|
110
|
+
{
|
|
111
|
+
kind: $.TypeKind.Basic,
|
|
112
|
+
name: 'uint16',
|
|
113
|
+
},
|
|
114
|
+
)
|
|
105
115
|
|
|
106
116
|
await m.Store(first, 'compressor')
|
|
107
117
|
expect(await m.Load(second)).toEqual(['compressor', true])
|
|
@@ -7,10 +7,15 @@ import { ValueOf } from './index.js'
|
|
|
7
7
|
describe('syscall/js override', () => {
|
|
8
8
|
test('ValueOf unwraps generated interface numeric boxes', () => {
|
|
9
9
|
const value = ValueOf(
|
|
10
|
-
$.namedValueInterfaceValue(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
$.namedValueInterfaceValue(
|
|
11
|
+
41,
|
|
12
|
+
'int',
|
|
13
|
+
{},
|
|
14
|
+
{
|
|
15
|
+
kind: $.TypeKind.Basic,
|
|
16
|
+
name: 'int',
|
|
17
|
+
},
|
|
18
|
+
),
|
|
14
19
|
)
|
|
15
20
|
|
|
16
21
|
expect(value.Int()).toBe(41)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "goscript",
|
|
3
3
|
"description": "Go to TypeScript transpiler",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.4",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Aperture Robotics LLC.",
|
|
7
7
|
"email": "support@aperture.us",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"example": "cd ./example/simple && bash run.bash",
|
|
49
49
|
"test": "bun run test:go && bun run test:js",
|
|
50
50
|
"test:go": "go test ./...",
|
|
51
|
-
"test:go:browser": "go run ./cmd/goscript test --browser --timeout 1m --dir compiler/gotest/testdata/browserapi --run
|
|
52
|
-
"test:go:browser:shim": "mkdir -p .tmp/bin && go build -o .tmp/bin/go_js_wasm_exec ./cmd/go_js_wasm_exec && sh -c 'exec_path=\"$PWD/.tmp/bin/go_js_wasm_exec\"; cd compiler/gotest/testdata/browserapi && GOOS=js GOARCH=wasm go test -exec \"$exec_path\" -run
|
|
51
|
+
"test:go:browser": "go run ./cmd/goscript test --browser --timeout 1m --dir compiler/gotest/testdata/browserapi --run TestBrowser .",
|
|
52
|
+
"test:go:browser:shim": "mkdir -p .tmp/bin && go build -o .tmp/bin/go_js_wasm_exec ./cmd/go_js_wasm_exec && sh -c 'exec_path=\"$PWD/.tmp/bin/go_js_wasm_exec\"; cd compiler/gotest/testdata/browserapi && GOOS=js GOARCH=wasm go test -exec \"$exec_path\" -run TestBrowser -count=1'",
|
|
53
53
|
"test:js": "bun run typecheck && vitest run",
|
|
54
54
|
"test:browser": "bun run scripts/generate-browser-tests.ts && vitest run --config vitest.browser.config.ts",
|
|
55
55
|
"test:browser:ui": "bun run scripts/generate-browser-tests.ts && vitest --config vitest.browser.config.ts --ui",
|
|
@@ -108,13 +108,14 @@
|
|
|
108
108
|
"husky": "^9.1.7",
|
|
109
109
|
"lint-staged": "^17.0.0",
|
|
110
110
|
"prettier": "^3.8.1",
|
|
111
|
-
"starpc": "0.49.
|
|
111
|
+
"starpc": "0.49.18",
|
|
112
112
|
"typescript": "^6.0.0",
|
|
113
113
|
"typescript-eslint": "^8.58.0",
|
|
114
114
|
"vitest": "^4.1.2"
|
|
115
115
|
},
|
|
116
116
|
"dependencies": {
|
|
117
117
|
"@noble/ciphers": "2.2.0",
|
|
118
|
+
"@noble/hashes": "2.2.0",
|
|
118
119
|
"globals": "^17.4.0"
|
|
119
120
|
},
|
|
120
121
|
"resolutions": {
|