goscript 0.0.39 → 0.0.41

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 (421) hide show
  1. package/compiler/analysis.go +15 -6
  2. package/compiler/compiler.go +185 -35
  3. package/compiler/expr-call.go +7 -9
  4. package/compiler/expr-type.go +25 -0
  5. package/compiler/field.go +21 -7
  6. package/compiler/gs_dependencies_test.go +80 -0
  7. package/compiler/lit.go +1 -6
  8. package/compiler/output.go +10 -4
  9. package/compiler/spec.go +16 -3
  10. package/compiler/type-assert.go +111 -21
  11. package/compiler/type.go +56 -12
  12. package/dist/gs/builtin/builtin.d.ts +20 -8
  13. package/dist/gs/builtin/builtin.js +30 -53
  14. package/dist/gs/builtin/builtin.js.map +1 -1
  15. package/dist/gs/builtin/errors.d.ts +8 -0
  16. package/dist/gs/builtin/errors.js +18 -0
  17. package/dist/gs/builtin/errors.js.map +1 -0
  18. package/dist/gs/builtin/index.d.ts +7 -0
  19. package/dist/gs/builtin/index.js +7 -0
  20. package/dist/gs/builtin/index.js.map +1 -1
  21. package/dist/gs/builtin/slice.d.ts +5 -2
  22. package/dist/gs/builtin/slice.js +123 -77
  23. package/dist/gs/builtin/slice.js.map +1 -1
  24. package/dist/gs/bytes/buffer.gs.d.ts +1 -1
  25. package/dist/gs/bytes/buffer.gs.js +1 -1
  26. package/dist/gs/bytes/buffer.gs.js.map +1 -1
  27. package/dist/gs/bytes/bytes.gs.d.ts +1 -1
  28. package/dist/gs/bytes/bytes.gs.js +111 -15
  29. package/dist/gs/bytes/bytes.gs.js.map +1 -1
  30. package/dist/gs/bytes/iter.gs.d.ts +1 -1
  31. package/dist/gs/bytes/iter.gs.js +1 -1
  32. package/dist/gs/bytes/iter.gs.js.map +1 -1
  33. package/dist/gs/bytes/reader.gs.d.ts +1 -1
  34. package/dist/gs/bytes/reader.gs.js +1 -1
  35. package/dist/gs/bytes/reader.gs.js.map +1 -1
  36. package/dist/gs/context/context.d.ts +1 -1
  37. package/dist/gs/context/context.js +1 -1
  38. package/dist/gs/context/context.js.map +1 -1
  39. package/dist/gs/errors/errors.d.ts +1 -1
  40. package/dist/gs/errors/errors.js +3 -15
  41. package/dist/gs/errors/errors.js.map +1 -1
  42. package/dist/gs/fmt/fmt.d.ts +49 -0
  43. package/dist/gs/fmt/fmt.js +322 -0
  44. package/dist/gs/fmt/fmt.js.map +1 -0
  45. package/dist/gs/fmt/index.d.ts +1 -0
  46. package/dist/gs/fmt/index.js +2 -0
  47. package/dist/gs/fmt/index.js.map +1 -0
  48. package/dist/gs/github.com/pkg/errors/errors.d.ts +1 -1
  49. package/dist/gs/github.com/pkg/errors/errors.js +1 -1
  50. package/dist/gs/github.com/pkg/errors/errors.js.map +1 -1
  51. package/dist/gs/github.com/pkg/errors/go113.d.ts +1 -1
  52. package/dist/gs/github.com/pkg/errors/go113.js +1 -1
  53. package/dist/gs/github.com/pkg/errors/go113.js.map +1 -1
  54. package/dist/gs/github.com/pkg/errors/stack.d.ts +1 -1
  55. package/dist/gs/github.com/pkg/errors/stack.js +1 -1
  56. package/dist/gs/github.com/pkg/errors/stack.js.map +1 -1
  57. package/dist/gs/internal/byteorder/index.d.ts +1 -1
  58. package/dist/gs/internal/byteorder/index.js +1 -1
  59. package/dist/gs/internal/byteorder/index.js.map +1 -1
  60. package/dist/gs/internal/oserror/errors.d.ts +1 -1
  61. package/dist/gs/io/fs/format.js +1 -1
  62. package/dist/gs/io/fs/format.js.map +1 -1
  63. package/dist/gs/io/fs/fs.d.ts +1 -1
  64. package/dist/gs/io/fs/fs.js +1 -1
  65. package/dist/gs/io/fs/fs.js.map +1 -1
  66. package/dist/gs/io/fs/glob.d.ts +1 -1
  67. package/dist/gs/io/fs/glob.js +1 -1
  68. package/dist/gs/io/fs/glob.js.map +1 -1
  69. package/dist/gs/io/fs/readdir.d.ts +1 -1
  70. package/dist/gs/io/fs/readdir.js +1 -1
  71. package/dist/gs/io/fs/readdir.js.map +1 -1
  72. package/dist/gs/io/fs/readfile.d.ts +1 -1
  73. package/dist/gs/io/fs/readfile.js +1 -1
  74. package/dist/gs/io/fs/readfile.js.map +1 -1
  75. package/dist/gs/io/fs/stat.d.ts +1 -1
  76. package/dist/gs/io/fs/stat.js +1 -1
  77. package/dist/gs/io/fs/stat.js.map +1 -1
  78. package/dist/gs/io/fs/sub.d.ts +1 -1
  79. package/dist/gs/io/fs/sub.js +1 -1
  80. package/dist/gs/io/fs/sub.js.map +1 -1
  81. package/dist/gs/io/fs/walk.d.ts +1 -1
  82. package/dist/gs/io/fs/walk.js +1 -1
  83. package/dist/gs/io/fs/walk.js.map +1 -1
  84. package/dist/gs/io/io.d.ts +1 -1
  85. package/dist/gs/maps/iter.d.ts +1 -1
  86. package/dist/gs/maps/iter.js +1 -1
  87. package/dist/gs/maps/iter.js.map +1 -1
  88. package/dist/gs/maps/maps.d.ts +1 -1
  89. package/dist/gs/maps/maps.js +1 -1
  90. package/dist/gs/maps/maps.js.map +1 -1
  91. package/dist/gs/math/erfinv.gs.js +1 -1
  92. package/dist/gs/math/erfinv.gs.js.map +1 -1
  93. package/dist/gs/math/gamma.gs.js +1 -1
  94. package/dist/gs/math/gamma.gs.js.map +1 -1
  95. package/dist/gs/math/j0.gs.js +1 -1
  96. package/dist/gs/math/j0.gs.js.map +1 -1
  97. package/dist/gs/math/j1.gs.js +1 -1
  98. package/dist/gs/math/j1.gs.js.map +1 -1
  99. package/dist/gs/math/lgamma.gs.js +1 -1
  100. package/dist/gs/math/lgamma.gs.js.map +1 -1
  101. package/dist/gs/math/pow10.gs.js +1 -1
  102. package/dist/gs/math/pow10.gs.js.map +1 -1
  103. package/dist/gs/math/sin.gs.js +1 -1
  104. package/dist/gs/math/sin.gs.js.map +1 -1
  105. package/dist/gs/math/tan.gs.js +1 -1
  106. package/dist/gs/math/tan.gs.js.map +1 -1
  107. package/dist/gs/math/tanh.gs.js +1 -1
  108. package/dist/gs/math/tanh.gs.js.map +1 -1
  109. package/dist/gs/math/trig_reduce.gs.js +1 -1
  110. package/dist/gs/math/trig_reduce.gs.js.map +1 -1
  111. package/dist/gs/os/dir.gs.d.ts +1 -1
  112. package/dist/gs/os/dir_unix.gs.d.ts +1 -1
  113. package/dist/gs/os/dir_unix.gs.js +1 -1
  114. package/dist/gs/os/dir_unix.gs.js.map +1 -1
  115. package/dist/gs/os/dirent_js.gs.d.ts +1 -1
  116. package/dist/gs/os/env.gs.d.ts +1 -1
  117. package/dist/gs/os/env.gs.js +1 -1
  118. package/dist/gs/os/env.gs.js.map +1 -1
  119. package/dist/gs/os/error.gs.d.ts +1 -1
  120. package/dist/gs/os/error.gs.js +1 -1
  121. package/dist/gs/os/error.gs.js.map +1 -1
  122. package/dist/gs/os/exec.gs.d.ts +1 -1
  123. package/dist/gs/os/exec.gs.js +1 -1
  124. package/dist/gs/os/exec.gs.js.map +1 -1
  125. package/dist/gs/os/exec_posix.gs.d.ts +1 -1
  126. package/dist/gs/os/exec_posix.gs.js +1 -1
  127. package/dist/gs/os/exec_posix.gs.js.map +1 -1
  128. package/dist/gs/os/exec_unix.gs.d.ts +1 -1
  129. package/dist/gs/os/executable.gs.d.ts +1 -1
  130. package/dist/gs/os/executable_js.gs.d.ts +1 -1
  131. package/dist/gs/os/executable_wasm.gs.d.ts +1 -1
  132. package/dist/gs/os/file_constants_js.gs.d.ts +1 -1
  133. package/dist/gs/os/file_constants_js.gs.js +1 -1
  134. package/dist/gs/os/file_constants_js.gs.js.map +1 -1
  135. package/dist/gs/os/file_js.gs.d.ts +1 -1
  136. package/dist/gs/os/file_open_unix.gs.d.ts +1 -1
  137. package/dist/gs/os/file_posix_js.gs.d.ts +1 -1
  138. package/dist/gs/os/file_unix_js.gs.d.ts +1 -1
  139. package/dist/gs/os/getwd_js.gs.d.ts +1 -1
  140. package/dist/gs/os/path.gs.d.ts +1 -1
  141. package/dist/gs/os/path.gs.js +1 -1
  142. package/dist/gs/os/path.gs.js.map +1 -1
  143. package/dist/gs/os/path_unix.gs.js +1 -1
  144. package/dist/gs/os/path_unix.gs.js.map +1 -1
  145. package/dist/gs/os/pidfd_js.gs.d.ts +1 -1
  146. package/dist/gs/os/pipe_wasm.gs.d.ts +1 -1
  147. package/dist/gs/os/proc.gs.d.ts +1 -1
  148. package/dist/gs/os/proc.gs.js +1 -1
  149. package/dist/gs/os/proc.gs.js.map +1 -1
  150. package/dist/gs/os/proc_js.gs.d.ts +1 -1
  151. package/dist/gs/os/proc_js.gs.js +1 -1
  152. package/dist/gs/os/proc_js.gs.js.map +1 -1
  153. package/dist/gs/os/rawconn_js.gs.d.ts +1 -1
  154. package/dist/gs/os/removeall_js.gs.d.ts +1 -1
  155. package/dist/gs/os/root_js.gs.d.ts +1 -1
  156. package/dist/gs/os/root_js.gs.js +1 -1
  157. package/dist/gs/os/root_js.gs.js.map +1 -1
  158. package/dist/gs/os/root_nonwindows.gs.d.ts +1 -1
  159. package/dist/gs/os/root_noopenat.gs.d.ts +1 -1
  160. package/dist/gs/os/stat.gs.d.ts +1 -1
  161. package/dist/gs/os/stat_js.gs.d.ts +1 -1
  162. package/dist/gs/os/stat_unix_js.gs.d.ts +1 -1
  163. package/dist/gs/os/sys.gs.d.ts +1 -1
  164. package/dist/gs/os/sys_bsd.gs.d.ts +1 -1
  165. package/dist/gs/os/sys_js.gs.d.ts +1 -1
  166. package/dist/gs/os/tempfile.gs.d.ts +1 -1
  167. package/dist/gs/os/types.gs.d.ts +1 -1
  168. package/dist/gs/os/types.gs.js +1 -1
  169. package/dist/gs/os/types.gs.js.map +1 -1
  170. package/dist/gs/os/types_js.gs.d.ts +1 -1
  171. package/dist/gs/os/types_js.gs.js +1 -1
  172. package/dist/gs/os/types_js.gs.js.map +1 -1
  173. package/dist/gs/os/types_unix.gs.d.ts +1 -1
  174. package/dist/gs/os/types_unix.gs.js +1 -1
  175. package/dist/gs/os/types_unix.gs.js.map +1 -1
  176. package/dist/gs/os/zero_copy_posix.gs.d.ts +1 -1
  177. package/dist/gs/os/zero_copy_posix.gs.js +1 -1
  178. package/dist/gs/os/zero_copy_posix.gs.js.map +1 -1
  179. package/dist/gs/path/filepath/index.d.ts +3 -0
  180. package/dist/gs/path/filepath/index.js +3 -0
  181. package/dist/gs/path/filepath/index.js.map +1 -0
  182. package/dist/gs/path/filepath/match.d.ts +3 -0
  183. package/dist/gs/path/filepath/match.js +212 -0
  184. package/dist/gs/path/filepath/match.js.map +1 -0
  185. package/dist/gs/path/filepath/path.d.ts +26 -0
  186. package/dist/gs/path/filepath/path.js +266 -0
  187. package/dist/gs/path/filepath/path.js.map +1 -0
  188. package/dist/gs/path/match.d.ts +1 -1
  189. package/dist/gs/path/match.js +1 -1
  190. package/dist/gs/path/match.js.map +1 -1
  191. package/dist/gs/path/path.js +1 -1
  192. package/dist/gs/path/path.js.map +1 -1
  193. package/dist/gs/reflect/value.d.ts +1 -1
  194. package/dist/gs/reflect/value.js +14 -6
  195. package/dist/gs/reflect/value.js.map +1 -1
  196. package/dist/gs/reflect/visiblefields.d.ts +1 -1
  197. package/dist/gs/reflect/visiblefields.js +1 -1
  198. package/dist/gs/reflect/visiblefields.js.map +1 -1
  199. package/dist/gs/slices/slices.d.ts +1 -1
  200. package/dist/gs/slices/slices.js +1 -1
  201. package/dist/gs/slices/slices.js.map +1 -1
  202. package/dist/gs/sort/index.d.ts +4 -0
  203. package/dist/gs/sort/index.js +4 -0
  204. package/dist/gs/sort/index.js.map +1 -0
  205. package/dist/gs/sort/search.gs.d.ts +6 -0
  206. package/dist/gs/sort/search.gs.js +125 -0
  207. package/dist/gs/sort/search.gs.js.map +1 -0
  208. package/dist/gs/sort/slice.gs.d.ts +4 -0
  209. package/dist/gs/sort/slice.gs.js +49 -0
  210. package/dist/gs/sort/slice.gs.js.map +1 -0
  211. package/dist/gs/sort/sort.gs.d.ts +37 -0
  212. package/dist/gs/sort/sort.gs.js +203 -0
  213. package/dist/gs/sort/sort.gs.js.map +1 -0
  214. package/dist/gs/strconv/atob.gs.d.ts +1 -1
  215. package/dist/gs/strconv/atob.gs.js +1 -1
  216. package/dist/gs/strconv/atob.gs.js.map +1 -1
  217. package/dist/gs/strconv/atof.gs.d.ts +1 -1
  218. package/dist/gs/strconv/atoi.gs.d.ts +1 -1
  219. package/dist/gs/strconv/atoi.gs.js +5 -6
  220. package/dist/gs/strconv/atoi.gs.js.map +1 -1
  221. package/dist/gs/strconv/ftoa.gs.d.ts +1 -1
  222. package/dist/gs/strconv/ftoa.gs.js +1 -1
  223. package/dist/gs/strconv/ftoa.gs.js.map +1 -1
  224. package/dist/gs/strconv/itoa.gs.d.ts +1 -1
  225. package/dist/gs/strconv/itoa.gs.js +1 -1
  226. package/dist/gs/strconv/itoa.gs.js.map +1 -1
  227. package/dist/gs/strconv/quote.gs.d.ts +1 -1
  228. package/dist/gs/strconv/quote.gs.js +1 -1
  229. package/dist/gs/strconv/quote.gs.js.map +1 -1
  230. package/dist/gs/strings/builder.d.ts +1 -1
  231. package/dist/gs/strings/builder.js +1 -1
  232. package/dist/gs/strings/builder.js.map +1 -1
  233. package/dist/gs/strings/iter.js +1 -1
  234. package/dist/gs/strings/iter.js.map +1 -1
  235. package/dist/gs/strings/reader.d.ts +1 -1
  236. package/dist/gs/strings/reader.js +7 -8
  237. package/dist/gs/strings/reader.js.map +1 -1
  238. package/dist/gs/strings/replace.d.ts +1 -1
  239. package/dist/gs/strings/replace.js +1 -1
  240. package/dist/gs/strings/replace.js.map +1 -1
  241. package/dist/gs/strings/strings.d.ts +1 -1
  242. package/dist/gs/strings/strings.js +1 -1
  243. package/dist/gs/strings/strings.js.map +1 -1
  244. package/dist/gs/sync/atomic/doc.gs.d.ts +1 -1
  245. package/dist/gs/sync/atomic/doc_64.gs.d.ts +1 -1
  246. package/dist/gs/sync/atomic/type.gs.d.ts +1 -1
  247. package/dist/gs/sync/atomic/type.gs.js +1 -1
  248. package/dist/gs/sync/atomic/type.gs.js.map +1 -1
  249. package/dist/gs/sync/atomic/value.gs.d.ts +1 -1
  250. package/dist/gs/sync/atomic/value.gs.js +1 -1
  251. package/dist/gs/sync/atomic/value.gs.js.map +1 -1
  252. package/dist/gs/syscall/index.d.ts +1 -1
  253. package/dist/gs/syscall/index.js +1 -1
  254. package/dist/gs/syscall/index.js.map +1 -1
  255. package/dist/gs/unicode/utf8/utf8.d.ts +1 -1
  256. package/dist/gs/unicode/utf8/utf8.js +1 -1
  257. package/dist/gs/unicode/utf8/utf8.js.map +1 -1
  258. package/gs/builtin/builtin.ts +33 -64
  259. package/gs/builtin/errors.ts +25 -0
  260. package/gs/builtin/index.ts +7 -0
  261. package/gs/builtin/slice.ts +142 -71
  262. package/gs/bytes/buffer.gs.ts +1 -1
  263. package/gs/bytes/bytes.gs.ts +123 -15
  264. package/gs/bytes/iter.gs.ts +1 -1
  265. package/gs/bytes/metadata.go +12 -0
  266. package/gs/bytes/reader.gs.ts +1 -1
  267. package/gs/context/context.ts +1 -1
  268. package/gs/errors/errors.ts +3 -16
  269. package/gs/fmt/fmt.ts +407 -0
  270. package/gs/fmt/godoc.txt +382 -0
  271. package/gs/fmt/index.ts +31 -0
  272. package/gs/fmt/metadata.go +7 -0
  273. package/gs/github.com/pkg/errors/errors.ts +1 -1
  274. package/gs/github.com/pkg/errors/go113.ts +2 -2
  275. package/gs/github.com/pkg/errors/stack.ts +1 -1
  276. package/gs/internal/byteorder/index.ts +1 -1
  277. package/gs/internal/metadata.go +7 -0
  278. package/gs/internal/oserror/errors.ts +1 -1
  279. package/gs/io/fs/format.ts +1 -1
  280. package/gs/io/fs/fs.ts +1 -1
  281. package/gs/io/fs/glob.ts +1 -1
  282. package/gs/io/fs/readdir.ts +1 -1
  283. package/gs/io/fs/readfile.ts +1 -1
  284. package/gs/io/fs/stat.ts +1 -1
  285. package/gs/io/fs/sub.ts +1 -1
  286. package/gs/io/fs/walk.ts +1 -1
  287. package/gs/io/io.ts +1 -1
  288. package/gs/io/metadata.go +11 -0
  289. package/gs/maps/iter.ts +1 -1
  290. package/gs/maps/maps.ts +1 -1
  291. package/gs/maps/metadata.go +8 -0
  292. package/gs/math/abs.gs.ts +1 -1
  293. package/gs/math/acosh.gs.ts +1 -1
  294. package/gs/math/asinh.gs.ts +1 -1
  295. package/gs/math/atan.gs.ts +1 -1
  296. package/gs/math/atan2.gs.ts +1 -1
  297. package/gs/math/atanh.gs.ts +1 -1
  298. package/gs/math/bits.gs.ts +1 -1
  299. package/gs/math/cbrt.gs.ts +1 -1
  300. package/gs/math/const.gs.ts +1 -1
  301. package/gs/math/copysign.gs.ts +1 -1
  302. package/gs/math/dim.gs.ts +1 -1
  303. package/gs/math/erf.gs.ts +1 -1
  304. package/gs/math/erfinv.gs.ts +1 -1
  305. package/gs/math/exp.gs.ts +1 -1
  306. package/gs/math/expm1.gs.ts +1 -1
  307. package/gs/math/floor.gs.ts +1 -1
  308. package/gs/math/frexp.gs.ts +1 -1
  309. package/gs/math/gamma.gs.ts +1 -1
  310. package/gs/math/hypot.gs.ts +1 -1
  311. package/gs/math/j0.gs.ts +1 -1
  312. package/gs/math/j1.gs.ts +1 -1
  313. package/gs/math/jn.gs.ts +1 -1
  314. package/gs/math/ldexp.gs.ts +1 -1
  315. package/gs/math/lgamma.gs.ts +1 -1
  316. package/gs/math/log.gs.ts +1 -1
  317. package/gs/math/log10.gs.ts +1 -1
  318. package/gs/math/log1p.gs.ts +1 -1
  319. package/gs/math/logb.gs.ts +1 -1
  320. package/gs/math/metadata.go +7 -0
  321. package/gs/math/mod.gs.ts +1 -1
  322. package/gs/math/modf.gs.ts +1 -1
  323. package/gs/math/nextafter.gs.ts +1 -1
  324. package/gs/math/pow.gs.ts +1 -1
  325. package/gs/math/pow10.gs.ts +1 -1
  326. package/gs/math/remainder.gs.ts +1 -1
  327. package/gs/math/signbit.gs.ts +1 -1
  328. package/gs/math/sin.gs.ts +1 -1
  329. package/gs/math/sincos.gs.ts +1 -1
  330. package/gs/math/sinh.gs.ts +1 -1
  331. package/gs/math/sqrt.gs.ts +1 -1
  332. package/gs/math/tan.gs.ts +1 -1
  333. package/gs/math/tanh.gs.ts +1 -1
  334. package/gs/math/trig_reduce.gs.ts +1 -1
  335. package/gs/math/unsafe.gs.ts +1 -1
  336. package/gs/os/dir.gs.ts +1 -1
  337. package/gs/os/dir_unix.gs.ts +1 -1
  338. package/gs/os/dirent_js.gs.ts +1 -1
  339. package/gs/os/env.gs.ts +1 -1
  340. package/gs/os/error.gs.ts +1 -1
  341. package/gs/os/error_errno.gs.ts +1 -1
  342. package/gs/os/exec.gs.ts +1 -1
  343. package/gs/os/exec_nohandle.gs.ts +1 -1
  344. package/gs/os/exec_posix.gs.ts +1 -1
  345. package/gs/os/exec_unix.gs.ts +1 -1
  346. package/gs/os/executable.gs.ts +1 -1
  347. package/gs/os/executable_js.gs.ts +1 -1
  348. package/gs/os/executable_wasm.gs.ts +1 -1
  349. package/gs/os/file_constants_js.gs.ts +1 -1
  350. package/gs/os/file_js.gs.ts +1 -1
  351. package/gs/os/file_open_unix.gs.ts +1 -1
  352. package/gs/os/file_posix_js.gs.ts +1 -1
  353. package/gs/os/file_unix_js.gs.ts +1 -1
  354. package/gs/os/getwd_js.gs.ts +1 -1
  355. package/gs/os/metadata.go +17 -0
  356. package/gs/os/path.gs.ts +1 -1
  357. package/gs/os/path_unix.gs.ts +1 -1
  358. package/gs/os/pidfd_js.gs.ts +1 -1
  359. package/gs/os/pipe_wasm.gs.ts +1 -1
  360. package/gs/os/proc.gs.ts +1 -1
  361. package/gs/os/proc_js.gs.ts +1 -1
  362. package/gs/os/rawconn_js.gs.ts +1 -1
  363. package/gs/os/removeall_js.gs.ts +1 -1
  364. package/gs/os/root_js.gs.ts +1 -1
  365. package/gs/os/root_nonwindows.gs.ts +1 -1
  366. package/gs/os/root_noopenat.gs.ts +1 -1
  367. package/gs/os/stat.gs.ts +1 -1
  368. package/gs/os/stat_js.gs.ts +1 -1
  369. package/gs/os/stat_unix_js.gs.ts +1 -1
  370. package/gs/os/sticky_bsd.gs.ts +1 -1
  371. package/gs/os/sys.gs.ts +1 -1
  372. package/gs/os/sys_bsd.gs.ts +1 -1
  373. package/gs/os/sys_js.gs.ts +1 -1
  374. package/gs/os/tempfile.gs.ts +1 -1
  375. package/gs/os/types.gs.ts +1 -1
  376. package/gs/os/types_js.gs.ts +1 -1
  377. package/gs/os/types_unix.gs.ts +1 -1
  378. package/gs/os/wait_unimp.gs.ts +1 -1
  379. package/gs/os/zero_copy_posix.gs.ts +1 -1
  380. package/gs/os/zero_copy_stub.gs.ts +1 -1
  381. package/gs/path/filepath/godoc.txt +35 -0
  382. package/gs/path/filepath/index.ts +27 -0
  383. package/gs/path/filepath/match.test.ts +274 -0
  384. package/gs/path/filepath/match.ts +249 -0
  385. package/gs/path/filepath/path.test.ts +246 -0
  386. package/gs/path/filepath/path.ts +329 -0
  387. package/gs/path/match.ts +1 -1
  388. package/gs/path/metadata.go +8 -0
  389. package/gs/path/path.ts +1 -1
  390. package/gs/reflect/metadata.go +7 -0
  391. package/gs/reflect/value.ts +14 -6
  392. package/gs/reflect/visiblefields.ts +1 -1
  393. package/gs/slices/slices.ts +1 -1
  394. package/gs/sort/godoc.txt +27 -0
  395. package/gs/sort/index.ts +24 -0
  396. package/gs/sort/search.gs.ts +128 -0
  397. package/gs/sort/slice.gs.ts +59 -0
  398. package/gs/sort/sort.gs.ts +227 -0
  399. package/gs/strconv/atob.gs.ts +1 -1
  400. package/gs/strconv/atof.gs.ts +1 -1
  401. package/gs/strconv/atoi.gs.ts +5 -6
  402. package/gs/strconv/doc.gs.ts +1 -1
  403. package/gs/strconv/ftoa.gs.ts +1 -1
  404. package/gs/strconv/itoa.gs.ts +1 -1
  405. package/gs/strconv/metadata.go +7 -0
  406. package/gs/strconv/quote.gs.ts +1 -1
  407. package/gs/strings/builder.ts +1 -1
  408. package/gs/strings/iter.ts +1 -1
  409. package/gs/strings/metadata.go +11 -0
  410. package/gs/strings/reader.ts +7 -9
  411. package/gs/strings/replace.ts +1 -1
  412. package/gs/strings/strings.ts +1 -1
  413. package/gs/sync/atomic/doc.gs.ts +1 -1
  414. package/gs/sync/atomic/doc_64.gs.ts +1 -1
  415. package/gs/sync/atomic/type.gs.ts +1 -1
  416. package/gs/sync/atomic/value.gs.ts +1 -1
  417. package/gs/sync/metadata.go +7 -0
  418. package/gs/syscall/index.ts +1 -1
  419. package/gs/unicode/utf8/utf8.ts +1 -1
  420. package/package.json +3 -3
  421. package/gs/builtin/io.ts +0 -22
