goscript 0.1.0 → 0.1.1
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/README.md +267 -255
- package/cmd/goscript/cmd-test.go +193 -0
- package/cmd/goscript/cmd-test_test.go +76 -0
- package/cmd/goscript/main.go +1 -0
- package/compiler/build-flags.go +38 -0
- package/compiler/compile-request.go +2 -0
- package/compiler/compliance_test.go +0 -8
- package/compiler/gotest/owner.go +24 -0
- package/compiler/gotest/package-result.go +67 -0
- package/compiler/gotest/request.go +145 -0
- package/compiler/gotest/result.go +28 -0
- package/compiler/gotest/runner.go +588 -0
- package/compiler/gotest/runner_test.go +627 -0
- package/compiler/gotest/test.go +9 -0
- package/compiler/index.test.ts +1 -1
- package/compiler/lowered-program.go +71 -19
- package/compiler/lowering.go +5065 -569
- package/compiler/override-facts.go +307 -0
- package/compiler/override-registry.go +50 -189
- package/compiler/override-registry_test.go +47 -0
- package/compiler/package-graph.go +50 -27
- package/compiler/package-graph_test.go +37 -2
- package/compiler/package-test-function.go +9 -0
- package/compiler/package-test-graph-package.go +40 -0
- package/compiler/package-test-graph-variant.go +105 -0
- package/compiler/package-test-graph.go +117 -0
- package/compiler/package-test-graph_test.go +144 -0
- package/compiler/runtime-contract.go +189 -29
- package/compiler/runtime-contract_test.go +44 -30
- package/compiler/semantic-model-types.go +9 -6
- package/compiler/semantic-model.go +538 -38
- package/compiler/semantic-model_test.go +55 -0
- package/compiler/service.go +1 -1
- package/compiler/skeleton_test.go +679 -49
- package/compiler/tsworkspace/owner.go +334 -0
- package/compiler/tsworkspace/owner_test.go +93 -0
- package/compiler/tsworkspace/result.go +17 -0
- package/compiler/typescript-emitter.go +459 -82
- package/compiler/wasm/compile.go +1 -1
- package/compiler/wasm/compile_test.go +61 -11
- package/compiler/wasm_api.go +172 -7
- package/dist/gs/builtin/builtin.d.ts +20 -2
- package/dist/gs/builtin/builtin.js +194 -6
- package/dist/gs/builtin/builtin.js.map +1 -1
- package/dist/gs/builtin/channel.d.ts +8 -0
- package/dist/gs/builtin/channel.js +12 -0
- package/dist/gs/builtin/channel.js.map +1 -1
- package/dist/gs/builtin/slice.d.ts +22 -2
- package/dist/gs/builtin/slice.js +216 -44
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/builtin/type.d.ts +5 -2
- package/dist/gs/builtin/type.js +83 -24
- package/dist/gs/builtin/type.js.map +1 -1
- package/dist/gs/builtin/varRef.d.ts +5 -0
- package/dist/gs/builtin/varRef.js +23 -0
- package/dist/gs/builtin/varRef.js.map +1 -1
- package/dist/gs/bytes/buffer.gs.js +48 -44
- package/dist/gs/bytes/buffer.gs.js.map +1 -1
- package/dist/gs/bytes/reader.gs.js +20 -18
- package/dist/gs/bytes/reader.gs.js.map +1 -1
- package/dist/gs/context/context.d.ts +5 -4
- package/dist/gs/context/context.js +10 -10
- package/dist/gs/context/context.js.map +1 -1
- package/dist/gs/crypto/internal/fips140deps/byteorder/index.d.ts +1 -0
- package/dist/gs/crypto/internal/fips140deps/byteorder/index.js +2 -0
- package/dist/gs/crypto/internal/fips140deps/byteorder/index.js.map +1 -0
- package/dist/gs/crypto/internal/fips140deps/godebug/index.d.ts +1 -0
- package/dist/gs/crypto/internal/fips140deps/godebug/index.js +2 -0
- package/dist/gs/crypto/internal/fips140deps/godebug/index.js.map +1 -0
- package/dist/gs/embed/index.d.ts +7 -0
- package/dist/gs/embed/index.js +16 -0
- package/dist/gs/embed/index.js.map +1 -0
- package/dist/gs/encoding/json/index.d.ts +1 -0
- package/dist/gs/encoding/json/index.js +18 -0
- package/dist/gs/encoding/json/index.js.map +1 -1
- package/dist/gs/errors/errors.d.ts +4 -0
- package/dist/gs/errors/errors.js +81 -0
- package/dist/gs/errors/errors.js.map +1 -1
- package/dist/gs/fmt/fmt.d.ts +4 -4
- package/dist/gs/fmt/fmt.js +42 -11
- package/dist/gs/fmt/fmt.js.map +1 -1
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.d.ts +35 -0
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js +211 -1
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js.map +1 -1
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.d.ts +189 -0
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.js +825 -0
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.js.map +1 -0
- package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.d.ts +163 -0
- package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.js +449 -0
- package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.js.map +1 -0
- package/dist/gs/github.com/klauspost/compress/internal/le/index.d.ts +9 -0
- package/dist/gs/github.com/klauspost/compress/internal/le/index.js +71 -0
- package/dist/gs/github.com/klauspost/compress/internal/le/index.js.map +1 -0
- package/dist/gs/go/internal/scannerhooks/index.d.ts +3 -0
- package/dist/gs/go/internal/scannerhooks/index.js +5 -0
- package/dist/gs/go/internal/scannerhooks/index.js.map +1 -0
- package/dist/gs/go/scanner/index.d.ts +13 -0
- package/dist/gs/go/scanner/index.js +35 -0
- package/dist/gs/go/scanner/index.js.map +1 -1
- package/dist/gs/go/token/index.d.ts +156 -0
- package/dist/gs/go/token/index.js +500 -4
- package/dist/gs/go/token/index.js.map +1 -1
- package/dist/gs/internal/abi/index.d.ts +4 -0
- package/dist/gs/internal/abi/index.js +10 -0
- package/dist/gs/internal/abi/index.js.map +1 -1
- package/dist/gs/internal/bytealg/index.d.ts +2 -0
- package/dist/gs/internal/bytealg/index.js +14 -0
- package/dist/gs/internal/bytealg/index.js.map +1 -1
- package/dist/gs/internal/byteorder/index.d.ts +8 -2
- package/dist/gs/internal/byteorder/index.js +56 -25
- package/dist/gs/internal/byteorder/index.js.map +1 -1
- package/dist/gs/internal/godebug/index.d.ts +12 -0
- package/dist/gs/internal/godebug/index.js +30 -0
- package/dist/gs/internal/godebug/index.js.map +1 -0
- package/dist/gs/io/fs/index.d.ts +1 -0
- package/dist/gs/io/fs/index.js +1 -0
- package/dist/gs/io/fs/index.js.map +1 -1
- package/dist/gs/io/fs/readlink.d.ts +8 -0
- package/dist/gs/io/fs/readlink.js +64 -0
- package/dist/gs/io/fs/readlink.js.map +1 -0
- package/dist/gs/io/fs/walk.d.ts +3 -3
- package/dist/gs/io/fs/walk.js +7 -7
- package/dist/gs/io/fs/walk.js.map +1 -1
- package/dist/gs/io/io.d.ts +40 -6
- package/dist/gs/io/io.js +151 -26
- package/dist/gs/io/io.js.map +1 -1
- package/dist/gs/maps/iter.d.ts +3 -3
- package/dist/gs/maps/iter.js +3 -3
- package/dist/gs/maps/iter.js.map +1 -1
- package/dist/gs/maps/maps.d.ts +2 -2
- package/dist/gs/maps/maps.js +1 -1
- package/dist/gs/maps/maps.js.map +1 -1
- package/dist/gs/math/bits/index.d.ts +13 -4
- package/dist/gs/math/bits/index.js +66 -34
- package/dist/gs/math/bits/index.js.map +1 -1
- package/dist/gs/math/const.gs.d.ts +5 -5
- package/dist/gs/math/const.gs.js +4 -4
- package/dist/gs/math/const.gs.js.map +1 -1
- package/dist/gs/mime/index.d.ts +1 -0
- package/dist/gs/mime/index.js +50 -0
- package/dist/gs/mime/index.js.map +1 -0
- package/dist/gs/net/http/httptest/index.d.ts +11 -0
- package/dist/gs/net/http/httptest/index.js +21 -0
- package/dist/gs/net/http/httptest/index.js.map +1 -0
- package/dist/gs/net/http/index.d.ts +27 -0
- package/dist/gs/net/http/index.js +61 -0
- package/dist/gs/net/http/index.js.map +1 -0
- package/dist/gs/os/dir_unix.gs.js +2 -2
- package/dist/gs/os/dir_unix.gs.js.map +1 -1
- package/dist/gs/os/types_js.gs.js.map +1 -1
- package/dist/gs/path/filepath/match.js +165 -3
- package/dist/gs/path/filepath/match.js.map +1 -1
- package/dist/gs/path/filepath/path.d.ts +3 -1
- package/dist/gs/path/filepath/path.js +133 -4
- package/dist/gs/path/filepath/path.js.map +1 -1
- package/dist/gs/path/path.d.ts +4 -1
- package/dist/gs/path/path.js +16 -4
- package/dist/gs/path/path.js.map +1 -1
- package/dist/gs/reflect/index.d.ts +1 -1
- package/dist/gs/reflect/index.js +1 -1
- package/dist/gs/reflect/index.js.map +1 -1
- package/dist/gs/reflect/map.js +3 -0
- package/dist/gs/reflect/map.js.map +1 -1
- package/dist/gs/reflect/type.d.ts +7 -4
- package/dist/gs/reflect/type.js +148 -7
- package/dist/gs/reflect/type.js.map +1 -1
- package/dist/gs/runtime/debug/index.d.ts +2 -0
- package/dist/gs/runtime/debug/index.js +8 -0
- package/dist/gs/runtime/debug/index.js.map +1 -0
- package/dist/gs/runtime/runtime.d.ts +35 -3
- package/dist/gs/runtime/runtime.js +72 -0
- package/dist/gs/runtime/runtime.js.map +1 -1
- package/dist/gs/slices/slices.d.ts +24 -5
- package/dist/gs/slices/slices.js +214 -5
- package/dist/gs/slices/slices.js.map +1 -1
- package/dist/gs/sort/slice.gs.d.ts +3 -3
- package/dist/gs/sort/slice.gs.js +6 -6
- package/dist/gs/sort/slice.gs.js.map +1 -1
- package/dist/gs/sort/sort.gs.d.ts +4 -4
- package/dist/gs/sort/sort.gs.js +11 -8
- package/dist/gs/sort/sort.gs.js.map +1 -1
- package/dist/gs/strings/builder.d.ts +1 -1
- package/dist/gs/strings/builder.js +3 -2
- package/dist/gs/strings/builder.js.map +1 -1
- package/dist/gs/sync/atomic/type.gs.d.ts +9 -8
- package/dist/gs/sync/atomic/type.gs.js +0 -2
- package/dist/gs/sync/atomic/type.gs.js.map +1 -1
- package/dist/gs/sync/sync.d.ts +2 -0
- package/dist/gs/sync/sync.js +27 -0
- package/dist/gs/sync/sync.js.map +1 -1
- package/dist/gs/syscall/constants.d.ts +36 -24
- package/dist/gs/syscall/constants.js +12 -0
- package/dist/gs/syscall/constants.js.map +1 -1
- package/dist/gs/syscall/errors.d.ts +2 -0
- package/dist/gs/syscall/errors.js +8 -0
- package/dist/gs/syscall/errors.js.map +1 -1
- package/dist/gs/syscall/fs.d.ts +43 -0
- package/dist/gs/syscall/fs.js +102 -0
- package/dist/gs/syscall/fs.js.map +1 -1
- package/dist/gs/syscall/js/index.d.ts +90 -0
- package/dist/gs/syscall/js/index.js +375 -0
- package/dist/gs/syscall/js/index.js.map +1 -0
- package/dist/gs/syscall/types.d.ts +22 -0
- package/dist/gs/syscall/types.js +45 -1
- package/dist/gs/syscall/types.js.map +1 -1
- package/dist/gs/testing/index.d.ts +1 -0
- package/dist/gs/testing/index.js +2 -0
- package/dist/gs/testing/index.js.map +1 -0
- package/dist/gs/testing/testing.d.ts +77 -0
- package/dist/gs/testing/testing.js +301 -0
- package/dist/gs/testing/testing.js.map +1 -0
- package/dist/gs/time/time.d.ts +41 -4
- package/dist/gs/time/time.js +205 -36
- package/dist/gs/time/time.js.map +1 -1
- package/dist/gs/unicode/unicode.d.ts +23 -1
- package/dist/gs/unicode/unicode.js +79 -10
- package/dist/gs/unicode/unicode.js.map +1 -1
- package/dist/gs/unicode/utf8/utf8.d.ts +4 -4
- package/dist/gs/unicode/utf8/utf8.js +24 -11
- package/dist/gs/unicode/utf8/utf8.js.map +1 -1
- package/dist/gs/unique/index.d.ts +11 -0
- package/dist/gs/unique/index.js +71 -0
- package/dist/gs/unique/index.js.map +1 -0
- package/go.sum +9 -0
- package/gs/builtin/builtin.ts +239 -8
- package/gs/builtin/channel.ts +22 -0
- package/gs/builtin/runtime-contract.test.ts +126 -0
- package/gs/builtin/slice.ts +259 -50
- package/gs/builtin/type.ts +109 -34
- package/gs/builtin/varRef.ts +38 -1
- package/gs/bytes/buffer.gs.ts +48 -44
- package/gs/bytes/meta.json +8 -3
- package/gs/bytes/reader.gs.ts +20 -19
- package/gs/context/context.test.ts +41 -0
- package/gs/context/context.ts +22 -26
- package/gs/crypto/internal/fips140deps/byteorder/index.ts +1 -0
- package/gs/crypto/internal/fips140deps/godebug/index.ts +1 -0
- package/gs/embed/index.ts +20 -0
- package/gs/embed/meta.json +5 -0
- package/gs/encoding/json/index.test.ts +15 -1
- package/gs/encoding/json/index.ts +24 -0
- package/gs/errors/errors.test.ts +82 -0
- package/gs/errors/errors.ts +104 -0
- package/gs/fmt/fmt.ts +56 -16
- package/gs/github.com/aperturerobotics/protobuf-go-lite/index.test.ts +73 -1
- package/gs/github.com/aperturerobotics/protobuf-go-lite/index.ts +297 -1
- package/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.test.ts +159 -0
- package/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.ts +1005 -0
- package/gs/github.com/aperturerobotics/starpc/srpc/index.ts +719 -0
- package/gs/github.com/aperturerobotics/starpc/srpc/meta.json +40 -0
- package/gs/github.com/klauspost/compress/internal/le/index.test.ts +36 -0
- package/gs/github.com/klauspost/compress/internal/le/index.ts +114 -0
- package/gs/go/internal/scannerhooks/index.test.ts +14 -0
- package/gs/go/internal/scannerhooks/index.ts +9 -0
- package/gs/go/scanner/index.test.ts +22 -0
- package/gs/go/scanner/index.ts +47 -0
- package/gs/go/token/index.test.ts +47 -1
- package/gs/go/token/index.ts +570 -4
- package/gs/internal/abi/index.test.ts +18 -0
- package/gs/internal/abi/index.ts +14 -0
- package/gs/internal/bytealg/index.test.ts +18 -0
- package/gs/internal/bytealg/index.ts +16 -0
- package/gs/internal/byteorder/index.test.ts +39 -0
- package/gs/internal/byteorder/index.ts +100 -27
- package/gs/internal/godebug/index.test.ts +16 -0
- package/gs/internal/godebug/index.ts +35 -0
- package/gs/io/fs/index.ts +1 -0
- package/gs/io/fs/meta.json +5 -0
- package/gs/io/fs/readlink.test.ts +43 -0
- package/gs/io/fs/readlink.ts +77 -0
- package/gs/io/fs/walk.test.ts +61 -0
- package/gs/io/fs/walk.ts +9 -9
- package/gs/io/io.ts +174 -31
- package/gs/io/meta.json +10 -2
- package/gs/maps/iter.ts +12 -6
- package/gs/maps/maps.ts +8 -6
- package/gs/math/bits/index.ts +103 -47
- package/gs/math/const.gs.test.ts +11 -5
- package/gs/math/const.gs.ts +5 -6
- package/gs/mime/index.ts +54 -0
- package/gs/net/http/httptest/index.ts +25 -0
- package/gs/net/http/index.test.ts +20 -0
- package/gs/net/http/index.ts +81 -0
- package/gs/os/dir_unix.gs.ts +2 -3
- package/gs/os/types_js.gs.ts +2 -2
- package/gs/path/filepath/match.test.ts +31 -12
- package/gs/path/filepath/match.ts +178 -3
- package/gs/path/filepath/path.test.ts +25 -0
- package/gs/path/filepath/path.ts +159 -5
- package/gs/path/path.ts +20 -5
- package/gs/reflect/index.ts +1 -0
- package/gs/reflect/map.test.ts +19 -0
- package/gs/reflect/map.ts +4 -0
- package/gs/reflect/type.ts +197 -17
- package/gs/runtime/debug/index.test.ts +24 -0
- package/gs/runtime/debug/index.ts +8 -0
- package/gs/runtime/runtime.test.ts +19 -0
- package/gs/runtime/runtime.ts +98 -3
- package/gs/slices/slices.test.ts +94 -0
- package/gs/slices/slices.ts +245 -5
- package/gs/sort/meta.json +7 -0
- package/gs/sort/slice.gs.ts +16 -7
- package/gs/sort/sort.gs.ts +16 -13
- package/gs/strings/builder.ts +4 -3
- package/gs/sync/atomic/type.gs.ts +13 -14
- package/gs/sync/meta.json +3 -1
- package/gs/sync/sync.test.ts +13 -1
- package/gs/sync/sync.ts +27 -0
- package/gs/syscall/constants.ts +39 -24
- package/gs/syscall/errors.ts +10 -0
- package/gs/syscall/fs.ts +195 -0
- package/gs/syscall/js/index.ts +458 -0
- package/gs/syscall/js/meta.json +4 -0
- package/gs/syscall/net.test.ts +85 -0
- package/gs/syscall/types.ts +56 -0
- package/gs/testing/index.ts +1 -0
- package/gs/testing/meta.json +5 -0
- package/gs/testing/testing.test.ts +90 -0
- package/gs/testing/testing.ts +382 -0
- package/gs/time/time.test.ts +106 -0
- package/gs/time/time.ts +278 -57
- package/gs/unicode/unicode.test.ts +25 -0
- package/gs/unicode/unicode.ts +119 -9
- package/gs/unicode/utf8/utf8.test.ts +13 -0
- package/gs/unicode/utf8/utf8.ts +28 -16
- package/gs/unique/index.ts +91 -0
- package/package.json +2 -1
package/gs/unicode/unicode.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Slice } from '@goscript/builtin/index.js'
|
|
2
|
+
|
|
1
3
|
// Package unicode provides data and functions to test some properties of Unicode code points.
|
|
2
4
|
|
|
3
5
|
// Constants
|
|
@@ -16,13 +18,27 @@ export const MaxCase = 3
|
|
|
16
18
|
export const UpperLower = MaxRune + 1
|
|
17
19
|
|
|
18
20
|
// Range16 represents a range of 16-bit Unicode code points
|
|
21
|
+
type Range16Init = {
|
|
22
|
+
Lo?: number
|
|
23
|
+
Hi?: number
|
|
24
|
+
Stride?: number
|
|
25
|
+
}
|
|
26
|
+
|
|
19
27
|
export class Range16 {
|
|
20
28
|
public Lo: number
|
|
21
29
|
public Hi: number
|
|
22
30
|
public Stride: number
|
|
23
31
|
|
|
24
|
-
constructor(
|
|
25
|
-
|
|
32
|
+
constructor(init?: Range16Init)
|
|
33
|
+
constructor(lo: number, hi: number, stride: number)
|
|
34
|
+
constructor(loOrInit: number | Range16Init = 0, hi = 0, stride = 0) {
|
|
35
|
+
if (typeof loOrInit === 'object') {
|
|
36
|
+
this.Lo = loOrInit.Lo ?? 0
|
|
37
|
+
this.Hi = loOrInit.Hi ?? 0
|
|
38
|
+
this.Stride = loOrInit.Stride ?? 0
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
this.Lo = loOrInit
|
|
26
42
|
this.Hi = hi
|
|
27
43
|
this.Stride = stride
|
|
28
44
|
}
|
|
@@ -33,13 +49,27 @@ export class Range16 {
|
|
|
33
49
|
}
|
|
34
50
|
|
|
35
51
|
// Range32 represents a range of 32-bit Unicode code points
|
|
52
|
+
type Range32Init = {
|
|
53
|
+
Lo?: number
|
|
54
|
+
Hi?: number
|
|
55
|
+
Stride?: number
|
|
56
|
+
}
|
|
57
|
+
|
|
36
58
|
export class Range32 {
|
|
37
59
|
public Lo: number
|
|
38
60
|
public Hi: number
|
|
39
61
|
public Stride: number
|
|
40
62
|
|
|
41
|
-
constructor(
|
|
42
|
-
|
|
63
|
+
constructor(init?: Range32Init)
|
|
64
|
+
constructor(lo: number, hi: number, stride: number)
|
|
65
|
+
constructor(loOrInit: number | Range32Init = 0, hi = 0, stride = 0) {
|
|
66
|
+
if (typeof loOrInit === 'object') {
|
|
67
|
+
this.Lo = loOrInit.Lo ?? 0
|
|
68
|
+
this.Hi = loOrInit.Hi ?? 0
|
|
69
|
+
this.Stride = loOrInit.Stride ?? 0
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
this.Lo = loOrInit
|
|
43
73
|
this.Hi = hi
|
|
44
74
|
this.Stride = stride
|
|
45
75
|
}
|
|
@@ -50,18 +80,36 @@ export class Range32 {
|
|
|
50
80
|
}
|
|
51
81
|
|
|
52
82
|
// RangeTable defines a set of Unicode code points by listing the ranges of code points within the set
|
|
83
|
+
type RangeTableInit = {
|
|
84
|
+
R16?: Slice<Range16>
|
|
85
|
+
R32?: Slice<Range32>
|
|
86
|
+
LatinOffset?: number
|
|
87
|
+
}
|
|
88
|
+
|
|
53
89
|
export class RangeTable {
|
|
54
90
|
public R16: Range16[]
|
|
55
91
|
public R32: Range32[]
|
|
56
92
|
public LatinOffset: number
|
|
57
93
|
|
|
94
|
+
constructor(init?: RangeTableInit)
|
|
58
95
|
constructor(
|
|
59
|
-
r16
|
|
60
|
-
r32
|
|
61
|
-
latinOffset
|
|
96
|
+
r16?: Slice<Range16>,
|
|
97
|
+
r32?: Slice<Range32>,
|
|
98
|
+
latinOffset?: number,
|
|
99
|
+
)
|
|
100
|
+
constructor(
|
|
101
|
+
r16OrInit: Slice<Range16> | RangeTableInit = [],
|
|
102
|
+
r32: Slice<Range32> = [],
|
|
103
|
+
latinOffset = 0,
|
|
62
104
|
) {
|
|
63
|
-
|
|
64
|
-
|
|
105
|
+
if (isRangeTableInit(r16OrInit)) {
|
|
106
|
+
this.R16 = sliceToArray(r16OrInit.R16)
|
|
107
|
+
this.R32 = sliceToArray(r16OrInit.R32)
|
|
108
|
+
this.LatinOffset = r16OrInit.LatinOffset ?? 0
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
this.R16 = sliceToArray(r16OrInit)
|
|
112
|
+
this.R32 = sliceToArray(r32)
|
|
65
113
|
this.LatinOffset = latinOffset
|
|
66
114
|
}
|
|
67
115
|
|
|
@@ -74,6 +122,23 @@ export class RangeTable {
|
|
|
74
122
|
}
|
|
75
123
|
}
|
|
76
124
|
|
|
125
|
+
function isRangeTableInit(
|
|
126
|
+
value: Slice<Range16> | RangeTableInit,
|
|
127
|
+
): value is RangeTableInit {
|
|
128
|
+
return (
|
|
129
|
+
value !== null &&
|
|
130
|
+
typeof value === 'object' &&
|
|
131
|
+
('R16' in value || 'R32' in value || 'LatinOffset' in value)
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function sliceToArray<T>(value: Slice<T> | undefined): T[] {
|
|
136
|
+
if (value == null) {
|
|
137
|
+
return []
|
|
138
|
+
}
|
|
139
|
+
return Array.from(value as ArrayLike<T>)
|
|
140
|
+
}
|
|
141
|
+
|
|
77
142
|
// CaseRange represents a range of Unicode code points for case mapping
|
|
78
143
|
export class CaseRange {
|
|
79
144
|
public Lo: number
|
|
@@ -345,6 +410,48 @@ export const Categories = new Map<string, RangeTable>([
|
|
|
345
410
|
['Z', Space],
|
|
346
411
|
])
|
|
347
412
|
|
|
413
|
+
export const CategoryAliases = new Map<string, string>([
|
|
414
|
+
['C', 'C'],
|
|
415
|
+
['Cc', 'Cc'],
|
|
416
|
+
['cntrl', 'Cc'],
|
|
417
|
+
['Cf', 'Cf'],
|
|
418
|
+
['Co', 'Co'],
|
|
419
|
+
['Cs', 'Cs'],
|
|
420
|
+
['L', 'L'],
|
|
421
|
+
['LC', 'LC'],
|
|
422
|
+
['Ll', 'Ll'],
|
|
423
|
+
['Lm', 'Lm'],
|
|
424
|
+
['Lo', 'Lo'],
|
|
425
|
+
['Lt', 'Lt'],
|
|
426
|
+
['Lu', 'Lu'],
|
|
427
|
+
['M', 'M'],
|
|
428
|
+
['Mc', 'Mc'],
|
|
429
|
+
['Me', 'Me'],
|
|
430
|
+
['Mn', 'Mn'],
|
|
431
|
+
['N', 'N'],
|
|
432
|
+
['Nd', 'Nd'],
|
|
433
|
+
['digit', 'Nd'],
|
|
434
|
+
['Nl', 'Nl'],
|
|
435
|
+
['No', 'No'],
|
|
436
|
+
['P', 'P'],
|
|
437
|
+
['Pc', 'Pc'],
|
|
438
|
+
['Pd', 'Pd'],
|
|
439
|
+
['Pe', 'Pe'],
|
|
440
|
+
['Pf', 'Pf'],
|
|
441
|
+
['Pi', 'Pi'],
|
|
442
|
+
['Po', 'Po'],
|
|
443
|
+
['Ps', 'Ps'],
|
|
444
|
+
['S', 'S'],
|
|
445
|
+
['Sc', 'Sc'],
|
|
446
|
+
['Sk', 'Sk'],
|
|
447
|
+
['Sm', 'Sm'],
|
|
448
|
+
['So', 'So'],
|
|
449
|
+
['Z', 'Z'],
|
|
450
|
+
['Zl', 'Zl'],
|
|
451
|
+
['Zp', 'Zp'],
|
|
452
|
+
['Zs', 'Zs'],
|
|
453
|
+
])
|
|
454
|
+
|
|
348
455
|
// Scripts and Properties maps (simplified)
|
|
349
456
|
export const Scripts = new Map<string, RangeTable>()
|
|
350
457
|
export const Properties = new Map<string, RangeTable>()
|
|
@@ -370,6 +477,7 @@ export const Cc = new RangeTable(
|
|
|
370
477
|
[],
|
|
371
478
|
)
|
|
372
479
|
export const Cf = new RangeTable([], [])
|
|
480
|
+
export const Cn = new RangeTable([], [])
|
|
373
481
|
export const Co = new RangeTable([], [])
|
|
374
482
|
export const Cs = new RangeTable([new Range16(0xd800, 0xdfff, 1)], [])
|
|
375
483
|
export const Lm = new RangeTable([], [])
|
|
@@ -416,3 +524,5 @@ export const So = new RangeTable([], [])
|
|
|
416
524
|
export const Zl = new RangeTable([], [])
|
|
417
525
|
export const Zp = new RangeTable([], [])
|
|
418
526
|
export const Zs = new RangeTable([new Range16(0x0020, 0x0020, 1)], []) // space
|
|
527
|
+
|
|
528
|
+
Categories.set('Cn', Cn)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import * as $ from '@goscript/builtin/index.js'
|
|
4
|
+
|
|
5
|
+
import { FullRune } from './utf8.js'
|
|
6
|
+
|
|
7
|
+
describe('unicode/utf8 overrides', () => {
|
|
8
|
+
it('accepts GoScript byte slices in FullRune', () => {
|
|
9
|
+
expect(FullRune($.arrayToSlice<number>([0x61]))).toBe(true)
|
|
10
|
+
expect(FullRune($.goSlice([0xe2, 0x82, 0xac], 0, 2))).toBe(false)
|
|
11
|
+
expect(FullRune($.goSlice([0xe2, 0x82, 0xac], 0, 3))).toBe(true)
|
|
12
|
+
})
|
|
13
|
+
})
|
package/gs/unicode/utf8/utf8.ts
CHANGED
|
@@ -26,19 +26,20 @@ export function AppendRune(p: $.Bytes, r: number): Uint8Array {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
// DecodeLastRune unpacks the last UTF-8 encoding in p and returns the rune and its width in bytes.
|
|
29
|
-
export function DecodeLastRune(p:
|
|
30
|
-
|
|
29
|
+
export function DecodeLastRune(p: $.Bytes): [number, number] {
|
|
30
|
+
const bytes = $.bytesToUint8Array(p)
|
|
31
|
+
if (bytes.length === 0) {
|
|
31
32
|
return [RuneError, 0]
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
// Simple implementation - find the start of the last rune
|
|
35
|
-
let start =
|
|
36
|
-
while (start > 0 && !RuneStart(
|
|
36
|
+
let start = bytes.length - 1
|
|
37
|
+
while (start > 0 && !RuneStart(bytes[start])) {
|
|
37
38
|
start--
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
const [r, size] = DecodeRune(
|
|
41
|
-
if (start + size !==
|
|
41
|
+
const [r, size] = DecodeRune(bytes.slice(start))
|
|
42
|
+
if (start + size !== bytes.length) {
|
|
42
43
|
return [RuneError, 1]
|
|
43
44
|
}
|
|
44
45
|
return [r, size]
|
|
@@ -141,17 +142,28 @@ export function EncodeRune(p: Uint8Array | $.Slice<number>, r: number): number {
|
|
|
141
142
|
}
|
|
142
143
|
|
|
143
144
|
// FullRune reports whether the bytes in p begin with a full UTF-8 encoding of a rune.
|
|
144
|
-
export function FullRune(p:
|
|
145
|
-
if (p
|
|
145
|
+
export function FullRune(p: $.Bytes): boolean {
|
|
146
|
+
if ($.len(p) === 0) {
|
|
146
147
|
return false
|
|
147
148
|
}
|
|
148
149
|
|
|
149
|
-
|
|
150
|
+
const first = $.indexStringOrBytes(p, 0)
|
|
151
|
+
if (first < RuneSelf) {
|
|
150
152
|
return true
|
|
151
153
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
154
|
+
if (first < 0xc0) {
|
|
155
|
+
return true
|
|
156
|
+
}
|
|
157
|
+
if (first < 0xe0) {
|
|
158
|
+
return $.len(p) >= 2
|
|
159
|
+
}
|
|
160
|
+
if (first < 0xf0) {
|
|
161
|
+
return $.len(p) >= 3
|
|
162
|
+
}
|
|
163
|
+
if (first < 0xf8) {
|
|
164
|
+
return $.len(p) >= 4
|
|
165
|
+
}
|
|
166
|
+
return true
|
|
155
167
|
}
|
|
156
168
|
|
|
157
169
|
// FullRuneInString is like FullRune but its input is a string.
|
|
@@ -170,9 +182,9 @@ export function FullRuneInString(s: string): boolean {
|
|
|
170
182
|
}
|
|
171
183
|
|
|
172
184
|
// RuneCount returns the number of runes in p.
|
|
173
|
-
export function RuneCount(p:
|
|
185
|
+
export function RuneCount(p: $.Bytes): number {
|
|
174
186
|
const decoder = new TextDecoder('utf-8', { fatal: false })
|
|
175
|
-
const str = decoder.decode(p)
|
|
187
|
+
const str = decoder.decode($.bytesToUint8Array(p))
|
|
176
188
|
return [...str].length
|
|
177
189
|
}
|
|
178
190
|
|
|
@@ -202,10 +214,10 @@ export function RuneStart(b: number): boolean {
|
|
|
202
214
|
}
|
|
203
215
|
|
|
204
216
|
// Valid reports whether p consists entirely of valid UTF-8-encoded runes.
|
|
205
|
-
export function Valid(p:
|
|
217
|
+
export function Valid(p: $.Bytes): boolean {
|
|
206
218
|
try {
|
|
207
219
|
const decoder = new TextDecoder('utf-8', { fatal: true })
|
|
208
|
-
decoder.decode(p)
|
|
220
|
+
decoder.decode($.bytesToUint8Array(p))
|
|
209
221
|
return true
|
|
210
222
|
} catch {
|
|
211
223
|
return false
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import * as $ from '@goscript/builtin/index.js'
|
|
2
|
+
|
|
3
|
+
const handles = new Map<string, Handle<any>>()
|
|
4
|
+
|
|
5
|
+
export class Handle<T = any> {
|
|
6
|
+
private readonly value: T | undefined
|
|
7
|
+
|
|
8
|
+
constructor(init?: Partial<{ value?: T }> | T) {
|
|
9
|
+
if (init && typeof init === 'object' && 'value' in init) {
|
|
10
|
+
this.value = init.value
|
|
11
|
+
} else {
|
|
12
|
+
this.value = init as T | undefined
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public Value(): T {
|
|
17
|
+
return this.value as T
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public clone(): Handle<T> {
|
|
21
|
+
return this
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static __typeInfo = $.registerStructType(
|
|
25
|
+
'unique.Handle',
|
|
26
|
+
new Handle(),
|
|
27
|
+
[{ name: 'Value', args: [], returns: [] }],
|
|
28
|
+
Handle,
|
|
29
|
+
{ value: { kind: $.TypeKind.Interface, methods: [] } },
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function Make<T = any>(
|
|
34
|
+
typeArgsOrValue: $.GenericTypeArgs | T | undefined,
|
|
35
|
+
maybeValue?: T,
|
|
36
|
+
): Handle<T> {
|
|
37
|
+
const value = arguments.length === 1 ? (typeArgsOrValue as T) : maybeValue
|
|
38
|
+
const key = stableKey(value)
|
|
39
|
+
const existing = handles.get(key)
|
|
40
|
+
if (existing) {
|
|
41
|
+
return existing as Handle<T>
|
|
42
|
+
}
|
|
43
|
+
const handle = new Handle<T>({ value })
|
|
44
|
+
handles.set(key, handle)
|
|
45
|
+
return handle
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function stableKey(value: unknown): string {
|
|
49
|
+
const seen = new WeakMap<object, number>()
|
|
50
|
+
let nextID = 0
|
|
51
|
+
return JSON.stringify(normalize(value, seen, () => nextID++))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function normalize(
|
|
55
|
+
value: unknown,
|
|
56
|
+
seen: WeakMap<object, number>,
|
|
57
|
+
nextID: () => number,
|
|
58
|
+
): unknown {
|
|
59
|
+
if (value == null || typeof value !== 'object') {
|
|
60
|
+
return value
|
|
61
|
+
}
|
|
62
|
+
const cached = seen.get(value)
|
|
63
|
+
if (cached !== undefined) {
|
|
64
|
+
return { $ref: cached }
|
|
65
|
+
}
|
|
66
|
+
seen.set(value, nextID())
|
|
67
|
+
if ($.isVarRef(value)) {
|
|
68
|
+
return { $varRef: normalize(value.value, seen, nextID) }
|
|
69
|
+
}
|
|
70
|
+
if (Array.isArray(value)) {
|
|
71
|
+
return value.map((entry) => normalize(entry, seen, nextID))
|
|
72
|
+
}
|
|
73
|
+
if (value instanceof Map) {
|
|
74
|
+
return {
|
|
75
|
+
$map: [...value.entries()]
|
|
76
|
+
.map(([key, entry]) => [normalize(key, seen, nextID), normalize(entry, seen, nextID)])
|
|
77
|
+
.sort(([a], [b]) => JSON.stringify(a).localeCompare(JSON.stringify(b))),
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if ('_fields' in value && value._fields && typeof value._fields === 'object') {
|
|
81
|
+
return {
|
|
82
|
+
$type: value.constructor.name,
|
|
83
|
+
$fields: normalize(value._fields, seen, nextID),
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const entries = Object.entries(value)
|
|
87
|
+
.filter(([, entry]) => typeof entry !== 'function')
|
|
88
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
89
|
+
.map(([key, entry]) => [key, normalize(entry, seen, nextID)])
|
|
90
|
+
return { $object: entries }
|
|
91
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "goscript",
|
|
3
3
|
"description": "Go to TypeScript transpiler",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.1",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Aperture Robotics LLC.",
|
|
7
7
|
"email": "support@aperture.us",
|
|
@@ -106,6 +106,7 @@
|
|
|
106
106
|
"husky": "^9.1.7",
|
|
107
107
|
"lint-staged": "^16.4.0",
|
|
108
108
|
"prettier": "^3.8.1",
|
|
109
|
+
"starpc": "0.49.9",
|
|
109
110
|
"typescript": "^6.0.0",
|
|
110
111
|
"typescript-eslint": "^8.58.0",
|
|
111
112
|
"vitest": "^4.1.2"
|