goscript 0.0.34 → 0.0.36

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 (358) hide show
  1. package/compiler/analysis.go +28 -20
  2. package/compiler/analysis_test.go +14 -0
  3. package/compiler/assignment.go +19 -7
  4. package/compiler/compiler.go +15 -99
  5. package/compiler/composite-lit.go +60 -17
  6. package/compiler/decl.go +1 -1
  7. package/compiler/expr-call.go +233 -35
  8. package/compiler/expr-selector.go +28 -2
  9. package/compiler/expr.go +13 -37
  10. package/compiler/lit.go +111 -2
  11. package/compiler/primitive.go +6 -6
  12. package/compiler/protobuf.go +0 -5
  13. package/compiler/sanitize.go +101 -0
  14. package/compiler/spec-struct.go +41 -8
  15. package/compiler/spec-value.go +29 -18
  16. package/compiler/stmt-assign.go +22 -1
  17. package/compiler/stmt.go +26 -9
  18. package/compiler/type.go +3 -3
  19. package/dist/gs/builtin/builtin.d.ts +3 -2
  20. package/dist/gs/builtin/builtin.js +2 -1
  21. package/dist/gs/builtin/builtin.js.map +1 -1
  22. package/dist/gs/builtin/map.js.map +1 -1
  23. package/dist/gs/builtin/slice.d.ts +7 -1
  24. package/dist/gs/builtin/slice.js +112 -22
  25. package/dist/gs/builtin/slice.js.map +1 -1
  26. package/dist/gs/github.com/pkg/errors/errors.d.ts +13 -0
  27. package/dist/gs/github.com/pkg/errors/errors.js +232 -0
  28. package/dist/gs/github.com/pkg/errors/errors.js.map +1 -0
  29. package/dist/gs/github.com/pkg/errors/go113.d.ts +4 -0
  30. package/dist/gs/github.com/pkg/errors/go113.js +34 -0
  31. package/dist/gs/github.com/pkg/errors/go113.js.map +1 -0
  32. package/dist/gs/github.com/pkg/errors/index.d.ts +3 -0
  33. package/dist/gs/github.com/pkg/errors/index.js +4 -0
  34. package/dist/gs/github.com/pkg/errors/index.js.map +1 -0
  35. package/dist/gs/github.com/pkg/errors/stack.d.ts +32 -0
  36. package/dist/gs/github.com/pkg/errors/stack.js +111 -0
  37. package/dist/gs/github.com/pkg/errors/stack.js.map +1 -0
  38. package/dist/gs/maps/index.d.ts +2 -2
  39. package/dist/gs/maps/index.js +2 -2
  40. package/dist/gs/maps/index.js.map +1 -1
  41. package/dist/gs/maps/iter.d.ts +7 -0
  42. package/dist/gs/maps/iter.js +57 -0
  43. package/dist/gs/maps/iter.js.map +1 -0
  44. package/dist/gs/maps/maps.d.ts +7 -0
  45. package/dist/gs/maps/maps.js +67 -0
  46. package/dist/gs/maps/maps.js.map +1 -0
  47. package/dist/gs/math/abs.gs.d.ts +1 -0
  48. package/dist/gs/math/abs.gs.js +10 -0
  49. package/dist/gs/math/abs.gs.js.map +1 -0
  50. package/dist/gs/math/acosh.gs.d.ts +2 -0
  51. package/dist/gs/math/acosh.gs.js +14 -0
  52. package/dist/gs/math/acosh.gs.js.map +1 -0
  53. package/dist/gs/math/asin.gs.d.ts +4 -0
  54. package/dist/gs/math/asin.gs.js +24 -0
  55. package/dist/gs/math/asin.gs.js.map +1 -0
  56. package/dist/gs/math/asinh.gs.d.ts +2 -0
  57. package/dist/gs/math/asinh.gs.js +14 -0
  58. package/dist/gs/math/asinh.gs.js.map +1 -0
  59. package/dist/gs/math/atan.gs.d.ts +4 -0
  60. package/dist/gs/math/atan.gs.js +22 -0
  61. package/dist/gs/math/atan.gs.js.map +1 -0
  62. package/dist/gs/math/atan2.gs.d.ts +2 -0
  63. package/dist/gs/math/atan2.gs.js +30 -0
  64. package/dist/gs/math/atan2.gs.js.map +1 -0
  65. package/dist/gs/math/atanh.gs.d.ts +2 -0
  66. package/dist/gs/math/atanh.gs.js +16 -0
  67. package/dist/gs/math/atanh.gs.js.map +1 -0
  68. package/dist/gs/math/bits.gs.d.ts +5 -0
  69. package/dist/gs/math/bits.gs.js +46 -0
  70. package/dist/gs/math/bits.gs.js.map +1 -0
  71. package/dist/gs/math/cbrt.gs.d.ts +2 -0
  72. package/dist/gs/math/cbrt.gs.js +14 -0
  73. package/dist/gs/math/cbrt.gs.js.map +1 -0
  74. package/dist/gs/math/const.gs.d.ts +30 -0
  75. package/dist/gs/math/const.gs.js +61 -0
  76. package/dist/gs/math/const.gs.js.map +1 -0
  77. package/dist/gs/math/copysign.gs.d.ts +1 -0
  78. package/dist/gs/math/copysign.gs.js +20 -0
  79. package/dist/gs/math/copysign.gs.js.map +1 -0
  80. package/dist/gs/math/dim.gs.d.ts +5 -0
  81. package/dist/gs/math/dim.gs.js +69 -0
  82. package/dist/gs/math/dim.gs.js.map +1 -0
  83. package/dist/gs/math/erf.gs.d.ts +4 -0
  84. package/dist/gs/math/erf.gs.js +336 -0
  85. package/dist/gs/math/erf.gs.js.map +1 -0
  86. package/dist/gs/math/erfinv.gs.d.ts +2 -0
  87. package/dist/gs/math/erfinv.gs.js +118 -0
  88. package/dist/gs/math/erfinv.gs.js.map +1 -0
  89. package/dist/gs/math/exp.gs.d.ts +5 -0
  90. package/dist/gs/math/exp.gs.js +30 -0
  91. package/dist/gs/math/exp.gs.js.map +1 -0
  92. package/dist/gs/math/expm1.gs.d.ts +2 -0
  93. package/dist/gs/math/expm1.gs.js +17 -0
  94. package/dist/gs/math/expm1.gs.js.map +1 -0
  95. package/dist/gs/math/floor.gs.d.ts +8 -0
  96. package/dist/gs/math/floor.gs.js +75 -0
  97. package/dist/gs/math/floor.gs.js.map +1 -0
  98. package/dist/gs/math/fma.gs.d.ts +1 -0
  99. package/dist/gs/math/fma.gs.js +8 -0
  100. package/dist/gs/math/fma.gs.js.map +1 -0
  101. package/dist/gs/math/frexp.gs.d.ts +2 -0
  102. package/dist/gs/math/frexp.gs.js +28 -0
  103. package/dist/gs/math/frexp.gs.js.map +1 -0
  104. package/dist/gs/math/gamma.gs.d.ts +3 -0
  105. package/dist/gs/math/gamma.gs.js +149 -0
  106. package/dist/gs/math/gamma.gs.js.map +1 -0
  107. package/dist/gs/math/hypot.gs.d.ts +2 -0
  108. package/dist/gs/math/hypot.gs.js +16 -0
  109. package/dist/gs/math/hypot.gs.js.map +1 -0
  110. package/dist/gs/math/index.d.ts +44 -0
  111. package/dist/gs/math/index.js +45 -0
  112. package/dist/gs/math/index.js.map +1 -0
  113. package/dist/gs/math/j0.gs.d.ts +4 -0
  114. package/dist/gs/math/j0.gs.js +228 -0
  115. package/dist/gs/math/j0.gs.js.map +1 -0
  116. package/dist/gs/math/j1.gs.d.ts +4 -0
  117. package/dist/gs/math/j1.gs.js +211 -0
  118. package/dist/gs/math/j1.gs.js.map +1 -0
  119. package/dist/gs/math/jn.gs.d.ts +2 -0
  120. package/dist/gs/math/jn.gs.js +412 -0
  121. package/dist/gs/math/jn.gs.js.map +1 -0
  122. package/dist/gs/math/ldexp.gs.d.ts +2 -0
  123. package/dist/gs/math/ldexp.gs.js +20 -0
  124. package/dist/gs/math/ldexp.gs.js.map +1 -0
  125. package/dist/gs/math/lgamma.gs.d.ts +2 -0
  126. package/dist/gs/math/lgamma.gs.js +243 -0
  127. package/dist/gs/math/lgamma.gs.js.map +1 -0
  128. package/dist/gs/math/log.gs.d.ts +2 -0
  129. package/dist/gs/math/log.gs.js +16 -0
  130. package/dist/gs/math/log.gs.js.map +1 -0
  131. package/dist/gs/math/log10.gs.d.ts +4 -0
  132. package/dist/gs/math/log10.gs.js +17 -0
  133. package/dist/gs/math/log10.gs.js.map +1 -0
  134. package/dist/gs/math/log1p.gs.d.ts +2 -0
  135. package/dist/gs/math/log1p.gs.js +17 -0
  136. package/dist/gs/math/log1p.gs.js.map +1 -0
  137. package/dist/gs/math/logb.gs.d.ts +3 -0
  138. package/dist/gs/math/logb.gs.js +43 -0
  139. package/dist/gs/math/logb.gs.js.map +1 -0
  140. package/dist/gs/math/mod.gs.d.ts +2 -0
  141. package/dist/gs/math/mod.gs.js +26 -0
  142. package/dist/gs/math/mod.gs.js.map +1 -0
  143. package/dist/gs/math/modf.gs.d.ts +2 -0
  144. package/dist/gs/math/modf.gs.js +24 -0
  145. package/dist/gs/math/modf.gs.js.map +1 -0
  146. package/dist/gs/math/nextafter.gs.d.ts +2 -0
  147. package/dist/gs/math/nextafter.gs.js +66 -0
  148. package/dist/gs/math/nextafter.gs.js.map +1 -0
  149. package/dist/gs/math/pow.gs.d.ts +3 -0
  150. package/dist/gs/math/pow.gs.js +40 -0
  151. package/dist/gs/math/pow.gs.js.map +1 -0
  152. package/dist/gs/math/pow10.gs.d.ts +1 -0
  153. package/dist/gs/math/pow10.gs.js +14 -0
  154. package/dist/gs/math/pow10.gs.js.map +1 -0
  155. package/dist/gs/math/remainder.gs.d.ts +2 -0
  156. package/dist/gs/math/remainder.gs.js +25 -0
  157. package/dist/gs/math/remainder.gs.js.map +1 -0
  158. package/dist/gs/math/signbit.gs.d.ts +1 -0
  159. package/dist/gs/math/signbit.gs.js +5 -0
  160. package/dist/gs/math/signbit.gs.js.map +1 -0
  161. package/dist/gs/math/sin.gs.d.ts +4 -0
  162. package/dist/gs/math/sin.gs.js +29 -0
  163. package/dist/gs/math/sin.gs.js.map +1 -0
  164. package/dist/gs/math/sincos.gs.d.ts +1 -0
  165. package/dist/gs/math/sincos.gs.js +11 -0
  166. package/dist/gs/math/sincos.gs.js.map +1 -0
  167. package/dist/gs/math/sinh.gs.d.ts +4 -0
  168. package/dist/gs/math/sinh.gs.js +27 -0
  169. package/dist/gs/math/sinh.gs.js.map +1 -0
  170. package/dist/gs/math/sqrt.gs.d.ts +2 -0
  171. package/dist/gs/math/sqrt.gs.js +15 -0
  172. package/dist/gs/math/sqrt.gs.js.map +1 -0
  173. package/dist/gs/math/tan.gs.d.ts +2 -0
  174. package/dist/gs/math/tan.gs.js +17 -0
  175. package/dist/gs/math/tan.gs.js.map +1 -0
  176. package/dist/gs/math/tanh.gs.d.ts +2 -0
  177. package/dist/gs/math/tanh.gs.js +17 -0
  178. package/dist/gs/math/tanh.gs.js.map +1 -0
  179. package/dist/gs/math/trig_reduce.gs.d.ts +1 -0
  180. package/dist/gs/math/trig_reduce.gs.js +62 -0
  181. package/dist/gs/math/trig_reduce.gs.js.map +1 -0
  182. package/dist/gs/math/unsafe.gs.d.ts +4 -0
  183. package/dist/gs/math/unsafe.gs.js +47 -0
  184. package/dist/gs/math/unsafe.gs.js.map +1 -0
  185. package/dist/gs/strconv/atob.gs.d.ts +4 -0
  186. package/dist/gs/strconv/atob.gs.js +42 -0
  187. package/dist/gs/strconv/atob.gs.js.map +1 -0
  188. package/dist/gs/strconv/atof.gs.d.ts +2 -0
  189. package/dist/gs/strconv/atof.gs.js +51 -0
  190. package/dist/gs/strconv/atof.gs.js.map +1 -0
  191. package/dist/gs/strconv/atoi.gs.d.ts +33 -0
  192. package/dist/gs/strconv/atoi.gs.js +200 -0
  193. package/dist/gs/strconv/atoi.gs.js.map +1 -0
  194. package/dist/gs/strconv/doc.gs.d.ts +1 -0
  195. package/dist/gs/strconv/doc.gs.js +2 -0
  196. package/dist/gs/strconv/doc.gs.js.map +1 -0
  197. package/dist/gs/strconv/ftoa.gs.d.ts +3 -0
  198. package/dist/gs/strconv/ftoa.gs.js +58 -0
  199. package/dist/gs/strconv/ftoa.gs.js.map +1 -0
  200. package/dist/gs/strconv/index.d.ts +6 -0
  201. package/dist/gs/strconv/index.js +7 -0
  202. package/dist/gs/strconv/index.js.map +1 -0
  203. package/dist/gs/strconv/itoa.gs.d.ts +6 -0
  204. package/dist/gs/strconv/itoa.gs.js +37 -0
  205. package/dist/gs/strconv/itoa.gs.js.map +1 -0
  206. package/dist/gs/strconv/quote.gs.d.ts +19 -0
  207. package/dist/gs/strconv/quote.gs.js +217 -0
  208. package/dist/gs/strconv/quote.gs.js.map +1 -0
  209. package/dist/gs/strings/index.d.ts +3 -0
  210. package/dist/gs/strings/index.js +4 -0
  211. package/dist/gs/strings/index.js.map +1 -1
  212. package/dist/gs/strings/replace.d.ts +0 -74
  213. package/dist/gs/strings/replace.js +6 -204
  214. package/dist/gs/strings/replace.js.map +1 -1
  215. package/dist/gs/strings/search.d.ts +0 -1
  216. package/dist/gs/strings/search.js +0 -21
  217. package/dist/gs/strings/search.js.map +1 -1
  218. package/dist/gs/sync/atomic/doc.gs.d.ts +28 -0
  219. package/dist/gs/sync/atomic/doc.gs.js +265 -0
  220. package/dist/gs/sync/atomic/doc.gs.js.map +1 -0
  221. package/dist/gs/sync/atomic/doc_64.gs.d.ts +15 -0
  222. package/dist/gs/sync/atomic/doc_64.gs.js +165 -0
  223. package/dist/gs/sync/atomic/doc_64.gs.js.map +1 -0
  224. package/dist/gs/sync/atomic/index.d.ts +4 -0
  225. package/dist/gs/sync/atomic/index.js +5 -0
  226. package/dist/gs/sync/atomic/index.js.map +1 -0
  227. package/dist/gs/sync/atomic/type.gs.d.ts +130 -0
  228. package/dist/gs/sync/atomic/type.gs.js +433 -0
  229. package/dist/gs/sync/atomic/type.gs.js.map +1 -0
  230. package/dist/gs/sync/atomic/value.gs.d.ts +19 -0
  231. package/dist/gs/sync/atomic/value.gs.js +116 -0
  232. package/dist/gs/sync/atomic/value.gs.js.map +1 -0
  233. package/dist/gs/unsafe/unsafe.d.ts +1 -0
  234. package/dist/gs/unsafe/unsafe.js +5 -0
  235. package/dist/gs/unsafe/unsafe.js.map +1 -1
  236. package/gs/builtin/builtin.ts +9 -7
  237. package/gs/builtin/map.ts +5 -1
  238. package/gs/builtin/slice.ts +152 -24
  239. package/gs/github.com/pkg/errors/errors.ts +307 -0
  240. package/gs/github.com/pkg/errors/go113.ts +39 -0
  241. package/gs/github.com/pkg/errors/index.ts +3 -0
  242. package/gs/github.com/pkg/errors/stack.ts +127 -0
  243. package/gs/maps/index.ts +2 -2
  244. package/gs/maps/iter.ts +67 -0
  245. package/gs/maps/maps.ts +89 -0
  246. package/gs/math/TODO.md +156 -0
  247. package/gs/math/abs.gs.test.ts +29 -0
  248. package/gs/math/abs.gs.ts +13 -0
  249. package/gs/math/acosh.gs.test.ts +39 -0
  250. package/gs/math/acosh.gs.ts +21 -0
  251. package/gs/math/asin.gs.test.ts +66 -0
  252. package/gs/math/asin.gs.ts +27 -0
  253. package/gs/math/asinh.gs.test.ts +37 -0
  254. package/gs/math/asinh.gs.ts +21 -0
  255. package/gs/math/atan.gs.test.ts +49 -0
  256. package/gs/math/atan.gs.ts +27 -0
  257. package/gs/math/atan2.gs.test.ts +55 -0
  258. package/gs/math/atan2.gs.ts +37 -0
  259. package/gs/math/atanh.gs.test.ts +47 -0
  260. package/gs/math/atanh.gs.ts +21 -0
  261. package/gs/math/bits.gs.test.ts +88 -0
  262. package/gs/math/bits.gs.ts +61 -0
  263. package/gs/math/cbrt.gs.test.ts +57 -0
  264. package/gs/math/cbrt.gs.ts +20 -0
  265. package/gs/math/const.gs.test.ts +54 -0
  266. package/gs/math/const.gs.ts +93 -0
  267. package/gs/math/copysign.gs.test.ts +44 -0
  268. package/gs/math/copysign.gs.ts +27 -0
  269. package/gs/math/dim.gs.test.ts +102 -0
  270. package/gs/math/dim.gs.ts +84 -0
  271. package/gs/math/erf.gs.test.ts +92 -0
  272. package/gs/math/erf.gs.ts +409 -0
  273. package/gs/math/erfinv.gs.test.ts +104 -0
  274. package/gs/math/erfinv.gs.ts +169 -0
  275. package/gs/math/exp.gs.test.ts +82 -0
  276. package/gs/math/exp.gs.ts +39 -0
  277. package/gs/math/expm1.gs.test.ts +48 -0
  278. package/gs/math/expm1.gs.ts +23 -0
  279. package/gs/math/floor.gs.test.ts +146 -0
  280. package/gs/math/floor.gs.ts +88 -0
  281. package/gs/math/fma.gs.test.ts +83 -0
  282. package/gs/math/fma.gs.ts +7 -0
  283. package/gs/math/frexp.gs.test.ts +146 -0
  284. package/gs/math/frexp.gs.ts +37 -0
  285. package/gs/math/gamma.gs.test.ts +66 -0
  286. package/gs/math/gamma.gs.ts +158 -0
  287. package/gs/math/hypot.gs.test.ts +73 -0
  288. package/gs/math/hypot.gs.ts +23 -0
  289. package/gs/math/index.ts +44 -0
  290. package/gs/math/j0.gs.test.ts +74 -0
  291. package/gs/math/j0.gs.ts +257 -0
  292. package/gs/math/j1.gs.test.ts +81 -0
  293. package/gs/math/j1.gs.ts +231 -0
  294. package/gs/math/jn.gs.test.ts +133 -0
  295. package/gs/math/jn.gs.ts +447 -0
  296. package/gs/math/ldexp.gs.test.ts +128 -0
  297. package/gs/math/ldexp.gs.ts +28 -0
  298. package/gs/math/lgamma.gs.test.ts +102 -0
  299. package/gs/math/lgamma.gs.ts +251 -0
  300. package/gs/math/log.gs.test.ts +40 -0
  301. package/gs/math/log.gs.ts +21 -0
  302. package/gs/math/log10.gs.test.ts +80 -0
  303. package/gs/math/log10.gs.ts +25 -0
  304. package/gs/math/log1p.gs.test.ts +55 -0
  305. package/gs/math/log1p.gs.ts +24 -0
  306. package/gs/math/logb.gs.test.ts +87 -0
  307. package/gs/math/logb.gs.ts +54 -0
  308. package/gs/math/mod.gs.test.ts +64 -0
  309. package/gs/math/mod.gs.ts +36 -0
  310. package/gs/math/modf.gs.test.ts +80 -0
  311. package/gs/math/modf.gs.ts +32 -0
  312. package/gs/math/nextafter.gs.test.ts +107 -0
  313. package/gs/math/nextafter.gs.ts +71 -0
  314. package/gs/math/pow.gs.test.ts +103 -0
  315. package/gs/math/pow.gs.ts +55 -0
  316. package/gs/math/pow10.gs.test.ts +58 -0
  317. package/gs/math/pow10.gs.ts +19 -0
  318. package/gs/math/remainder.gs.test.ts +70 -0
  319. package/gs/math/remainder.gs.ts +33 -0
  320. package/gs/math/signbit.gs.test.ts +33 -0
  321. package/gs/math/signbit.gs.ts +8 -0
  322. package/gs/math/sin.gs.test.ts +83 -0
  323. package/gs/math/sin.gs.ts +38 -0
  324. package/gs/math/sincos.gs.test.ts +91 -0
  325. package/gs/math/sincos.gs.ts +15 -0
  326. package/gs/math/sinh.gs.test.ts +66 -0
  327. package/gs/math/sinh.gs.ts +34 -0
  328. package/gs/math/sqrt.gs.test.ts +49 -0
  329. package/gs/math/sqrt.gs.ts +20 -0
  330. package/gs/math/tan.gs.test.ts +50 -0
  331. package/gs/math/tan.gs.ts +23 -0
  332. package/gs/math/tanh.gs.test.ts +52 -0
  333. package/gs/math/tanh.gs.ts +23 -0
  334. package/gs/math/trig_reduce.gs.ts +66 -0
  335. package/gs/math/unsafe.gs.ts +52 -0
  336. package/gs/strconv/atob.gs.ts +45 -0
  337. package/gs/strconv/atof.gs.ts +60 -0
  338. package/gs/strconv/atoi.gs.ts +243 -0
  339. package/gs/strconv/doc.gs.ts +2 -0
  340. package/gs/strconv/ftoa.gs.ts +66 -0
  341. package/gs/strconv/index.ts +6 -0
  342. package/gs/strconv/itoa.gs.ts +41 -0
  343. package/gs/strconv/quote.gs.ts +245 -0
  344. package/gs/strings/index.ts +4 -0
  345. package/gs/strings/replace.ts +9 -237
  346. package/gs/strings/search.ts +0 -28
  347. package/gs/sync/atomic/doc.gs.ts +276 -0
  348. package/gs/sync/atomic/doc_64.gs.ts +168 -0
  349. package/gs/sync/atomic/index.ts +4 -0
  350. package/gs/sync/atomic/type.gs.ts +596 -0
  351. package/gs/sync/atomic/value.gs.ts +158 -0
  352. package/gs/unsafe/unsafe.ts +6 -0
  353. package/package.json +1 -1
  354. package/gs/maps/iter.gs.ts +0 -71
  355. package/gs/maps/maps.gs.ts +0 -87
  356. package/gs/stringslite/godoc.txt +0 -17
  357. package/gs/stringslite/index.ts +0 -1
  358. package/gs/stringslite/strings.ts +0 -82