@@ -0,0 +1,246 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import {
3
+ Base,
4
+ Dir,
5
+ Ext,
6
+ Clean,
7
+ Join,
8
+ Split,
9
+ IsAbs,
10
+ ToSlash,
11
+ FromSlash,
12
+ VolumeName,
13
+ IsLocal,
14
+ SplitList,
15
+ HasPrefix,
16
+ Abs,
17
+ Rel,
18
+ EvalSymlinks,
19
+ Separator,
20
+ ListSeparator,
21
+ } from './path.js'
22
+
23
+ describe('path/filepath - Path manipulation functions', () => {
24
+ describe('Base', () => {
25
+ it('should return the last element of path', () => {
26
+ expect(Base('dir/subdir/file.txt')).toBe('file.txt')
27
+ expect(Base('/usr/bin/ls')).toBe('ls')
28
+ expect(Base('file.txt')).toBe('file.txt')
29
+ expect(Base('/')).toBe('/')
30
+ expect(Base('')).toBe('.')
31
+ expect(Base('//')).toBe('/')
32
+ expect(Base('dir/')).toBe('dir')
33
+ expect(Base('dir//')).toBe('dir')
34
+ })
35
+ })
36
+
37
+ describe('Dir', () => {
38
+ it('should return directory portion of path', () => {
39
+ expect(Dir('dir/subdir/file.txt')).toBe('dir/subdir')
40
+ expect(Dir('/usr/bin/ls')).toBe('/usr/bin')
41
+ expect(Dir('file.txt')).toBe('.')
42
+ expect(Dir('/')).toBe('/')
43
+ expect(Dir('')).toBe('.')
44
+ expect(Dir('/file')).toBe('/')
45
+ expect(Dir('dir/')).toBe('.')
46
+ })
47
+ })
48
+
49
+ describe('Ext', () => {
50
+ it('should return file extension', () => {
51
+ expect(Ext('file.txt')).toBe('.txt')
52
+ expect(Ext('file.tar.gz')).toBe('.gz')
53
+ expect(Ext('file')).toBe('')
54
+ expect(Ext('.hidden')).toBe('')
55
+ expect(Ext('dir/file.txt')).toBe('.txt')
56
+ expect(Ext('')).toBe('')
57
+ })
58
+ })
59
+
60
+ describe('Clean', () => {
61
+ it('should clean up path by resolving . and .. elements', () => {
62
+ expect(Clean('dir//subdir/../subdir/./file.txt')).toBe(
63
+ 'dir/subdir/file.txt',
64
+ )
65
+ expect(Clean('/dir/../file')).toBe('/file')
66
+ expect(Clean('./file')).toBe('file')
67
+ expect(Clean('../file')).toBe('../file')
68
+ expect(Clean('dir/..')).toBe('.')
69
+ expect(Clean('/dir/..')).toBe('/')
70
+ expect(Clean('')).toBe('.')
71
+ expect(Clean('/')).toBe('/')
72
+ expect(Clean('///')).toBe('/')
73
+ })
74
+ })
75
+
76
+ describe('Join', () => {
77
+ it('should join path elements with separator', () => {
78
+ expect(Join('dir', 'subdir', 'file.txt')).toBe('dir/subdir/file.txt')
79
+ expect(Join('/usr', 'bin', 'ls')).toBe('/usr/bin/ls')
80
+ expect(Join('', 'file')).toBe('file')
81
+ expect(Join('dir', '', 'file')).toBe('dir/file')
82
+ expect(Join()).toBe('')
83
+ expect(Join('', '', '')).toBe('')
84
+ })
85
+ })
86
+
87
+ describe('Split', () => {
88
+ it('should split path into directory and file', () => {
89
+ expect(Split('dir/subdir/file.txt')).toEqual(['dir/subdir/', 'file.txt'])
90
+ expect(Split('/usr/bin/ls')).toEqual(['/usr/bin/', 'ls'])
91
+ expect(Split('file.txt')).toEqual(['', 'file.txt'])
92
+ expect(Split('/')).toEqual(['/', ''])
93
+ expect(Split('')).toEqual(['', ''])
94
+ })
95
+ })
96
+
97
+ describe('IsAbs', () => {
98
+ it('should check if path is absolute', () => {
99
+ expect(IsAbs('/absolute/path')).toBe(true)
100
+ expect(IsAbs('relative/path')).toBe(false)
101
+ expect(IsAbs('/')).toBe(true)
102
+ expect(IsAbs('')).toBe(false)
103
+ expect(IsAbs('./relative')).toBe(false)
104
+ })
105
+ })
106
+
107
+ describe('ToSlash', () => {
108
+ it('should preserve path on Unix systems (backslashes are regular chars)', () => {
109
+ // On Unix systems, ToSlash doesn't convert backslashes because they're not separators
110
+ expect(ToSlash('dir\\subdir\\file.txt')).toBe('dir\\subdir\\file.txt')
111
+ expect(ToSlash('dir/subdir/file.txt')).toBe('dir/subdir/file.txt')
112
+ expect(ToSlash('')).toBe('')
113
+ })
114
+ })
115
+
116
+ describe('FromSlash', () => {
117
+ it('should preserve path on Unix systems', () => {
118
+ // On Unix systems, FromSlash doesn't change anything because separator is already '/'
119
+ expect(FromSlash('dir/subdir/file.txt')).toBe('dir/subdir/file.txt')
120
+ expect(FromSlash('')).toBe('')
121
+ })
122
+ })
123
+
124
+ describe('VolumeName', () => {
125
+ it('should return empty string on Unix systems', () => {
126
+ expect(VolumeName('C:\\Windows\\System32')).toBe('')
127
+ expect(VolumeName('/usr/local')).toBe('')
128
+ expect(VolumeName('')).toBe('')
129
+ })
130
+ })
131
+
132
+ describe('IsLocal', () => {
133
+ it('should check if path is local (not escaping)', () => {
134
+ expect(IsLocal('file.txt')).toBe(true)
135
+ expect(IsLocal('dir/file.txt')).toBe(true)
136
+ expect(IsLocal('../file.txt')).toBe(false)
137
+ expect(IsLocal('/absolute/path')).toBe(false)
138
+ expect(IsLocal('')).toBe(false)
139
+ expect(IsLocal('dir/../file')).toBe(true)
140
+ expect(IsLocal('dir/../../file')).toBe(false)
141
+ })
142
+ })
143
+
144
+ describe('SplitList', () => {
145
+ it('should split PATH-style lists', () => {
146
+ expect(SplitList('/usr/bin:/usr/local/bin:/bin')).toEqual([
147
+ '/usr/bin',
148
+ '/usr/local/bin',
149
+ '/bin',
150
+ ])
151
+ expect(SplitList('')).toEqual([])
152
+ expect(SplitList('/single/path')).toEqual(['/single/path'])
153
+ expect(SplitList('a:b:c')).toEqual(['a', 'b', 'c'])
154
+ })
155
+ })
156
+
157
+ describe('HasPrefix', () => {
158
+ it('should check if path has prefix', () => {
159
+ expect(HasPrefix('/usr/local/bin', '/usr/local')).toBe(true)
160
+ expect(HasPrefix('/usr/local', '/usr/local')).toBe(true)
161
+ expect(HasPrefix('/usr/local/bin', '/usr/bin')).toBe(false)
162
+ expect(HasPrefix('relative/path', 'relative')).toBe(true)
163
+ expect(HasPrefix('file.txt', '')).toBe(true)
164
+ expect(HasPrefix('', 'prefix')).toBe(false)
165
+ })
166
+ })
167
+
168
+ describe('Abs', () => {
169
+ it('should handle absolute paths', () => {
170
+ const [result1, err1] = Abs('/absolute/path')
171
+ expect(err1).toBeNull()
172
+ expect(result1).toBe('/absolute/path')
173
+
174
+ const [result2, err2] = Abs('relative/path')
175
+ expect(err2).toBeNull()
176
+ expect(result2).toBe('/relative/path')
177
+ })
178
+ })
179
+
180
+ describe('Rel', () => {
181
+ it('should calculate relative path', () => {
182
+ const [result1, err1] = Rel('/usr/local', '/usr/local')
183
+ expect(err1).toBeNull()
184
+ expect(result1).toBe('.')
185
+
186
+ const [result2, err2] = Rel('/usr/local', '/usr/local/bin')
187
+ expect(err2).toBeNull()
188
+ expect(result2).toBe('bin')
189
+
190
+ const [result3, err3] = Rel('/usr/local', '/other/path')
191
+ expect(err3).toBeNull()
192
+ expect(result3).toBe('/other/path')
193
+ })
194
+ })
195
+
196
+ describe('EvalSymlinks', () => {
197
+ it('should return cleaned path (stubbed)', () => {
198
+ const [result, err] = EvalSymlinks('/path/with/../dots')
199
+ expect(err).toBeNull()
200
+ expect(result).toBe('/path/dots')
201
+ })
202
+ })
203
+
204
+ describe('Constants', () => {
205
+ it('should have correct separator constants', () => {
206
+ expect(Separator).toBe('/')
207
+ expect(ListSeparator).toBe(':')
208
+ })
209
+ })
210
+ })
211
+
212
+ describe('Complex path operations', () => {
213
+ it('should handle edge cases correctly', () => {
214
+ // Test Clean with complex paths
215
+ expect(Clean('/a/b/../c/./d/')).toBe('/a/c/d')
216
+ expect(Clean('a/b/../../c')).toBe('c')
217
+ expect(Clean('../../a/b')).toBe('../../a/b')
218
+
219
+ // Test Join with various inputs
220
+ expect(Join('/a', '../b', 'c')).toBe('/b/c')
221
+ expect(Join('a', '/b', 'c')).toBe('/b/c')
222
+
223
+ // Test Split edge cases
224
+ expect(Split('/a/')).toEqual(['/a/', ''])
225
+ expect(Split('//a')).toEqual(['//', 'a'])
226
+ })
227
+
228
+ it('should maintain path consistency', () => {
229
+ const testPaths = [
230
+ 'simple/path',
231
+ '/absolute/path',
232
+ 'path/with/../dots',
233
+ './relative/path',
234
+ '../../parent/path',
235
+ ]
236
+
237
+ for (const path of testPaths) {
238
+ const cleaned = Clean(path)
239
+ const [dir, file] = Split(cleaned)
240
+ const rejoined = dir + file
241
+
242
+ // Split and rejoin should preserve the cleaned path
243
+ expect(rejoined).toBe(cleaned)
244
+ }
245
+ })
246
+ })
@@ -0,0 +1,329 @@
1
+ // Package filepath implements utility routines for manipulating filename paths
2
+ // in a way compatible with the target operating system-defined file paths.
3
+ import * as $ from "@goscript/builtin/index.js"
4
+
5
+ // Path separator constants
6
+ export const Separator = '/'
7
+ export const ListSeparator = ':'
8
+
9
+ // Error constants
10
+ export const SkipDir = $.newError('skip this directory')
11
+ export const SkipAll = $.newError('skip everything and stop the walk')
12
+
13
+ // Base returns the last element of path.
14
+ // Trailing path separators are removed before extracting the last element.
15
+ // If the path is empty, Base returns ".".
16
+ // If the path consists entirely of separators, Base returns a single separator.
17
+ export function Base(path: string): string {
18
+ if (path === '') {
19
+ return '.'
20
+ }
21
+
22
+ // Strip trailing slashes
23
+ path = path.replace(/\/+$/, '')
24
+
25
+ if (path === '') {
26
+ return '/'
27
+ }
28
+
29
+ // Find the last slash
30
+ const i = path.lastIndexOf('/')
31
+ if (i >= 0) {
32
+ return path.substring(i + 1)
33
+ }
34
+
35
+ return path
36
+ }
37
+
38
+ // Dir returns all but the last element of path, typically the path's directory.
39
+ // After dropping the final element, Dir calls Clean on the path and trailing
40
+ // slashes are removed. If the path is empty, Dir returns ".".
41
+ // If the path consists entirely of separators, Dir returns a single separator.
42
+ export function Dir(path: string): string {
43
+ if (path === '') {
44
+ return '.'
45
+ }
46
+
47
+ // Strip trailing slashes
48
+ path = path.replace(/\/+$/, '')
49
+
50
+ if (path === '') {
51
+ return '/'
52
+ }
53
+
54
+ // Find the last slash
55
+ const i = path.lastIndexOf('/')
56
+ if (i >= 0) {
57
+ const dir = path.substring(0, i)
58
+ return Clean(dir === '' ? '/' : dir)
59
+ }
60
+
61
+ return '.'
62
+ }
63
+
64
+ // Ext returns the file name extension used by path.
65
+ // The extension is the suffix beginning at the final dot
66
+ // in the final element of path; it is empty if there is no dot.
67
+ export function Ext(path: string): string {
68
+ const base = Base(path)
69
+
70
+ // Handle special case: if the base starts with a dot and has no other dots,
71
+ // it's a hidden file with no extension
72
+ if (base.startsWith('.') && base.indexOf('.', 1) === -1) {
73
+ return ''
74
+ }
75
+
76
+ const i = base.lastIndexOf('.')
77
+ if (i >= 0) {
78
+ return base.substring(i)
79
+ }
80
+ return ''
81
+ }
82
+
83
+ // Clean returns the shortest path name equivalent to path
84
+ // by purely lexical processing.
85
+ export function Clean(path: string): string {
86
+ if (path === '') {
87
+ return '.'
88
+ }
89
+
90
+ const isAbs = path.startsWith('/')
91
+ const segments = path
92
+ .split('/')
93
+ .filter((segment) => segment !== '' && segment !== '.')
94
+ const result: string[] = []
95
+
96
+ for (const segment of segments) {
97
+ if (segment === '..') {
98
+ if (result.length > 0 && result[result.length - 1] !== '..') {
99
+ result.pop()
100
+ } else if (!isAbs) {
101
+ result.push('..')
102
+ }
103
+ } else {
104
+ result.push(segment)
105
+ }
106
+ }
107
+
108
+ let cleaned = result.join('/')
109
+ if (isAbs) {
110
+ cleaned = '/' + cleaned
111
+ }
112
+
113
+ return (
114
+ cleaned === '' ?
115
+ isAbs ? '/'
116
+ : '.'
117
+ : cleaned
118
+ )
119
+ }
120
+
121
+ // Join joins any number of path elements into a single path,
122
+ // separating them with an OS specific Separator. Empty elements
123
+ // are ignored. The result is Cleaned. However, if the argument
124
+ // list is empty or all its elements are empty, Join returns
125
+ // an empty string.
126
+ export function Join(...elem: string[]): string {
127
+ if (elem.length === 0) {
128
+ return ''
129
+ }
130
+
131
+ // Filter out empty elements but handle absolute paths
132
+ const parts: string[] = []
133
+
134
+ for (const e of elem) {
135
+ if (e === '') {
136
+ continue
137
+ }
138
+
139
+ // If this element is absolute, start over from here
140
+ if (IsAbs(e)) {
141
+ parts.length = 0 // Clear previous parts
142
+ parts.push(e)
143
+ } else {
144
+ parts.push(e)
145
+ }
146
+ }
147
+
148
+ if (parts.length === 0) {
149
+ return ''
150
+ }
151
+
152
+ return Clean(parts.join('/'))
153
+ }
154
+
155
+ // Split splits path immediately following the final Separator,
156
+ // separating it into a directory and file name component.
157
+ // If there is no Separator in path, Split returns an empty dir
158
+ // and file set to path. The returned values have the property
159
+ // that path = dir+file.
160
+ export function Split(path: string): [string, string] {
161
+ const i = path.lastIndexOf('/')
162
+ if (i < 0) {
163
+ return ['', path]
164
+ }
165
+ return [path.substring(0, i + 1), path.substring(i + 1)]
166
+ }
167
+
168
+ // IsAbs reports whether the path is absolute.
169
+ export function IsAbs(path: string): boolean {
170
+ return path.startsWith('/')
171
+ }
172
+
173
+ // ToSlash returns the result of replacing each separator character
174
+ // in path with a slash ('/') character. Multiple separators are
175
+ // replaced by multiple slashes.
176
+ export function ToSlash(path: string): string {
177
+ // On Unix-like systems (including our JS environment), the separator is already '/'
178
+ // so backslashes are just regular characters and should not be converted
179
+ // This matches Go's behavior on Unix systems
180
+ return path
181
+ }
182
+
183
+ // FromSlash returns the result of replacing each slash ('/') character
184
+ // in path with a separator character. Multiple slashes are replaced
185
+ // by multiple separators.
186
+ export function FromSlash(path: string): string {
187
+ // On Unix-like systems (including our JS environment), separator is '/'
188
+ // so no conversion needed
189
+ return path
190
+ }
191
+
192
+ // VolumeName returns leading volume name.
193
+ // Given "C:\foo\bar" it returns "C:" on Windows.
194
+ // Given "\\host\share\foo" it returns "\\host\share".
195
+ // On other systems, it returns "".
196
+ export function VolumeName(_path: string): string {
197
+ // In our JS environment, we don't have volume names
198
+ return ''
199
+ }
200
+
201
+ // IsLocal reports whether path, using lexical analysis only,
202
+ // has all of these properties:
203
+ // - is within the subtree rooted at the directory in which path is evaluated
204
+ // - is not an absolute path
205
+ // - is not empty
206
+ // - on Windows, is not a reserved name such as "NUL"
207
+ export function IsLocal(path: string): boolean {
208
+ if (path === '' || IsAbs(path)) {
209
+ return false
210
+ }
211
+
212
+ // Check for .. components that would escape
213
+ const segments = path.split('/')
214
+ let depth = 0
215
+
216
+ for (const segment of segments) {
217
+ if (segment === '..') {
218
+ depth--
219
+ if (depth < 0) {
220
+ return false
221
+ }
222
+ } else if (segment !== '.' && segment !== '') {
223
+ depth++
224
+ }
225
+ }
226
+
227
+ return true
228
+ }
229
+
230
+ // SplitList splits a list of paths joined by the OS-specific ListSeparator,
231
+ // usually found in PATH or GOPATH environment variables.
232
+ // Unlike strings.Split, SplitList returns an empty slice when passed an empty string.
233
+ export function SplitList(path: string): string[] {
234
+ if (path === '') {
235
+ return []
236
+ }
237
+ return path.split(ListSeparator)
238
+ }
239
+
240
+ // HasPrefix tests whether the path p begins with prefix.
241
+ export function HasPrefix(p: string, prefix: string): boolean {
242
+ if (prefix === '') {
243
+ return true
244
+ }
245
+
246
+ // Normalize both paths
247
+ const normalP = Clean(p)
248
+ const normalPrefix = Clean(prefix)
249
+
250
+ if (normalP === normalPrefix) {
251
+ return true
252
+ }
253
+
254
+ // Check if p starts with prefix followed by a separator
255
+ if (normalP.startsWith(normalPrefix)) {
256
+ const remaining = normalP.substring(normalPrefix.length)
257
+ return remaining.startsWith('/')
258
+ }
259
+
260
+ return false
261
+ }
262
+
263
+ // Stubs for functions that require filesystem operations
264
+ // These are simplified implementations for compatibility
265
+
266
+ export function Abs(path: string): [string, $.GoError] {
267
+ if (IsAbs(path)) {
268
+ return [Clean(path), null]
269
+ }
270
+ // In a real implementation, this would resolve relative to current working directory
271
+ // For our purposes, we'll just prepend a fake absolute path
272
+ return ['/' + Clean(path), null]
273
+ }
274
+
275
+ export function Rel(
276
+ basepath: string,
277
+ targpath: string,
278
+ ): [string, $.GoError] {
279
+ // Simplified implementation - in reality this is much more complex
280
+ const base = Clean(basepath)
281
+ const targ = Clean(targpath)
282
+
283
+ if (base === targ) {
284
+ return ['.', null]
285
+ }
286
+
287
+ // Very basic relative path calculation
288
+ if (targ.startsWith(base + '/')) {
289
+ return [targ.substring(base.length + 1), null]
290
+ }
291
+
292
+ return [targ, null]
293
+ }
294
+
295
+ export function EvalSymlinks(path: string): [string, $.GoError] {
296
+ // No filesystem support, just return the cleaned path
297
+ return [Clean(path), null]
298
+ }
299
+
300
+ export function Glob(_pattern: string): [string[], $.GoError] {
301
+ // No filesystem support, return empty array
302
+ return [[], null]
303
+ }
304
+
305
+ // WalkFunc is the type of the function called for each file or directory
306
+ // visited by Walk. The path argument contains the argument to Walk as a
307
+ // prefix; that is, if Walk is called with "dir" and finds a file "a"
308
+ // in that directory, the walk function will be called with argument
309
+ // "dir/a". The info argument is the fs.FileInfo for the named path.
310
+ export type WalkFunc = (
311
+ path: string,
312
+ info: any,
313
+ err: $.GoError,
314
+ ) => $.GoError
315
+
316
+ export function Walk(root: string, walkFn: WalkFunc): $.GoError {
317
+ // No filesystem support, just call the function with the root
318
+ return walkFn(root, null, $.newError('filesystem not supported'))
319
+ }
320
+
321
+ export function WalkDir(_root: string, _walkFn: any): $.GoError {
322
+ // No filesystem support
323
+ return $.newError('filesystem not supported')
324
+ }
325
+
326
+ // Localize is a stub - in Go it's used for Windows path localization
327
+ export function Localize(path: string): [string, $.GoError] {
328
+ return [path, null]
329
+ }
package/gs/path/match.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as $ from '@goscript/builtin/builtin.js'
1
+ import * as $ from '@goscript/builtin/index.js'
2
2
 
