goscript 0.0.39 → 0.0.40

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 (77) hide show
  1. package/compiler/analysis.go +15 -6
  2. package/compiler/compiler.go +184 -34
  3. package/compiler/expr-call.go +7 -9
  4. package/compiler/field.go +17 -3
  5. package/compiler/gs_dependencies_test.go +80 -0
  6. package/compiler/lit.go +1 -6
  7. package/compiler/output.go +10 -4
  8. package/compiler/spec.go +15 -2
  9. package/compiler/type-assert.go +111 -21
  10. package/compiler/type.go +37 -8
  11. package/dist/gs/builtin/builtin.d.ts +10 -0
  12. package/dist/gs/builtin/builtin.js +16 -0
  13. package/dist/gs/builtin/builtin.js.map +1 -1
  14. package/dist/gs/builtin/slice.js +13 -0
  15. package/dist/gs/builtin/slice.js.map +1 -1
  16. package/dist/gs/bytes/bytes.gs.js +110 -14
  17. package/dist/gs/bytes/bytes.gs.js.map +1 -1
  18. package/dist/gs/fmt/fmt.d.ts +49 -0
  19. package/dist/gs/fmt/fmt.js +322 -0
  20. package/dist/gs/fmt/fmt.js.map +1 -0
  21. package/dist/gs/fmt/index.d.ts +1 -0
  22. package/dist/gs/fmt/index.js +2 -0
  23. package/dist/gs/fmt/index.js.map +1 -0
  24. package/dist/gs/path/filepath/index.d.ts +3 -0
  25. package/dist/gs/path/filepath/index.js +3 -0
  26. package/dist/gs/path/filepath/index.js.map +1 -0
  27. package/dist/gs/path/filepath/match.d.ts +3 -0
  28. package/dist/gs/path/filepath/match.js +212 -0
  29. package/dist/gs/path/filepath/match.js.map +1 -0
  30. package/dist/gs/path/filepath/path.d.ts +25 -0
  31. package/dist/gs/path/filepath/path.js +265 -0
  32. package/dist/gs/path/filepath/path.js.map +1 -0
  33. package/dist/gs/reflect/value.js +13 -5
  34. package/dist/gs/reflect/value.js.map +1 -1
  35. package/dist/gs/sort/index.d.ts +4 -0
  36. package/dist/gs/sort/index.js +4 -0
  37. package/dist/gs/sort/index.js.map +1 -0
  38. package/dist/gs/sort/search.gs.d.ts +6 -0
  39. package/dist/gs/sort/search.gs.js +125 -0
  40. package/dist/gs/sort/search.gs.js.map +1 -0
  41. package/dist/gs/sort/slice.gs.d.ts +4 -0
  42. package/dist/gs/sort/slice.gs.js +49 -0
  43. package/dist/gs/sort/slice.gs.js.map +1 -0
  44. package/dist/gs/sort/sort.gs.d.ts +37 -0
  45. package/dist/gs/sort/sort.gs.js +203 -0
  46. package/dist/gs/sort/sort.gs.js.map +1 -0
  47. package/gs/builtin/builtin.ts +17 -0
  48. package/gs/builtin/slice.ts +17 -1
  49. package/gs/bytes/bytes.gs.ts +122 -14
  50. package/gs/bytes/metadata.go +12 -0
  51. package/gs/fmt/fmt.ts +407 -0
  52. package/gs/fmt/godoc.txt +382 -0
  53. package/gs/fmt/index.ts +31 -0
  54. package/gs/fmt/metadata.go +7 -0
  55. package/gs/internal/metadata.go +7 -0
  56. package/gs/io/metadata.go +11 -0
  57. package/gs/maps/metadata.go +8 -0
  58. package/gs/math/metadata.go +7 -0
  59. package/gs/os/metadata.go +17 -0
  60. package/gs/path/filepath/godoc.txt +35 -0
  61. package/gs/path/filepath/index.ts +27 -0
  62. package/gs/path/filepath/match.test.ts +274 -0
  63. package/gs/path/filepath/match.ts +249 -0
  64. package/gs/path/filepath/path.test.ts +246 -0
  65. package/gs/path/filepath/path.ts +328 -0
  66. package/gs/path/metadata.go +8 -0
  67. package/gs/reflect/metadata.go +7 -0
  68. package/gs/reflect/value.ts +13 -5
  69. package/gs/sort/godoc.txt +27 -0
  70. package/gs/sort/index.ts +24 -0
  71. package/gs/sort/search.gs.ts +128 -0
  72. package/gs/sort/slice.gs.ts +59 -0
  73. package/gs/sort/sort.gs.ts +227 -0
  74. package/gs/strconv/metadata.go +7 -0
  75. package/gs/strings/metadata.go +11 -0
  76. package/gs/sync/metadata.go +7 -0
  77. package/package.json +1 -1