@@ -317,9 +317,6 @@ func (v *analysisVisitor) Visit(node ast.Node) ast.Visitor {
317
317
  if lhsObj == nil {
318
318
  continue
319
319
  }
320
- // Ensure usage info exists for LHS
321
- lhsUsageInfo := v.getOrCreateUsageInfo(lhsObj)
322
-
323
320
  // Check if there's a corresponding initial value (RHS)
324
321
  if valueSpec.Values != nil && i < len(valueSpec.Values) {
325
322
  rhsExpr := valueSpec.Values[i]
@@ -327,12 +324,18 @@ func (v *analysisVisitor) Visit(node ast.Node) ast.Visitor {
327
324
  // --- Analyze RHS and Update Usage Info (similar to AssignStmt) ---
328
325
  assignmentType := DirectAssignment
329
326
  var sourceObj types.Object
327
+ shouldTrackUsage := true
330
328
 
331
329
  if unaryExpr, ok := rhsExpr.(*ast.UnaryExpr); ok && unaryExpr.Op == token.AND {
332
- // Case: var lhs = &rhs_ident
330
+ // Case: var lhs = &rhs_expr
333
331
  assignmentType = AddressOfAssignment
334
332
  if rhsIdent, ok := unaryExpr.X.(*ast.Ident); ok {
333
+ // Case: var lhs = &rhs_ident (taking address of a variable)
335
334
  sourceObj = v.pkg.TypesInfo.ObjectOf(rhsIdent)
335
+ } else {
336
+ // Case: var lhs = &CompositeLit{} (taking address of composite literal)
337
+ // No variable tracking needed - this doesn't create VarRef requirements
338
+ shouldTrackUsage = false
336
339
  }
337
340
  } else if rhsIdent, ok := rhsExpr.(*ast.Ident); ok {
338
341
  // Case: var lhs = rhs_ident
@@ -341,21 +344,26 @@ func (v *analysisVisitor) Visit(node ast.Node) ast.Visitor {
341
344
  }
342
345
 
343
346
  // --- Record Usage ---
344
- if sourceObj != nil {
345
- // Record source for LHS
346
- lhsUsageInfo.Sources = append(lhsUsageInfo.Sources, AssignmentInfo{
347
- Object: sourceObj,
348
- Type: assignmentType,
349
- })
350
-
351
- // Record destination for RHS source
352
- sourceUsageInfo := v.getOrCreateUsageInfo(sourceObj)
353
- sourceUsageInfo.Destinations = append(sourceUsageInfo.Destinations, AssignmentInfo{
354
- Object: lhsObj,
355
- Type: assignmentType,
356
- })
347
+ // Only create usage tracking if we're dealing with variable references
348
+ if shouldTrackUsage {
349
+ // Ensure usage info exists for LHS only when needed
350
+ lhsUsageInfo := v.getOrCreateUsageInfo(lhsObj)
351
+
352
+ if sourceObj != nil {
353
+ // Record source for LHS
354
+ lhsUsageInfo.Sources = append(lhsUsageInfo.Sources, AssignmentInfo{
355
+ Object: sourceObj,
356
+ Type: assignmentType,
357
+ })
358
+
359
+ // Record destination for RHS source
360
+ sourceUsageInfo := v.getOrCreateUsageInfo(sourceObj)
361
+ sourceUsageInfo.Destinations = append(sourceUsageInfo.Destinations, AssignmentInfo{
362
+ Object: lhsObj,
363
+ Type: assignmentType,
364
+ })
365
+ }
357
366
  }
358
- // Note: We might need to handle var lhs = &T{} cases later if necessary.
359
367
  }
360
368
  }
361
369
  }
@@ -418,12 +426,12 @@ func (v *analysisVisitor) Visit(node ast.Node) ast.Visitor {
418
426
  }
419
427
  }
420
428
 
421
- // Store named return variables
429
+ // Store named return variables (sanitized for TypeScript)
422
430
  if n.Type != nil && n.Type.Results != nil {
423
431
  var namedReturns []string
424
432
  for _, field := range n.Type.Results.List {
425
433
  for _, name := range field.Names {
426
- namedReturns = append(namedReturns, name.Name)
434
+ namedReturns = append(namedReturns, sanitizeIdentifier(name.Name))
427
435
  }
428
436
  }
429
437
  if len(namedReturns) > 0 {
@@ -88,6 +88,20 @@ func main() {
88
88
  "data": {NeedsVarRef: false, NeedsVarRefAccess: false}, // Should NOT be varrefed
89
89
  },
90
90
  },
91
+ {
92
+ name: "var_declaration_composite_literal",
93
+ code: `package main
94
+ type MockInode struct {
95
+ Value int
96
+ }
97
+ func main() {
98
+ var childInode *MockInode = &MockInode{Value: 42}
99
+ println("childInode.Value:", childInode.Value)
100
+ }`,
101
+ expected: map[string]AnalysisExpectation{
102
+ "childInode": {NeedsVarRef: false, NeedsVarRefAccess: false}, // Should NOT be varrefed
103
+ },
104
+ },
91
105
  }
92
106
 
93
107
  for _, tt := range tests {
@@ -94,7 +94,7 @@ func (c *GoToTSCompiler) writeAssignmentCore(lhs, rhs []ast.Expr, tok token.Toke
94
94
  if isLHSVarRefed && lhsIdent != nil {
95
95
  c.tsw.WriteLiterally("let ")
96
96
  // Just write the identifier name without .value
97
- c.tsw.WriteLiterally(lhsIdent.Name)
97
+ c.tsw.WriteLiterally(c.sanitizeIdentifier(lhsIdent.Name))
98
98
  // No type annotation, allow TypeScript to infer it from varRef.
99
99
  c.tsw.WriteLiterally(" = ")
100
100
 
@@ -282,14 +282,21 @@ func (c *GoToTSCompiler) writeAssignmentCore(lhs, rhs []ast.Expr, tok token.Toke
282
282
  // Continue, we've already written part of the mapSet() function call
283
283
  } else {
284
284
  c.tsw.WriteLiterally(" ")
285
- tokStr, ok := TokenToTs(tok) // Use explicit gstypes alias
286
- if !ok {
287
- c.tsw.WriteLiterally("?= ")
288
- c.tsw.WriteCommentLine("Unknown token " + tok.String())
285
+
286
+ // Special handling for &^= (bitwise AND NOT assignment)
287
+ if tok == token.AND_NOT_ASSIGN {
288
+ // Transform x &^= y to x &= ~(y)
289
+ c.tsw.WriteLiterally("&= ~(")
289
290
  } else {
290
- c.tsw.WriteLiterally(tokStr)
291
+ tokStr, ok := TokenToTs(tok) // Use explicit gstypes alias
292
+ if !ok {
293
+ c.tsw.WriteLiterally("?= ")
294
+ c.tsw.WriteCommentLine("Unknown token " + tok.String())
295
+ } else {
296
+ c.tsw.WriteLiterally(tokStr)
297
+ }
298
+ c.tsw.WriteLiterally(" ")
291
299
  }
292
- c.tsw.WriteLiterally(" ")
293
300
  }
294
301
 
295
302
  // Write RHS
@@ -353,6 +360,11 @@ func (c *GoToTSCompiler) writeAssignmentCore(lhs, rhs []ast.Expr, tok token.Toke
353
360
  }
354
361
  }
355
362
 
363
+ // Close the parenthesis for &^= transformation
364
+ if tok == token.AND_NOT_ASSIGN && !(isMapIndexLHS && len(lhs) == 1) {
365
+ c.tsw.WriteLiterally(")")
366
+ }
367
+
356
368
  // If the LHS was a single map index, close the mapSet call
357
369
  if isMapIndexLHS && len(lhs) == 1 {
358
370
  c.tsw.WriteLiterally(")")
@@ -611,7 +611,15 @@ func (c *FileCompiler) Compile(ctx context.Context) error {
611
611
  // Generate auto-imports for functions from other files in the same package
612
612
  currentFileName := strings.TrimSuffix(filepath.Base(c.fullPath), ".go")
613
613
  if imports := c.PackageAnalysis.FunctionCalls[currentFileName]; imports != nil {
614
- for sourceFile, functions := range imports {
614
+ // Sort source files for consistent import order
615
+ var sourceFiles []string
616
+ for sourceFile := range imports {
617
+ sourceFiles = append(sourceFiles, sourceFile)
618
+ }
619
+ sort.Strings(sourceFiles)
620
+
621
+ for _, sourceFile := range sourceFiles {
622
+ functions := imports[sourceFile]
615
623
  if len(functions) > 0 {
616
624
  // Sort functions for consistent output
617
625
  sort.Strings(functions)
@@ -891,104 +899,9 @@ func (c *GoToTSCompiler) WriteDoc(doc *ast.CommentGroup) {
891
899
  }
892
900
  }
893
901
 
894
- // sanitizeIdentifier checks if an identifier is a JavaScript/TypeScript reserved word
895
- // or conflicts with built-in types, and transforms it if needed. This prevents
896
- // compilation errors when Go identifiers conflict with JS/TS keywords or built-ins.
902
+ // sanitizeIdentifier is a method wrapper around the package-level sanitizeIdentifier function
897
903
  func (c *GoToTSCompiler) sanitizeIdentifier(name string) string {
898
- // Don't sanitize boolean literals - they are valid in both Go and JS/TS
899
- if name == "true" || name == "false" {
900
- return name
901
- }
902
-
903
- // Handle TypeScript built-in types that conflict with Go type parameter names
904
- builtinTypes := map[string]string{
905
- "Map": "MapType",
906
- // Add other built-in types as needed
907
- }
908
-
909
- if replacement, exists := builtinTypes[name]; exists {
910
- return replacement
911
- }
912
-
913
- // List of JavaScript/TypeScript reserved words that could conflict
914
- reservedWords := map[string]bool{
915
- "abstract": true,
916
- "any": true,
917
- "as": true,
918
- "asserts": true,
919
- "async": true,
920
- "await": true,
921
- "boolean": true,
922
- "break": true,
923
- "case": true,
924
- "catch": true,
925
- "class": true,
926
- "const": true,
927
- "constructor": true,
928
- "continue": true,
929
- "debugger": true,
930
- "declare": true,
931
- "default": true,
932
- "delete": true,
933
- "do": true,
934
- "else": true,
935
- "enum": true,
936
- "export": true,
937
- "extends": true,
938
- "finally": true,
939
- "for": true,
940
- "from": true,
941
- "function": true,
942
- "get": true,
943
- "if": true,
944
- "implements": true,
945
- "import": true,
946
- "in": true,
947
- "instanceof": true,
948
- "interface": true,
949
- "is": true,
950
- "keyof": true,
951
- "let": true,
952
- "module": true,
953
- "namespace": true,
954
- "never": true,
955
- "new": true,
956
- "null": true,
957
- "number": true,
958
- "object": true,
959
- "of": true,
960
- "package": true,
961
- "private": true,
962
- "protected": true,
963
- "public": true,
964
- "readonly": true,
965
- "require": true,
966
- "return": true,
967
- "set": true,
968
- "static": true,
969
- "string": true,
970
- "super": true,
971
- "switch": true,
972
- "symbol": true,
973
- "this": true,
974
- "throw": true,
975
- "try": true,
976
- "type": true,
977
- "typeof": true,
978
- "undefined": true,
979
- "unique": true,
980
- "unknown": true,
981
- "var": true,
982
- "void": true,
983
- "while": true,
984
- "with": true,
985
- "yield": true,
986
- }
987
-
988
- if reservedWords[name] {
989
- return "_" + name
990
- }
991
- return name
904
+ return sanitizeIdentifier(name)
992
905
  }
993
906
 
994
907
  // writeConstantValue writes the evaluated value of a Go constant to TypeScript.
@@ -1006,7 +919,10 @@ func (c *GoToTSCompiler) writeConstantValue(constObj *types.Const) {
1006
919
  c.tsw.WriteLiterally(val.String())
1007
920
  case constant.String:
1008
921
  // For string constants, write as a quoted string literal
1009
- c.tsw.WriteLiterally(val.String()) // val.String() already includes quotes
922
+ // Use constant.StringVal to get the full string value without truncation,
923
+ // then manually add quotes since StringVal returns the unquoted string
924
+ stringValue := constant.StringVal(val)
925
+ c.tsw.WriteLiterallyf("%q", stringValue) // %q adds proper quotes and escaping
1010
926
  case constant.Bool:
1011
927
  // For boolean constants, write true/false
1012
928
  if constant.BoolVal(val) {
@@ -3,6 +3,7 @@ package compiler
3
3
  import (
4
4
  "fmt"
5
5
  "go/ast"
6
+ "go/constant"
6
7
  "go/token"
7
8
  "go/types"
8
9
  "slices"
@@ -108,6 +109,9 @@ func (c *GoToTSCompiler) WriteCompositeLit(exp *ast.CompositeLit) error {
108
109
  if at, ok := typ.Underlying().(*types.Array); ok {
109
110
  arrayLen = int(at.Len())
110
111
  goElemType = at.Elem()
112
+ } else if st, ok := typ.Underlying().(*types.Slice); ok {
113
+ // For slices, get the element type
114
+ goElemType = st.Elem()
111
115
  }
112
116
  }
113
117
  if arrType.Len != nil {
@@ -116,6 +120,13 @@ func (c *GoToTSCompiler) WriteCompositeLit(exp *ast.CompositeLit) error {
116
120
  if _, err := fmt.Sscan(bl.Value, &arrayLen); err != nil {
117
121
  return fmt.Errorf("failed to parse array length from basic literal: %w", err)
118
122
  }
123
+ } else {
124
+ // Try to evaluate as a constant expression (e.g., const N = 5; [N]int{})
125
+ if lenValue := c.evaluateConstantExpr(arrType.Len); lenValue != nil {
126
+ if length, ok := lenValue.(int); ok {
127
+ arrayLen = length
128
+ }
129
+ }
119
130
  }
120
131
  }
121
132
  elemType = arrType.Elt
@@ -128,28 +139,35 @@ func (c *GoToTSCompiler) WriteCompositeLit(exp *ast.CompositeLit) error {
128
139
 
129
140
  for _, elm := range exp.Elts {
130
141
  if kv, ok := elm.(*ast.KeyValueExpr); ok {
131
- if lit, ok := kv.Key.(*ast.BasicLit); ok && lit.Kind == token.INT {
132
- var index int
133
- if _, err := fmt.Sscan(lit.Value, &index); err != nil {
134
- return fmt.Errorf("failed to parse array index from basic literal: %w", err)
135
- }
136
- elements[index] = kv.Value
137
- if index > maxIndex {
138
- maxIndex = index
142
+ // Try to evaluate the key expression as a constant (handles both literals and expressions)
143
+ if keyValue := c.evaluateConstantExpr(kv.Key); keyValue != nil {
144
+ if index, ok := keyValue.(int); ok {
145
+ elements[index] = kv.Value
146
+ if index > maxIndex {
147
+ maxIndex = index
148
+ }
149
+ hasKeyedElements = true
150
+ } else {
151
+ return fmt.Errorf("keyed array literal key must evaluate to an integer, got %T", keyValue)
139
152
  }
140
- hasKeyedElements = true
141
153
  } else {
142
- c.tsw.WriteCommentInline("unhandled keyed array literal key type")
143
- if err := c.WriteVarRefedValue(elm); err != nil {
144
- return fmt.Errorf("failed to write keyed array literal element with unhandled key type: %w", err)
145
- }
154
+ return fmt.Errorf("keyed array literal key must be a constant expression")
146
155
  }
147
156
  } else {
148
- elements[orderedCount] = elm
149
- if orderedCount > maxIndex {
150
- maxIndex = orderedCount
157
+ // For unkeyed elements, place them at the next available index
158
+ // If we have keyed elements, start after the highest keyed index
159
+ currentIndex := orderedCount
160
+ if hasKeyedElements && orderedCount <= maxIndex {
161
+ currentIndex = maxIndex + 1
162
+ for elements[currentIndex] != nil {
163
+ currentIndex++
164
+ }
151
165
  }
152
- orderedCount++
166
+ elements[currentIndex] = elm
167
+ if currentIndex > maxIndex {
168
+ maxIndex = currentIndex
169
+ }
170
+ orderedCount = currentIndex + 1
153
171
  }
154
172
  }
155
173
 
@@ -639,3 +657,28 @@ func (c *GoToTSCompiler) WriteVarRefedValue(expr ast.Expr) error {
639
657
  return c.WriteValueExpr(expr)
640
658
  }
641
659
  }
660
+
661
+ // evaluateConstantExpr attempts to evaluate a Go expression as a compile-time constant.
662
+ // It returns the constant value if successful, or nil if the expression is not a constant.
663
+ // This is used for evaluating array literal keys that are constant expressions.
664
+ func (c *GoToTSCompiler) evaluateConstantExpr(expr ast.Expr) interface{} {
665
+ // Use the type checker's constant evaluation
666
+ if tv, ok := c.pkg.TypesInfo.Types[expr]; ok && tv.Value != nil {
667
+ // The expression has a constant value
668
+ switch tv.Value.Kind() {
669
+ case constant.Int:
670
+ if val, exact := constant.Int64Val(tv.Value); exact {
671
+ return int(val)
672
+ }
673
+ case constant.Float:
674
+ if val, exact := constant.Float64Val(tv.Value); exact {
675
+ return val
676
+ }
677
+ case constant.String:
678
+ return constant.StringVal(tv.Value)
679
+ case constant.Bool:
680
+ return constant.BoolVal(tv.Value)
681
+ }
682
+ }
683
+ return nil
684
+ }
package/compiler/decl.go CHANGED
@@ -118,7 +118,7 @@ func (c *GoToTSCompiler) WriteFuncDeclAsFunction(decl *ast.FuncDecl) error {
118
118
  // Declare named return variables and initialize them to their zero values
119
119
  for _, field := range decl.Type.Results.List {
120
120
  for _, name := range field.Names {
121
- c.tsw.WriteLiterallyf("let %s: ", name.Name)
121
+ c.tsw.WriteLiterallyf("let %s: ", c.sanitizeIdentifier(name.Name))
122
122
  c.WriteTypeExpr(field.Type)
123
123
  c.tsw.WriteLiterally(" = ")
124
124
  c.WriteZeroValueForType(c.pkg.TypesInfo.TypeOf(field.Type))