goscript 0.0.33 → 0.0.35

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 (347) hide show
  1. package/compiler/analysis.go +30 -22
  2. package/compiler/analysis_test.go +14 -0
  3. package/compiler/assignment.go +45 -7
  4. package/compiler/builtin_test.go +2 -0
  5. package/compiler/compiler.go +15 -89
  6. package/compiler/compiler_test.go +0 -53
  7. package/compiler/composite-lit.go +60 -17
  8. package/compiler/decl.go +1 -1
  9. package/compiler/expr-call.go +347 -30
  10. package/compiler/expr-selector.go +28 -2
  11. package/compiler/expr.go +79 -38
  12. package/compiler/lit.go +112 -3
  13. package/compiler/primitive.go +6 -6
  14. package/compiler/protobuf.go +0 -5
  15. package/compiler/sanitize.go +101 -0
  16. package/compiler/spec-value.go +25 -18
  17. package/compiler/stmt-assign.go +128 -91
  18. package/compiler/stmt-for.go +78 -1
  19. package/compiler/stmt-range.go +333 -461
  20. package/compiler/stmt.go +46 -9
  21. package/compiler/type.go +14 -11
  22. package/dist/gs/builtin/builtin.d.ts +8 -0
  23. package/dist/gs/builtin/builtin.js +31 -0
  24. package/dist/gs/builtin/builtin.js.map +1 -1
  25. package/dist/gs/builtin/map.d.ts +4 -4
  26. package/dist/gs/builtin/map.js +12 -6
  27. package/dist/gs/builtin/map.js.map +1 -1
  28. package/dist/gs/builtin/slice.d.ts +14 -8
  29. package/dist/gs/builtin/slice.js +131 -31
  30. package/dist/gs/builtin/slice.js.map +1 -1
  31. package/dist/gs/github.com/pkg/errors/errors.d.ts +13 -0
  32. package/dist/gs/github.com/pkg/errors/errors.js +232 -0
  33. package/dist/gs/github.com/pkg/errors/errors.js.map +1 -0
  34. package/dist/gs/github.com/pkg/errors/go113.d.ts +4 -0
  35. package/dist/gs/github.com/pkg/errors/go113.js +34 -0
  36. package/dist/gs/github.com/pkg/errors/go113.js.map +1 -0
  37. package/dist/gs/github.com/pkg/errors/index.d.ts +3 -0
  38. package/dist/gs/github.com/pkg/errors/index.js +4 -0
  39. package/dist/gs/github.com/pkg/errors/index.js.map +1 -0
  40. package/dist/gs/github.com/pkg/errors/stack.d.ts +32 -0
  41. package/dist/gs/github.com/pkg/errors/stack.js +111 -0
  42. package/dist/gs/github.com/pkg/errors/stack.js.map +1 -0
  43. package/dist/gs/maps/index.d.ts +2 -0
  44. package/dist/gs/maps/index.js +3 -0
  45. package/dist/gs/maps/index.js.map +1 -0
  46. package/dist/gs/maps/iter.d.ts +7 -0
  47. package/dist/gs/maps/iter.gs.d.ts +7 -0
  48. package/dist/gs/maps/iter.gs.js +65 -0
  49. package/dist/gs/maps/iter.gs.js.map +1 -0
  50. package/dist/gs/maps/iter.js +57 -0
  51. package/dist/gs/maps/iter.js.map +1 -0
  52. package/dist/gs/maps/maps.d.ts +7 -0
  53. package/dist/gs/maps/maps.gs.d.ts +7 -0
  54. package/dist/gs/maps/maps.gs.js +79 -0
  55. package/dist/gs/maps/maps.gs.js.map +1 -0
  56. package/dist/gs/maps/maps.js +67 -0
  57. package/dist/gs/maps/maps.js.map +1 -0
  58. package/dist/gs/math/abs.gs.d.ts +1 -0
  59. package/dist/gs/math/abs.gs.js +10 -0
  60. package/dist/gs/math/abs.gs.js.map +1 -0
  61. package/dist/gs/math/acosh.gs.d.ts +2 -0
  62. package/dist/gs/math/acosh.gs.js +14 -0
  63. package/dist/gs/math/acosh.gs.js.map +1 -0
  64. package/dist/gs/math/asin.gs.d.ts +4 -0
  65. package/dist/gs/math/asin.gs.js +24 -0
  66. package/dist/gs/math/asin.gs.js.map +1 -0
  67. package/dist/gs/math/asinh.gs.d.ts +2 -0
  68. package/dist/gs/math/asinh.gs.js +14 -0
  69. package/dist/gs/math/asinh.gs.js.map +1 -0
  70. package/dist/gs/math/atan.gs.d.ts +4 -0
  71. package/dist/gs/math/atan.gs.js +22 -0
  72. package/dist/gs/math/atan.gs.js.map +1 -0
  73. package/dist/gs/math/atan2.gs.d.ts +2 -0
  74. package/dist/gs/math/atan2.gs.js +30 -0
  75. package/dist/gs/math/atan2.gs.js.map +1 -0
  76. package/dist/gs/math/atanh.gs.d.ts +2 -0
  77. package/dist/gs/math/atanh.gs.js +16 -0
  78. package/dist/gs/math/atanh.gs.js.map +1 -0
  79. package/dist/gs/math/bits.gs.d.ts +5 -0
  80. package/dist/gs/math/bits.gs.js +46 -0
  81. package/dist/gs/math/bits.gs.js.map +1 -0
  82. package/dist/gs/math/cbrt.gs.d.ts +2 -0
  83. package/dist/gs/math/cbrt.gs.js +14 -0
  84. package/dist/gs/math/cbrt.gs.js.map +1 -0
  85. package/dist/gs/math/const.gs.d.ts +30 -0
  86. package/dist/gs/math/const.gs.js +61 -0
  87. package/dist/gs/math/const.gs.js.map +1 -0
  88. package/dist/gs/math/copysign.gs.d.ts +1 -0
  89. package/dist/gs/math/copysign.gs.js +20 -0
  90. package/dist/gs/math/copysign.gs.js.map +1 -0
  91. package/dist/gs/math/dim.gs.d.ts +5 -0
  92. package/dist/gs/math/dim.gs.js +69 -0
  93. package/dist/gs/math/dim.gs.js.map +1 -0
  94. package/dist/gs/math/erf.gs.d.ts +4 -0
  95. package/dist/gs/math/erf.gs.js +336 -0
  96. package/dist/gs/math/erf.gs.js.map +1 -0
  97. package/dist/gs/math/erfinv.gs.d.ts +2 -0
  98. package/dist/gs/math/erfinv.gs.js +118 -0
  99. package/dist/gs/math/erfinv.gs.js.map +1 -0
  100. package/dist/gs/math/exp.gs.d.ts +5 -0
  101. package/dist/gs/math/exp.gs.js +30 -0
  102. package/dist/gs/math/exp.gs.js.map +1 -0
  103. package/dist/gs/math/expm1.gs.d.ts +2 -0
  104. package/dist/gs/math/expm1.gs.js +17 -0
  105. package/dist/gs/math/expm1.gs.js.map +1 -0
  106. package/dist/gs/math/floor.gs.d.ts +8 -0
  107. package/dist/gs/math/floor.gs.js +75 -0
  108. package/dist/gs/math/floor.gs.js.map +1 -0
  109. package/dist/gs/math/fma.gs.d.ts +1 -0
  110. package/dist/gs/math/fma.gs.js +8 -0
  111. package/dist/gs/math/fma.gs.js.map +1 -0
  112. package/dist/gs/math/frexp.gs.d.ts +2 -0
  113. package/dist/gs/math/frexp.gs.js +28 -0
  114. package/dist/gs/math/frexp.gs.js.map +1 -0
  115. package/dist/gs/math/gamma.gs.d.ts +3 -0
  116. package/dist/gs/math/gamma.gs.js +149 -0
  117. package/dist/gs/math/gamma.gs.js.map +1 -0
  118. package/dist/gs/math/hypot.gs.d.ts +2 -0
  119. package/dist/gs/math/hypot.gs.js +16 -0
  120. package/dist/gs/math/hypot.gs.js.map +1 -0
  121. package/dist/gs/math/index.d.ts +44 -0
  122. package/dist/gs/math/index.js +45 -0
  123. package/dist/gs/math/index.js.map +1 -0
  124. package/dist/gs/math/j0.gs.d.ts +4 -0
  125. package/dist/gs/math/j0.gs.js +228 -0
  126. package/dist/gs/math/j0.gs.js.map +1 -0
  127. package/dist/gs/math/j1.gs.d.ts +4 -0
  128. package/dist/gs/math/j1.gs.js +211 -0
  129. package/dist/gs/math/j1.gs.js.map +1 -0
  130. package/dist/gs/math/jn.gs.d.ts +2 -0
  131. package/dist/gs/math/jn.gs.js +412 -0
  132. package/dist/gs/math/jn.gs.js.map +1 -0
  133. package/dist/gs/math/ldexp.gs.d.ts +2 -0
  134. package/dist/gs/math/ldexp.gs.js +20 -0
  135. package/dist/gs/math/ldexp.gs.js.map +1 -0
  136. package/dist/gs/math/lgamma.gs.d.ts +2 -0
  137. package/dist/gs/math/lgamma.gs.js +243 -0
  138. package/dist/gs/math/lgamma.gs.js.map +1 -0
  139. package/dist/gs/math/log.gs.d.ts +2 -0
  140. package/dist/gs/math/log.gs.js +16 -0
  141. package/dist/gs/math/log.gs.js.map +1 -0
  142. package/dist/gs/math/log10.gs.d.ts +4 -0
  143. package/dist/gs/math/log10.gs.js +17 -0
  144. package/dist/gs/math/log10.gs.js.map +1 -0
  145. package/dist/gs/math/log1p.gs.d.ts +2 -0
  146. package/dist/gs/math/log1p.gs.js +17 -0
  147. package/dist/gs/math/log1p.gs.js.map +1 -0
  148. package/dist/gs/math/logb.gs.d.ts +3 -0
  149. package/dist/gs/math/logb.gs.js +43 -0
  150. package/dist/gs/math/logb.gs.js.map +1 -0
  151. package/dist/gs/math/mod.gs.d.ts +2 -0
  152. package/dist/gs/math/mod.gs.js +26 -0
  153. package/dist/gs/math/mod.gs.js.map +1 -0
  154. package/dist/gs/math/modf.gs.d.ts +2 -0
  155. package/dist/gs/math/modf.gs.js +24 -0
  156. package/dist/gs/math/modf.gs.js.map +1 -0
  157. package/dist/gs/math/nextafter.gs.d.ts +2 -0
  158. package/dist/gs/math/nextafter.gs.js +66 -0
  159. package/dist/gs/math/nextafter.gs.js.map +1 -0
  160. package/dist/gs/math/pow.gs.d.ts +3 -0
  161. package/dist/gs/math/pow.gs.js +40 -0
  162. package/dist/gs/math/pow.gs.js.map +1 -0
  163. package/dist/gs/math/pow10.gs.d.ts +1 -0
  164. package/dist/gs/math/pow10.gs.js +14 -0
  165. package/dist/gs/math/pow10.gs.js.map +1 -0
  166. package/dist/gs/math/remainder.gs.d.ts +2 -0
  167. package/dist/gs/math/remainder.gs.js +25 -0
  168. package/dist/gs/math/remainder.gs.js.map +1 -0
  169. package/dist/gs/math/signbit.gs.d.ts +1 -0
  170. package/dist/gs/math/signbit.gs.js +5 -0
  171. package/dist/gs/math/signbit.gs.js.map +1 -0
  172. package/dist/gs/math/sin.gs.d.ts +4 -0
  173. package/dist/gs/math/sin.gs.js +29 -0
  174. package/dist/gs/math/sin.gs.js.map +1 -0
  175. package/dist/gs/math/sincos.gs.d.ts +1 -0
  176. package/dist/gs/math/sincos.gs.js +11 -0
  177. package/dist/gs/math/sincos.gs.js.map +1 -0
  178. package/dist/gs/math/sinh.gs.d.ts +4 -0
  179. package/dist/gs/math/sinh.gs.js +27 -0
  180. package/dist/gs/math/sinh.gs.js.map +1 -0
  181. package/dist/gs/math/sqrt.gs.d.ts +2 -0
  182. package/dist/gs/math/sqrt.gs.js +15 -0
  183. package/dist/gs/math/sqrt.gs.js.map +1 -0
  184. package/dist/gs/math/tan.gs.d.ts +2 -0
  185. package/dist/gs/math/tan.gs.js +17 -0
  186. package/dist/gs/math/tan.gs.js.map +1 -0
  187. package/dist/gs/math/tanh.gs.d.ts +2 -0
  188. package/dist/gs/math/tanh.gs.js +17 -0
  189. package/dist/gs/math/tanh.gs.js.map +1 -0
  190. package/dist/gs/math/trig_reduce.gs.d.ts +1 -0
  191. package/dist/gs/math/trig_reduce.gs.js +62 -0
  192. package/dist/gs/math/trig_reduce.gs.js.map +1 -0
  193. package/dist/gs/math/unsafe.gs.d.ts +4 -0
  194. package/dist/gs/math/unsafe.gs.js +47 -0
  195. package/dist/gs/math/unsafe.gs.js.map +1 -0
  196. package/dist/gs/slices/slices.d.ts +6 -0
  197. package/dist/gs/slices/slices.js +8 -0
  198. package/dist/gs/slices/slices.js.map +1 -1
  199. package/dist/gs/strconv/atob.gs.d.ts +4 -0
  200. package/dist/gs/strconv/atob.gs.js +42 -0
  201. package/dist/gs/strconv/atob.gs.js.map +1 -0
  202. package/dist/gs/strconv/atof.gs.d.ts +2 -0
  203. package/dist/gs/strconv/atof.gs.js +51 -0
  204. package/dist/gs/strconv/atof.gs.js.map +1 -0
  205. package/dist/gs/strconv/atoi.gs.d.ts +33 -0
  206. package/dist/gs/strconv/atoi.gs.js +200 -0
  207. package/dist/gs/strconv/atoi.gs.js.map +1 -0
  208. package/dist/gs/strconv/doc.gs.d.ts +1 -0
  209. package/dist/gs/strconv/doc.gs.js +2 -0
  210. package/dist/gs/strconv/doc.gs.js.map +1 -0
  211. package/dist/gs/strconv/ftoa.gs.d.ts +3 -0
  212. package/dist/gs/strconv/ftoa.gs.js +58 -0
  213. package/dist/gs/strconv/ftoa.gs.js.map +1 -0
  214. package/dist/gs/strconv/index.d.ts +6 -0
  215. package/dist/gs/strconv/index.js +7 -0
  216. package/dist/gs/strconv/index.js.map +1 -0
  217. package/dist/gs/strconv/itoa.gs.d.ts +6 -0
  218. package/dist/gs/strconv/itoa.gs.js +37 -0
  219. package/dist/gs/strconv/itoa.gs.js.map +1 -0
  220. package/dist/gs/strconv/quote.gs.d.ts +19 -0
  221. package/dist/gs/strconv/quote.gs.js +217 -0
  222. package/dist/gs/strconv/quote.gs.js.map +1 -0
  223. package/dist/gs/strings/index.d.ts +3 -0
  224. package/dist/gs/strings/index.js +4 -0
  225. package/dist/gs/strings/index.js.map +1 -1
  226. package/dist/gs/strings/replace.d.ts +0 -74
  227. package/dist/gs/strings/replace.js +6 -204
  228. package/dist/gs/strings/replace.js.map +1 -1
  229. package/dist/gs/strings/search.d.ts +0 -1
  230. package/dist/gs/strings/search.js +0 -21
  231. package/dist/gs/strings/search.js.map +1 -1
  232. package/gs/builtin/builtin.ts +40 -0
  233. package/gs/builtin/map.ts +12 -7
  234. package/gs/builtin/slice.ts +174 -34
  235. package/gs/github.com/pkg/errors/errors.ts +307 -0
  236. package/gs/github.com/pkg/errors/go113.ts +39 -0
  237. package/gs/github.com/pkg/errors/index.ts +3 -0
  238. package/gs/github.com/pkg/errors/stack.ts +127 -0
  239. package/gs/maps/index.ts +2 -0
  240. package/gs/maps/iter.ts +67 -0
  241. package/gs/maps/maps.ts +89 -0
  242. package/gs/math/TODO.md +156 -0
  243. package/gs/math/abs.gs.test.ts +29 -0
  244. package/gs/math/abs.gs.ts +13 -0
  245. package/gs/math/acosh.gs.test.ts +39 -0
  246. package/gs/math/acosh.gs.ts +21 -0
  247. package/gs/math/asin.gs.test.ts +66 -0
  248. package/gs/math/asin.gs.ts +27 -0
  249. package/gs/math/asinh.gs.test.ts +37 -0
  250. package/gs/math/asinh.gs.ts +21 -0
  251. package/gs/math/atan.gs.test.ts +49 -0
  252. package/gs/math/atan.gs.ts +27 -0
  253. package/gs/math/atan2.gs.test.ts +55 -0
  254. package/gs/math/atan2.gs.ts +37 -0
  255. package/gs/math/atanh.gs.test.ts +47 -0
  256. package/gs/math/atanh.gs.ts +21 -0
  257. package/gs/math/bits.gs.test.ts +88 -0
  258. package/gs/math/bits.gs.ts +61 -0
  259. package/gs/math/cbrt.gs.test.ts +57 -0
  260. package/gs/math/cbrt.gs.ts +20 -0
  261. package/gs/math/const.gs.test.ts +54 -0
  262. package/gs/math/const.gs.ts +93 -0
  263. package/gs/math/copysign.gs.test.ts +44 -0
  264. package/gs/math/copysign.gs.ts +27 -0
  265. package/gs/math/dim.gs.test.ts +102 -0
  266. package/gs/math/dim.gs.ts +84 -0
  267. package/gs/math/erf.gs.test.ts +92 -0
  268. package/gs/math/erf.gs.ts +409 -0
  269. package/gs/math/erfinv.gs.test.ts +104 -0
  270. package/gs/math/erfinv.gs.ts +169 -0
  271. package/gs/math/exp.gs.test.ts +82 -0
  272. package/gs/math/exp.gs.ts +39 -0
  273. package/gs/math/expm1.gs.test.ts +48 -0
  274. package/gs/math/expm1.gs.ts +23 -0
  275. package/gs/math/floor.gs.test.ts +146 -0
  276. package/gs/math/floor.gs.ts +88 -0
  277. package/gs/math/fma.gs.test.ts +83 -0
  278. package/gs/math/fma.gs.ts +7 -0
  279. package/gs/math/frexp.gs.test.ts +146 -0
  280. package/gs/math/frexp.gs.ts +37 -0
  281. package/gs/math/gamma.gs.test.ts +66 -0
  282. package/gs/math/gamma.gs.ts +158 -0
  283. package/gs/math/hypot.gs.test.ts +73 -0
  284. package/gs/math/hypot.gs.ts +23 -0
  285. package/gs/math/index.ts +44 -0
  286. package/gs/math/j0.gs.test.ts +74 -0
  287. package/gs/math/j0.gs.ts +257 -0
  288. package/gs/math/j1.gs.test.ts +81 -0
  289. package/gs/math/j1.gs.ts +231 -0
  290. package/gs/math/jn.gs.test.ts +133 -0
  291. package/gs/math/jn.gs.ts +447 -0
  292. package/gs/math/ldexp.gs.test.ts +128 -0
  293. package/gs/math/ldexp.gs.ts +28 -0
  294. package/gs/math/lgamma.gs.test.ts +102 -0
  295. package/gs/math/lgamma.gs.ts +251 -0
  296. package/gs/math/log.gs.test.ts +40 -0
  297. package/gs/math/log.gs.ts +21 -0
  298. package/gs/math/log10.gs.test.ts +80 -0
  299. package/gs/math/log10.gs.ts +25 -0
  300. package/gs/math/log1p.gs.test.ts +55 -0
  301. package/gs/math/log1p.gs.ts +24 -0
  302. package/gs/math/logb.gs.test.ts +87 -0
  303. package/gs/math/logb.gs.ts +54 -0
  304. package/gs/math/mod.gs.test.ts +64 -0
  305. package/gs/math/mod.gs.ts +36 -0
  306. package/gs/math/modf.gs.test.ts +80 -0
  307. package/gs/math/modf.gs.ts +32 -0
  308. package/gs/math/nextafter.gs.test.ts +107 -0
  309. package/gs/math/nextafter.gs.ts +71 -0
  310. package/gs/math/pow.gs.test.ts +103 -0
  311. package/gs/math/pow.gs.ts +55 -0
  312. package/gs/math/pow10.gs.test.ts +58 -0
  313. package/gs/math/pow10.gs.ts +19 -0
  314. package/gs/math/remainder.gs.test.ts +70 -0
  315. package/gs/math/remainder.gs.ts +33 -0
  316. package/gs/math/signbit.gs.test.ts +33 -0
  317. package/gs/math/signbit.gs.ts +8 -0
  318. package/gs/math/sin.gs.test.ts +83 -0
  319. package/gs/math/sin.gs.ts +38 -0
  320. package/gs/math/sincos.gs.test.ts +91 -0
  321. package/gs/math/sincos.gs.ts +15 -0
  322. package/gs/math/sinh.gs.test.ts +66 -0
  323. package/gs/math/sinh.gs.ts +34 -0
  324. package/gs/math/sqrt.gs.test.ts +49 -0
  325. package/gs/math/sqrt.gs.ts +20 -0
  326. package/gs/math/tan.gs.test.ts +50 -0
  327. package/gs/math/tan.gs.ts +23 -0
  328. package/gs/math/tanh.gs.test.ts +52 -0
  329. package/gs/math/tanh.gs.ts +23 -0
  330. package/gs/math/trig_reduce.gs.ts +66 -0
  331. package/gs/math/unsafe.gs.ts +52 -0
  332. package/gs/slices/slices.ts +9 -0
  333. package/gs/strconv/atob.gs.ts +45 -0
  334. package/gs/strconv/atof.gs.ts +60 -0
  335. package/gs/strconv/atoi.gs.ts +243 -0
  336. package/gs/strconv/doc.gs.ts +2 -0
  337. package/gs/strconv/ftoa.gs.ts +66 -0
  338. package/gs/strconv/index.ts +6 -0
  339. package/gs/strconv/itoa.gs.ts +41 -0
  340. package/gs/strconv/quote.gs.ts +245 -0
  341. package/gs/strings/index.ts +4 -0
  342. package/gs/strings/replace.ts +9 -237
  343. package/gs/strings/search.ts +0 -28
  344. package/package.json +1 -1
  345. package/gs/stringslite/godoc.txt +0 -17
  346. package/gs/stringslite/index.ts +0 -1
  347. package/gs/stringslite/strings.ts +0 -82