@@ -0,0 +1,203 @@
1
+ import * as $ from '../builtin/builtin.js';
2
+ // IntSlice type for sorting integers
3
+ export class IntSlice {
4
+ _value;
5
+ constructor(_value) {
6
+ this._value = _value;
7
+ }
8
+ Len() {
9
+ return $.len(this._value);
10
+ }
11
+ Less(i, j) {
12
+ return $.index(this._value, i) < $.index(this._value, j);
13
+ }
14
+ Swap(i, j) {
15
+ const temp = $.index(this._value, i);
16
+ if (Array.isArray(this._value)) {
17
+ this._value[i] = $.index(this._value, j);
18
+ this._value[j] = temp;
19
+ }
20
+ else if (this._value && typeof this._value === 'object' && '__meta__' in this._value) {
21
+ const meta = this._value.__meta__;
22
+ const backing = meta.backing;
23
+ backing[meta.offset + i] = $.index(this._value, j);
24
+ backing[meta.offset + j] = temp;
25
+ }
26
+ }
27
+ }
28
+ // Float64Slice type for sorting float64s
29
+ export class Float64Slice {
30
+ _value;
31
+ constructor(_value) {
32
+ this._value = _value;
33
+ }
34
+ Len() {
35
+ return $.len(this._value);
36
+ }
37
+ Less(i, j) {
38
+ return $.index(this._value, i) < $.index(this._value, j);
39
+ }
40
+ Swap(i, j) {
41
+ const temp = $.index(this._value, i);
42
+ if (Array.isArray(this._value)) {
43
+ this._value[i] = $.index(this._value, j);
44
+ this._value[j] = temp;
45
+ }
46
+ else if (this._value && typeof this._value === 'object' && '__meta__' in this._value) {
47
+ const meta = this._value.__meta__;
48
+ const backing = meta.backing;
49
+ backing[meta.offset + i] = $.index(this._value, j);
50
+ backing[meta.offset + j] = temp;
51
+ }
52
+ }
53
+ }
54
+ // StringSlice type for sorting strings
55
+ export class StringSlice {
56
+ _value;
57
+ constructor(_value) {
58
+ this._value = _value;
59
+ }
60
+ Len() {
61
+ return $.len(this._value);
62
+ }
63
+ Less(i, j) {
64
+ return $.index(this._value, i) < $.index(this._value, j);
65
+ }
66
+ Swap(i, j) {
67
+ const temp = $.index(this._value, i);
68
+ if (Array.isArray(this._value)) {
69
+ this._value[i] = $.index(this._value, j);
70
+ this._value[j] = temp;
71
+ }
72
+ else if (this._value && typeof this._value === 'object' && '__meta__' in this._value) {
73
+ const meta = this._value.__meta__;
74
+ const backing = meta.backing;
75
+ backing[meta.offset + i] = $.index(this._value, j);
76
+ backing[meta.offset + j] = temp;
77
+ }
78
+ }
79
+ }
80
+ // Sort sorts data in ascending order as determined by the Less method
81
+ export function Sort(data) {
82
+ // Use a simple insertion sort for now - can be optimized later
83
+ const n = data.Len();
84
+ for (let i = 1; i < n; i++) {
85
+ for (let j = i; j > 0 && data.Less(j, j - 1); j--) {
86
+ data.Swap(j, j - 1);
87
+ }
88
+ }
89
+ }
90
+ // Stable sorts data while keeping the original order of equal elements
91
+ export function Stable(data) {
92
+ // For simplicity, use the same sort - can be improved later
93
+ Sort(data);
94
+ }
95
+ // IsSorted reports whether data is sorted
96
+ export function IsSorted(data) {
97
+ const n = data.Len();
98
+ for (let i = n - 1; i > 0; i--) {
99
+ if (data.Less(i, i - 1)) {
100
+ return false;
101
+ }
102
+ }
103
+ return true;
104
+ }
105
+ // Reverse returns the reverse order for data
106
+ export function Reverse(data) {
107
+ return {
108
+ Len: () => data.Len(),
109
+ Less: (i, j) => data.Less(j, i),
110
+ Swap: (i, j) => data.Swap(i, j)
111
+ };
112
+ }
113
+ // Helper function to swap elements in a slice
114
+ function swapInSlice(slice, i, j) {
115
+ if (!slice)
116
+ return;
117
+ const temp = $.index(slice, i);
118
+ if (Array.isArray(slice)) {
119
+ const val_j = $.index(slice, j);
120
+ const val_i = temp;
121
+ slice[i] = val_j;
122
+ slice[j] = val_i;
123
+ }
124
+ else if (typeof slice === 'object' && '__meta__' in slice) {
125
+ const meta = slice.__meta__;
126
+ const backing = meta.backing;
127
+ backing[meta.offset + i] = $.index(slice, j);
128
+ backing[meta.offset + j] = temp;
129
+ }
130
+ }
131
+ // Ints sorts a slice of ints in increasing order
132
+ export function Ints(x) {
133
+ if (!x)
134
+ return;
135
+ const n = $.len(x);
136
+ // Simple insertion sort
137
+ for (let i = 1; i < n; i++) {
138
+ for (let j = i; j > 0 && $.index(x, j) < $.index(x, j - 1); j--) {
139
+ swapInSlice(x, j, j - 1);
140
+ }
141
+ }
142
+ }
143
+ // IntsAreSorted reports whether the slice x is sorted in increasing order
144
+ export function IntsAreSorted(x) {
145
+ if (!x)
146
+ return true;
147
+ const n = $.len(x);
148
+ for (let i = n - 1; i > 0; i--) {
149
+ if ($.index(x, i) < $.index(x, i - 1)) {
150
+ return false;
151
+ }
152
+ }
153
+ return true;
154
+ }
155
+ // Float64s sorts a slice of float64s in increasing order
156
+ export function Float64s(x) {
157
+ if (!x)
158
+ return;
159
+ const n = $.len(x);
160
+ // Simple insertion sort
161
+ for (let i = 1; i < n; i++) {
162
+ for (let j = i; j > 0 && $.index(x, j) < $.index(x, j - 1); j--) {
163
+ swapInSlice(x, j, j - 1);
164
+ }
165
+ }
166
+ }
167
+ // Float64sAreSorted reports whether the slice x is sorted in increasing order
168
+ export function Float64sAreSorted(x) {
169
+ if (!x)
170
+ return true;
171
+ const n = $.len(x);
172
+ for (let i = n - 1; i > 0; i--) {
173
+ if ($.index(x, i) < $.index(x, i - 1)) {
174
+ return false;
175
+ }
176
+ }
177
+ return true;
178
+ }
179
+ // Strings sorts a slice of strings in increasing order
180
+ export function Strings(x) {
181
+ if (!x)
182
+ return;
183
+ const n = $.len(x);
184
+ // Simple insertion sort
185
+ for (let i = 1; i < n; i++) {
186
+ for (let j = i; j > 0 && $.index(x, j) < $.index(x, j - 1); j--) {
187
+ swapInSlice(x, j, j - 1);
188
+ }
189
+ }
190
+ }
191
+ // StringsAreSorted reports whether the slice x is sorted in increasing order
192
+ export function StringsAreSorted(x) {
193
+ if (!x)
194
+ return true;
195
+ const n = $.len(x);
196
+ for (let i = n - 1; i > 0; i--) {
197
+ if ($.index(x, i) < $.index(x, i - 1)) {
198
+ return false;
199
+ }
200
+ }
201
+ return true;
202
+ }
203
+ //# sourceMappingURL=sort.gs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sort.gs.js","sourceRoot":"","sources":["../../../gs/sort/sort.gs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,C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AC;AAED,6EAA6E;AAC7E,MAAM,UAAU,gBAAgB,CAAC,CAAkB;IACjD,IAAI,CAAC,CAAC;QAAE,OAAO,IAAI,CAAA;IAEnB,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IAClB,KAAK,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC/B,IAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAY,GAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAY,EAAE,CAAC;YAC9D,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC"}
@@ -422,6 +422,23 @@ export function max(a: number, b: number): number {
422
422
  return Math.max(a, b)
423
423
  }
