goscript 0.2.5 → 0.2.7

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 (264) hide show
  1. package/cmd/goscript/cmd-compile.go +7 -0
  2. package/cmd/goscript/cmd_compile_test.go +83 -0
  3. package/compiler/compile-request.go +3 -0
  4. package/compiler/compiler-cache.go +828 -0
  5. package/compiler/compiler-cache_test.go +705 -0
  6. package/compiler/config.go +2 -0
  7. package/compiler/index.test.ts +26 -1
  8. package/compiler/index.ts +5 -0
  9. package/compiler/lowered-program.go +31 -20
  10. package/compiler/lowering.go +349 -93
  11. package/compiler/lowering_bench_test.go +1 -0
  12. package/compiler/override-facts.go +309 -8
  13. package/compiler/override-parity-verifier.go +45 -1
  14. package/compiler/override-parity-verifier_test.go +100 -0
  15. package/compiler/override-registry_test.go +1 -0
  16. package/compiler/package-graph.go +40 -12
  17. package/compiler/package-graph_test.go +29 -0
  18. package/compiler/runtime-contract.go +8 -0
  19. package/compiler/service.go +98 -11
  20. package/compiler/skeleton_test.go +110 -14
  21. package/compiler/typescript-emitter.go +120 -23
  22. package/dist/compiler/index.d.ts +2 -0
  23. package/dist/compiler/index.js +3 -0
  24. package/dist/compiler/index.js.map +1 -1
  25. package/dist/gs/builtin/builtin.d.ts +24 -33
  26. package/dist/gs/builtin/builtin.js +54 -61
  27. package/dist/gs/builtin/builtin.js.map +1 -1
  28. package/dist/gs/builtin/hostio.d.ts +1 -0
  29. package/dist/gs/builtin/hostio.js +1 -1
  30. package/dist/gs/builtin/hostio.js.map +1 -1
  31. package/dist/gs/builtin/index.d.ts +1 -0
  32. package/dist/gs/builtin/index.js +1 -0
  33. package/dist/gs/builtin/index.js.map +1 -1
  34. package/dist/gs/builtin/panic.d.ts +18 -0
  35. package/dist/gs/builtin/panic.js +98 -0
  36. package/dist/gs/builtin/panic.js.map +1 -0
  37. package/dist/gs/builtin/slice.d.ts +10 -0
  38. package/dist/gs/builtin/slice.js +110 -53
  39. package/dist/gs/builtin/slice.js.map +1 -1
  40. package/dist/gs/builtin/type.js +15 -3
  41. package/dist/gs/builtin/type.js.map +1 -1
  42. package/dist/gs/builtin/varRef.d.ts +1 -1
  43. package/dist/gs/builtin/varRef.js +3 -2
  44. package/dist/gs/builtin/varRef.js.map +1 -1
  45. package/dist/gs/bytes/bytes.gs.js +51 -38
  46. package/dist/gs/bytes/bytes.gs.js.map +1 -1
  47. package/dist/gs/bytes/reader.gs.d.ts +1 -1
  48. package/dist/gs/bytes/reader.gs.js +6 -7
  49. package/dist/gs/bytes/reader.gs.js.map +1 -1
  50. package/dist/gs/cmp/index.d.ts +1 -1
  51. package/dist/gs/cmp/index.js +43 -10
  52. package/dist/gs/cmp/index.js.map +1 -1
  53. package/dist/gs/context/context.d.ts +2 -2
  54. package/dist/gs/context/context.js +1 -1
  55. package/dist/gs/context/context.js.map +1 -1
  56. package/dist/gs/embed/index.js +1 -1
  57. package/dist/gs/embed/index.js.map +1 -1
  58. package/dist/gs/encoding/binary/index.js +201 -8
  59. package/dist/gs/encoding/binary/index.js.map +1 -1
  60. package/dist/gs/encoding/json/index.d.ts +5 -0
  61. package/dist/gs/encoding/json/index.js +388 -25
  62. package/dist/gs/encoding/json/index.js.map +1 -1
  63. package/dist/gs/errors/errors.js +17 -24
  64. package/dist/gs/errors/errors.js.map +1 -1
  65. package/dist/gs/fmt/fmt.js +129 -35
  66. package/dist/gs/fmt/fmt.js.map +1 -1
  67. package/dist/gs/golang.org/x/crypto/cryptobyte/index.js +1 -1
  68. package/dist/gs/golang.org/x/crypto/cryptobyte/index.js.map +1 -1
  69. package/dist/gs/internal/bytealg/index.js +43 -8
  70. package/dist/gs/internal/bytealg/index.js.map +1 -1
  71. package/dist/gs/internal/byteorder/index.d.ts +2 -2
  72. package/dist/gs/internal/byteorder/index.js +2 -2
  73. package/dist/gs/internal/byteorder/index.js.map +1 -1
  74. package/dist/gs/io/fs/format.js +2 -2
  75. package/dist/gs/io/fs/format.js.map +1 -1
  76. package/dist/gs/io/fs/fs.d.ts +1 -1
  77. package/dist/gs/io/fs/fs.js +1 -1
  78. package/dist/gs/io/fs/fs.js.map +1 -1
  79. package/dist/gs/io/io.d.ts +21 -21
  80. package/dist/gs/io/io.js +49 -50
  81. package/dist/gs/io/io.js.map +1 -1
  82. package/dist/gs/math/bits/index.js +26 -8
  83. package/dist/gs/math/bits/index.js.map +1 -1
  84. package/dist/gs/math/copysign.gs.js +10 -17
  85. package/dist/gs/math/copysign.gs.js.map +1 -1
  86. package/dist/gs/math/pow.gs.js +5 -0
  87. package/dist/gs/math/pow.gs.js.map +1 -1
  88. package/dist/gs/math/signbit.gs.js +6 -2
  89. package/dist/gs/math/signbit.gs.js.map +1 -1
  90. package/dist/gs/mime/index.js +1 -0
  91. package/dist/gs/mime/index.js.map +1 -1
  92. package/dist/gs/net/http/index.d.ts +6 -6
  93. package/dist/gs/net/http/index.js +507 -43
  94. package/dist/gs/net/http/index.js.map +1 -1
  95. package/dist/gs/os/stat.gs.d.ts +2 -2
  96. package/dist/gs/os/types.gs.d.ts +1 -1
  97. package/dist/gs/os/types.gs.js +1 -1
  98. package/dist/gs/os/types.gs.js.map +1 -1
  99. package/dist/gs/os/types_js.gs.d.ts +1 -1
  100. package/dist/gs/os/types_js.gs.js +7 -7
  101. package/dist/gs/os/types_js.gs.js.map +1 -1
  102. package/dist/gs/os/types_unix.gs.d.ts +1 -1
  103. package/dist/gs/os/types_unix.gs.js +1 -1
  104. package/dist/gs/os/types_unix.gs.js.map +1 -1
  105. package/dist/gs/os/zero_copy_posix.gs.d.ts +1 -1
  106. package/dist/gs/os/zero_copy_posix.gs.js +1 -1
  107. package/dist/gs/os/zero_copy_posix.gs.js.map +1 -1
  108. package/dist/gs/path/filepath/match.js +8 -4
  109. package/dist/gs/path/filepath/match.js.map +1 -1
  110. package/dist/gs/path/filepath/path.js +216 -42
  111. package/dist/gs/path/filepath/path.js.map +1 -1
  112. package/dist/gs/path/match.js +6 -3
  113. package/dist/gs/path/match.js.map +1 -1
  114. package/dist/gs/reflect/type.d.ts +5 -4
  115. package/dist/gs/reflect/type.js +29 -11
  116. package/dist/gs/reflect/type.js.map +1 -1
  117. package/dist/gs/slices/slices.js +11 -11
  118. package/dist/gs/slices/slices.js.map +1 -1
  119. package/dist/gs/strconv/atof.gs.js +156 -43
  120. package/dist/gs/strconv/atof.gs.js.map +1 -1
  121. package/dist/gs/strconv/atoi.gs.d.ts +3 -2
  122. package/dist/gs/strconv/atoi.gs.js +86 -67
  123. package/dist/gs/strconv/atoi.gs.js.map +1 -1
  124. package/dist/gs/strconv/ftoa.gs.js +73 -3
  125. package/dist/gs/strconv/ftoa.gs.js.map +1 -1
  126. package/dist/gs/strconv/itoa.gs.d.ts +4 -4
  127. package/dist/gs/strconv/itoa.gs.js +5 -4
  128. package/dist/gs/strconv/itoa.gs.js.map +1 -1
  129. package/dist/gs/strconv/quote.gs.d.ts +1 -1
  130. package/dist/gs/strconv/quote.gs.js +311 -103
  131. package/dist/gs/strconv/quote.gs.js.map +1 -1
  132. package/dist/gs/strings/reader.d.ts +1 -1
  133. package/dist/gs/strings/reader.js +8 -8
  134. package/dist/gs/strings/reader.js.map +1 -1
  135. package/dist/gs/strings/strings.js +87 -61
  136. package/dist/gs/strings/strings.js.map +1 -1
  137. package/dist/gs/sync/atomic/doc_64.gs.d.ts +14 -14
  138. package/dist/gs/sync/atomic/doc_64.gs.js +10 -10
  139. package/dist/gs/sync/atomic/doc_64.gs.js.map +1 -1
  140. package/dist/gs/sync/atomic/type.gs.d.ts +22 -22
  141. package/dist/gs/sync/atomic/type.gs.js +4 -4
  142. package/dist/gs/sync/atomic/type.gs.js.map +1 -1
  143. package/dist/gs/sync/sync.js +50 -12
  144. package/dist/gs/sync/sync.js.map +1 -1
  145. package/dist/gs/syscall/fs.d.ts +6 -6
  146. package/dist/gs/syscall/fs.js +1 -1
  147. package/dist/gs/syscall/fs.js.map +1 -1
  148. package/dist/gs/time/time.d.ts +18 -18
  149. package/dist/gs/time/time.js +58 -55
  150. package/dist/gs/time/time.js.map +1 -1
  151. package/dist/gs/unicode/tables.d.ts +11 -0
  152. package/dist/gs/unicode/tables.js +635 -0
  153. package/dist/gs/unicode/tables.js.map +1 -0
  154. package/dist/gs/unicode/unicode.d.ts +58 -38
  155. package/dist/gs/unicode/unicode.js +362 -278
  156. package/dist/gs/unicode/unicode.js.map +1 -1
  157. package/go.sum +13 -0
  158. package/gs/builtin/builtin.ts +83 -93
  159. package/gs/builtin/hostio.ts +1 -1
  160. package/gs/builtin/index.ts +1 -0
  161. package/gs/builtin/panic.test.ts +189 -0
  162. package/gs/builtin/panic.ts +107 -0
  163. package/gs/builtin/runtime-contract.test.ts +5 -5
  164. package/gs/builtin/slice.test.ts +23 -0
  165. package/gs/builtin/slice.ts +133 -95
  166. package/gs/builtin/type.ts +16 -3
  167. package/gs/builtin/varRef.ts +4 -2
  168. package/gs/builtin/wide-int.test.ts +41 -0
  169. package/gs/bytes/bytes.gs.ts +54 -41
  170. package/gs/bytes/bytes.test.ts +18 -1
  171. package/gs/bytes/reader.gs.ts +7 -8
  172. package/gs/cmp/index.test.ts +55 -0
  173. package/gs/cmp/index.ts +45 -9
  174. package/gs/context/context.ts +3 -3
  175. package/gs/embed/index.ts +2 -2
  176. package/gs/encoding/binary/index.test.ts +104 -0
  177. package/gs/encoding/binary/index.ts +259 -11
  178. package/gs/encoding/json/index.test.ts +107 -0
  179. package/gs/encoding/json/index.ts +400 -29
  180. package/gs/errors/errors.test.ts +44 -1
  181. package/gs/errors/errors.ts +15 -31
  182. package/gs/fmt/fmt.test.ts +70 -2
  183. package/gs/fmt/fmt.ts +128 -34
  184. package/gs/golang.org/x/crypto/cryptobyte/index.ts +1 -1
  185. package/gs/internal/bytealg/index.test.ts +26 -1
  186. package/gs/internal/bytealg/index.ts +44 -8
  187. package/gs/internal/byteorder/index.ts +6 -4
  188. package/gs/io/fs/format.ts +2 -2
  189. package/gs/io/fs/fs.ts +2 -2
  190. package/gs/io/fs/stat.test.ts +2 -2
  191. package/gs/io/fs/sub.test.ts +2 -2
  192. package/gs/io/fs/walk.test.ts +2 -2
  193. package/gs/io/io.test.ts +47 -5
  194. package/gs/io/io.ts +73 -73
  195. package/gs/io/limit.test.ts +103 -0
  196. package/gs/math/bits/index.test.ts +128 -0
  197. package/gs/math/bits/index.ts +26 -8
  198. package/gs/math/copysign.gs.test.ts +3 -1
  199. package/gs/math/copysign.gs.ts +10 -22
  200. package/gs/math/pow.gs.test.ts +4 -5
  201. package/gs/math/pow.gs.ts +5 -0
  202. package/gs/math/signbit.gs.test.ts +2 -1
  203. package/gs/math/signbit.gs.ts +6 -3
  204. package/gs/mime/index.ts +1 -0
  205. package/gs/net/http/index.test.ts +683 -2
  206. package/gs/net/http/index.ts +598 -57
  207. package/gs/net/http/meta.json +3 -0
  208. package/gs/os/stat.gs.ts +2 -2
  209. package/gs/os/types.gs.ts +2 -2
  210. package/gs/os/types_js.gs.ts +9 -9
  211. package/gs/os/types_unix.gs.ts +2 -2
  212. package/gs/os/zero_copy_posix.gs.ts +2 -2
  213. package/gs/path/filepath/match.test.ts +16 -0
  214. package/gs/path/filepath/match.ts +8 -4
  215. package/gs/path/filepath/path.test.ts +91 -9
  216. package/gs/path/filepath/path.ts +223 -49
  217. package/gs/path/match.test.ts +32 -0
  218. package/gs/path/match.ts +6 -3
  219. package/gs/reflect/deepequal.test.ts +1 -1
  220. package/gs/reflect/field.test.ts +1 -1
  221. package/gs/reflect/function-types.test.ts +6 -6
  222. package/gs/reflect/sliceat.test.ts +13 -13
  223. package/gs/reflect/structof.test.ts +4 -4
  224. package/gs/reflect/type.ts +34 -14
  225. package/gs/reflect/typefor.test.ts +5 -5
  226. package/gs/runtime/pprof/index.test.ts +20 -0
  227. package/gs/runtime/trace/index.test.ts +3 -0
  228. package/gs/slices/slices.test.ts +31 -0
  229. package/gs/slices/slices.ts +11 -11
  230. package/gs/strconv/append.test.ts +99 -0
  231. package/gs/strconv/atof.gs.ts +156 -42
  232. package/gs/strconv/atof.test.ts +45 -0
  233. package/gs/strconv/atoi.gs.ts +87 -69
  234. package/gs/strconv/atoi.test.ts +49 -0
  235. package/gs/strconv/ftoa.gs.ts +85 -10
  236. package/gs/strconv/ftoa.test.ts +43 -0
  237. package/gs/strconv/itoa.gs.ts +10 -9
  238. package/gs/strconv/quote.gs.ts +335 -108
  239. package/gs/strconv/quote.test.ts +111 -0
  240. package/gs/strings/reader.test.ts +10 -10
  241. package/gs/strings/reader.ts +9 -9
  242. package/gs/strings/strings.test.ts +18 -5
  243. package/gs/strings/strings.ts +81 -68
  244. package/gs/sync/atomic/doc_64.gs.ts +24 -24
  245. package/gs/sync/atomic/doc_64.test.ts +5 -5
  246. package/gs/sync/atomic/type.gs.ts +28 -28
  247. package/gs/sync/sync.test.ts +109 -1
  248. package/gs/sync/sync.ts +46 -12
  249. package/gs/syscall/fs.ts +8 -8
  250. package/gs/syscall/net.test.ts +1 -1
  251. package/gs/time/parse.test.ts +45 -0
  252. package/gs/time/time.test.ts +46 -23
  253. package/gs/time/time.ts +69 -66
  254. package/gs/unicode/gen.go +198 -0
  255. package/gs/unicode/tables.ts +646 -0
  256. package/gs/unicode/unicode.test.ts +69 -0
  257. package/gs/unicode/unicode.ts +396 -312
  258. package/package.json +2 -2
  259. package/dist/gs/github.com/aperturerobotics/util/conc/index.d.ts +0 -20
  260. package/dist/gs/github.com/aperturerobotics/util/conc/index.js +0 -134
  261. package/dist/gs/github.com/aperturerobotics/util/conc/index.js.map +0 -1
  262. package/gs/github.com/aperturerobotics/util/conc/index.test.ts +0 -30
  263. package/gs/github.com/aperturerobotics/util/conc/index.ts +0 -172
  264. package/gs/github.com/aperturerobotics/util/conc/meta.json +0 -9
