goscript 0.0.37 → 0.0.39

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.
Files changed (198) hide show
  1. package/compiler/analysis.go +129 -8
  2. package/compiler/compiler.go +4 -1
  3. package/compiler/composite-lit.go +2 -4
  4. package/compiler/expr-call.go +12 -0
  5. package/compiler/lit.go +100 -6
  6. package/compiler/protobuf.go +2 -2
  7. package/compiler/spec-value.go +3 -3
  8. package/compiler/spec.go +6 -3
  9. package/compiler/stmt-assign.go +1 -1
  10. package/dist/gs/builtin/builtin.d.ts +45 -0
  11. package/dist/gs/builtin/builtin.js +197 -0
  12. package/dist/gs/builtin/builtin.js.map +1 -1
  13. package/dist/gs/builtin/slice.js +2 -1
  14. package/dist/gs/builtin/slice.js.map +1 -1
  15. package/dist/gs/bytes/buffer.gs.d.ts +56 -0
  16. package/dist/gs/bytes/buffer.gs.js +611 -0
  17. package/dist/gs/bytes/buffer.gs.js.map +1 -0
  18. package/dist/gs/bytes/bytes.gs.d.ts +78 -0
  19. package/dist/gs/bytes/bytes.gs.js +1011 -0
  20. package/dist/gs/bytes/bytes.gs.js.map +1 -0
  21. package/dist/gs/bytes/index.d.ts +4 -0
  22. package/dist/gs/bytes/index.js +5 -0
  23. package/dist/gs/bytes/index.js.map +1 -0
  24. package/dist/gs/bytes/iter.gs.d.ts +9 -0
  25. package/dist/gs/bytes/iter.gs.js +143 -0
  26. package/dist/gs/bytes/iter.gs.js.map +1 -0
  27. package/dist/gs/bytes/reader.gs.d.ts +34 -0
  28. package/dist/gs/bytes/reader.gs.js +198 -0
  29. package/dist/gs/bytes/reader.gs.js.map +1 -0
  30. package/dist/gs/github.com/pkg/errors/errors.d.ts +1 -1
  31. package/dist/gs/github.com/pkg/errors/errors.js +182 -23
  32. package/dist/gs/github.com/pkg/errors/errors.js.map +1 -1
  33. package/dist/gs/github.com/pkg/errors/go113.d.ts +1 -1
  34. package/dist/gs/github.com/pkg/errors/go113.js +1 -1
  35. package/dist/gs/github.com/pkg/errors/go113.js.map +1 -1
  36. package/dist/gs/github.com/pkg/errors/index.d.ts +3 -3
  37. package/dist/gs/github.com/pkg/errors/index.js +3 -3
  38. package/dist/gs/github.com/pkg/errors/index.js.map +1 -1
  39. package/dist/gs/github.com/pkg/errors/stack.d.ts +1 -1
  40. package/dist/gs/github.com/pkg/errors/stack.js +8 -5
  41. package/dist/gs/github.com/pkg/errors/stack.js.map +1 -1
  42. package/dist/gs/internal/abi/index.d.ts +20 -0
  43. package/dist/gs/internal/abi/index.js +20 -0
  44. package/dist/gs/internal/abi/index.js.map +1 -0
  45. package/dist/gs/internal/bytealg/index.d.ts +14 -0
  46. package/dist/gs/internal/bytealg/index.js +139 -0
  47. package/dist/gs/internal/bytealg/index.js.map +1 -0
  48. package/dist/gs/internal/byteorder/index.d.ts +1 -1
  49. package/dist/gs/internal/byteorder/index.js +4 -4
  50. package/dist/gs/internal/byteorder/index.js.map +1 -1
  51. package/dist/gs/math/index.d.ts +44 -44
  52. package/dist/gs/math/index.js +44 -44
  53. package/dist/gs/math/index.js.map +1 -1
  54. package/dist/gs/os/index.d.ts +19 -19
  55. package/dist/gs/os/index.js +19 -19
  56. package/dist/gs/os/index.js.map +1 -1
  57. package/dist/gs/reflect/deepequal.d.ts +2 -0
  58. package/dist/gs/reflect/deepequal.js +91 -0
  59. package/dist/gs/reflect/deepequal.js.map +1 -0
  60. package/dist/gs/reflect/index.d.ts +8 -0
  61. package/dist/gs/reflect/index.js +10 -0
  62. package/dist/gs/reflect/index.js.map +1 -0
  63. package/dist/gs/reflect/iter.d.ts +4 -0
  64. package/dist/gs/reflect/iter.js +24 -0
  65. package/dist/gs/reflect/iter.js.map +1 -0
  66. package/dist/gs/reflect/map.d.ts +20 -0
  67. package/dist/gs/reflect/map.js +74 -0
  68. package/dist/gs/reflect/map.js.map +1 -0
  69. package/dist/gs/reflect/swapper.d.ts +2 -0
  70. package/dist/gs/reflect/swapper.js +46 -0
  71. package/dist/gs/reflect/swapper.js.map +1 -0
  72. package/dist/gs/reflect/type.d.ts +134 -0
  73. package/dist/gs/reflect/type.js +825 -0
  74. package/dist/gs/reflect/type.js.map +1 -0
  75. package/dist/gs/reflect/types.d.ts +90 -0
  76. package/dist/gs/reflect/types.js +119 -0
  77. package/dist/gs/reflect/types.js.map +1 -0
  78. package/dist/gs/reflect/value.d.ts +13 -0
  79. package/dist/gs/reflect/value.js +202 -0
  80. package/dist/gs/reflect/value.js.map +1 -0
  81. package/dist/gs/reflect/visiblefields.d.ts +4 -0
  82. package/dist/gs/reflect/visiblefields.js +149 -0
  83. package/dist/gs/reflect/visiblefields.js.map +1 -0
  84. package/dist/gs/strconv/index.d.ts +6 -6
  85. package/dist/gs/strconv/index.js +6 -6
  86. package/dist/gs/strconv/index.js.map +1 -1
  87. package/dist/gs/strings/index.d.ts +1 -1
  88. package/dist/gs/strings/index.js +1 -1
  89. package/dist/gs/strings/index.js.map +1 -1
  90. package/dist/gs/strings/replace.js.map +1 -1
  91. package/dist/gs/sync/atomic/index.d.ts +4 -4
  92. package/dist/gs/sync/atomic/index.js +4 -4
  93. package/dist/gs/sync/atomic/index.js.map +1 -1
  94. package/dist/gs/syscall/index.d.ts +6 -6
  95. package/dist/gs/syscall/index.js +34 -28
  96. package/dist/gs/syscall/index.js.map +1 -1
  97. package/dist/gs/unicode/utf8/utf8.d.ts +1 -1
  98. package/dist/gs/unicode/utf8/utf8.js +4 -2
  99. package/dist/gs/unicode/utf8/utf8.js.map +1 -1
  100. package/dist/gs/unsafe/unsafe.js.map +1 -1
  101. package/gs/builtin/builtin.ts +219 -0
  102. package/gs/builtin/slice.ts +2 -1
  103. package/gs/bytes/buffer.gs.ts +614 -0
  104. package/gs/bytes/bytes.gs.ts +1180 -0
  105. package/gs/bytes/godoc.txt +69 -0
  106. package/gs/bytes/index.ts +69 -0
  107. package/gs/bytes/iter.gs.ts +149 -0
  108. package/gs/bytes/reader.gs.ts +230 -0
  109. package/gs/github.com/pkg/errors/errors.ts +408 -238
  110. package/gs/github.com/pkg/errors/go113.ts +5 -6
  111. package/gs/github.com/pkg/errors/index.ts +12 -3
  112. package/gs/github.com/pkg/errors/stack.ts +107 -105
  113. package/gs/internal/abi/index.ts +37 -0
  114. package/gs/internal/bytealg/index.ts +149 -0
  115. package/gs/internal/byteorder/index.ts +5 -5
  116. package/gs/math/abs.gs.test.ts +1 -1
  117. package/gs/math/acosh.gs.test.ts +4 -2
  118. package/gs/math/asin.gs.test.ts +1 -1
  119. package/gs/math/asinh.gs.test.ts +7 -3
  120. package/gs/math/atan.gs.test.ts +1 -1
  121. package/gs/math/atan2.gs.test.ts +17 -9
  122. package/gs/math/atanh.gs.test.ts +1 -1
  123. package/gs/math/bits.gs.test.ts +1 -1
  124. package/gs/math/cbrt.gs.test.ts +1 -1
  125. package/gs/math/const.gs.test.ts +34 -8
  126. package/gs/math/copysign.gs.test.ts +7 -3
  127. package/gs/math/dim.gs.test.ts +19 -7
  128. package/gs/math/erf.gs.test.ts +1 -1
  129. package/gs/math/erfinv.gs.test.ts +4 -2
  130. package/gs/math/exp.gs.test.ts +1 -1
  131. package/gs/math/expm1.gs.test.ts +6 -4
  132. package/gs/math/floor.gs.test.ts +17 -4
  133. package/gs/math/fma.gs.test.ts +53 -53
  134. package/gs/math/frexp.gs.test.ts +112 -117
  135. package/gs/math/gamma.gs.test.ts +1 -1
  136. package/gs/math/hypot.gs.test.ts +53 -53
  137. package/gs/math/index.ts +80 -44
  138. package/gs/math/j0.gs.test.ts +6 -2
  139. package/gs/math/j1.gs.test.ts +6 -2
  140. package/gs/math/jn.gs.test.ts +9 -5
  141. package/gs/math/ldexp.gs.test.ts +103 -86
  142. package/gs/math/lgamma.gs.test.ts +10 -10
  143. package/gs/math/log.gs.test.ts +1 -1
  144. package/gs/math/log10.gs.test.ts +1 -1
  145. package/gs/math/log1p.gs.test.ts +2 -2
  146. package/gs/math/logb.gs.test.ts +1 -1
  147. package/gs/math/mod.gs.test.ts +2 -2
  148. package/gs/math/modf.gs.test.ts +7 -7
  149. package/gs/math/nextafter.gs.test.ts +9 -7
  150. package/gs/math/pow.gs.test.ts +6 -4
  151. package/gs/math/pow10.gs.test.ts +1 -1
  152. package/gs/math/remainder.gs.test.ts +1 -1
  153. package/gs/math/signbit.gs.test.ts +1 -1
  154. package/gs/math/sin.gs.test.ts +1 -1
  155. package/gs/math/sincos.gs.test.ts +33 -14
  156. package/gs/math/sinh.gs.test.ts +1 -1
  157. package/gs/math/sqrt.gs.test.ts +1 -1
  158. package/gs/math/tan.gs.test.ts +3 -3
  159. package/gs/math/tanh.gs.test.ts +1 -1
  160. package/gs/os/index.ts +128 -19
  161. package/gs/reflect/ANALYSIS.md +278 -0
  162. package/gs/reflect/deepequal.test.ts +41 -0
  163. package/gs/reflect/deepequal.ts +169 -0
  164. package/gs/reflect/function-types.test.ts +146 -0
  165. package/gs/reflect/godoc.txt +67 -0
  166. package/gs/reflect/index.ts +83 -0
  167. package/gs/reflect/iter.ts +44 -0
  168. package/gs/reflect/map.test.ts +30 -0
  169. package/gs/reflect/map.ts +85 -0
  170. package/gs/reflect/swapper.ts +52 -0
  171. package/gs/reflect/type.ts +1016 -0
  172. package/gs/reflect/types.ts +214 -0
  173. package/gs/reflect/value.ts +270 -0
  174. package/gs/reflect/visiblefields.ts +177 -0
  175. package/gs/strconv/index.ts +39 -6
  176. package/gs/strings/index.ts +7 -1
  177. package/gs/strings/replace.ts +1 -9
  178. package/gs/sync/atomic/index.ts +53 -4
  179. package/gs/syscall/index.ts +45 -37
  180. package/gs/unicode/utf8/utf8.ts +8 -5
  181. package/gs/unsafe/unsafe.ts +1 -1
  182. package/package.json +2 -1
  183. package/dist/gs/internal/testlog/index.d.ts +0 -1
  184. package/dist/gs/internal/testlog/index.js +0 -5
  185. package/dist/gs/internal/testlog/index.js.map +0 -1
  186. package/dist/gs/maps/iter.gs.d.ts +0 -7
  187. package/dist/gs/maps/iter.gs.js +0 -65
  188. package/dist/gs/maps/iter.gs.js.map +0 -1
  189. package/dist/gs/maps/maps.gs.d.ts +0 -7
  190. package/dist/gs/maps/maps.gs.js +0 -79
  191. package/dist/gs/maps/maps.gs.js.map +0 -1
  192. package/dist/gs/stringslite/index.d.ts +0 -1
  193. package/dist/gs/stringslite/index.js +0 -2
  194. package/dist/gs/stringslite/index.js.map +0 -1
  195. package/dist/gs/stringslite/strings.d.ts +0 -11
  196. package/dist/gs/stringslite/strings.js +0 -67
  197. package/dist/gs/stringslite/strings.js.map +0 -1
  198. package/gs/internal/testlog/index.ts +0 -7