424
424
 
425
+ /**
426
+ * Converts a rune (number) or string to a string.
427
+ * This is used to replace String.fromCharCode() in Go string(rune) conversions.
428
+ * Since sometimes single-char rune literals are compiled to strings, this function
429
+ * needs to handle both numbers (runes) and strings.
430
+ *
431
+ * @param runeOrString A rune (Unicode code point as number) or a string
432
+ * @returns The resulting string
433
+ */
434
+ export function runeOrStringToString(runeOrString: number | string): string {
435
+ if (typeof runeOrString === 'string') {
436
+ return runeOrString
437
+ }
438
+ // For numbers, use String.fromCharCode to convert the rune to a string
439
+ return String.fromCharCode(runeOrString)
440
+ }
441
+
425
442
  // Panic recovery function (simplified implementation)
426
443
  export function recover(): any {
427
444
  // In a real implementation, this would interact with Go's panic/recover mechanism
@@ -192,6 +192,11 @@ export const makeSlice = <T>(
192
192
  // The rest of backingArr (from length to actualCapacity-1) remains uninitialized (undefined),
193
193
  // representing available capacity.
194
194
 
195
+ // OPTIMIZATION: If length equals capacity, return backing array directly
196
+ if (length === actualCapacity) {
197
+ return backingArr as Slice<T>
198
+ }
199
+
195
200
  // The proxyTargetArray serves as the shell for the proxy.
196
201
  // Its elements up to 'length' should reflect the initialized part of the slice.
197
202
  const proxyTargetArray = new Array<T>(length)
@@ -252,7 +257,7 @@ export const makeSlice = <T>(
252
257
  },
253
258
  }
254
259
 
255
- return new Proxy(proxy, handler) as Slice<T>
260
+ return new Proxy(proxy, handler) as unknown as SliceProxy<T>
256
261
  }