package/gs/time/time.ts CHANGED
@@ -37,25 +37,25 @@ export class Time {
37
37
  }
38
38
 
39
39
  // Unix returns t as a Unix time, the number of seconds elapsed since January 1, 1970 UTC
40
- public Unix(): number {
41
- return Math.floor(this._date.getTime() / 1000)
40
+ public Unix(): bigint {
41
+ return BigInt(Math.floor(this._date.getTime() / 1000))
42
42
  }
43
43
 
44
44
  // UnixMilli returns t as a Unix time, the number of milliseconds elapsed since January 1, 1970 UTC
45
- public UnixMilli(): number {
46
- return this._date.getTime()
45
+ public UnixMilli(): bigint {
46
+ return BigInt(this._date.getTime())
47
47
  }
48
48
 
49
49
  // UnixMicro returns t as a Unix time, the number of microseconds elapsed since January 1, 1970 UTC
50
- public UnixMicro(): number {
50
+ public UnixMicro(): bigint {
51
51
  return (
52
- Math.floor(this._date.getTime() * 1000) + Math.floor(this._nsec / 1000)
52
+ BigInt(this._date.getTime()) * 1000n + BigInt(Math.floor(this._nsec / 1000))
53
53
  )
54
54
  }
55
55
 
56
56
  // UnixNano returns t as a Unix time, the number of nanoseconds elapsed since January 1, 1970 UTC
57
- public UnixNano(): number {
58
- return this._date.getTime() * 1000000 + this._nsec
57
+ public UnixNano(): bigint {
58
+ return BigInt(this._date.getTime()) * 1000000n + BigInt(this._nsec)
59
59
  }
60
60
 
61
61
  // Weekday returns the day of the week specified by t
@@ -553,7 +553,7 @@ export class Time {
553
553
  }
554
554
  }
555
555
 
556
- const seconds = BigInt(this.Unix()) + unixToInternalSeconds
556
+ const seconds = this.Unix() + unixToInternalSeconds
557
557
  const nanos = this.Nanosecond()
558
558
  const bytes = new Uint8Array(version === timeBinaryVersionV2 ? 16 : 15)
559
559
  bytes[0] = version
@@ -580,13 +580,13 @@ export class Time {
580
580
  // If both times have monotonic readings, use them for more accurate duration calculation
581
581
  if (this._monotonic !== undefined && u._monotonic !== undefined) {
582
582
  const diffNs = this._monotonic - u._monotonic
583
- return diffNs
583
+ return BigInt(diffNs)
584
584
  }
585
585
 
586
586
  // Fallback to Date-based calculation
587
587
  const diffMs = this._date.getTime() - u._date.getTime()
588
588
  const diffNs = this._nsec - u._nsec
589
- return diffMs * 1000000 + diffNs
589
+ return BigInt(diffMs) * 1000000n + BigInt(diffNs)
590
590
  }
591
591
 
592
592
  // Add adds the duration d to t, returning the sum
@@ -720,10 +720,12 @@ export class Time {
720
720
  }
721
721
 
722
722
  // Duration represents a span of time (nanoseconds)
723
- export type Duration = number
723
+ export type Duration = bigint
724
724
 
725
725
  const maxDuration = Number(9223372036854775807n)
726
726
  const minDuration = Number(-9223372036854775808n)
727
+ const maxDurationBig = 9223372036854775807n
728
+ const minDurationBig = -9223372036854775808n
727
729
  const maxTimerDelayMilliseconds = 0x7fffffff
728
730
  const millisecondsPerDay = 24 * 60 * 60 * 1000
729
731
  const unixToInternalSeconds = 62135596800n
@@ -777,38 +779,37 @@ export function Duration_multiply(
777
779
  receiver: Duration,
778
780
  multiplier: number,
779
781
  ): Duration {
780
- return durationNumber(receiver) * multiplier
782
+ return BigInt(Math.trunc(durationNumber(receiver) * multiplier))
781
783
  }
782
784
 
783
785
  export function Duration_Abs(receiver: Duration): Duration {
784
- const value = durationNumber(receiver)
785
- if (value >= 0) {
786
- return value
786
+ if (receiver >= 0n) {
787
+ return receiver
787
788
  }
788
- if (value === minDuration) {
789
- return maxDuration
789
+ if (receiver === minDurationBig) {
790
+ return maxDurationBig
790
791
  }
791
- return -value
792
+ return -receiver
792
793
  }
793
794
 
794
795
  export function Duration_Hours(receiver: Duration): number {
795
- return durationNumber(receiver) / Hour
796
+ return durationNumber(receiver) / 3.6e12
796
797
  }
797
798
 
798
- export function Duration_Microseconds(receiver: Duration): number {
799
- return Math.trunc(durationNumber(receiver) / Microsecond)
799
+ export function Duration_Microseconds(receiver: Duration): bigint {
800
+ return receiver / 1000n
800
801
  }
801
802
 
802
- export function Duration_Milliseconds(receiver: Duration): number {
803
- return Math.trunc(durationNumber(receiver) / Millisecond)
803
+ export function Duration_Milliseconds(receiver: Duration): bigint {
804
+ return receiver / 1000000n
804
805
  }
805
806
 
806
807
  export function Duration_Minutes(receiver: Duration): number {
807
- return durationNumber(receiver) / Minute
808
+ return durationNumber(receiver) / 6e10
808
809
  }
809
810
 
810
- export function Duration_Nanoseconds(receiver: Duration): number {
811
- return durationNumber(receiver)
811
+ export function Duration_Nanoseconds(receiver: Duration): bigint {
812
+ return receiver
812
813
  }
813
814
 
814
815
  export function Duration_Round(
@@ -818,30 +819,28 @@ export function Duration_Round(
818
819
  const value = durationNumber(receiver)
819
820
  const unit = durationNumber(multiple)
820
821
  if (unit <= 0) {
821
- return value
822
+ return receiver
822
823
  }
823
824
  const rounded =
824
825
  value >= 0 ?
825
826
  Math.floor(value / unit + 0.5) * unit
826
827
  : Math.ceil(value / unit - 0.5) * unit
827
- return Math.max(minDuration, Math.min(maxDuration, rounded))
828
+ return BigInt(Math.max(minDuration, Math.min(maxDuration, rounded)))
828
829
  }
829
830
 
830
831
  // Duration_Seconds returns the duration as a floating point number of seconds.
831
832
  export function Duration_Seconds(receiver: Duration): number {
832
- return durationNumber(receiver) / Second
833
+ return durationNumber(receiver) / 1e9
833
834
  }
834
835
 
835
836
  export function Duration_Truncate(
836
837
  receiver: Duration,
837
838
  multiple: Duration,
838
839
  ): Duration {
839
- const value = durationNumber(receiver)
840
- const unit = durationNumber(multiple)
841
- if (unit <= 0) {
842
- return value
840
+ if (multiple <= 0n) {
841
+ return receiver
843
842
  }
844
- return value - (value % unit)
843
+ return receiver - (receiver % multiple)
845
844
  }
846
845
 
847
846
  export function Duration_String(receiver: Duration): string {
@@ -851,15 +850,15 @@ export function Duration_String(receiver: Duration): string {
851
850
  }
852
851
  const sign = value < 0 ? '-' : ''
853
852
  let remaining = Math.abs(value)
854
- if (remaining < Second) {
853
+ if (remaining < 1e9) {
855
854
  return sign + formatSubsecond(remaining)
856
855
  }
857
- const hours = Math.floor(remaining / Hour)
858
- remaining -= hours * Hour
859
- const minutes = Math.floor(remaining / Minute)
860
- remaining -= minutes * Minute
861
- const seconds = Math.floor(remaining / Second)
862
- remaining -= seconds * Second
856
+ const hours = Math.floor(remaining / 3.6e12)
857
+ remaining -= hours * 3.6e12
858
+ const minutes = Math.floor(remaining / 6e10)
859
+ remaining -= minutes * 6e10
860
+ const seconds = Math.floor(remaining / 1e9)
861
+ remaining -= seconds * 1e9
863
862
 
864
863
  let out = sign
865
864
  if (hours !== 0) {
@@ -900,11 +899,11 @@ function formatSeconds(seconds: number, nanos: number): string {
900
899
  }
901
900
 
902
901
  function formatSubsecond(nanos: number): string {
903
- if (nanos >= Millisecond) {
904
- return formatUnit(nanos, Millisecond, 'ms')
902
+ if (nanos >= 1e6) {
903
+ return formatUnit(nanos, 1e6, 'ms')
905
904
  }
906
- if (nanos >= Microsecond) {
907
- return formatUnit(nanos, Microsecond, '\u00b5s')
905
+ if (nanos >= 1e3) {
906
+ return formatUnit(nanos, 1e3, '\u00b5s')
908
907
  }
909
908
  return `${nanos}ns`
910
909
  }
@@ -1184,12 +1183,12 @@ export function FixedZone(name: string, offset: number): Location {
1184
1183
  }
1185
1184
 
1186
1185
  // Common durations (matching Go's time package constants)
1187
- export const Nanosecond = 1
1188
- export const Microsecond = 1000
1189
- export const Millisecond = 1000000
1190
- export const Second = 1000000000
1191
- export const Minute = 60000000000
1192
- export const Hour = 3600000000000
1186
+ export const Nanosecond: Duration = 1n
1187
+ export const Microsecond: Duration = 1000n
1188
+ export const Millisecond: Duration = 1000000n
1189
+ export const Second: Duration = 1000000000n
1190
+ export const Minute: Duration = 60000000000n
1191
+ export const Hour: Duration = 3600000000000n
1193
1192
 
1194
1193
  // Since returns the time elapsed since t
1195
1194
  // Uses monotonic clock if available for accurate measurement
@@ -1255,31 +1254,35 @@ export const TimeOnly = '15:04:05'
1255
1254
 
1256
1255
  // Unix returns the local Time corresponding to the given Unix time,
1257
1256
  // sec seconds and nsec nanoseconds since January 1, 1970 UTC
1258
- export function Unix(sec: number, nsec: number = 0): Time {
1259
- const ms = sec * 1000 + Math.floor(nsec / 1000000)
1260
- const remainingNsec = nsec % 1000000
1257
+ export function Unix(sec: bigint, nsec: bigint = 0n): Time {
1258
+ const secNum = Number(sec)
1259
+ const nsecNum = Number(nsec)
1260
+ const ms = secNum * 1000 + Math.floor(nsecNum / 1000000)
1261
+ const remainingNsec = nsecNum % 1000000
1261
1262
  return Time.create(new globalThis.Date(ms), remainingNsec, undefined, UTC)
1262
1263
  }
1263
1264
 
1264
1265
  // UnixMilli returns the local Time corresponding to the given Unix time,
1265
1266
  // msec milliseconds since January 1, 1970 UTC
1266
- export function UnixMilli(msec: number): Time {
1267
- return Time.create(new globalThis.Date(msec), 0, undefined, UTC)
1267
+ export function UnixMilli(msec: bigint): Time {
1268
+ return Time.create(new globalThis.Date(Number(msec)), 0, undefined, UTC)
1268
1269
  }
1269
1270
 
1270
1271
  // UnixMicro returns the local Time corresponding to the given Unix time,
1271
1272
  // usec microseconds since January 1, 1970 UTC
1272
- export function UnixMicro(usec: number): Time {
1273
- const ms = Math.floor(usec / 1000)
1274
- const nsec = (usec % 1000) * 1000
1273
+ export function UnixMicro(usec: bigint): Time {
1274
+ const usecNum = Number(usec)
1275
+ const ms = Math.floor(usecNum / 1000)
1276
+ const nsec = (usecNum % 1000) * 1000
1275
1277
  return Time.create(new globalThis.Date(ms), nsec, undefined, UTC)
1276
1278
  }
1277
1279
 
1278
1280
  // UnixNano returns the local Time corresponding to the given Unix time,
1279
1281
  // nsec nanoseconds since January 1, 1970 UTC
1280
- export function UnixNano(nsec: number): Time {
1281
- const ms = Math.floor(nsec / 1000000)
1282
- const remainingNsec = nsec % 1000000
1282
+ export function UnixNano(nsec: bigint): Time {
1283
+ const nsecNum = Number(nsec)
1284
+ const ms = Math.floor(nsecNum / 1000000)
1285
+ const remainingNsec = nsecNum % 1000000
1283
1286
  return Time.create(new globalThis.Date(ms), remainingNsec, undefined, UTC)
1284
1287
  }
1285
1288
 
@@ -1291,7 +1294,7 @@ export function ParseDuration(s: string): [Duration, $.GoError] {
1291
1294
  const match = s.match(regex)
1292
1295
 
1293
1296
  if (!match) {
1294
- return [0, $.newError(`time: invalid duration "${s}"`)]
1297
+ return [0n, $.newError(`time: invalid duration "${s}"`)]
1295
1298
  }
1296
1299
 
1297
1300
  const [, sign, valueStr, unit] = match
@@ -1320,10 +1323,10 @@ export function ParseDuration(s: string): [Duration, $.GoError] {
1320
1323
  nanoseconds = value * 3600000000000
1321
1324
  break
1322
1325
  default:
1323
- return [0, $.newError(`time: unknown unit "${unit}" in duration "${s}"`)]
1326
+ return [0n, $.newError(`time: unknown unit "${unit}" in duration "${s}"`)]
1324
1327
  }
1325
1328
 
1326
- return [nanoseconds, null]
1329
+ return [BigInt(Math.trunc(nanoseconds)), null]
1327
1330
  }
1328
1331
 
1329
1332
  // Parse parses a formatted string and returns the time value it represents
@@ -0,0 +1,198 @@
1
+ //go:build ignore
2
+
3
+ // Command gen marshals Go's unicode package tables into gs/unicode/tables.ts as
4
+ // pure numeric data. The gs/unicode override constructs RangeTable/CaseRange
5
+ // objects and runs Go's lookup algorithms over this data, so the override stays
6
+ // byte-faithful to the Go reference across all of Unicode. Regenerate after a Go
7
+ // (Unicode version) bump with: go run gen.go > tables.ts
8
+ package main
9
+
10
+ import (
11
+ "fmt"
12
+ "os"
13
+ "sort"
14
+ "strings"
15
+ "unicode"
16
+ )
17
+
18
+ func main() {
19
+ var b strings.Builder
20
+ b.WriteString("// Code generated by gen.go; DO NOT EDIT.\n")
21
+ b.WriteString("// Unicode " + unicode.Version + " tables marshaled from Go's unicode package.\n")
22
+ b.WriteString("// Pure numeric data with no imports; gs/unicode/unicode.ts builds the objects.\n\n")
23
+ b.WriteString("export type RangeData = [Array<[number, number, number]>, Array<[number, number, number]>, number]\n\n")
24
+
25
+ writeTableMap(&b, "categoryData", toStringMap(unicode.Categories))
26
+ writeTableMap(&b, "scriptData", toStringMap(unicode.Scripts))
27
+ writeTableMap(&b, "propertyData", toStringMap(unicode.Properties))
28
+ writeTableMap(&b, "foldCategoryData", toStringMap(unicode.FoldCategory))
29
+ writeTableMap(&b, "foldScriptData", toStringMap(unicode.FoldScript))
30
+
31
+ writeCaseRanges(&b, "caseRangeData", unicode.CaseRanges)
32
+ writeCaseRanges(&b, "turkishCaseData", []unicode.CaseRange(unicode.TurkishCase))
33
+
34
+ writeAsciiFold(&b)
35
+ writeCaseOrbit(&b)
36
+ writeLatin1Props(&b)
37
+
38
+ if _, err := os.Stdout.WriteString(b.String()); err != nil {
39
+ fmt.Fprintln(os.Stderr, err)
40
+ os.Exit(1)
41
+ }
42
+ }
43
+
44
+ func toStringMap(m map[string]*unicode.RangeTable) map[string]*unicode.RangeTable {
45
+ return m
46
+ }
47
+
48
+ func sortedKeys(m map[string]*unicode.RangeTable) []string {
49
+ keys := make([]string, 0, len(m))
50
+ for k := range m {
51
+ keys = append(keys, k)
52
+ }
53
+ sort.Strings(keys)
54
+ return keys
55
+ }
56
+
57
+ func writeTableMap(b *strings.Builder, name string, m map[string]*unicode.RangeTable) {
58
+ fmt.Fprintf(b, "export const %s: Record<string, RangeData> = {\n", name)
59
+ for _, k := range sortedKeys(m) {
60
+ fmt.Fprintf(b, " %q: %s,\n", k, rangeTable(m[k]))
61
+ }
62
+ b.WriteString("}\n\n")
63
+ }
64
+
65
+ func rangeTable(t *unicode.RangeTable) string {
66
+ var r16 strings.Builder
67
+ r16.WriteByte('[')
68
+ for i, r := range t.R16 {
69
+ if i > 0 {
70
+ r16.WriteByte(',')
71
+ }
72
+ fmt.Fprintf(&r16, "[0x%x,0x%x,%d]", r.Lo, r.Hi, r.Stride)
73
+ }
74
+ r16.WriteByte(']')
75
+
76
+ var r32 strings.Builder
77
+ r32.WriteByte('[')
78
+ for i, r := range t.R32 {
79
+ if i > 0 {
80
+ r32.WriteByte(',')
81
+ }
82
+ fmt.Fprintf(&r32, "[0x%x,0x%x,%d]", r.Lo, r.Hi, r.Stride)
83
+ }
84
+ r32.WriteByte(']')
85
+
86
+ return fmt.Sprintf("[%s,%s,%d]", r16.String(), r32.String(), t.LatinOffset)
87
+ }
88
+
89
+ func writeCaseRanges(b *strings.Builder, name string, ranges []unicode.CaseRange) {
90
+ fmt.Fprintf(b, "export const %s: Array<[number, number, number, number, number]> = [\n", name)
91
+ for _, cr := range ranges {
92
+ fmt.Fprintf(b, " [0x%x,0x%x,%d,%d,%d],\n", cr.Lo, cr.Hi, int32(cr.Delta[0]), int32(cr.Delta[1]), int32(cr.Delta[2]))
93
+ }
94
+ b.WriteString("]\n\n")
95
+ }
96
+
97
+ func writeAsciiFold(b *strings.Builder) {
98
+ b.WriteString("export const asciiFold: number[] = [")
99
+ for r := rune(0); r <= unicode.MaxASCII; r++ {
100
+ if r > 0 {
101
+ b.WriteByte(',')
102
+ }
103
+ fmt.Fprintf(b, "0x%x", unicode.SimpleFold(r))
104
+ }
105
+ b.WriteString("]\n\n")
106
+ }
107
+
108
+ // writeCaseOrbit reconstructs Go's unexported caseOrbit table: every rune above
109
+ // ASCII whose SimpleFold result differs from the plain case-toggle fallback is an
110
+ // orbit entry. Go's SimpleFold consults this exact set before the case fallback.
111
+ func writeCaseOrbit(b *strings.Builder) {
112
+ b.WriteString("export const caseOrbitData: Array<[number, number]> = [\n")
113
+ for r := rune(unicode.MaxASCII + 1); r <= unicode.MaxRune; r++ {
114
+ fold := unicode.SimpleFold(r)
115
+ if fold == foldFallback(r) {
116
+ continue
117
+ }
118
+ fmt.Fprintf(b, " [0x%x,0x%x],\n", r, fold)
119
+ }
120
+ b.WriteString("]\n\n")
121
+ }
122
+
123
+ func foldFallback(r rune) rune {
124
+ if l := unicode.ToLower(r); l != r {
125
+ return l
126
+ }
127
+ return unicode.ToUpper(r)
128
+ }
129
+
130
+ // Latin1 property bits; these must stay in sync with the L1_* constants in
131
+ // unicode.ts. The table captures Go's predicate results for U+0000..U+00FF so the
132
+ // Latin1 fast paths match Go exactly without re-deriving its property masks.
133
+ const (
134
+ l1Control = 1 << 0
135
+ l1Letter = 1 << 1
136
+ l1Upper = 1 << 2
137
+ l1Lower = 1 << 3
138
+ l1Title = 1 << 4
139
+ l1Number = 1 << 5
140
+ l1Digit = 1 << 6
141
+ l1Mark = 1 << 7
142
+ l1Punct = 1 << 8
143
+ l1Symbol = 1 << 9
144
+ l1Space = 1 << 10
145
+ l1Graphic = 1 << 11
146
+ l1Print = 1 << 12
147
+ )
148
+
149
+ func writeLatin1Props(b *strings.Builder) {
150
+ b.WriteString("export const latin1Props: number[] = [")
151
+ for r := rune(0); r <= unicode.MaxLatin1; r++ {
152
+ if r > 0 {
153
+ b.WriteByte(',')
154
+ }
155
+ var bits int
156
+ if unicode.IsControl(r) {
157
+ bits |= l1Control
158
+ }
159
+ if unicode.IsLetter(r) {
160
+ bits |= l1Letter
161
+ }
162
+ if unicode.IsUpper(r) {
163
+ bits |= l1Upper
164
+ }
165
+ if unicode.IsLower(r) {
166
+ bits |= l1Lower
167
+ }
168
+ if unicode.IsTitle(r) {
169
+ bits |= l1Title
170
+ }
171
+ if unicode.IsNumber(r) {
172
+ bits |= l1Number
173
+ }
174
+ if unicode.IsDigit(r) {
175
+ bits |= l1Digit
176
+ }
177
+ if unicode.IsMark(r) {
178
+ bits |= l1Mark
179
+ }
180
+ if unicode.IsPunct(r) {
181
+ bits |= l1Punct
182
+ }
183
+ if unicode.IsSymbol(r) {
184
+ bits |= l1Symbol
185
+ }
186
+ if unicode.IsSpace(r) {
187
+ bits |= l1Space
188
+ }
189
+ if unicode.IsGraphic(r) {
190
+ bits |= l1Graphic
191
+ }
192
+ if unicode.IsPrint(r) {
193
+ bits |= l1Print
194
+ }
195
+ fmt.Fprintf(b, "0x%x", bits)
196
+ }
197
+ b.WriteString("]\n")
198
+ }