goscript 0.0.34 → 0.0.35
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/analysis.go +28 -20
- package/compiler/analysis_test.go +14 -0
- package/compiler/assignment.go +19 -7
- package/compiler/compiler.go +15 -99
- package/compiler/composite-lit.go +60 -17
- package/compiler/decl.go +1 -1
- package/compiler/expr-call.go +233 -35
- package/compiler/expr-selector.go +28 -2
- package/compiler/expr.go +13 -37
- package/compiler/lit.go +111 -2
- package/compiler/primitive.go +6 -6
- package/compiler/protobuf.go +0 -5
- package/compiler/sanitize.go +101 -0
- package/compiler/spec-value.go +25 -18
- package/compiler/stmt-assign.go +22 -1
- package/compiler/stmt.go +26 -9
- package/compiler/type.go +3 -3
- package/dist/gs/builtin/builtin.d.ts +3 -2
- package/dist/gs/builtin/builtin.js +2 -1
- package/dist/gs/builtin/builtin.js.map +1 -1
- package/dist/gs/builtin/map.js.map +1 -1
- package/dist/gs/builtin/slice.d.ts +7 -1
- package/dist/gs/builtin/slice.js +112 -22
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/github.com/pkg/errors/errors.d.ts +13 -0
- package/dist/gs/github.com/pkg/errors/errors.js +232 -0
- package/dist/gs/github.com/pkg/errors/errors.js.map +1 -0
- package/dist/gs/github.com/pkg/errors/go113.d.ts +4 -0
- package/dist/gs/github.com/pkg/errors/go113.js +34 -0
- package/dist/gs/github.com/pkg/errors/go113.js.map +1 -0
- package/dist/gs/github.com/pkg/errors/index.d.ts +3 -0
- package/dist/gs/github.com/pkg/errors/index.js +4 -0
- package/dist/gs/github.com/pkg/errors/index.js.map +1 -0
- package/dist/gs/github.com/pkg/errors/stack.d.ts +32 -0
- package/dist/gs/github.com/pkg/errors/stack.js +111 -0
- package/dist/gs/github.com/pkg/errors/stack.js.map +1 -0
- package/dist/gs/maps/index.d.ts +2 -2
- package/dist/gs/maps/index.js +2 -2
- package/dist/gs/maps/index.js.map +1 -1
- package/dist/gs/maps/iter.d.ts +7 -0
- package/dist/gs/maps/iter.js +57 -0
- package/dist/gs/maps/iter.js.map +1 -0
- package/dist/gs/maps/maps.d.ts +7 -0
- package/dist/gs/maps/maps.js +67 -0
- package/dist/gs/maps/maps.js.map +1 -0
- package/dist/gs/math/abs.gs.d.ts +1 -0
- package/dist/gs/math/abs.gs.js +10 -0
- package/dist/gs/math/abs.gs.js.map +1 -0
- package/dist/gs/math/acosh.gs.d.ts +2 -0
- package/dist/gs/math/acosh.gs.js +14 -0
- package/dist/gs/math/acosh.gs.js.map +1 -0
- package/dist/gs/math/asin.gs.d.ts +4 -0
- package/dist/gs/math/asin.gs.js +24 -0
- package/dist/gs/math/asin.gs.js.map +1 -0
- package/dist/gs/math/asinh.gs.d.ts +2 -0
- package/dist/gs/math/asinh.gs.js +14 -0
- package/dist/gs/math/asinh.gs.js.map +1 -0
- package/dist/gs/math/atan.gs.d.ts +4 -0
- package/dist/gs/math/atan.gs.js +22 -0
- package/dist/gs/math/atan.gs.js.map +1 -0
- package/dist/gs/math/atan2.gs.d.ts +2 -0
- package/dist/gs/math/atan2.gs.js +30 -0
- package/dist/gs/math/atan2.gs.js.map +1 -0
- package/dist/gs/math/atanh.gs.d.ts +2 -0
- package/dist/gs/math/atanh.gs.js +16 -0
- package/dist/gs/math/atanh.gs.js.map +1 -0
- package/dist/gs/math/bits.gs.d.ts +5 -0
- package/dist/gs/math/bits.gs.js +46 -0
- package/dist/gs/math/bits.gs.js.map +1 -0
- package/dist/gs/math/cbrt.gs.d.ts +2 -0
- package/dist/gs/math/cbrt.gs.js +14 -0
- package/dist/gs/math/cbrt.gs.js.map +1 -0
- package/dist/gs/math/const.gs.d.ts +30 -0
- package/dist/gs/math/const.gs.js +61 -0
- package/dist/gs/math/const.gs.js.map +1 -0
- package/dist/gs/math/copysign.gs.d.ts +1 -0
- package/dist/gs/math/copysign.gs.js +20 -0
- package/dist/gs/math/copysign.gs.js.map +1 -0
- package/dist/gs/math/dim.gs.d.ts +5 -0
- package/dist/gs/math/dim.gs.js +69 -0
- package/dist/gs/math/dim.gs.js.map +1 -0
- package/dist/gs/math/erf.gs.d.ts +4 -0
- package/dist/gs/math/erf.gs.js +336 -0
- package/dist/gs/math/erf.gs.js.map +1 -0
- package/dist/gs/math/erfinv.gs.d.ts +2 -0
- package/dist/gs/math/erfinv.gs.js +118 -0
- package/dist/gs/math/erfinv.gs.js.map +1 -0
- package/dist/gs/math/exp.gs.d.ts +5 -0
- package/dist/gs/math/exp.gs.js +30 -0
- package/dist/gs/math/exp.gs.js.map +1 -0
- package/dist/gs/math/expm1.gs.d.ts +2 -0
- package/dist/gs/math/expm1.gs.js +17 -0
- package/dist/gs/math/expm1.gs.js.map +1 -0
- package/dist/gs/math/floor.gs.d.ts +8 -0
- package/dist/gs/math/floor.gs.js +75 -0
- package/dist/gs/math/floor.gs.js.map +1 -0
- package/dist/gs/math/fma.gs.d.ts +1 -0
- package/dist/gs/math/fma.gs.js +8 -0
- package/dist/gs/math/fma.gs.js.map +1 -0
- package/dist/gs/math/frexp.gs.d.ts +2 -0
- package/dist/gs/math/frexp.gs.js +28 -0
- package/dist/gs/math/frexp.gs.js.map +1 -0
- package/dist/gs/math/gamma.gs.d.ts +3 -0
- package/dist/gs/math/gamma.gs.js +149 -0
- package/dist/gs/math/gamma.gs.js.map +1 -0
- package/dist/gs/math/hypot.gs.d.ts +2 -0
- package/dist/gs/math/hypot.gs.js +16 -0
- package/dist/gs/math/hypot.gs.js.map +1 -0
- package/dist/gs/math/index.d.ts +44 -0
- package/dist/gs/math/index.js +45 -0
- package/dist/gs/math/index.js.map +1 -0
- package/dist/gs/math/j0.gs.d.ts +4 -0
- package/dist/gs/math/j0.gs.js +228 -0
- package/dist/gs/math/j0.gs.js.map +1 -0
- package/dist/gs/math/j1.gs.d.ts +4 -0
- package/dist/gs/math/j1.gs.js +211 -0
- package/dist/gs/math/j1.gs.js.map +1 -0
- package/dist/gs/math/jn.gs.d.ts +2 -0
- package/dist/gs/math/jn.gs.js +412 -0
- package/dist/gs/math/jn.gs.js.map +1 -0
- package/dist/gs/math/ldexp.gs.d.ts +2 -0
- package/dist/gs/math/ldexp.gs.js +20 -0
- package/dist/gs/math/ldexp.gs.js.map +1 -0
- package/dist/gs/math/lgamma.gs.d.ts +2 -0
- package/dist/gs/math/lgamma.gs.js +243 -0
- package/dist/gs/math/lgamma.gs.js.map +1 -0
- package/dist/gs/math/log.gs.d.ts +2 -0
- package/dist/gs/math/log.gs.js +16 -0
- package/dist/gs/math/log.gs.js.map +1 -0
- package/dist/gs/math/log10.gs.d.ts +4 -0
- package/dist/gs/math/log10.gs.js +17 -0
- package/dist/gs/math/log10.gs.js.map +1 -0
- package/dist/gs/math/log1p.gs.d.ts +2 -0
- package/dist/gs/math/log1p.gs.js +17 -0
- package/dist/gs/math/log1p.gs.js.map +1 -0
- package/dist/gs/math/logb.gs.d.ts +3 -0
- package/dist/gs/math/logb.gs.js +43 -0
- package/dist/gs/math/logb.gs.js.map +1 -0
- package/dist/gs/math/mod.gs.d.ts +2 -0
- package/dist/gs/math/mod.gs.js +26 -0
- package/dist/gs/math/mod.gs.js.map +1 -0
- package/dist/gs/math/modf.gs.d.ts +2 -0
- package/dist/gs/math/modf.gs.js +24 -0
- package/dist/gs/math/modf.gs.js.map +1 -0
- package/dist/gs/math/nextafter.gs.d.ts +2 -0
- package/dist/gs/math/nextafter.gs.js +66 -0
- package/dist/gs/math/nextafter.gs.js.map +1 -0
- package/dist/gs/math/pow.gs.d.ts +3 -0
- package/dist/gs/math/pow.gs.js +40 -0
- package/dist/gs/math/pow.gs.js.map +1 -0
- package/dist/gs/math/pow10.gs.d.ts +1 -0
- package/dist/gs/math/pow10.gs.js +14 -0
- package/dist/gs/math/pow10.gs.js.map +1 -0
- package/dist/gs/math/remainder.gs.d.ts +2 -0
- package/dist/gs/math/remainder.gs.js +25 -0
- package/dist/gs/math/remainder.gs.js.map +1 -0
- package/dist/gs/math/signbit.gs.d.ts +1 -0
- package/dist/gs/math/signbit.gs.js +5 -0
- package/dist/gs/math/signbit.gs.js.map +1 -0
- package/dist/gs/math/sin.gs.d.ts +4 -0
- package/dist/gs/math/sin.gs.js +29 -0
- package/dist/gs/math/sin.gs.js.map +1 -0
- package/dist/gs/math/sincos.gs.d.ts +1 -0
- package/dist/gs/math/sincos.gs.js +11 -0
- package/dist/gs/math/sincos.gs.js.map +1 -0
- package/dist/gs/math/sinh.gs.d.ts +4 -0
- package/dist/gs/math/sinh.gs.js +27 -0
- package/dist/gs/math/sinh.gs.js.map +1 -0
- package/dist/gs/math/sqrt.gs.d.ts +2 -0
- package/dist/gs/math/sqrt.gs.js +15 -0
- package/dist/gs/math/sqrt.gs.js.map +1 -0
- package/dist/gs/math/tan.gs.d.ts +2 -0
- package/dist/gs/math/tan.gs.js +17 -0
- package/dist/gs/math/tan.gs.js.map +1 -0
- package/dist/gs/math/tanh.gs.d.ts +2 -0
- package/dist/gs/math/tanh.gs.js +17 -0
- package/dist/gs/math/tanh.gs.js.map +1 -0
- package/dist/gs/math/trig_reduce.gs.d.ts +1 -0
- package/dist/gs/math/trig_reduce.gs.js +62 -0
- package/dist/gs/math/trig_reduce.gs.js.map +1 -0
- package/dist/gs/math/unsafe.gs.d.ts +4 -0
- package/dist/gs/math/unsafe.gs.js +47 -0
- package/dist/gs/math/unsafe.gs.js.map +1 -0
- package/dist/gs/strconv/atob.gs.d.ts +4 -0
- package/dist/gs/strconv/atob.gs.js +42 -0
- package/dist/gs/strconv/atob.gs.js.map +1 -0
- package/dist/gs/strconv/atof.gs.d.ts +2 -0
- package/dist/gs/strconv/atof.gs.js +51 -0
- package/dist/gs/strconv/atof.gs.js.map +1 -0
- package/dist/gs/strconv/atoi.gs.d.ts +33 -0
- package/dist/gs/strconv/atoi.gs.js +200 -0
- package/dist/gs/strconv/atoi.gs.js.map +1 -0
- package/dist/gs/strconv/doc.gs.d.ts +1 -0
- package/dist/gs/strconv/doc.gs.js +2 -0
- package/dist/gs/strconv/doc.gs.js.map +1 -0
- package/dist/gs/strconv/ftoa.gs.d.ts +3 -0
- package/dist/gs/strconv/ftoa.gs.js +58 -0
- package/dist/gs/strconv/ftoa.gs.js.map +1 -0
- package/dist/gs/strconv/index.d.ts +6 -0
- package/dist/gs/strconv/index.js +7 -0
- package/dist/gs/strconv/index.js.map +1 -0
- package/dist/gs/strconv/itoa.gs.d.ts +6 -0
- package/dist/gs/strconv/itoa.gs.js +37 -0
- package/dist/gs/strconv/itoa.gs.js.map +1 -0
- package/dist/gs/strconv/quote.gs.d.ts +19 -0
- package/dist/gs/strconv/quote.gs.js +217 -0
- package/dist/gs/strconv/quote.gs.js.map +1 -0
- package/dist/gs/strings/index.d.ts +3 -0
- package/dist/gs/strings/index.js +4 -0
- package/dist/gs/strings/index.js.map +1 -1
- package/dist/gs/strings/replace.d.ts +0 -74
- package/dist/gs/strings/replace.js +6 -204
- package/dist/gs/strings/replace.js.map +1 -1
- package/dist/gs/strings/search.d.ts +0 -1
- package/dist/gs/strings/search.js +0 -21
- package/dist/gs/strings/search.js.map +1 -1
- package/gs/builtin/builtin.ts +9 -7
- package/gs/builtin/map.ts +5 -1
- package/gs/builtin/slice.ts +152 -24
- package/gs/github.com/pkg/errors/errors.ts +307 -0
- package/gs/github.com/pkg/errors/go113.ts +39 -0
- package/gs/github.com/pkg/errors/index.ts +3 -0
- package/gs/github.com/pkg/errors/stack.ts +127 -0
- package/gs/maps/index.ts +2 -2
- package/gs/maps/iter.ts +67 -0
- package/gs/maps/maps.ts +89 -0
- package/gs/math/TODO.md +156 -0
- package/gs/math/abs.gs.test.ts +29 -0
- package/gs/math/abs.gs.ts +13 -0
- package/gs/math/acosh.gs.test.ts +39 -0
- package/gs/math/acosh.gs.ts +21 -0
- package/gs/math/asin.gs.test.ts +66 -0
- package/gs/math/asin.gs.ts +27 -0
- package/gs/math/asinh.gs.test.ts +37 -0
- package/gs/math/asinh.gs.ts +21 -0
- package/gs/math/atan.gs.test.ts +49 -0
- package/gs/math/atan.gs.ts +27 -0
- package/gs/math/atan2.gs.test.ts +55 -0
- package/gs/math/atan2.gs.ts +37 -0
- package/gs/math/atanh.gs.test.ts +47 -0
- package/gs/math/atanh.gs.ts +21 -0
- package/gs/math/bits.gs.test.ts +88 -0
- package/gs/math/bits.gs.ts +61 -0
- package/gs/math/cbrt.gs.test.ts +57 -0
- package/gs/math/cbrt.gs.ts +20 -0
- package/gs/math/const.gs.test.ts +54 -0
- package/gs/math/const.gs.ts +93 -0
- package/gs/math/copysign.gs.test.ts +44 -0
- package/gs/math/copysign.gs.ts +27 -0
- package/gs/math/dim.gs.test.ts +102 -0
- package/gs/math/dim.gs.ts +84 -0
- package/gs/math/erf.gs.test.ts +92 -0
- package/gs/math/erf.gs.ts +409 -0
- package/gs/math/erfinv.gs.test.ts +104 -0
- package/gs/math/erfinv.gs.ts +169 -0
- package/gs/math/exp.gs.test.ts +82 -0
- package/gs/math/exp.gs.ts +39 -0
- package/gs/math/expm1.gs.test.ts +48 -0
- package/gs/math/expm1.gs.ts +23 -0
- package/gs/math/floor.gs.test.ts +146 -0
- package/gs/math/floor.gs.ts +88 -0
- package/gs/math/fma.gs.test.ts +83 -0
- package/gs/math/fma.gs.ts +7 -0
- package/gs/math/frexp.gs.test.ts +146 -0
- package/gs/math/frexp.gs.ts +37 -0
- package/gs/math/gamma.gs.test.ts +66 -0
- package/gs/math/gamma.gs.ts +158 -0
- package/gs/math/hypot.gs.test.ts +73 -0
- package/gs/math/hypot.gs.ts +23 -0
- package/gs/math/index.ts +44 -0
- package/gs/math/j0.gs.test.ts +74 -0
- package/gs/math/j0.gs.ts +257 -0
- package/gs/math/j1.gs.test.ts +81 -0
- package/gs/math/j1.gs.ts +231 -0
- package/gs/math/jn.gs.test.ts +133 -0
- package/gs/math/jn.gs.ts +447 -0
- package/gs/math/ldexp.gs.test.ts +128 -0
- package/gs/math/ldexp.gs.ts +28 -0
- package/gs/math/lgamma.gs.test.ts +102 -0
- package/gs/math/lgamma.gs.ts +251 -0
- package/gs/math/log.gs.test.ts +40 -0
- package/gs/math/log.gs.ts +21 -0
- package/gs/math/log10.gs.test.ts +80 -0
- package/gs/math/log10.gs.ts +25 -0
- package/gs/math/log1p.gs.test.ts +55 -0
- package/gs/math/log1p.gs.ts +24 -0
- package/gs/math/logb.gs.test.ts +87 -0
- package/gs/math/logb.gs.ts +54 -0
- package/gs/math/mod.gs.test.ts +64 -0
- package/gs/math/mod.gs.ts +36 -0
- package/gs/math/modf.gs.test.ts +80 -0
- package/gs/math/modf.gs.ts +32 -0
- package/gs/math/nextafter.gs.test.ts +107 -0
- package/gs/math/nextafter.gs.ts +71 -0
- package/gs/math/pow.gs.test.ts +103 -0
- package/gs/math/pow.gs.ts +55 -0
- package/gs/math/pow10.gs.test.ts +58 -0
- package/gs/math/pow10.gs.ts +19 -0
- package/gs/math/remainder.gs.test.ts +70 -0
- package/gs/math/remainder.gs.ts +33 -0
- package/gs/math/signbit.gs.test.ts +33 -0
- package/gs/math/signbit.gs.ts +8 -0
- package/gs/math/sin.gs.test.ts +83 -0
- package/gs/math/sin.gs.ts +38 -0
- package/gs/math/sincos.gs.test.ts +91 -0
- package/gs/math/sincos.gs.ts +15 -0
- package/gs/math/sinh.gs.test.ts +66 -0
- package/gs/math/sinh.gs.ts +34 -0
- package/gs/math/sqrt.gs.test.ts +49 -0
- package/gs/math/sqrt.gs.ts +20 -0
- package/gs/math/tan.gs.test.ts +50 -0
- package/gs/math/tan.gs.ts +23 -0
- package/gs/math/tanh.gs.test.ts +52 -0
- package/gs/math/tanh.gs.ts +23 -0
- package/gs/math/trig_reduce.gs.ts +66 -0
- package/gs/math/unsafe.gs.ts +52 -0
- package/gs/strconv/atob.gs.ts +45 -0
- package/gs/strconv/atof.gs.ts +60 -0
- package/gs/strconv/atoi.gs.ts +243 -0
- package/gs/strconv/doc.gs.ts +2 -0
- package/gs/strconv/ftoa.gs.ts +66 -0
- package/gs/strconv/index.ts +6 -0
- package/gs/strconv/itoa.gs.ts +41 -0
- package/gs/strconv/quote.gs.ts +245 -0
- package/gs/strings/index.ts +4 -0
- package/gs/strings/replace.ts +9 -237
- package/gs/strings/search.ts +0 -28
- package/package.json +1 -1
- package/gs/maps/iter.gs.ts +0 -71
- package/gs/maps/maps.gs.ts +0 -87
- package/gs/stringslite/godoc.txt +0 -17
- package/gs/stringslite/index.ts +0 -1
- package/gs/stringslite/strings.ts +0 -82
package/compiler/lit.go
CHANGED
|
@@ -4,7 +4,9 @@ import (
|
|
|
4
4
|
"fmt"
|
|
5
5
|
"go/ast"
|
|
6
6
|
"go/token"
|
|
7
|
+
"regexp"
|
|
7
8
|
"strconv"
|
|
9
|
+
"strings"
|
|
8
10
|
)
|
|
9
11
|
|
|
10
12
|
// WriteBasicLit translates a Go basic literal (`ast.BasicLit`) into its
|
|
@@ -15,6 +17,8 @@ import (
|
|
|
15
17
|
// `exp.Value` string, which typically corresponds to valid TypeScript syntax
|
|
16
18
|
// (e.g., `123`, `3.14`, `"hello"`). Imaginary literals might need special
|
|
17
19
|
// handling if they are to be fully supported beyond direct string output.
|
|
20
|
+
// - Legacy octal literals (e.g., `0777`) are converted to modern TypeScript
|
|
21
|
+
// octal syntax (e.g., `0o777`) to avoid ES module compatibility issues.
|
|
18
22
|
func (c *GoToTSCompiler) WriteBasicLit(exp *ast.BasicLit) {
|
|
19
23
|
if exp.Kind == token.CHAR {
|
|
20
24
|
// Go char literal 'x' is a rune (int32). Translate to its numeric code point.
|
|
@@ -26,8 +30,60 @@ func (c *GoToTSCompiler) WriteBasicLit(exp *ast.BasicLit) {
|
|
|
26
30
|
} else {
|
|
27
31
|
c.tsw.WriteLiterallyf("%d", val)
|
|
28
32
|
}
|
|
33
|
+
} else if exp.Kind == token.INT {
|
|
34
|
+
// Handle integer literals, including legacy octal conversion
|
|
35
|
+
value := exp.Value
|
|
36
|
+
|
|
37
|
+
// Check for legacy octal literals (starts with 0, followed by octal digits, but not 0x, 0b, or 0o)
|
|
38
|
+
if len(value) > 1 && value[0] == '0' && value != "0" {
|
|
39
|
+
// Check if it's already modern syntax (0x, 0b, 0o) or just legacy octal
|
|
40
|
+
if len(value) > 2 && (value[1] == 'x' || value[1] == 'X' ||
|
|
41
|
+
value[1] == 'b' || value[1] == 'B' ||
|
|
42
|
+
value[1] == 'o' || value[1] == 'O') {
|
|
43
|
+
// Already modern syntax (hex, binary, or modern octal), write as-is
|
|
44
|
+
c.tsw.WriteLiterally(value)
|
|
45
|
+
} else {
|
|
46
|
+
// Check if all remaining characters are valid octal digits (0-7)
|
|
47
|
+
isLegacyOctal := true
|
|
48
|
+
for i := 1; i < len(value); i++ {
|
|
49
|
+
if value[i] < '0' || value[i] > '7' {
|
|
50
|
+
isLegacyOctal = false
|
|
51
|
+
break
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if isLegacyOctal {
|
|
56
|
+
// Convert legacy octal 0777 to modern octal 0o777
|
|
57
|
+
c.tsw.WriteLiterallyf("0o%s", value[1:])
|
|
58
|
+
} else {
|
|
59
|
+
// Not a valid octal, write as-is (might be decimal with leading zero)
|
|
60
|
+
c.tsw.WriteLiterally(value)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
// Regular decimal integer or single zero, write as-is
|
|
65
|
+
c.tsw.WriteLiterally(value)
|
|
66
|
+
}
|
|
67
|
+
} else if exp.Kind == token.STRING {
|
|
68
|
+
// Handle string literals, with special processing for raw strings
|
|
69
|
+
value := exp.Value
|
|
70
|
+
|
|
71
|
+
// Check if this is a raw string literal (starts and ends with backticks)
|
|
72
|
+
if len(value) >= 2 && value[0] == '`' && value[len(value)-1] == '`' {
|
|
73
|
+
// This is a Go raw string - need to escape invalid \x sequences for JavaScript
|
|
74
|
+
content := value[1 : len(value)-1] // Remove surrounding backticks
|
|
75
|
+
|
|
76
|
+
// Escape invalid \x, \u, and \U sequences that would cause TS1125 errors
|
|
77
|
+
content = c.escapeInvalidEscapeSequences(content)
|
|
78
|
+
|
|
79
|
+
// Write as template literal with corrected content
|
|
80
|
+
c.tsw.WriteLiterallyf("`%s`", content)
|
|
81
|
+
} else {
|
|
82
|
+
// Regular string literal (double quotes) - write as-is
|
|
83
|
+
c.tsw.WriteLiterally(value)
|
|
84
|
+
}
|
|
29
85
|
} else {
|
|
30
|
-
// Other literals (
|
|
86
|
+
// Other literals (FLOAT, IMAG)
|
|
31
87
|
c.tsw.WriteLiterally(exp.Value)
|
|
32
88
|
}
|
|
33
89
|
}
|
|
@@ -108,7 +164,7 @@ func (c *GoToTSCompiler) WriteFuncLitValue(exp *ast.FuncLit) error {
|
|
|
108
164
|
// Declare named return variables and initialize them to their zero values
|
|
109
165
|
for _, field := range exp.Type.Results.List {
|
|
110
166
|
for _, name := range field.Names {
|
|
111
|
-
c.tsw.WriteLiterallyf("let %s: ", name.Name)
|
|
167
|
+
c.tsw.WriteLiterallyf("let %s: ", c.sanitizeIdentifier(name.Name))
|
|
112
168
|
c.WriteTypeExpr(field.Type)
|
|
113
169
|
c.tsw.WriteLiterally(" = ")
|
|
114
170
|
c.WriteZeroValueForType(c.pkg.TypesInfo.TypeOf(field.Type))
|
|
@@ -129,3 +185,56 @@ func (c *GoToTSCompiler) WriteFuncLitValue(exp *ast.FuncLit) error {
|
|
|
129
185
|
|
|
130
186
|
return nil
|
|
131
187
|
}
|
|
188
|
+
|
|
189
|
+
// escapeInvalidEscapeSequences escapes \x, \u, and \U sequences in raw strings that would be invalid in JavaScript template literals.
|
|
190
|
+
// JavaScript template literals expect:
|
|
191
|
+
// - \x to be followed by exactly 2 hexadecimal digits
|
|
192
|
+
// - \u to be followed by exactly 4 hexadecimal digits
|
|
193
|
+
// - \U to be followed by exactly 8 hexadecimal digits
|
|
194
|
+
// This function escapes sequences that don't meet these requirements.
|
|
195
|
+
func (c *GoToTSCompiler) escapeInvalidEscapeSequences(content string) string {
|
|
196
|
+
// Use regex to find all \x, \u, and \U sequences
|
|
197
|
+
re := regexp.MustCompile(`\\([xuU])([0-9a-fA-F]*)`)
|
|
198
|
+
|
|
199
|
+
return re.ReplaceAllStringFunc(content, func(match string) string {
|
|
200
|
+
if len(match) < 2 {
|
|
201
|
+
return match
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
escapeType := match[1] // x, u, or U
|
|
205
|
+
suffix := match[2:] // The hex digits that follow
|
|
206
|
+
|
|
207
|
+
var expectedLength int
|
|
208
|
+
switch escapeType {
|
|
209
|
+
case 'x':
|
|
210
|
+
expectedLength = 2
|
|
211
|
+
case 'u':
|
|
212
|
+
expectedLength = 4
|
|
213
|
+
case 'U':
|
|
214
|
+
expectedLength = 8
|
|
215
|
+
default:
|
|
216
|
+
return match
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Check if it has exactly the expected number of hex digits
|
|
220
|
+
if len(suffix) == expectedLength {
|
|
221
|
+
// Check if all characters are hex digits
|
|
222
|
+
isValidHex := true
|
|
223
|
+
for _, char := range suffix {
|
|
224
|
+
if !((char >= '0' && char <= '9') ||
|
|
225
|
+
(char >= 'a' && char <= 'f') ||
|
|
226
|
+
(char >= 'A' && char <= 'F')) {
|
|
227
|
+
isValidHex = false
|
|
228
|
+
break
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if isValidHex {
|
|
232
|
+
// Valid escape sequence, keep as-is
|
|
233
|
+
return match
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Invalid escape sequence, escape the backslash
|
|
238
|
+
return strings.Replace(match, `\`, `\\`, 1)
|
|
239
|
+
})
|
|
240
|
+
}
|
package/compiler/primitive.go
CHANGED
|
@@ -100,12 +100,12 @@ var tokenMap = map[token.Token]string{
|
|
|
100
100
|
token.QUO_ASSIGN: "/=",
|
|
101
101
|
token.REM_ASSIGN: "%=",
|
|
102
102
|
|
|
103
|
-
token.AND_ASSIGN:
|
|
104
|
-
token.OR_ASSIGN:
|
|
105
|
-
token.XOR_ASSIGN:
|
|
106
|
-
token.SHL_ASSIGN:
|
|
107
|
-
token.SHR_ASSIGN:
|
|
108
|
-
token.AND_NOT_ASSIGN: "&^=",
|
|
103
|
+
token.AND_ASSIGN: "&=",
|
|
104
|
+
token.OR_ASSIGN: "|=",
|
|
105
|
+
token.XOR_ASSIGN: "^=", // TODO: check if this works
|
|
106
|
+
token.SHL_ASSIGN: "<<=",
|
|
107
|
+
token.SHR_ASSIGN: ">>=",
|
|
108
|
+
// token.AND_NOT_ASSIGN: "&^=", // Handled specially in assignment logic
|
|
109
109
|
|
|
110
110
|
token.LAND: "&&",
|
|
111
111
|
token.LOR: "||",
|
package/compiler/protobuf.go
CHANGED
|
@@ -61,11 +61,6 @@ func isProtobufGoLitePackage(pkgPath string) bool {
|
|
|
61
61
|
if strings.HasPrefix(pkgPath, "github.com/aperturerobotics/json-iterator-lite") {
|
|
62
62
|
return true
|
|
63
63
|
}
|
|
64
|
-
// Skip other packages commonly used only by .pb.go files
|
|
65
|
-
switch pkgPath {
|
|
66
|
-
case "encoding/json", "encoding/base64", "strconv", "fmt":
|
|
67
|
-
return true
|
|
68
|
-
}
|
|
69
64
|
return false
|
|
70
65
|
}
|
|
71
66
|
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
package compiler
|
|
2
|
+
|
|
3
|
+
// sanitizeIdentifier checks if an identifier is a JavaScript/TypeScript reserved word
|
|
4
|
+
// or conflicts with built-in types, and transforms it if needed. This prevents
|
|
5
|
+
// compilation errors when Go identifiers conflict with JS/TS keywords or built-ins.
|
|
6
|
+
func sanitizeIdentifier(name string) string {
|
|
7
|
+
// Don't sanitize boolean literals - they are valid in both Go and JS/TS
|
|
8
|
+
if name == "true" || name == "false" {
|
|
9
|
+
return name
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Handle TypeScript built-in types that conflict with Go type parameter names
|
|
13
|
+
builtinTypes := map[string]string{
|
|
14
|
+
"Map": "MapType",
|
|
15
|
+
// Add other built-in types as needed
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if replacement, exists := builtinTypes[name]; exists {
|
|
19
|
+
return replacement
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// List of JavaScript/TypeScript reserved words that could conflict
|
|
23
|
+
reservedWords := map[string]bool{
|
|
24
|
+
"abstract": true,
|
|
25
|
+
"any": true,
|
|
26
|
+
"as": true,
|
|
27
|
+
"asserts": true,
|
|
28
|
+
"async": true,
|
|
29
|
+
"await": true,
|
|
30
|
+
"boolean": true,
|
|
31
|
+
"break": true,
|
|
32
|
+
"case": true,
|
|
33
|
+
"catch": true,
|
|
34
|
+
"class": true,
|
|
35
|
+
"const": true,
|
|
36
|
+
"constructor": true,
|
|
37
|
+
"continue": true,
|
|
38
|
+
"debugger": true,
|
|
39
|
+
"declare": true,
|
|
40
|
+
"default": true,
|
|
41
|
+
"delete": true,
|
|
42
|
+
"do": true,
|
|
43
|
+
"else": true,
|
|
44
|
+
"enum": true,
|
|
45
|
+
"export": true,
|
|
46
|
+
"extends": true,
|
|
47
|
+
"finally": true,
|
|
48
|
+
"for": true,
|
|
49
|
+
"from": true,
|
|
50
|
+
"function": true,
|
|
51
|
+
"get": true,
|
|
52
|
+
"if": true,
|
|
53
|
+
"implements": true,
|
|
54
|
+
"import": true,
|
|
55
|
+
"in": true,
|
|
56
|
+
"instanceof": true,
|
|
57
|
+
"interface": true,
|
|
58
|
+
"is": true,
|
|
59
|
+
"keyof": true,
|
|
60
|
+
"let": true,
|
|
61
|
+
"module": true,
|
|
62
|
+
"namespace": true,
|
|
63
|
+
"never": true,
|
|
64
|
+
"new": true,
|
|
65
|
+
"null": true,
|
|
66
|
+
"number": true,
|
|
67
|
+
"object": true,
|
|
68
|
+
"of": true,
|
|
69
|
+
"package": true,
|
|
70
|
+
"private": true,
|
|
71
|
+
"protected": true,
|
|
72
|
+
"public": true,
|
|
73
|
+
"readonly": true,
|
|
74
|
+
"require": true,
|
|
75
|
+
"return": true,
|
|
76
|
+
"set": true,
|
|
77
|
+
"static": true,
|
|
78
|
+
"string": true,
|
|
79
|
+
"super": true,
|
|
80
|
+
"switch": true,
|
|
81
|
+
"symbol": true,
|
|
82
|
+
"this": true,
|
|
83
|
+
"throw": true,
|
|
84
|
+
"try": true,
|
|
85
|
+
"type": true,
|
|
86
|
+
"typeof": true,
|
|
87
|
+
"undefined": true,
|
|
88
|
+
"unique": true,
|
|
89
|
+
"unknown": true,
|
|
90
|
+
"var": true,
|
|
91
|
+
"void": true,
|
|
92
|
+
"while": true,
|
|
93
|
+
"with": true,
|
|
94
|
+
"yield": true,
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if reservedWords[name] {
|
|
98
|
+
return "_" + name
|
|
99
|
+
}
|
|
100
|
+
return name
|
|
101
|
+
}
|
package/compiler/spec-value.go
CHANGED
|
@@ -91,7 +91,7 @@ func (c *GoToTSCompiler) WriteValueSpec(a *ast.ValueSpec) error {
|
|
|
91
91
|
c.tsw.WriteLiterally("export ")
|
|
92
92
|
}
|
|
93
93
|
c.tsw.WriteLiterally("let ")
|
|
94
|
-
c.tsw.WriteLiterally(name.Name)
|
|
94
|
+
c.tsw.WriteLiterally(c.sanitizeIdentifier(name.Name))
|
|
95
95
|
|
|
96
96
|
// Write type annotation if:
|
|
97
97
|
// 1. Not a slice conversion (normal case), OR
|
|
@@ -193,27 +193,34 @@ func (c *GoToTSCompiler) WriteValueSpec(a *ast.ValueSpec) error {
|
|
|
193
193
|
if hasInitializer {
|
|
194
194
|
// Handle &v initializer specifically for unvarrefed variables
|
|
195
195
|
if unaryExpr, isUnary := initializerExpr.(*ast.UnaryExpr); isUnary && unaryExpr.Op == token.AND {
|
|
196
|
-
// Initializer is &
|
|
197
|
-
// Check if
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
196
|
+
// Initializer is &expr
|
|
197
|
+
// Check if expr is an identifier (variable) or something else (e.g., composite literal)
|
|
198
|
+
if unaryExprXIdent, ok := unaryExpr.X.(*ast.Ident); ok {
|
|
199
|
+
// Case: &variable
|
|
200
|
+
// Check if the variable is varrefed
|
|
201
201
|
innerObj := c.pkg.TypesInfo.Uses[unaryExprXIdent]
|
|
202
|
-
needsVarRefOperand
|
|
203
|
-
}
|
|
202
|
+
needsVarRefOperand := innerObj != nil && c.analysis.NeedsVarRef(innerObj)
|
|
204
203
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
204
|
+
// If variable is varrefed, assign the varRef itself (variable)
|
|
205
|
+
// If variable is not varrefed, assign $.varRef(variable)
|
|
206
|
+
if needsVarRefOperand {
|
|
207
|
+
// do not write .value here.
|
|
208
|
+
c.WriteIdent(unaryExprXIdent, false)
|
|
209
|
+
} else {
|
|
210
|
+
// &unvarrefedVar -> $.varRef(unvarrefedVar)
|
|
211
|
+
c.tsw.WriteLiterally("$.varRef(")
|
|
212
|
+
if err := c.WriteValueExpr(unaryExpr.X); err != nil { // Write 'variable'
|
|
213
|
+
return err
|
|
214
|
+
}
|
|
215
|
+
c.tsw.WriteLiterally(")")
|
|
216
|
+
}
|
|
210
217
|
} else {
|
|
211
|
-
// &
|
|
212
|
-
|
|
213
|
-
|
|
218
|
+
// Case: &compositeLiteral or &otherExpression
|
|
219
|
+
// For composite literals and other expressions, just write the expression directly
|
|
220
|
+
// Example: &MyStruct{} -> new MyStruct({})
|
|
221
|
+
if err := c.WriteValueExpr(unaryExpr.X); err != nil {
|
|
214
222
|
return err
|
|
215
223
|
}
|
|
216
|
-
c.tsw.WriteLiterally(")")
|
|
217
224
|
}
|
|
218
225
|
} else {
|
|
219
226
|
// Check if this is a named type with methods and the initializer is a basic value
|
|
@@ -315,7 +322,7 @@ func (c *GoToTSCompiler) WriteValueSpec(a *ast.ValueSpec) error {
|
|
|
315
322
|
if i != 0 {
|
|
316
323
|
c.tsw.WriteLiterally(", ")
|
|
317
324
|
}
|
|
318
|
-
c.tsw.WriteLiterally(name.Name)
|
|
325
|
+
c.tsw.WriteLiterally(c.sanitizeIdentifier(name.Name))
|
|
319
326
|
// TODO: Add type annotations for multi-var declarations if possible/needed
|
|
320
327
|
}
|
|
321
328
|
c.tsw.WriteLiterally("]")
|
package/compiler/stmt-assign.go
CHANGED
|
@@ -222,10 +222,25 @@ func (c *GoToTSCompiler) WriteStmtAssign(exp *ast.AssignStmt) error {
|
|
|
222
222
|
}
|
|
223
223
|
|
|
224
224
|
// For simple cases without selector expressions, use array destructuring
|
|
225
|
+
// Add semicolon before destructuring assignment to prevent TypeScript
|
|
226
|
+
// from interpreting it as array access on the previous line
|
|
227
|
+
if tok != token.DEFINE {
|
|
228
|
+
c.tsw.WriteLiterally(";")
|
|
229
|
+
}
|
|
225
230
|
c.tsw.WriteLiterally("[")
|
|
226
231
|
|
|
232
|
+
// Find the last non-blank identifier to avoid trailing commas
|
|
233
|
+
lastNonBlankIndex := -1
|
|
234
|
+
for i := len(lhs) - 1; i >= 0; i-- {
|
|
235
|
+
if ident, ok := lhs[i].(*ast.Ident); !ok || ident.Name != "_" {
|
|
236
|
+
lastNonBlankIndex = i
|
|
237
|
+
break
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
227
241
|
for i, lhsExpr := range lhs {
|
|
228
|
-
|
|
242
|
+
// Write comma before non-first elements
|
|
243
|
+
if i > 0 {
|
|
229
244
|
c.tsw.WriteLiterally(", ")
|
|
230
245
|
}
|
|
231
246
|
|
|
@@ -234,6 +249,7 @@ func (c *GoToTSCompiler) WriteStmtAssign(exp *ast.AssignStmt) error {
|
|
|
234
249
|
if ident.Name != "_" {
|
|
235
250
|
c.WriteIdent(ident, false)
|
|
236
251
|
}
|
|
252
|
+
// For blank identifiers, we write nothing (empty slot)
|
|
237
253
|
} else if selectorExpr, ok := lhsExpr.(*ast.SelectorExpr); ok {
|
|
238
254
|
// Handle selector expressions (e.g., a.b) by using WriteValueExpr
|
|
239
255
|
if err := c.WriteValueExpr(selectorExpr); err != nil {
|
|
@@ -263,6 +279,11 @@ func (c *GoToTSCompiler) WriteStmtAssign(exp *ast.AssignStmt) error {
|
|
|
263
279
|
// Should not happen for valid Go code in this context, but handle defensively
|
|
264
280
|
return errors.Errorf("unhandled LHS expression in destructuring: %T", lhsExpr)
|
|
265
281
|
}
|
|
282
|
+
|
|
283
|
+
// Stop writing if we've reached the last non-blank element
|
|
284
|
+
if i == lastNonBlankIndex {
|
|
285
|
+
break
|
|
286
|
+
}
|
|
266
287
|
}
|
|
267
288
|
c.tsw.WriteLiterally("] = ")
|
|
268
289
|
|
package/compiler/stmt.go
CHANGED
|
@@ -520,13 +520,17 @@ func (c *GoToTSCompiler) WriteStmtReturn(exp *ast.ReturnStmt) error {
|
|
|
520
520
|
}
|
|
521
521
|
}
|
|
522
522
|
|
|
523
|
-
if len(namedReturns)
|
|
523
|
+
if len(namedReturns) == 1 {
|
|
524
|
+
// Single named return - don't wrap in array
|
|
525
|
+
c.tsw.WriteLiterally(c.sanitizeIdentifier(namedReturns[0]))
|
|
526
|
+
} else if len(namedReturns) > 1 {
|
|
527
|
+
// Multiple named returns - wrap in array
|
|
524
528
|
c.tsw.WriteLiterally("[")
|
|
525
529
|
for i, name := range namedReturns {
|
|
526
530
|
if i != 0 {
|
|
527
531
|
c.tsw.WriteLiterally(", ")
|
|
528
532
|
}
|
|
529
|
-
c.tsw.WriteLiterally(name)
|
|
533
|
+
c.tsw.WriteLiterally(c.sanitizeIdentifier(name))
|
|
530
534
|
}
|
|
531
535
|
c.tsw.WriteLiterally("]")
|
|
532
536
|
}
|
|
@@ -849,15 +853,28 @@ func (c *GoToTSCompiler) WriteStmtDefer(exp *ast.DeferStmt) error {
|
|
|
849
853
|
}
|
|
850
854
|
|
|
851
855
|
// WriteStmtLabeled handles labeled statements (ast.LabeledStmt), such as "label: statement".
|
|
852
|
-
// In TypeScript,
|
|
856
|
+
// In TypeScript, labels cannot be used with variable declarations, so we need to handle this case specially.
|
|
853
857
|
func (c *GoToTSCompiler) WriteStmtLabeled(stmt *ast.LabeledStmt) error {
|
|
854
|
-
//
|
|
855
|
-
|
|
856
|
-
|
|
858
|
+
// Check if the labeled statement is a declaration statement
|
|
859
|
+
if declStmt, ok := stmt.Stmt.(*ast.DeclStmt); ok {
|
|
860
|
+
// For declaration statements, we need to put the label on a separate line
|
|
861
|
+
// because TypeScript doesn't allow labels with declarations
|
|
862
|
+
c.tsw.WriteLiterally(stmt.Label.Name)
|
|
863
|
+
c.tsw.WriteLine(": {}")
|
|
857
864
|
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
865
|
+
// Write the declaration statement without the label
|
|
866
|
+
if err := c.WriteStmt(declStmt); err != nil {
|
|
867
|
+
return fmt.Errorf("failed to write labeled declaration statement: %w", err)
|
|
868
|
+
}
|
|
869
|
+
} else {
|
|
870
|
+
// For non-declaration statements, write the label normally
|
|
871
|
+
c.tsw.WriteLiterally(stmt.Label.Name)
|
|
872
|
+
c.tsw.WriteLiterally(": ")
|
|
873
|
+
|
|
874
|
+
// Write the labeled statement
|
|
875
|
+
if err := c.WriteStmt(stmt.Stmt); err != nil {
|
|
876
|
+
return fmt.Errorf("failed to write labeled statement: %w", err)
|
|
877
|
+
}
|
|
861
878
|
}
|
|
862
879
|
|
|
863
880
|
return nil
|
package/compiler/type.go
CHANGED
|
@@ -369,12 +369,12 @@ func (c *GoToTSCompiler) WriteFuncType(exp *ast.FuncType, isAsync bool) {
|
|
|
369
369
|
if isAsync {
|
|
370
370
|
c.tsw.WriteLiterally("Promise<")
|
|
371
371
|
}
|
|
372
|
-
if len(exp.Results.List) == 1
|
|
373
|
-
// Single
|
|
372
|
+
if len(exp.Results.List) == 1 {
|
|
373
|
+
// Single return type (named or unnamed)
|
|
374
374
|
typ := c.pkg.TypesInfo.TypeOf(exp.Results.List[0].Type)
|
|
375
375
|
c.WriteGoType(typ, GoTypeContextFunctionReturn)
|
|
376
376
|
} else {
|
|
377
|
-
// Multiple
|
|
377
|
+
// Multiple return types -> tuple
|
|
378
378
|
c.tsw.WriteLiterally("[")
|
|
379
379
|
for i, field := range exp.Results.List {
|
|
380
380
|
if i > 0 {
|
|
@@ -5,7 +5,8 @@ export * from './io.js';
|
|
|
5
5
|
export * from './map.js';
|
|
6
6
|
export * from './slice.js';
|
|
7
7
|
export * from './type.js';
|
|
8
|
-
|
|
8
|
+
import type { Slice } from './slice.js';
|
|
9
|
+
export type Bytes = Uint8Array | Slice<number>;
|
|
9
10
|
export declare function int(value: number): number;
|
|
10
11
|
export declare function copy<T>(dst: T[] | Uint8Array, src: T[] | Uint8Array | string): number;
|
|
11
12
|
export declare function multiplyDuration(duration: any, multiplier: number): any;
|
|
@@ -32,4 +33,4 @@ export declare function normalizeBytes(bytes: Uint8Array | number[] | null | und
|
|
|
32
33
|
* Handles all slice types including null, arrays, Uint8Array, and SliceProxy.
|
|
33
34
|
* @param s The slice to sort in place
|
|
34
35
|
*/
|
|
35
|
-
export declare function sortSlice<T extends string | number>(s:
|
|
36
|
+
export declare function sortSlice<T extends string | number>(s: Slice<T>): void;
|
|
@@ -5,6 +5,7 @@ export * from './io.js';
|
|
|
5
5
|
export * from './map.js';
|
|
6
6
|
export * from './slice.js';
|
|
7
7
|
export * from './type.js';
|
|
8
|
+
import { isSliceProxy } from './slice.js';
|
|
8
9
|
// int converts a value to a Go int type, handling proper signed integer conversion
|
|
9
10
|
// This ensures that values like 2147483648 (2^31) are properly handled according to Go semantics
|
|
10
11
|
export function int(value) {
|
|
@@ -152,7 +153,7 @@ export function sortSlice(s) {
|
|
|
152
153
|
return;
|
|
153
154
|
}
|
|
154
155
|
// Handle SliceProxy case - sort the backing array in-place within the slice bounds
|
|
155
|
-
if (s
|
|
156
|
+
if (isSliceProxy(s)) {
|
|
156
157
|
const proxy = s;
|
|
157
158
|
const meta = proxy.__meta__;
|
|
158
159
|
const section = meta.backing.slice(meta.offset, meta.offset + meta.length);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builtin.js","sourceRoot":"","sources":["../../../gs/builtin/builtin.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,S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MAAM,UAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"map.js","sourceRoot":"","sources":["../../../gs/builtin/map.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,GAAoB,EAAE;IAC3C,OAAO,IAAI,GAAG,EAAQ,CAAA;AACxB,CAAC,CAAA;AACD;;;;;;GAMG;AACH,MAAM,UAAU,MAAM,CACpB,GAAc,EACd,GAAM,EACN,YAAe;IAEf,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAC3B,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAE,EAAE,IAAI,CAAC,CAAA;IAC9B,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,YAAY,EAAE,KAAK,CAAC,CAAA;IAC9B,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAO,GAAc,EAAE,GAAM,EAAE,KAAQ,EAAQ,EAAE;IACrE,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;AACrB,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAO,GAAc,EAAE,GAAM,EAAQ,EAAE;IACnE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;AACjB,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAO,GAAc,EAAE,GAAM,EAAW,EAAE;IAC9D,OAAO,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AACrB,CAAC,CAAA"}
|
|
@@ -21,6 +21,11 @@ export type SliceProxy<T> = T[] & {
|
|
|
21
21
|
*/
|
|
22
22
|
export type Slice<T> = T[] | SliceProxy<T> | null | (T extends number ? Uint8Array : never);
|
|
23
23
|
export declare function asArray<T>(slice: Slice<T>): T[];
|
|
24
|
+
/**
|
|
25
|
+
* isSliceProxy checks if a slice is a SliceProxy (has __meta__ property)
|
|
26
|
+
* This is an alias for isComplexSlice for better type hinting
|
|
27
|
+
*/
|
|
28
|
+
export declare function isSliceProxy<T>(slice: Slice<T>): slice is SliceProxy<T>;
|
|
24
29
|
/**
|
|
25
30
|
* Creates a new slice with the specified length and capacity.
|
|
26
31
|
* @param length The length of the slice.
|
|
@@ -67,7 +72,8 @@ export declare const cap: <T>(obj: Slice<T> | Uint8Array) => number;
|
|
|
67
72
|
* @param elements The elements to append.
|
|
68
73
|
* @returns The modified or new slice.
|
|
69
74
|
*/
|
|
70
|
-
export declare
|
|
75
|
+
export declare function append(slice: Uint8Array, ...elements: any[]): Uint8Array;
|
|
76
|
+
export declare function append<T>(slice: Slice<T>, ...elements: any[]): Slice<T>;
|
|
71
77
|
/**
|
|
72
78
|
* Copies elements from src to dst.
|
|
73
79
|
* @param dst The destination slice.
|