3
3
  import * as errors from '@goscript/errors/index.js'
4
4
 
@@ -0,0 +1,8 @@
1
+ package path
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
+ "unicode/utf8",
8
+ }
package/gs/path/path.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as $ from '@goscript/builtin/builtin.js'
1
+ import * as $ from '@goscript/builtin/index.js'
2
2
 
3
3
  class lazybuf {
4
4
  public get s(): string {
@@ -0,0 +1,7 @@
1
+ package reflect
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
+ "iter",
7
+ }
@@ -26,7 +26,7 @@ import {
26
26
  Invalid,
27
27
  } from './type.js'
28
28
  import { ReflectValue, SelectCase, SelectRecv, SelectDefault } from './types.js'
29
- import * as $ from '@goscript/builtin/builtin.js'
29
+ import * as $ from '@goscript/builtin/index.js'
30
30
 
31
31
  interface ChannelObject {
32
32
  _sendQueue?: unknown[]
@@ -210,11 +210,19 @@ export function MakeChan(typ: Type, buffer: number): Value {
210
210
  export function Select(cases: $.Slice<SelectCase>): [number, Value, boolean] {
211
211
  // Extract the backing array from the GoScript slice
212
212
  let selectCases: SelectCase[] = []
213
- if (cases && typeof cases === 'object' && '__meta__' in cases) {
214
- // This is a GoScript slice, extract the backing array
215
- const meta = (cases as { __meta__?: { backing?: SelectCase[] } }).__meta__
216
- if (meta && meta.backing) {
217
- selectCases = meta.backing
213
+
214
+ if (cases && typeof cases === 'object') {
215
+ if ('__meta__' in cases) {
216
+ // This is a GoScript SliceProxy, extract the backing array
217
+ const meta = (cases as { __meta__?: { backing?: SelectCase[], offset?: number, length?: number } }).__meta__
218
+ if (meta && meta.backing) {
219
+ const offset = meta.offset ?? 0
220
+ const length = meta.length ?? meta.backing.length
221
+ selectCases = meta.backing.slice(offset, offset + length)
222
+ }
223
+ } else if (globalThis.Array.isArray(cases)) {
224
+ // This is a plain array (optimized case where offset=0 and length=capacity)
225
+ selectCases = cases as SelectCase[]
218
226
  }
219
227
  }
220
228
 
@@ -1,4 +1,4 @@
1
- import * as $ from '@goscript/builtin/builtin.js'
1
+ import * as $ from '@goscript/builtin/index.js'
2
2
  import { Type, Ptr, Struct } from './type.js'
3
3
  import { StructField } from './types.js'
4
4
 
@@ -1,5 +1,5 @@
1
1
  // TypeScript implementation of Go's slices package
2
- import * as $ from '@goscript/builtin/builtin.js'
2
+ import * as $ from '@goscript/builtin/index.js'
3
3
 
4
4
  /**
5
5
  * All returns an iterator over index-value pairs in the slice.
@@ -0,0 +1,27 @@
1
+ package sort // import "sort"
2
+
3
+ Package sort provides primitives for sorting slices and user-defined
4
+ collections.
5
+
6
+ func Find(n int, cmp func(int) int) (i int, found bool)
7
+ func Float64s(x []float64)
8
+ func Float64sAreSorted(x []float64) bool
9
+ func Ints(x []int)
10
+ func IntsAreSorted(x []int) bool
11
+ func IsSorted(data Interface) bool
12
+ func Search(n int, f func(int) bool) int
13
+ func SearchFloat64s(a []float64, x float64) int
14
+ func SearchInts(a []int, x int) int
15
+ func SearchStrings(a []string, x string) int
16
+ func Slice(x any, less func(i, j int) bool)
17
+ func SliceIsSorted(x any, less func(i, j int) bool) bool
18
+ func SliceStable(x any, less func(i, j int) bool)
19
+ func Sort(data Interface)
20
+ func Stable(data Interface)
21
+ func Strings(x []string)
22
+ func StringsAreSorted(x []string) bool
23
+ type Float64Slice []float64
24
+ type IntSlice []int
25
+ type Interface interface{ ... }
26
+ func Reverse(data Interface) Interface
27
+ type StringSlice []string