@@ -209,3 +209,222 @@ export function sortSlice<T extends string | number>(s: Slice<T>): void {
209
209
  return
210
210
  }
211
211
  }
212
+
213
+ /**
214
+ * bytesEqual efficiently compares two byte slices for equality.
215
+ * Optimized for different byte representations.
216
+ */
217
+ export function bytesEqual(a: Bytes | null, b: Bytes | null): boolean {
218
+ // Handle null cases
219
+ if (a === null && b === null) return true
220
+ if (a === null || b === null) return false
221
+
222
+ // Convert to arrays for comparison
223
+ const aArr = bytesToArray(a)
224
+ const bArr = bytesToArray(b)
225
+
226
+ if (aArr.length !== bArr.length) return false
227
+
228
+ for (let i = 0; i < aArr.length; i++) {
229
+ if (aArr[i] !== bArr[i]) return false
230
+ }
231
+
232
+ return true
233
+ }
234
+
235
+ /**
236
+ * bytesCompare compares two byte slices lexicographically.
237
+ * Returns -1 if a < b, 0 if a == b, +1 if a > b.
238
+ */
239
+ export function bytesCompare(a: Bytes | null, b: Bytes | null): number {
240
+ // Handle null cases
241
+ if (a === null && b === null) return 0
242
+ if (a === null) return -1
243
+ if (b === null) return 1
244
+
245
+ const aArr = bytesToArray(a)
246
+ const bArr = bytesToArray(b)
247
+
248
+ const minLen = Math.min(aArr.length, bArr.length)
249
+
250
+ for (let i = 0; i < minLen; i++) {
251
+ if (aArr[i] < bArr[i]) return -1
252
+ if (aArr[i] > bArr[i]) return 1
253
+ }
254
+
255
+ if (aArr.length < bArr.length) return -1
256
+ if (aArr.length > bArr.length) return 1
257
+ return 0
258
+ }
259
+
260
+ /**
261
+ * bytesToArray converts any Bytes representation to a number array.
262
+ */
263
+ export function bytesToArray(bytes: Bytes | null): number[] {
264
+ if (bytes === null) return []
265
+
266
+ if (bytes instanceof Uint8Array) {
267
+ return Array.from(bytes)
268
+ }
269
+
270
+ if (Array.isArray(bytes)) {
271
+ return bytes
272
+ }
273
+
274
+ // Handle SliceProxy
275
+ if (isSliceProxy(bytes)) {
276
+ const proxy = bytes as SliceProxy<number>
277
+ const meta = proxy.__meta__
278
+ return meta.backing.slice(meta.offset, meta.offset + meta.length)
279
+ }
280
+
281
+ throw new Error(`Cannot convert bytes of type ${typeof bytes} to array`)
282
+ }
283
+
284
+ /**
285
+ * bytesToUint8Array converts any Bytes representation to a Uint8Array.
286
+ */
287
+ export function bytesToUint8Array(bytes: Bytes | null): Uint8Array {
288
+ if (bytes === null) return new Uint8Array(0)
289
+
290
+ if (bytes instanceof Uint8Array) {
291
+ return bytes
292
+ }
293
+
294
+ return new Uint8Array(bytesToArray(bytes))
295
+ }
296
+
297
+ /**
298
+ * bytesIndexOf finds the first occurrence of subslice in bytes.
299
+ * Returns -1 if not found.
300
+ */
301
+ export function bytesIndexOf(
302
+ bytes: Bytes | null,
303
+ subslice: Bytes | null,
304
+ ): number {
305
+ if (bytes === null || subslice === null) return -1
306
+
307
+ const haystack = bytesToArray(bytes)
308
+ const needle = bytesToArray(subslice)
309
+
310
+ if (needle.length === 0) return 0
311
+ if (needle.length > haystack.length) return -1
312
+
313
+ for (let i = 0; i <= haystack.length - needle.length; i++) {
314
+ let found = true
315
+ for (let j = 0; j < needle.length; j++) {
316
+ if (haystack[i + j] !== needle[j]) {
317
+ found = false
318
+ break
319
+ }
320
+ }
321
+ if (found) return i
322
+ }
323
+
324
+ return -1
325
+ }
326
+
327
+ /**
328
+ * bytesLastIndexOf finds the last occurrence of subslice in bytes.
329
+ * Returns -1 if not found.
330
+ */
331
+ export function bytesLastIndexOf(
332
+ bytes: Bytes | null,
333
+ subslice: Bytes | null,
334
+ ): number {
335
+ if (bytes === null || subslice === null) return -1
336
+
337
+ const haystack = bytesToArray(bytes)
338
+ const needle = bytesToArray(subslice)
339
+
340
+ if (needle.length === 0) return haystack.length
341
+ if (needle.length > haystack.length) return -1
342
+
343
+ for (let i = haystack.length - needle.length; i >= 0; i--) {
344
+ let found = true
345
+ for (let j = 0; j < needle.length; j++) {
346
+ if (haystack[i + j] !== needle[j]) {
347
+ found = false
348
+ break
349
+ }
350
+ }
351
+ if (found) return i
352
+ }
353
+
354
+ return -1
355
+ }
356
+
357
+ /**
358
+ * bytesIndexByte finds the first occurrence of byte c in bytes.
359
+ * Returns -1 if not found.
360
+ */
361
+ export function bytesIndexByte(bytes: Bytes | null, c: number): number {
362
+ if (bytes === null) return -1
363
+
364
+ const arr = bytesToArray(bytes)
365
+ return arr.indexOf(c)
366
+ }
367
+
368
+ /**
369
+ * bytesLastIndexByte finds the last occurrence of byte c in bytes.
370
+ * Returns -1 if not found.
371
+ */
372
+ export function bytesLastIndexByte(bytes: Bytes | null, c: number): number {
373
+ if (bytes === null) return -1
374
+
375
+ const arr = bytesToArray(bytes)
376
+ return arr.lastIndexOf(c)
377
+ }
378
+
379
+ /**
380
+ * bytesCount counts non-overlapping instances of sep in bytes.
381
+ */
382
+ export function bytesCount(bytes: Bytes | null, sep: Bytes | null): number {
383
+ if (bytes === null || sep === null) return 0
384
+
385
+ const haystack = bytesToArray(bytes)
386
+ const needle = bytesToArray(sep)
387
+
388
+ if (needle.length === 0) {
389
+ // Special case: empty separator counts code points + 1
390
+ // For now, just return length + 1 (ASCII assumption)
391
+ return haystack.length + 1
392
+ }
393
+
394
+ let count = 0
395
+ let pos = 0
396
+
397
+ while (pos <= haystack.length - needle.length) {
398
+ let found = true
399
+ for (let i = 0; i < needle.length; i++) {
400
+ if (haystack[pos + i] !== needle[i]) {
401
+ found = false
402
+ break
403
+ }
404
+ }
405
+ if (found) {
406
+ count++
407
+ pos += needle.length
408
+ } else {
409
+ pos++
410
+ }
411
+ }
412
+
413
+ return count
414
+ }
415
+
416
+ // Math functions needed by various packages
417
+ export function min(a: number, b: number): number {
418
+ return Math.min(a, b)
419
+ }
420
+
421
+ export function max(a: number, b: number): number {
422
+ return Math.max(a, b)
423
+ }
424
+
425
+ // Panic recovery function (simplified implementation)
426
+ export function recover(): any {
427
+ // In a real implementation, this would interact with Go's panic/recover mechanism
428
+ // For now, return null to indicate no panic was recovered
429
+ return null
430
+ }
@@ -1041,7 +1041,8 @@ export const sliceString = (
1041
1041
  // Attempt to decode with strict UTF-8 validation
1042
1042
  const result = new TextDecoder('utf-8', { fatal: true }).decode(slicedBytes)
1043
1043
  return result
1044
- } catch (_e) { //eslint-disable-line @typescript-eslint/no-unused-vars
1044
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1045
+ } catch (_e) {
1045
1046
  // If we get here, the slice would create invalid UTF-8
1046
1047
  // This is a fundamental limitation of JavaScript string handling
1047
1048
  throw new Error(