@@ -206,17 +206,31 @@ func (c *GoToTSCompiler) WriteCallExpr(exp *ast.CallExpr) error {
206
206
 
207
207
  // Check if it's make([]byte, ...)
208
208
  if basicElem, isBasic := goElemType.(*types.Basic); isBasic && basicElem.Kind() == types.Uint8 {
209
- c.tsw.WriteLiterally("new Uint8Array(")
210
- if len(exp.Args) >= 2 {
209
+ // Check if capacity is different from length
210
+ if len(exp.Args) == 3 {
211
+ // make([]byte, len, cap) - need to handle capacity
212
+ c.tsw.WriteLiterally("$.makeSlice<number>(")
211
213
  if err := c.WriteValueExpr(exp.Args[1]); err != nil { // Length
212
214
  return err
213
215
  }
214
- // Capacity argument for make([]byte, len, cap) is ignored for new Uint8Array(len)
216
+ c.tsw.WriteLiterally(", ")
217
+ if err := c.WriteValueExpr(exp.Args[2]); err != nil { // Capacity
218
+ return err
219
+ }
220
+ c.tsw.WriteLiterally(", 'byte')")
215
221
  } else {
216
- // If no length is provided, default to 0
217
- c.tsw.WriteLiterally("0")
222
+ // make([]byte, len) - capacity equals length, use Uint8Array
223
+ c.tsw.WriteLiterally("new Uint8Array(")
224
+ if len(exp.Args) >= 2 {
225
+ if err := c.WriteValueExpr(exp.Args[1]); err != nil { // Length
226
+ return err
227
+ }
228
+ } else {
229
+ // If no length is provided, default to 0
230
+ c.tsw.WriteLiterally("0")
231
+ }
232
+ c.tsw.WriteLiterally(")")
218
233
  }
219
- c.tsw.WriteLiterally(")")
220
234
  return nil // Handled make for []byte
221
235
  }
222
236
 
@@ -251,11 +265,13 @@ func (c *GoToTSCompiler) WriteCallExpr(exp *ast.CallExpr) error {
251
265
  c.WriteGoType(goElemType, GoTypeContextGeneral) // Write the element type
252
266
  c.tsw.WriteLiterally(">(")
253
267
 
268
+ hasCapacity := len(exp.Args) == 3
269
+
254
270
  if len(exp.Args) >= 2 {
255
271
  if err := c.WriteValueExpr(exp.Args[1]); err != nil { // Length
256
272
  return err
257
273
  }
258
- if len(exp.Args) == 3 {
274
+ if hasCapacity {
259
275
  c.tsw.WriteLiterally(", ")
260
276
  if err := c.WriteValueExpr(exp.Args[2]); err != nil { // Capacity
261
277
  return err
@@ -267,6 +283,19 @@ func (c *GoToTSCompiler) WriteCallExpr(exp *ast.CallExpr) error {
267
283
  // If no length is provided, default to 0
268
284
  c.tsw.WriteLiterally("0")
269
285
  }
286
+
287
+ // Add type hint for proper zero value initialization
288
+ typeHint := c.getTypeHintForSliceElement(goElemType)
289
+ if typeHint != "" {
290
+ if !hasCapacity {
291
+ // If no capacity was provided, add undefined for capacity parameter
292
+ c.tsw.WriteLiterally(", undefined")
293
+ }
294
+ c.tsw.WriteLiterally(", '")
295
+ c.tsw.WriteLiterally(typeHint)
296
+ c.tsw.WriteLiterally("'")
297
+ }
298
+
270
299
  c.tsw.WriteLiterally(")")
271
300
  return nil // Handled make for slice
272
301
  }
@@ -291,17 +320,31 @@ func (c *GoToTSCompiler) WriteCallExpr(exp *ast.CallExpr) error {
291
320
  if elemType != nil {
292
321
  // Check if it's make(S, ...) where S constrains to []byte
293
322
  if basicElem, isBasic := elemType.(*types.Basic); isBasic && basicElem.Kind() == types.Uint8 {
294
- c.tsw.WriteLiterally("new Uint8Array(")
295
- if len(exp.Args) >= 2 {
323
+ // Check if capacity is different from length
324
+ if len(exp.Args) == 3 {
325
+ // make([]byte, len, cap) - need to handle capacity
326
+ c.tsw.WriteLiterally("$.makeSlice<number>(")
296
327
  if err := c.WriteValueExpr(exp.Args[1]); err != nil { // Length
297
328
  return err
298
329
  }
299
- // Capacity argument for make([]byte, len, cap) is ignored for new Uint8Array(len)
330
+ c.tsw.WriteLiterally(", ")
331
+ if err := c.WriteValueExpr(exp.Args[2]); err != nil { // Capacity
332
+ return err
333
+ }
334
+ c.tsw.WriteLiterally(", 'byte')")
300
335
  } else {
301
- // If no length is provided, default to 0
302
- c.tsw.WriteLiterally("0")
336
+ // make([]byte, len) - capacity equals length, use Uint8Array
337
+ c.tsw.WriteLiterally("new Uint8Array(")
338
+ if len(exp.Args) >= 2 {
339
+ if err := c.WriteValueExpr(exp.Args[1]); err != nil { // Length
340
+ return err
341
+ }
342
+ } else {
343
+ // If no length is provided, default to 0
344
+ c.tsw.WriteLiterally("0")
345
+ }
346
+ c.tsw.WriteLiterally(")")
303
347
  }
304
- c.tsw.WriteLiterally(")")
305
348
  return nil // Handled make for generic []byte
306
349
  }
307
350
 
@@ -309,11 +352,13 @@ func (c *GoToTSCompiler) WriteCallExpr(exp *ast.CallExpr) error {
309
352
  c.WriteGoType(elemType, GoTypeContextGeneral) // Write the element type
310
353
  c.tsw.WriteLiterally(">(")
311
354
 
355
+ hasCapacity := len(exp.Args) == 3
356
+
312
357
  if len(exp.Args) >= 2 {
313
358
  if err := c.WriteValueExpr(exp.Args[1]); err != nil { // Length
314
359
  return err
315
360
  }
316
- if len(exp.Args) == 3 {
361
+ if hasCapacity {
317
362
  c.tsw.WriteLiterally(", ")
318
363
  if err := c.WriteValueExpr(exp.Args[2]); err != nil { // Capacity
319
364
  return err
@@ -325,6 +370,19 @@ func (c *GoToTSCompiler) WriteCallExpr(exp *ast.CallExpr) error {
325
370
  // If no length is provided, default to 0
326
371
  c.tsw.WriteLiterally("0")
327
372
  }
373
+
374
+ // Add type hint for proper zero value initialization
375
+ typeHint := c.getTypeHintForSliceElement(elemType)
376
+ if typeHint != "" {
377
+ if !hasCapacity {
378
+ // If no capacity was provided, add undefined for capacity parameter
379
+ c.tsw.WriteLiterally(", undefined")
380
+ }
381
+ c.tsw.WriteLiterally(", '")
382
+ c.tsw.WriteLiterally(typeHint)
383
+ c.tsw.WriteLiterally("'")
384
+ }
385
+
328
386
  c.tsw.WriteLiterally(")")
329
387
  return nil // Handled make for generic slice
330
388
  }
@@ -340,17 +398,31 @@ func (c *GoToTSCompiler) WriteCallExpr(exp *ast.CallExpr) error {
340
398
 
341
399
  // Check if it's a named type with []byte underlying type
342
400
  if basicElem, isBasic := goElemType.(*types.Basic); isBasic && basicElem.Kind() == types.Uint8 {
343
- c.tsw.WriteLiterally("new Uint8Array(")
344
- if len(exp.Args) >= 2 {
401
+ // Check if capacity is different from length
402
+ if len(exp.Args) == 3 {
403
+ // make([]byte, len, cap) - need to handle capacity
404
+ c.tsw.WriteLiterally("$.makeSlice<number>(")
345
405
  if err := c.WriteValueExpr(exp.Args[1]); err != nil { // Length
346
406
  return err
347
407
  }
348
- // Capacity argument for make([]byte, len, cap) is ignored for new Uint8Array(len)
408
+ c.tsw.WriteLiterally(", ")
409
+ if err := c.WriteValueExpr(exp.Args[2]); err != nil { // Capacity
410
+ return err
411
+ }
412
+ c.tsw.WriteLiterally(", 'byte')")
349
413
  } else {
350
- // If no length is provided, default to 0
351
- c.tsw.WriteLiterally("0")
414
+ // make([]byte, len) - capacity equals length, use Uint8Array
415
+ c.tsw.WriteLiterally("new Uint8Array(")
416
+ if len(exp.Args) >= 2 {
417
+ if err := c.WriteValueExpr(exp.Args[1]); err != nil { // Length
418
+ return err
419
+ }
420
+ } else {
421
+ // If no length is provided, default to 0
422
+ c.tsw.WriteLiterally("0")
423
+ }
424
+ c.tsw.WriteLiterally(")")
352
425
  }
353
- c.tsw.WriteLiterally(")")
354
426
  return nil // Handled make for named []byte type
355
427
  }
356
428
 
@@ -359,11 +431,13 @@ func (c *GoToTSCompiler) WriteCallExpr(exp *ast.CallExpr) error {
359
431
  c.WriteGoType(goElemType, GoTypeContextGeneral) // Write the element type
360
432
  c.tsw.WriteLiterally(">(")
361
433
 
434
+ hasCapacity := len(exp.Args) == 3
435
+
362
436
  if len(exp.Args) >= 2 {
363
437
  if err := c.WriteValueExpr(exp.Args[1]); err != nil { // Length
364
438
  return err
365
439
  }
366
- if len(exp.Args) == 3 {
440
+ if hasCapacity {
367
441
  c.tsw.WriteLiterally(", ")
368
442
  if err := c.WriteValueExpr(exp.Args[2]); err != nil { // Capacity
369
443
  return err
@@ -375,6 +449,19 @@ func (c *GoToTSCompiler) WriteCallExpr(exp *ast.CallExpr) error {
375
449
  // If no length is provided, default to 0
376
450
  c.tsw.WriteLiterally("0")
377
451
  }
452
+
453
+ // Add type hint for proper zero value initialization
454
+ typeHint := c.getTypeHintForSliceElement(goElemType)
455
+ if typeHint != "" {
456
+ if !hasCapacity {
457
+ // If no capacity was provided, add undefined for capacity parameter
458
+ c.tsw.WriteLiterally(", undefined")
459
+ }
460
+ c.tsw.WriteLiterally(", '")
461
+ c.tsw.WriteLiterally(typeHint)
462
+ c.tsw.WriteLiterally("'")
463
+ }
464
+
378
465
  c.tsw.WriteLiterally(")")
379
466
  return nil // Handled make for named slice type
380
467
  }
@@ -461,17 +548,31 @@ func (c *GoToTSCompiler) WriteCallExpr(exp *ast.CallExpr) error {
461
548
 
462
549
  // Check if it's an instantiated generic type with []byte underlying type
463
550
  if basicElem, isBasic := goElemType.(*types.Basic); isBasic && basicElem.Kind() == types.Uint8 {
464
- c.tsw.WriteLiterally("new Uint8Array(")
465
- if len(exp.Args) >= 2 {
551
+ // Check if capacity is different from length
552
+ if len(exp.Args) == 3 {
553
+ // make([]byte, len, cap) - need to handle capacity
554
+ c.tsw.WriteLiterally("$.makeSlice<number>(")
466
555
  if err := c.WriteValueExpr(exp.Args[1]); err != nil { // Length
467
556
  return err
468
557
  }
469
- // Capacity argument for make([]byte, len, cap) is ignored for new Uint8Array(len)
558
+ c.tsw.WriteLiterally(", ")
559
+ if err := c.WriteValueExpr(exp.Args[2]); err != nil { // Capacity
560
+ return err
561
+ }
562
+ c.tsw.WriteLiterally(", 'byte')")
470
563
  } else {
471
- // If no length is provided, default to 0
472
- c.tsw.WriteLiterally("0")
564
+ // make([]byte, len) - capacity equals length, use Uint8Array
565
+ c.tsw.WriteLiterally("new Uint8Array(")
566
+ if len(exp.Args) >= 2 {
567
+ if err := c.WriteValueExpr(exp.Args[1]); err != nil { // Length
568
+ return err
569
+ }
570
+ } else {
571
+ // If no length is provided, default to 0
572
+ c.tsw.WriteLiterally("0")
573
+ }
574
+ c.tsw.WriteLiterally(")")
473
575
  }
474
- c.tsw.WriteLiterally(")")
475
576
  return nil // Handled make for instantiated generic []byte type
476
577
  }
477
578
 
@@ -480,11 +581,13 @@ func (c *GoToTSCompiler) WriteCallExpr(exp *ast.CallExpr) error {
480
581
  c.WriteGoType(goElemType, GoTypeContextGeneral) // Write the element type
481
582
  c.tsw.WriteLiterally(">(")
482
583
 
584
+ hasCapacity := len(exp.Args) == 3
585
+
483
586
  if len(exp.Args) >= 2 {
484
587
  if err := c.WriteValueExpr(exp.Args[1]); err != nil { // Length
485
588
  return err
486
589
  }
487
- if len(exp.Args) == 3 {
590
+ if hasCapacity {
488
591
  c.tsw.WriteLiterally(", ")
489
592
  if err := c.WriteValueExpr(exp.Args[2]); err != nil { // Capacity
490
593
  return err
@@ -496,6 +599,19 @@ func (c *GoToTSCompiler) WriteCallExpr(exp *ast.CallExpr) error {
496
599
  // If no length is provided, default to 0
497
600
  c.tsw.WriteLiterally("0")
498
601
  }
602
+
603
+ // Add type hint for proper zero value initialization
604
+ typeHint := c.getTypeHintForSliceElement(goElemType)
605
+ if typeHint != "" {
606
+ if !hasCapacity {
607
+ // If no capacity was provided, add undefined for capacity parameter
608
+ c.tsw.WriteLiterally(", undefined")
609
+ }
610
+ c.tsw.WriteLiterally(", '")
611
+ c.tsw.WriteLiterally(typeHint)
612
+ c.tsw.WriteLiterally("'")
613
+ }
614
+
499
615
  c.tsw.WriteLiterally(")")
500
616
  return nil // Handled make for instantiated generic slice type
501
617
  }
@@ -545,6 +661,143 @@ func (c *GoToTSCompiler) WriteCallExpr(exp *ast.CallExpr) error {
545
661
  }
546
662
  }
547
663
  }
664
+ // Handle selector expressions: make(pkg.TypeName, ...)
665
+ // This handles cases like: make(fstest.MapFS) where fstest.MapFS is map[string]*MapFile
666
+ if selectorExpr, ok := exp.Args[0].(*ast.SelectorExpr); ok {
667
+ // Get the type information for the selector expression
668
+ if typ := c.pkg.TypesInfo.TypeOf(selectorExpr); typ != nil {
669
+ // Check the underlying type of the selector expression
670
+ underlying := typ.Underlying()
671
+
672
+ // Handle selector expression map types: make(pkg.MapType)
673
+ if mapType, isMap := underlying.(*types.Map); isMap {
674
+ c.tsw.WriteLiterally("$.makeMap<")
675
+ c.WriteGoType(mapType.Key(), GoTypeContextGeneral) // Write the key type
676
+ c.tsw.WriteLiterally(", ")
677
+ c.WriteGoType(mapType.Elem(), GoTypeContextGeneral) // Write the value type
678
+ c.tsw.WriteLiterally(">()")
679
+ return nil // Handled make for selector expression map type
680
+ }
681
+
682
+ // Handle selector expression slice types: make(pkg.SliceType, len, cap)
683
+ if sliceType, isSlice := underlying.(*types.Slice); isSlice {
684
+ goElemType := sliceType.Elem()
685
+
686
+ // Check if it's a selector expression with []byte underlying type
687
+ if basicElem, isBasic := goElemType.(*types.Basic); isBasic && basicElem.Kind() == types.Uint8 {
688
+ // Check if capacity is different from length
689
+ if len(exp.Args) == 3 {
690
+ // make([]byte, len, cap) - need to handle capacity
691
+ c.tsw.WriteLiterally("$.makeSlice<number>(")
692
+ if err := c.WriteValueExpr(exp.Args[1]); err != nil { // Length
693
+ return err
694
+ }
695
+ c.tsw.WriteLiterally(", ")
696
+ if err := c.WriteValueExpr(exp.Args[2]); err != nil { // Capacity
697
+ return err
698
+ }
699
+ c.tsw.WriteLiterally(", 'byte')")
700
+ } else {
701
+ // make([]byte, len) - capacity equals length, use Uint8Array
702
+ c.tsw.WriteLiterally("new Uint8Array(")
703
+ if len(exp.Args) >= 2 {
704
+ if err := c.WriteValueExpr(exp.Args[1]); err != nil { // Length
705
+ return err
706
+ }
707
+ } else {
708
+ // If no length is provided, default to 0
709
+ c.tsw.WriteLiterally("0")
710
+ }
711
+ c.tsw.WriteLiterally(")")
712
+ }
713
+ return nil // Handled make for selector expression []byte type
714
+ }
715
+
716
+ // Handle other selector expression slice types
717
+ c.tsw.WriteLiterally("$.makeSlice<")
718
+ c.WriteGoType(goElemType, GoTypeContextGeneral) // Write the element type
719
+ c.tsw.WriteLiterally(">(")
720
+
721
+ hasCapacity := len(exp.Args) == 3
722
+
723
+ if len(exp.Args) >= 2 {
724
+ if err := c.WriteValueExpr(exp.Args[1]); err != nil { // Length
725
+ return err
726
+ }
727
+ if hasCapacity {
728
+ c.tsw.WriteLiterally(", ")
729
+ if err := c.WriteValueExpr(exp.Args[2]); err != nil { // Capacity
730
+ return err
731
+ }
732
+ } else if len(exp.Args) > 3 {
733
+ return errors.New("makeSlice expects 2 or 3 arguments")
734
+ }
735
+ } else {
736
+ // If no length is provided, default to 0
737
+ c.tsw.WriteLiterally("0")
738
+ }
739
+
740
+ // Add type hint for proper zero value initialization
741
+ typeHint := c.getTypeHintForSliceElement(goElemType)
742
+ if typeHint != "" {
743
+ if !hasCapacity {
744
+ // If no capacity was provided, add undefined for capacity parameter
745
+ c.tsw.WriteLiterally(", undefined")
746
+ }
747
+ c.tsw.WriteLiterally(", '")
748
+ c.tsw.WriteLiterally(typeHint)
749
+ c.tsw.WriteLiterally("'")
750
+ }
751
+
752
+ c.tsw.WriteLiterally(")")
753
+ return nil // Handled make for selector expression slice type
754
+ }
755
+
756
+ // Handle selector expression channel types: make(pkg.ChannelType, bufferSize)
757
+ if chanType, isChan := underlying.(*types.Chan); isChan {
758
+ c.tsw.WriteLiterally("$.makeChannel<")
759
+ c.WriteGoType(chanType.Elem(), GoTypeContextGeneral)
760
+ c.tsw.WriteLiterally(">(")
761
+
762
+ // If buffer size is provided, add it
763
+ if len(exp.Args) >= 2 {
764
+ if err := c.WriteValueExpr(exp.Args[1]); err != nil {
765
+ return fmt.Errorf("failed to write buffer size in makeChannel: %w", err)
766
+ }
767
+ } else {
768
+ // Default to 0 (unbuffered channel)
769
+ c.tsw.WriteLiterally("0")
770
+ }
771
+
772
+ c.tsw.WriteLiterally(", ") // Add comma for zero value argument
773
+
774
+ // Write the zero value for the channel's element type
775
+ if chanType.Elem().String() == "struct{}" {
776
+ c.tsw.WriteLiterally("{}")
777
+ } else {
778
+ c.WriteZeroValueForType(chanType.Elem())
779
+ }
780
+
781
+ // Add direction parameter
782
+ c.tsw.WriteLiterally(", ")
783
+
784
+ // Determine channel direction
785
+ switch chanType.Dir() {
786
+ case types.SendRecv:
787
+ c.tsw.WriteLiterally("'both'")
788
+ case types.SendOnly:
789
+ c.tsw.WriteLiterally("'send'")
790
+ case types.RecvOnly:
791
+ c.tsw.WriteLiterally("'receive'")
792
+ default:
793
+ c.tsw.WriteLiterally("'both'") // Default to bidirectional
794
+ }
795
+
796
+ c.tsw.WriteLiterally(")")
797
+ return nil // Handled make for selector expression channel type
798
+ }
799
+ }
800
+ }
548
801
  // Fallthrough for unhandled make calls (e.g., channels)
549
802
  return errors.New("unhandled make call")
550
803
  case "string":
@@ -666,6 +919,40 @@ func (c *GoToTSCompiler) WriteCallExpr(exp *ast.CallExpr) error {
666
919
  if i > 0 || len(exp.Args) > 1 { // Add comma before elements if there are any
667
920
  c.tsw.WriteLiterally(", ")
668
921
  }
922
+
923
+ // Special case: append([]byte, string...) should convert string to bytes
924
+ if exp.Ellipsis != token.NoPos && i == 0 { // This is the first element after slice and has ellipsis
925
+ // Check if the slice is []byte and the argument is a string
926
+ sliceType := c.pkg.TypesInfo.TypeOf(exp.Args[0])
927
+ argType := c.pkg.TypesInfo.TypeOf(arg)
928
+
929
+ if sliceType != nil && argType != nil {
930
+ // Check if slice is []byte (Uint8Array)
931
+ isSliceOfBytes := false
932
+ if sliceUnder, ok := sliceType.Underlying().(*types.Slice); ok {
933
+ if basicElem, ok := sliceUnder.Elem().(*types.Basic); ok && basicElem.Kind() == types.Uint8 {
934
+ isSliceOfBytes = true
935
+ }
936
+ }
937
+
938
+ // Check if argument is string (including untyped string)
939
+ isArgString := false
940
+ if basicArg, ok := argType.Underlying().(*types.Basic); ok && (basicArg.Kind() == types.String || basicArg.Kind() == types.UntypedString) {
941
+ isArgString = true
942
+ }
943
+
944
+ if isSliceOfBytes && isArgString {
945
+ // Convert string to bytes: append([]byte, string...) -> $.append(slice, ...$.stringToBytes(string))
946
+ c.tsw.WriteLiterally("...$.stringToBytes(")
947
+ if err := c.WriteValueExpr(arg); err != nil {
948
+ return fmt.Errorf("failed to write string argument in append call: %w", err)
949
+ }
950
+ c.tsw.WriteLiterally(")")
951
+ continue
952
+ }
953
+ }
954
+ }
955
+
669
956
  if err := c.WriteValueExpr(arg); err != nil {
670
957
  return fmt.Errorf("failed to write argument %d in append call: %w", i+1, err)
671
958
  }
@@ -879,12 +1166,16 @@ func (c *GoToTSCompiler) WriteCallExpr(exp *ast.CallExpr) error {
879
1166
  }
880
1167
  c.tsw.WriteLiterally(")")
881
1168
  } else {
882
- // Not an identifier (e.g., method call on a value)
1169
+ // Not an identifier (e.g., method call on a value, function call result)
883
1170
  if err := c.WriteValueExpr(expFun); err != nil {
884
1171
  return fmt.Errorf("failed to write method expression in call: %w", err)
885
1172
  }
886
1173
 
887
- if funType := c.pkg.TypesInfo.TypeOf(expFun); funType != nil {
1174
+ // Check if this is a function call that returns a function (e.g., simpleIterator(m)())
1175
+ // Add non-null assertion since the returned function could be null
1176
+ if _, isCallExpr := expFun.(*ast.CallExpr); isCallExpr {
1177
+ c.tsw.WriteLiterally("!")
1178
+ } else if funType := c.pkg.TypesInfo.TypeOf(expFun); funType != nil {
888
1179
  if _, ok := funType.Underlying().(*types.Signature); ok {
889
1180
  // Check if this is a function parameter identifier that needs not-null assertion
890
1181
  if ident, isIdent := expFun.(*ast.Ident); isIdent {
@@ -899,6 +1190,13 @@ func (c *GoToTSCompiler) WriteCallExpr(exp *ast.CallExpr) error {
899
1190
  } else if _, isNamed := funType.(*types.Named); isNamed {
900
1191
  c.tsw.WriteLiterally("!")
901
1192
  }
1193
+ } else {
1194
+ // Check if the function type is nullable (e.g., func(...) | null)
1195
+ // This handles cases where a function call returns a nullable function
1196
+ funTypeStr := funType.String()
1197
+ if strings.Contains(funTypeStr, "| null") || strings.Contains(funTypeStr, "null |") {
1198
+ c.tsw.WriteLiterally("!")
1199
+ }
902
1200
  }
903
1201
  }
904
1202
  }
@@ -1004,3 +1302,22 @@ func hasMixedStringByteConstraint(iface *types.Interface) bool {
1004
1302
  // Return true only if we have both string and []byte in the constraint
1005
1303
  return hasString && hasByteSlice
1006
1304
  }
1305
+
1306
+ // getTypeHintForSliceElement returns the appropriate type hint for makeSlice based on the Go element type
1307
+ func (c *GoToTSCompiler) getTypeHintForSliceElement(elemType types.Type) string {
1308
+ if basicType, isBasic := elemType.(*types.Basic); isBasic {
1309
+ switch basicType.Kind() {
1310
+ case types.Int, types.Int8, types.Int16, types.Int32, types.Int64,
1311
+ types.Uint, types.Uint8, types.Uint16, types.Uint32, types.Uint64,
1312
+ types.Float32, types.Float64, types.Complex64, types.Complex128:
1313
+ return "number"
1314
+ case types.Bool:
1315
+ return "boolean"
1316
+ case types.String:
1317
+ return "string"
1318
+ }
1319
+ }
1320
+ // For other types (structs, interfaces, pointers, etc.), don't provide a hint
1321
+ // This will use the default null initialization which is appropriate for object types
1322
+ return ""
1323
+ }
@@ -129,7 +129,33 @@ func (c *GoToTSCompiler) WriteSelectorExpr(exp *ast.SelectorExpr) error {
129
129
  // Add null assertion for selector expressions when accessing fields/methods on nullable types
130
130
  // In Go, accessing fields or calling methods on nil pointers/interfaces panics, so we should throw in TypeScript
131
131
  baseType := c.pkg.TypesInfo.TypeOf(exp.X)
132
- if baseType != nil {
132
+
133
+ // Special case: Check if this is a method receiver alias (e.g., `b` in `const b = this`)
134
+ // In this case, we should use regular field access instead of pointer access
135
+ isMethodReceiverAlias := false
136
+ if baseIdent, ok := exp.X.(*ast.Ident); ok {
137
+ // Check if this identifier refers to a method receiver
138
+ // Method receivers are typically named variables that alias `this`
139
+ if obj := c.pkg.TypesInfo.ObjectOf(baseIdent); obj != nil {
140
+ if varObj, ok := obj.(*types.Var); ok {
141
+ // Check if this is a local variable in a method context
142
+ // Method receiver aliases are local variables with pointer types that represent `this`
143
+ if _, isPtr := varObj.Type().(*types.Pointer); isPtr {
144
+ // Additional check: only consider it a method receiver alias if the variable name
145
+ // suggests it's an alias (single letter names are common for aliases like `b`, `r`, etc.)
146
+ // and it's not a common variable name like `f` which is often used for regular variables
147
+ varName := baseIdent.Name
148
+ if len(varName) == 1 && varName != "f" {
149
+ // This is likely a method receiver alias like `const b = this`
150
+ // We should treat it as a regular object access, not a pointer access
151
+ isMethodReceiverAlias = true
152
+ }
153
+ }
154
+ }
155
+ }
156
+ }
157
+
158
+ if baseType != nil && !isMethodReceiverAlias {
133
159
  // Check if the base is a pointer type
134
160
  if _, isPtr := baseType.(*types.Pointer); isPtr {
135
161
  c.tsw.WriteLiterally("!.")
@@ -145,7 +171,7 @@ func (c *GoToTSCompiler) WriteSelectorExpr(exp *ast.SelectorExpr) error {
145
171
  c.tsw.WriteLiterally(".")
146
172
  }
147
173
  } else {
148
- // Add .
174
+ // Add . (either baseType is nil or this is a method receiver alias)
149
175
  c.tsw.WriteLiterally(".")
150
176
  }
151
177