257
262
 
258
263
  /**
@@ -454,6 +459,11 @@ export const goSlice = <T>( // T can be number for Uint8Array case
454
459
  const newLength = high - low
455
460
  const newOffset = oldOffset + low
456
461
 
462
+ // OPTIMIZATION: If the result would have offset=0 and length=capacity, return backing directly
463
+ if (newOffset === 0 && newLength === newCap) {
464
+ return backing as Slice<T>
465
+ }
466
+
457
467
  // Create an array-like target with the correct length
458
468
  const proxyTargetArray = new Array<T>(newLength)
459
469
  // Note: We don't need to initialize the values here since the proxy handler
@@ -487,6 +497,12 @@ export const arrayToSlice = <T>(
487
497
 
488
498
  if (arr.length === 0) return arr
489
499
 
500
+ // OPTIMIZATION: For arrays where offset=0 and length=capacity, return the array directly
501
+ // if we're not doing deep conversion
502
+ if (depth === 1) {
503
+ return arr as Slice<T>
504
+ }
505
+
490
506
  const target = {
491
507
  __meta__: {
492
508
  backing: arr,
@@ -488,8 +488,36 @@ export function HasSuffix(s: $.Bytes, suffix: $.Bytes): boolean {
488
488
  // dropped from the byte slice with no replacement. The characters in s and the
489
489
  // output are interpreted as UTF-8-encoded code points.
490
490
  export function Map(mapping: ((r: number) => number) | null, s: $.Bytes): $.Bytes {
491
- // TODO: Implement Map function with proper UTF-8 handling
492
- throw new Error("Map: not implemented")
491
+ if (s === null || $.len(s) === 0 || mapping === null) {
492
+ return s === null ? null : new Uint8Array(0)
493
+ }
494
+
495
+ const result: number[] = []
496
+
497
+ for (let i = 0; i < $.len(s); ) {
498
+ const [r, size] = utf8.DecodeRune($.goSlice(s, i, undefined))
499
+ if (size <= 0) {
500
+ // Invalid UTF-8, copy the byte as-is
501
+ result.push(s![i])
502
+ i++
503
+ } else {
504
+ const mappedR = mapping(r)
505
+ if (mappedR >= 0) {
506
+ // Encode the mapped rune back to bytes
507
+ const runeBytes = new Uint8Array(utf8.UTFMax)
508
+ const n = utf8.EncodeRune(runeBytes, mappedR)
509
+
510
+ // Add the encoded bytes to result
511
+ for (let j = 0; j < n; j++) {
512
+ result.push(runeBytes[j])
513
+ }
514
+ }
515
+
516
+ i += size
517
+ }
518
+ }
519
+
520
+ return new Uint8Array(result)
493
521
  }
494
522
 
495
523
  // Repeat returns a new byte slice consisting of count copies of b.
@@ -607,29 +635,51 @@ export function ToTitle(s: $.Bytes): $.Bytes {
607
635
  // ToUpperSpecial treats s as UTF-8-encoded bytes and returns a copy with all the Unicode letters mapped to their
608
636
  // upper case, giving priority to the special casing rules.
609
637
  export function ToUpperSpecial(c: unicode.SpecialCase, s: $.Bytes): $.Bytes {
610
- // TODO: Fix SpecialCase method calls
611
- throw new Error("ToUpperSpecial: not implemented")
638
+ // For now, ignore special case and fall back to regular ToUpper
639
+ return ToUpper(s)
612
640
  }
613
641
 
614
642
  // ToLowerSpecial treats s as UTF-8-encoded bytes and returns a copy with all the Unicode letters mapped to their
615
643
  // lower case, giving priority to the special casing rules.
616
644
  export function ToLowerSpecial(c: unicode.SpecialCase, s: $.Bytes): $.Bytes {
617
- // TODO: Fix SpecialCase method calls
618
- throw new Error("ToLowerSpecial: not implemented")
645
+ // For now, ignore special case and fall back to regular ToLower
646
+ return ToLower(s)
619
647
  }
620
648
 
621
649
  // ToTitleSpecial treats s as UTF-8-encoded bytes and returns a copy with all the Unicode letters mapped to their
622
650
  // title case, giving priority to the special casing rules.
623
651
  export function ToTitleSpecial(c: unicode.SpecialCase, s: $.Bytes): $.Bytes {
624
- // TODO: Fix SpecialCase method calls
625
- throw new Error("ToTitleSpecial: not implemented")
652
+ // For now, ignore special case and fall back to regular ToTitle
653
+ return ToTitle(s)
626
654
  }
627
655
 
628
656
  // ToValidUTF8 treats s as UTF-8-encoded bytes and returns a copy with each run of bytes
629
657
  // representing invalid UTF-8 replaced with the bytes in replacement, which may be empty.
630
658
  export function ToValidUTF8(s: $.Bytes, replacement: $.Bytes): $.Bytes {
631
- // TODO: Implement ToValidUTF8 with proper UTF-8 validation
632
- throw new Error("ToValidUTF8: not implemented")
659
+ if (s === null || $.len(s) === 0) {
660
+ return s === null ? null : new Uint8Array(0)
661
+ }
662
+
663
+ const result: number[] = []
664
+ const replacementArr = replacement ? $.bytesToArray(replacement) : []
665
+
666
+ for (let i = 0; i < $.len(s); ) {
667
+ const [r, size] = utf8.DecodeRune($.goSlice(s, i, undefined))
668
+ if (size <= 0 || r === utf8.RuneError) {
669
+ // Invalid UTF-8, replace with replacement bytes
670
+ for (const b of replacementArr) {
671
+ result.push(b)
672
+ }
673
+ i++
674
+ } else {
675
+ for (let j = 0; j < size; j++) {
676
+ result.push(s![i + j])
677
+ }
678
+ i += size
679
+ }
680
+ }
681
+
682
+ return new Uint8Array(result)
633
683
  }
634
684
 
635
685
  // isSeparator reports whether the rune could mark a word boundary.
@@ -659,8 +709,41 @@ export function isSeparator(r: number): boolean {
659
709
  // Deprecated: The rule Title uses for word boundaries does not handle Unicode
660
710
  // punctuation properly. Use golang.org/x/text/cases instead.
661
711
  export function Title(s: $.Bytes): $.Bytes {
662
- // TODO: Implement Title function properly
663
- throw new Error("Title: not implemented")
712
+ if (s === null || $.len(s) === 0) {
713
+ return s === null ? null : new Uint8Array(0)
714
+ }
715
+
716
+ const result: number[] = []
717
+ let prevIsSep = true // Start of string counts as separator
718
+
719
+ for (let i = 0; i < $.len(s); ) {
720
+ const [r, size] = utf8.DecodeRune($.goSlice(s, i, undefined))
721
+ if (size <= 0) {
722
+ // Invalid UTF-8, copy the byte as-is
723
+ result.push(s![i])
724
+ i++
725
+ prevIsSep = true
726
+ } else {
727
+ let transformedR = r
728
+ if (prevIsSep && unicode.IsLetter(r)) {
729
+ transformedR = unicode.ToTitle(r)
730
+ }
731
+
732
+ // Encode the (possibly transformed) rune back to bytes
733
+ const runeBytes = new Uint8Array(utf8.UTFMax)
734
+ const n = utf8.EncodeRune(runeBytes, transformedR)
735
+
736
+ // Add the encoded bytes to result
737
+ for (let j = 0; j < n; j++) {
738
+ result.push(runeBytes[j])
739
+ }
740
+
741
+ prevIsSep = isSeparator(r)
742
+ i += size
743
+ }
744
+ }
745
+
746
+ return new Uint8Array(result)
664
747
  }
665
748
 
666
749
  // TrimLeftFunc treats s as UTF-8-encoded bytes and returns a subslice of s by slicing off
@@ -1119,8 +1202,33 @@ export function ReplaceAll(s: $.Bytes, old: $.Bytes, _new: $.Bytes): $.Bytes {
1119
1202
  // are equal under simple Unicode case-folding, which is a more general
1120
1203
  // form of case-insensitivity.
1121
1204
  export function EqualFold(s: $.Bytes, t: $.Bytes): boolean {
1122
- // TODO: Implement EqualFold function properly (complex Unicode folding logic)
1123
- throw new Error("EqualFold: not implemented")
1205
+ if (s === null && t === null) return true
1206
+ if (s === null || t === null) return false
1207
+
1208
+ let si = 0, ti = 0
1209
+
1210
+ while (si < $.len(s) && ti < $.len(t)) {
1211
+ const [sr, ssize] = utf8.DecodeRune($.goSlice(s, si, undefined))
1212
+ const [tr, tsize] = utf8.DecodeRune($.goSlice(t, ti, undefined))
1213
+
1214
+ if (ssize <= 0 || tsize <= 0) {
1215
+ // Invalid UTF-8, fall back to byte comparison
1216
+ if (s![si] !== t![ti]) return false
1217
+ si++
1218
+ ti++
1219
+ } else {
1220
+ // Convert both to lowercase for comparison
1221
+ const sLower = unicode.ToLower(sr)
1222
+ const tLower = unicode.ToLower(tr)
1223
+
1224
+ if (sLower !== tLower) return false
1225
+
1226
+ si += ssize
1227
+ ti += tsize
1228
+ }
1229
+ }
1230
+
1231
+ return si === $.len(s) && ti === $.len(t)
1124
1232
  }
1125
1233
 
1126
1234
  // Index returns the index of the first instance of sep in s, or -1 if sep is not present in s.
@@ -0,0 +1,12 @@
1
+ package bytes
2
+
3
+ // GsDependencies lists the import paths that this gs/ package requires
4
+ // These dependencies will be automatically copied when this package is included
5
+ var GsDependencies = []string{
6
+ "errors",
7
+ "io",
8
+ "iter",
9
+ "unicode",
10
+ "unicode/utf8",
11
+ "unsafe",
12
+ }