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,27 @@
1
+ export { ErrBadPattern, Glob, Match } from './match.js'
2
+ export {
3
+ Abs,
4
+ Base,
5
+ Clean,
6
+ Dir,
7
+ EvalSymlinks,
8
+ Ext,
9
+ FromSlash,
10
+ IsAbs,
11
+ IsLocal,
12
+ Join,
13
+ ListSeparator,
14
+ Localize,
15
+ Rel,
16
+ Separator,
17
+ SkipAll,
18
+ SkipDir,
19
+ Split,
20
+ SplitList,
21
+ ToSlash,
22
+ VolumeName,
23
+ Walk,
24
+ WalkDir,
25
+ HasPrefix,
26
+ } from './path.js'
27
+ export type { WalkFunc } from './path.js'
@@ -0,0 +1,274 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { Match, Glob, ErrBadPattern } from './match.js'
3
+
4
+ describe('path/filepath - Pattern matching functions', () => {
5
+ describe('Match', () => {
6
+ describe('Basic patterns', () => {
7
+ it('should match exact strings', () => {
8
+ const [matched, err] = Match('file.txt', 'file.txt')
9
+ expect(err).toBeNull()
10
+ expect(matched).toBe(true)
11
+
12
+ const [notMatched, err2] = Match('file.txt', 'other.txt')
13
+ expect(err2).toBeNull()
14
+ expect(notMatched).toBe(false)
15
+ })
16
+
17
+ it('should handle empty patterns and names', () => {
18
+ const [empty1, err1] = Match('', '')
19
+ expect(err1).toBeNull()
20
+ expect(empty1).toBe(true)
21
+
22
+ const [empty2, err2] = Match('', 'file')
23
+ expect(err2).toBeNull()
24
+ expect(empty2).toBe(false)
25
+
26
+ const [empty3, err3] = Match('pattern', '')
27
+ expect(err3).toBeNull()
28
+ expect(empty3).toBe(false)
29
+ })
30
+ })
31
+
32
+ describe('Wildcard patterns', () => {
33
+ it('should match with * (star)', () => {
34
+ const [match1, err1] = Match('*.txt', 'file.txt')
35
+ expect(err1).toBeNull()
36
+ expect(match1).toBe(true)
37
+
38
+ const [match2, err2] = Match('*.txt', 'file.doc')
39
+ expect(err2).toBeNull()
40
+ expect(match2).toBe(false)
41
+
42
+ const [match3, err3] = Match('file.*', 'file.txt')
43
+ expect(err3).toBeNull()
44
+ expect(match3).toBe(true)
45
+
46
+ const [match4, err4] = Match('*', 'anything')
47
+ expect(err4).toBeNull()
48
+ expect(match4).toBe(true)
49
+
50
+ const [match5, err5] = Match('*', '')
51
+ expect(err5).toBeNull()
52
+ expect(match5).toBe(true)
53
+ })
54
+
55
+ it('should match with ? (question mark)', () => {
56
+ const [match1, err1] = Match('file?.txt', 'file1.txt')
57
+ expect(err1).toBeNull()
58
+ expect(match1).toBe(true)
59
+
60
+ const [match2, err2] = Match('file?.txt', 'fileAB.txt')
61
+ expect(err2).toBeNull()
62
+ expect(match2).toBe(false)
63
+
64
+ const [match3, err3] = Match('?', 'a')
65
+ expect(err3).toBeNull()
66
+ expect(match3).toBe(true)
67
+
68
+ const [match4, err4] = Match('?', '')
69
+ expect(err4).toBeNull()
70
+ expect(match4).toBe(false)
71
+
72
+ const [match5, err5] = Match('?', 'ab')
73
+ expect(err5).toBeNull()
74
+ expect(match5).toBe(false)
75
+ })
76
+ })
77
+
78
+ describe('Character classes', () => {
79
+ it('should match character ranges', () => {
80
+ const [match1, err1] = Match('[a-z]', 'c')
81
+ expect(err1).toBeNull()
82
+ expect(match1).toBe(true)
83
+
84
+ const [match2, err2] = Match('[a-z]', 'Z')
85
+ expect(err2).toBeNull()
86
+ expect(match2).toBe(false)
87
+
88
+ const [match3, err3] = Match('[0-9]', '5')
89
+ expect(err3).toBeNull()
90
+ expect(match3).toBe(true)
91
+ })
92
+
93
+ it('should match specific characters', () => {
94
+ const [match1, err1] = Match('[abc]', 'b')
95
+ expect(err1).toBeNull()
96
+ expect(match1).toBe(true)
97
+
98
+ const [match2, err2] = Match('[abc]', 'd')
99
+ expect(err2).toBeNull()
100
+ expect(match2).toBe(false)
101
+ })
102
+
103
+ it('should handle negated character classes', () => {
104
+ const [match1, err1] = Match('[^abc]', 'd')
105
+ expect(err1).toBeNull()
106
+ expect(match1).toBe(true)
107
+
108
+ const [match2, err2] = Match('[^abc]', 'a')
109
+ expect(err2).toBeNull()
110
+ expect(match2).toBe(false)
111
+
112
+ const [match3, err3] = Match('[^a-z]', '1')
113
+ expect(err3).toBeNull()
114
+ expect(match3).toBe(true)
115
+
116
+ const [match4, err4] = Match('[^a-z]', 'c')
117
+ expect(err4).toBeNull()
118
+ expect(match4).toBe(false)
119
+ })
120
+ })
121
+
122
+ describe('Escaped characters', () => {
123
+ it('should handle escaped special characters', () => {
124
+ const [match1, err1] = Match('\\*', '*')
125
+ expect(err1).toBeNull()
126
+ expect(match1).toBe(true)
127
+
128
+ const [match2, err2] = Match('\\?', '?')
129
+ expect(err2).toBeNull()
130
+ expect(match2).toBe(true)
131
+
132
+ const [match3, err3] = Match('\\[', '[')
133
+ expect(err3).toBeNull()
134
+ expect(match3).toBe(true)
135
+ })
136
+
137
+ it('should handle escaped characters in character classes', () => {
138
+ const [match1, err1] = Match('[\\-]', '-')
139
+ expect(err1).toBeNull()
140
+ expect(match1).toBe(true)
141
+
142
+ const [match2, err2] = Match('[\\]]', ']')
143
+ expect(err2).toBeNull()
144
+ expect(match2).toBe(true)
145
+ })
146
+ })
147
+
148
+ describe('Complex patterns', () => {
149
+ it('should match complex combinations', () => {
150
+ const [match1, err1] = Match('dir/*', 'dir/file.txt')
151
+ expect(err1).toBeNull()
152
+ expect(match1).toBe(true)
153
+
154
+ const [match2, err2] = Match('*.{txt,doc}', 'file.txt')
155
+ expect(err2).toBeNull()
156
+ // This pattern is not supported in our implementation, should not match
157
+ expect(match2).toBe(false)
158
+
159
+ const [match3, err3] = Match('file[0-9].txt', 'file5.txt')
160
+ expect(err3).toBeNull()
161
+ expect(match3).toBe(true)
162
+
163
+ const [match4, err4] = Match('*.[tT][xX][tT]', 'file.TXT')
164
+ expect(err4).toBeNull()
165
+ expect(match4).toBe(true)
166
+ })
167
+
168
+ it('should not match across path separators with ?', () => {
169
+ const [match1, err1] = Match('dir?file', 'dir/file')
170
+ expect(err1).toBeNull()
171
+ expect(match1).toBe(false)
172
+ })
173
+ })
174
+
175
+ describe('Error cases', () => {
176
+ it('should return error for malformed patterns', () => {
177
+ const [_unclosed, err1] = Match('[unclosed', 'test')
178
+ expect(err1).toBe(ErrBadPattern)
179
+
180
+ const [_trailing, err2] = Match('trailing\\', 'test')
181
+ expect(err2).toBe(ErrBadPattern)
182
+
183
+ const [_bracket, err3] = Match('[', 'test')
184
+ expect(err3).toBe(ErrBadPattern)
185
+ })
186
+ })
187
+
188
+ describe('Real-world examples', () => {
189
+ it('should match common file patterns', () => {
190
+ // JavaScript files
191
+ const [js1, _js1] = Match('*.js', 'app.js')
192
+ expect(js1).toBe(true)
193
+
194
+ const [js2, _js2] = Match('*.js', 'app.jsx')
195
+ expect(js2).toBe(false)
196
+
197
+ // Backup files
198
+ const [bak1, _bak1] = Match('*.bak', 'file.txt.bak')
199
+ expect(bak1).toBe(true)
200
+
201
+ // Hidden files
202
+ const [hidden1, _hidden1] = Match('.*', '.hidden')
203
+ expect(hidden1).toBe(true)
204
+
205
+ const [hidden2, _hidden2] = Match('.*', 'visible')
206
+ expect(hidden2).toBe(false)
207
+
208
+ // Version numbers
209
+ const [ver1, _ver1] = Match('v[0-9]*', 'v1.2.3')
210
+ expect(ver1).toBe(true)
211
+
212
+ const [ver2, _ver2] = Match('v[0-9]*', 'version')
213
+ expect(ver2).toBe(false)
214
+ })
215
+ })
216
+ })
217
+
218
+ describe('Glob', () => {
219
+ it('should validate patterns but return empty results (no filesystem)', () => {
220
+ // Valid patterns should not error
221
+ const [files1, err1] = Glob('*.txt')
222
+ expect(err1).toBeNull()
223
+ expect(files1).toEqual([])
224
+
225
+ const [files2, err2] = Glob('dir/*')
226
+ expect(err2).toBeNull()
227
+ expect(files2).toEqual([])
228
+
229
+ // Invalid patterns should error
230
+ const [files3, err3] = Glob('[unclosed')
231
+ expect(err3).toBe(ErrBadPattern)
232
+ expect(files3).toEqual([])
233
+ })
234
+ })
235
+
236
+ describe('Pattern edge cases', () => {
237
+ it('should handle patterns at string boundaries', () => {
238
+ const [match1, _edge1] = Match('*txt', 'file.txt')
239
+ expect(match1).toBe(true)
240
+
241
+ const [match2, _edge2] = Match('file*', 'file.txt')
242
+ expect(match2).toBe(true)
243
+
244
+ const [match3, _edge3] = Match('*file*', 'myfile.txt')
245
+ expect(match3).toBe(true)
246
+ })
247
+
248
+ it('should handle multiple stars', () => {
249
+ const [match1, _star1] = Match('**', 'anything')
250
+ expect(match1).toBe(true)
251
+
252
+ const [match2, _star2] = Match('*.*.*', 'a.b.c')
253
+ expect(match2).toBe(true)
254
+
255
+ const [match3, _star3] = Match('*.*.*', 'a.b')
256
+ expect(match3).toBe(false)
257
+ })
258
+
259
+ it('should handle character class edge cases', () => {
260
+ // Empty character class (should be invalid)
261
+ const [_empty, err1] = Match('[]', 'test')
262
+ expect(err1).toBe(ErrBadPattern)
263
+
264
+ // Character class with dash
265
+ const [match1, err2] = Match('[a-]', 'a')
266
+ expect(err2).toBeNull()
267
+ expect(match1).toBe(true)
268
+
269
+ const [match2, err3] = Match('[a-]', '-')
270
+ expect(err3).toBeNull()
271
+ expect(match2).toBe(true)
272
+ })
273
+ })
274
+ })
@@ -0,0 +1,249 @@
1
+ // Pattern matching functions for filepath
2
+
3
+ export const ErrBadPattern = new Error('syntax error in pattern')
4
+
5
+ // Match reports whether name matches the shell file name pattern.
6
+ // The pattern syntax is:
7
+ //
8
+ // pattern:
9
+ // { term }
10
+ // term:
11
+ // '*' matches any sequence of non-Separator characters
12
+ // '?' matches any single non-Separator character
13
+ // '[' [ '^' ] { character-range } ']'
14
+ // character class (must be non-empty)
15
+ // c matches character c (c != '*', '?', '\\', '[')
16
+ // '\\' c matches character c
17
+ //
18
+ // character-range:
19
+ // c matches character c (c != '\\', '-', ']')
20
+ // '\\' c matches character c
21
+ // lo '-' hi matches character c for lo <= c <= hi
22
+ //
23
+ // Match requires pattern to match all of name, not just a substring.
24
+ // The only possible returned error is ErrBadPattern, when pattern
25
+ // is malformed.
26
+ export function Match(pattern: string, name: string): [boolean, Error | null] {
27
+ try {
28
+ // Validate pattern first
29
+ validatePattern(pattern)
30
+ return [matchPattern(pattern, name), null]
31
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
32
+ } catch (err) {
33
+ return [false, ErrBadPattern]
34
+ }
35
+ }
36
+
37
+ function validatePattern(pattern: string): void {
38
+ let i = 0
39
+
40
+ while (i < pattern.length) {
41
+ const char = pattern[i]
42
+
43
+ switch (char) {
44
+ case '\\':
45
+ // Must be followed by another character
46
+ i++
47
+ if (i >= pattern.length) {
48
+ throw new Error('bad pattern')
49
+ }
50
+ i++
51
+ break
52
+
53
+ case '[': {
54
+ // Must have a properly closed character class
55
+ i++
56
+ let foundContent = false
57
+ let foundClose = false
58
+
59
+ // Skip negation
60
+ if (i < pattern.length && pattern[i] === '^') {
61
+ i++
62
+ }
63
+
64
+ while (i < pattern.length) {
65
+ if (pattern[i] === ']') {
66
+ foundClose = true
67
+ i++
68
+ break
69
+ }
70
+
71
+ foundContent = true
72
+
73
+ if (pattern[i] === '\\') {
74
+ i++ // Skip escape character
75
+ if (i >= pattern.length) {
76
+ throw new Error('bad pattern')
77
+ }
78
+ }
79
+ i++
80
+ }
81
+
82
+ if (!foundClose || !foundContent) {
83
+ throw new Error('bad pattern')
84
+ }
85
+ break
86
+ }
87
+
88
+ default:
89
+ i++
90
+ break
91
+ }
92
+ }
93
+ }
94
+
95
+ function matchPattern(pattern: string, name: string): boolean {
96
+ let patternIndex = 0
97
+ let nameIndex = 0
98
+
99
+ while (patternIndex < pattern.length && nameIndex < name.length) {
100
+ const p = pattern[patternIndex]
101
+
102
+ switch (p) {
103
+ case '*':
104
+ // Handle star - match any sequence of characters
105
+ patternIndex++
106
+ if (patternIndex >= pattern.length) {
107
+ // Pattern ends with *, matches rest of name
108
+ return true
109
+ }
110
+
111
+ // Try to match the rest of the pattern with remaining name
112
+ for (let i = nameIndex; i <= name.length; i++) {
113
+ if (
114
+ matchPattern(pattern.substring(patternIndex), name.substring(i))
115
+ ) {
116
+ return true
117
+ }
118
+ }
119
+ return false
120
+
121
+ case '?':
122
+ // Match any single character except separator
123
+ if (name[nameIndex] === '/') {
124
+ return false
125
+ }
126
+ patternIndex++
127
+ nameIndex++
128
+ break
129
+
130
+ case '[': {
131
+ // Character class
132
+ const [matched, newPatternIndex] = matchCharClass(
133
+ pattern,
134
+ patternIndex,
135
+ name[nameIndex],
136
+ )
137
+ if (!matched) {
138
+ return false
139
+ }
140
+ patternIndex = newPatternIndex
141
+ nameIndex++
142
+ break
143
+ }
144
+
145
+ case '\\':
146
+ // Escaped character (pattern already validated)
147
+ patternIndex++
148
+ if (pattern[patternIndex] !== name[nameIndex]) {
149
+ return false
150
+ }
151
+ patternIndex++
152
+ nameIndex++
153
+ break
154
+
155
+ default:
156
+ // Literal character
157
+ if (p !== name[nameIndex]) {
158
+ return false
159
+ }
160
+ patternIndex++
161
+ nameIndex++
162
+ break
163
+ }
164
+ }
165
+
166
+ // Handle any remaining stars in pattern
167
+ while (patternIndex < pattern.length && pattern[patternIndex] === '*') {
168
+ patternIndex++
169
+ }
170
+
171
+ // Both pattern and name should be fully consumed
172
+ return patternIndex >= pattern.length && nameIndex >= name.length
173
+ }
174
+
175
+ function matchCharClass(
176
+ pattern: string,
177
+ start: number,
178
+ char: string,
179
+ ): [boolean, number] {
180
+ let index = start + 1
181
+ let negated = false
182
+
183
+ // Check for negation
184
+ if (index < pattern.length && pattern[index] === '^') {
185
+ negated = true
186
+ index++
187
+ }
188
+
189
+ let matched = false
190
+
191
+ while (index < pattern.length) {
192
+ if (pattern[index] === ']') {
193
+ index++
194
+ break
195
+ }
196
+
197
+ if (pattern[index] === '\\') {
198
+ // Escaped character
199
+ index++
200
+ if (pattern[index] === char) {
201
+ matched = true
202
+ }
203
+ index++
204
+ } else if (
205
+ index + 2 < pattern.length &&
206
+ pattern[index + 1] === '-' &&
207
+ pattern[index + 2] !== ']'
208
+ ) {
209
+ // Character range
210
+ const lo = pattern[index]
211
+ const hi = pattern[index + 2]
212
+ if (char >= lo && char <= hi) {
213
+ matched = true
214
+ }
215
+ index += 3
216
+ } else {
217
+ // Single character
218
+ if (pattern[index] === char) {
219
+ matched = true
220
+ }
221
+ index++
222
+ }
223
+ }
224
+
225
+ if (negated) {
226
+ matched = !matched
227
+ }
228
+
229
+ return [matched, index]
230
+ }
231
+
232
+ // Glob returns the names of all files matching pattern or null
233
+ // if there is no matching file. The syntax of patterns is the same
234
+ // as in Match. The pattern may describe hierarchical names such as
235
+ // /usr/*/bin/ed (assuming the Separator is '/').
236
+ //
237
+ // Glob ignores file system errors such as I/O errors reading directories.
238
+ // The only possible returned error is ErrBadPattern, when pattern is malformed.
239
+ export function Glob(pattern: string): [string[], Error | null] {
240
+ try {
241
+ // Validate the pattern using the same logic as Match
242
+ validatePattern(pattern)
243
+ // We don't have filesystem access, so return empty array
244
+ return [[], null]
245
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
246
+ } catch (err) {
247
+ return [[], ErrBadPattern]
248
+ }
249
+ }