@backbencher/brain 0.0.0-stage → 0.1.1

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 (319) hide show
  1. package/CHANGELOG.md +298 -0
  2. package/EMBEDDINGS.md +355 -0
  3. package/LICENSE +21 -0
  4. package/README.md +415 -2
  5. package/bin/bb +13 -0
  6. package/dist/analysis-exclusions-7ZJDXOVZ.js +35 -0
  7. package/dist/brain-index-health-Q5APTJQL.js +17 -0
  8. package/dist/brain-relationship-enrichment-MYR2AM4F.js +558 -0
  9. package/dist/brain.sql-EIM4WS4D.js +29 -0
  10. package/dist/chunk-22V37YTK.js +1758 -0
  11. package/dist/chunk-2BSKD7O3.js +40 -0
  12. package/dist/chunk-2DE27DVC.js +1314 -0
  13. package/dist/chunk-2RRBMNBQ.js +322 -0
  14. package/dist/chunk-2WXYNLBA.js +29 -0
  15. package/dist/chunk-3CTFIJJB.js +17 -0
  16. package/dist/chunk-3ZTOHHSW.js +2104 -0
  17. package/dist/chunk-4H22TLOT.js +543 -0
  18. package/dist/chunk-5BVAH26D.js +340 -0
  19. package/dist/chunk-62DHLYW6.js +3427 -0
  20. package/dist/chunk-7AN7U5IZ.js +371 -0
  21. package/dist/chunk-7DRPNVIN.js +782 -0
  22. package/dist/chunk-7MBYT777.js +174 -0
  23. package/dist/chunk-AHDWGM7Q.js +236 -0
  24. package/dist/chunk-B5GEAAYF.js +818 -0
  25. package/dist/chunk-BEIZZ73B.js +1479 -0
  26. package/dist/chunk-BQ3OVQ3P.js +125 -0
  27. package/dist/chunk-D2Q4Y47A.js +53 -0
  28. package/dist/chunk-DIYAGQJL.js +34 -0
  29. package/dist/chunk-DWKXZ6IF.js +336 -0
  30. package/dist/chunk-DYM4FQEE.js +90 -0
  31. package/dist/chunk-ENW4BTBA.js +930 -0
  32. package/dist/chunk-EWMWK7WN.js +75 -0
  33. package/dist/chunk-EY5ZZUUA.js +626 -0
  34. package/dist/chunk-GBI7V7KY.js +69 -0
  35. package/dist/chunk-GEFFO6O2.js +152 -0
  36. package/dist/chunk-HJEWO5EV.js +247 -0
  37. package/dist/chunk-HQSPJDHI.js +613 -0
  38. package/dist/chunk-KAET47ZL.js +125 -0
  39. package/dist/chunk-KCDECRJY.js +440 -0
  40. package/dist/chunk-L5TDYKYK.js +76 -0
  41. package/dist/chunk-MLKGABMK.js +9 -0
  42. package/dist/chunk-NO3U3FJQ.js +201 -0
  43. package/dist/chunk-OWISBAOF.js +61 -0
  44. package/dist/chunk-QKTRECYS.js +1119 -0
  45. package/dist/chunk-QLK6ED4Q.js +235 -0
  46. package/dist/chunk-R2GW4F6R.js +19 -0
  47. package/dist/chunk-RCMTFSEF.js +87 -0
  48. package/dist/chunk-RM3PY6TG.js +376 -0
  49. package/dist/chunk-ROMM6KMC.js +433 -0
  50. package/dist/chunk-SGGCSHAX.js +12050 -0
  51. package/dist/chunk-SK6YVHFZ.js +211 -0
  52. package/dist/chunk-SM7RFQRO.js +214 -0
  53. package/dist/chunk-UGR4QIGS.js +67 -0
  54. package/dist/chunk-UQNQZXHY.js +711 -0
  55. package/dist/chunk-UUNHHX4M.js +13 -0
  56. package/dist/chunk-VL52PL2T.js +71 -0
  57. package/dist/chunk-WIG36E67.js +196 -0
  58. package/dist/chunk-XHK3WWGB.js +7436 -0
  59. package/dist/chunk-XTQM2IP3.js +2863 -0
  60. package/dist/chunk-ZE2LG76D.js +1296 -0
  61. package/dist/chunk-ZETTGPAW.js +6950 -0
  62. package/dist/cli/index.js +37 -0
  63. package/dist/config-HZAAYDP3.js +10 -0
  64. package/dist/content-search-7XIP555Q.js +593 -0
  65. package/dist/database-76RP44JG.js +9 -0
  66. package/dist/doctor-ANGETYMN.js +395 -0
  67. package/dist/edit-engine-CG72LDZD.js +51 -0
  68. package/dist/engine-BKEOGN7N.js +11 -0
  69. package/dist/engine-VIW6NSKO.js +18 -0
  70. package/dist/fingerprint-OBLIMZLP.js +33 -0
  71. package/dist/framework-intelligence-3LORTPOX.js +860 -0
  72. package/dist/freshness-3K6VU5OT.js +174 -0
  73. package/dist/graph-engine-HBSQNPTB.js +21 -0
  74. package/dist/graph_request-Q6NKB6N2.js +350 -0
  75. package/dist/impact_request-LYP672WE.js +68 -0
  76. package/dist/index-space-IUUN5WYV.js +15 -0
  77. package/dist/index-status-7OVGYSGW.js +34 -0
  78. package/dist/index.js +159 -0
  79. package/dist/instance-FO6QZRLH.js +19 -0
  80. package/dist/language-detection-DFCAU5DZ.js +11 -0
  81. package/dist/lsp/server.js +4301 -0
  82. package/dist/mcp/server.js +132 -0
  83. package/dist/onboard-DIQZV2NW.js +161 -0
  84. package/dist/override-companion-pass-XR7MHTP7.js +117 -0
  85. package/dist/parallel-indexer-FK2XKZXY.js +88 -0
  86. package/dist/pool-worker.js +1153 -0
  87. package/dist/project-health-6XPENVAA.js +94 -0
  88. package/dist/project-index-5SDPHITE.js +57 -0
  89. package/dist/project-registry-ZJ3DVUGO.js +355 -0
  90. package/dist/real-bash-analyzer-EJAU5LW5.js +2201 -0
  91. package/dist/real-c-analyzer-HBD3FNNH.js +5942 -0
  92. package/dist/real-clean-analyzer-4EEZLPV5.js +3470 -0
  93. package/dist/real-clojure-analyzer-Q55EBOO2.js +2818 -0
  94. package/dist/real-cpp-analyzer-IVVOD25R.js +4101 -0
  95. package/dist/real-csharp-analyzer-ZBNLNJZJ.js +3298 -0
  96. package/dist/real-css-analyzer-6XRQLUN7.js +15 -0
  97. package/dist/real-dart-analyzer-OLR72EFW.js +3944 -0
  98. package/dist/real-elixir-analyzer-MQWGAH2I.js +2192 -0
  99. package/dist/real-erlang-analyzer-7BVPQEHO.js +1731 -0
  100. package/dist/real-fsharp-analyzer-C2UPFNOA.js +2390 -0
  101. package/dist/real-go-analyzer-UKGI43YS.js +4126 -0
  102. package/dist/real-graphql-analyzer-VE2EEFII.js +1442 -0
  103. package/dist/real-groovy-analyzer-W26VACFW.js +2285 -0
  104. package/dist/real-haskell-analyzer-5CVVAJRX.js +2533 -0
  105. package/dist/real-hcl-analyzer-5ZT4U43N.js +725 -0
  106. package/dist/real-html-analyzer-JWNX3C6I.js +1759 -0
  107. package/dist/real-java-analyzer-GU42VBGQ.js +4677 -0
  108. package/dist/real-javascript-analyzer-QA4QOJ6W.js +14 -0
  109. package/dist/real-json-analyzer-MPA6PRXL.js +1640 -0
  110. package/dist/real-julia-analyzer-22CWYQMN.js +2085 -0
  111. package/dist/real-kotlin-analyzer-QDZJLXXU.js +3956 -0
  112. package/dist/real-lua-analyzer-G7NHLYKS.js +1957 -0
  113. package/dist/real-makefile-analyzer-OCY3GT5N.js +920 -0
  114. package/dist/real-markdown-analyzer-TEJK2JXJ.js +1215 -0
  115. package/dist/real-matlab-analyzer-Q5SWLN7Z.js +480 -0
  116. package/dist/real-nim-analyzer-YLXSK563.js +3603 -0
  117. package/dist/real-objective-c-analyzer-D23ACC2R.js +1518 -0
  118. package/dist/real-perl-analyzer-WWTRHYDT.js +1865 -0
  119. package/dist/real-php-analyzer-JNKJHTCL.js +9368 -0
  120. package/dist/real-powershell-analyzer-XRSNQERV.js +2915 -0
  121. package/dist/real-protobuf-analyzer-3OKUCZ7T.js +867 -0
  122. package/dist/real-python-analyzer-VXAFWI72.js +4880 -0
  123. package/dist/real-r-analyzer-ZGAIDVI4.js +2596 -0
  124. package/dist/real-ruby-analyzer-X2KTLVBH.js +2429 -0
  125. package/dist/real-rust-analyzer-OFFHPL2A.js +3359 -0
  126. package/dist/real-scala-analyzer-TSTW27J6.js +3293 -0
  127. package/dist/real-scss-analyzer-AVWYPSOQ.js +1515 -0
  128. package/dist/real-solidity-analyzer-UCI2KWUB.js +2608 -0
  129. package/dist/real-sql-analyzer-F77ZMQXR.js +3840 -0
  130. package/dist/real-svelte-analyzer-SF7NRUO5.js +2532 -0
  131. package/dist/real-swift-analyzer-MN5QT3QN.js +2311 -0
  132. package/dist/real-toml-analyzer-66L7BDCQ.js +929 -0
  133. package/dist/real-typescript-analyzer-6KEMVDWQ.js +14 -0
  134. package/dist/real-vb-analyzer-VICVPOP7.js +3145 -0
  135. package/dist/real-vba-analyzer-HXLTTHKM.js +466 -0
  136. package/dist/real-vue-analyzer-QXR56CFV.js +2680 -0
  137. package/dist/real-xml-analyzer-YL465ZJW.js +2405 -0
  138. package/dist/real-yaml-analyzer-SUBCBNSI.js +3528 -0
  139. package/dist/real-zig-analyzer-HIQLZMGY.js +2430 -0
  140. package/dist/regex-search-NJKHMZNO.js +239 -0
  141. package/dist/rules-ACHPB7QU.js +152 -0
  142. package/dist/scoped-path-MJYWJZQX.js +11 -0
  143. package/dist/setup-show-NT5ZHYNE.js +15 -0
  144. package/dist/setup-wizard-G5YYR5T6.js +24 -0
  145. package/dist/symbol-search-GZJIM2J2.js +16 -0
  146. package/dist/taint-KXUHHPIE.js +202 -0
  147. package/dist/taint-analyzer-N7YLZU3N.js +163 -0
  148. package/dist/tool-handlers-OJDC35DI.js +72 -0
  149. package/dist/tool-registry-BPEJNSZG.js +17 -0
  150. package/dist/tool-validation-Q57YMMBX.js +32 -0
  151. package/dist/type-inference-QMT2RMLV.js +13 -0
  152. package/dist/vector-binary-LMY4QGAN.js +19 -0
  153. package/dist/version-ABP2TUL2.js +9 -0
  154. package/dist/wasm-NMWO3WXY.js +16 -0
  155. package/docs/EMBEDDINGS.md +132 -0
  156. package/docs/README.md +178 -0
  157. package/docs/data/m10-baseline.json +602 -0
  158. package/docs/data/m10-benchmark-baseline.json +57 -0
  159. package/docs/data/m10-benchmark-last-run.json +127 -0
  160. package/docs/data/m10-final-audit.json +215 -0
  161. package/docs/data/m12-final-audit.json +138 -0
  162. package/docs/data/m12-surface-matrix.json +50 -0
  163. package/docs/data/public-tools.json +1902 -0
  164. package/docs/indexing/DEAD-ASSETS.md +88 -0
  165. package/docs/indexing/INDEXER-REVIEW.md +634 -0
  166. package/docs/indexing/PERFORMANCE-FINDINGS.md +106 -0
  167. package/docs/indexing/README.md +427 -0
  168. package/docs/indexing/discovery-matrix.md +41 -0
  169. package/docs/indexing/embeddings.md +325 -0
  170. package/docs/indexing/environment-variables.md +77 -0
  171. package/docs/indexing/performance.md +323 -0
  172. package/docs/indexing/resume.md +345 -0
  173. package/docs/indexing/troubleshooting.md +391 -0
  174. package/docs/man/bb.1 +190 -0
  175. package/docs/tools/bb_analyze.md +147 -0
  176. package/docs/tools/bb_annotate.md +110 -0
  177. package/docs/tools/bb_annotations.md +106 -0
  178. package/docs/tools/bb_ask.md +101 -0
  179. package/docs/tools/bb_cross_language.md +103 -0
  180. package/docs/tools/bb_doc.md +169 -0
  181. package/docs/tools/bb_edit.md +185 -0
  182. package/docs/tools/bb_graph.md +169 -0
  183. package/docs/tools/bb_health.md +156 -0
  184. package/docs/tools/bb_impact.md +117 -0
  185. package/docs/tools/bb_index.md +108 -0
  186. package/docs/tools/bb_migrate.md +135 -0
  187. package/docs/tools/bb_patterns.md +140 -0
  188. package/docs/tools/bb_search.md +150 -0
  189. package/docs/tools/bb_security.md +100 -0
  190. package/docs/tools/bb_visualize.md +184 -0
  191. package/grammars/README.md +57 -0
  192. package/grammars/THIRD-PARTY-NOTICES.md +50 -0
  193. package/grammars/tree-sitter-c/LICENSE +21 -0
  194. package/grammars/tree-sitter-clojure/LICENSE.md +21 -0
  195. package/grammars/tree-sitter-cpp/LICENSE +21 -0
  196. package/grammars/tree-sitter-csharp/LICENSE +21 -0
  197. package/grammars/tree-sitter-css/LICENSE +21 -0
  198. package/grammars/tree-sitter-css/README.md +21 -0
  199. package/grammars/tree-sitter-dart/LICENSE +20 -0
  200. package/grammars/tree-sitter-dart-upstream/LICENSE +20 -0
  201. package/grammars/tree-sitter-dart-upstream/README.md +18 -0
  202. package/grammars/tree-sitter-elixir/LICENSE +176 -0
  203. package/grammars/tree-sitter-elixir/README.md +11 -0
  204. package/grammars/tree-sitter-fsharp/LICENSE +21 -0
  205. package/grammars/tree-sitter-fsharp/README.md +45 -0
  206. package/grammars/tree-sitter-graphql/LICENSE +21 -0
  207. package/grammars/tree-sitter-graphql/README.md +106 -0
  208. package/grammars/tree-sitter-groovy/LICENSE +21 -0
  209. package/grammars/tree-sitter-groovy/README.md +4 -0
  210. package/grammars/tree-sitter-haskell/LICENSE +21 -0
  211. package/grammars/tree-sitter-haskell/README.md +394 -0
  212. package/grammars/tree-sitter-hcl/CHANGELOG.md +102 -0
  213. package/grammars/tree-sitter-hcl/LICENSE +201 -0
  214. package/grammars/tree-sitter-hcl/README.md +39 -0
  215. package/grammars/tree-sitter-html/LICENSE +21 -0
  216. package/grammars/tree-sitter-html/README.md +21 -0
  217. package/grammars/tree-sitter-julia/LICENSE +21 -0
  218. package/grammars/tree-sitter-julia/README.md +24 -0
  219. package/grammars/tree-sitter-kotlin/LICENSE +9 -0
  220. package/grammars/tree-sitter-lua/LICENSE.md +21 -0
  221. package/grammars/tree-sitter-lua/README.md +29 -0
  222. package/grammars/tree-sitter-make/LICENSE +21 -0
  223. package/grammars/tree-sitter-matlab/LICENSE +19 -0
  224. package/grammars/tree-sitter-matlab/README.md +99 -0
  225. package/grammars/tree-sitter-nim/LICENSE +373 -0
  226. package/grammars/tree-sitter-nim/README.md +46 -0
  227. package/grammars/tree-sitter-objc/LICENSE +21 -0
  228. package/grammars/tree-sitter-objc/README.md +20 -0
  229. package/grammars/tree-sitter-perl/LICENSE +7 -0
  230. package/grammars/tree-sitter-perl/README.md +100 -0
  231. package/grammars/tree-sitter-powershell/LICENSE +21 -0
  232. package/grammars/tree-sitter-powershell/README.md +7 -0
  233. package/grammars/tree-sitter-proto/LICENSE +21 -0
  234. package/grammars/tree-sitter-proto/README.md +105 -0
  235. package/grammars/tree-sitter-r/LICENSE +9 -0
  236. package/grammars/tree-sitter-r/README.md +66 -0
  237. package/grammars/tree-sitter-ruby/LICENSE +22 -0
  238. package/grammars/tree-sitter-scss/LICENSE +21 -0
  239. package/grammars/tree-sitter-scss/README.md +17 -0
  240. package/grammars/tree-sitter-solidity/LICENSE +7 -0
  241. package/grammars/tree-sitter-sql/LICENSE +21 -0
  242. package/grammars/tree-sitter-typescript/LICENSE +21 -0
  243. package/grammars/tree-sitter-vba/LICENSE +21 -0
  244. package/grammars/tree-sitter-vba/README.md +738 -0
  245. package/grammars/tree-sitter-vbnet/LICENSE +21 -0
  246. package/grammars/tree-sitter-vbnet/README.md +322 -0
  247. package/grammars/tree-sitter-xml/LICENSE +19 -0
  248. package/grammars/tree-sitter-yaml/LICENSE +20 -0
  249. package/grammars/tree-sitter-yaml/README.md +21 -0
  250. package/package.json +184 -4
  251. package/wasm/dart.wasm +0 -0
  252. package/wasm/tree-sitter-bash.wasm +0 -0
  253. package/wasm/tree-sitter-c.wasm +0 -0
  254. package/wasm/tree-sitter-c_sharp.wasm +0 -0
  255. package/wasm/tree-sitter-clean.wasm +0 -0
  256. package/wasm/tree-sitter-clojure.wasm +0 -0
  257. package/wasm/tree-sitter-core_schema.wasm +0 -0
  258. package/wasm/tree-sitter-cpp.wasm +0 -0
  259. package/wasm/tree-sitter-css.wasm +0 -0
  260. package/wasm/tree-sitter-dart.wasm +0 -0
  261. package/wasm/tree-sitter-elisp.wasm +0 -0
  262. package/wasm/tree-sitter-elixir.wasm +0 -0
  263. package/wasm/tree-sitter-elm.wasm +0 -0
  264. package/wasm/tree-sitter-embedded_template.wasm +0 -0
  265. package/wasm/tree-sitter-erlang.wasm +0 -0
  266. package/wasm/tree-sitter-fsharp.wasm +0 -0
  267. package/wasm/tree-sitter-fsharp_signature.wasm +0 -0
  268. package/wasm/tree-sitter-go.wasm +0 -0
  269. package/wasm/tree-sitter-graphql.wasm +0 -0
  270. package/wasm/tree-sitter-groovy.wasm +0 -0
  271. package/wasm/tree-sitter-haskell.wasm +0 -0
  272. package/wasm/tree-sitter-hcl.wasm +0 -0
  273. package/wasm/tree-sitter-html.wasm +0 -0
  274. package/wasm/tree-sitter-java.wasm +0 -0
  275. package/wasm/tree-sitter-javascript.wasm +0 -0
  276. package/wasm/tree-sitter-json.wasm +0 -0
  277. package/wasm/tree-sitter-json_schema.wasm +0 -0
  278. package/wasm/tree-sitter-julia.wasm +0 -0
  279. package/wasm/tree-sitter-kotlin.wasm +0 -0
  280. package/wasm/tree-sitter-lua.wasm +0 -0
  281. package/wasm/tree-sitter-make.wasm +0 -0
  282. package/wasm/tree-sitter-markdown.wasm +0 -0
  283. package/wasm/tree-sitter-markdown_inline.wasm +0 -0
  284. package/wasm/tree-sitter-matlab.wasm +0 -0
  285. package/wasm/tree-sitter-nim.wasm +0 -0
  286. package/wasm/tree-sitter-objc.wasm +0 -0
  287. package/wasm/tree-sitter-ocaml.wasm +0 -0
  288. package/wasm/tree-sitter-perl.wasm +0 -0
  289. package/wasm/tree-sitter-php.wasm +0 -0
  290. package/wasm/tree-sitter-php_only.wasm +0 -0
  291. package/wasm/tree-sitter-powershell.wasm +0 -0
  292. package/wasm/tree-sitter-protobuf.wasm +0 -0
  293. package/wasm/tree-sitter-python.wasm +0 -0
  294. package/wasm/tree-sitter-ql.wasm +0 -0
  295. package/wasm/tree-sitter-r.wasm +0 -0
  296. package/wasm/tree-sitter-rescript.wasm +0 -0
  297. package/wasm/tree-sitter-ruby.wasm +0 -0
  298. package/wasm/tree-sitter-rust.wasm +0 -0
  299. package/wasm/tree-sitter-scala.wasm +0 -0
  300. package/wasm/tree-sitter-scss.wasm +0 -0
  301. package/wasm/tree-sitter-solidity.wasm +0 -0
  302. package/wasm/tree-sitter-sql.wasm +0 -0
  303. package/wasm/tree-sitter-svelte.wasm +0 -0
  304. package/wasm/tree-sitter-swift.wasm +0 -0
  305. package/wasm/tree-sitter-systemrdl.wasm +0 -0
  306. package/wasm/tree-sitter-terraform.wasm +0 -0
  307. package/wasm/tree-sitter-tlaplus.wasm +0 -0
  308. package/wasm/tree-sitter-toml.wasm +0 -0
  309. package/wasm/tree-sitter-tsx.wasm +0 -0
  310. package/wasm/tree-sitter-typescript.wasm +0 -0
  311. package/wasm/tree-sitter-vba.wasm +0 -0
  312. package/wasm/tree-sitter-vbnet.wasm +0 -0
  313. package/wasm/tree-sitter-vue.wasm +0 -0
  314. package/wasm/tree-sitter-xml.wasm +0 -0
  315. package/wasm/tree-sitter-yaml.wasm +0 -0
  316. package/wasm/tree-sitter-zig.wasm +0 -0
  317. package/wasm/tree-sitter.wasm +0 -0
  318. package/wasm/tsx.wasm +0 -0
  319. package/wasm/typescript.wasm +0 -0
@@ -0,0 +1,782 @@
1
+ import {
2
+ ASTEngine
3
+ } from "./chunk-3ZTOHHSW.js";
4
+
5
+ // src/ast/type-inference.ts
6
+ var TypeInference;
7
+ ((TypeInference2) => {
8
+ let TypeKind;
9
+ ((TypeKind2) => {
10
+ TypeKind2["Primitive"] = "primitive";
11
+ TypeKind2["Class"] = "class";
12
+ TypeKind2["Interface"] = "interface";
13
+ TypeKind2["Enum"] = "enum";
14
+ TypeKind2["Function"] = "function";
15
+ TypeKind2["Array"] = "array";
16
+ TypeKind2["Object"] = "object";
17
+ TypeKind2["Generic"] = "generic";
18
+ TypeKind2["Union"] = "union";
19
+ TypeKind2["Intersection"] = "intersection";
20
+ TypeKind2["Tuple"] = "tuple";
21
+ TypeKind2["Literal"] = "literal";
22
+ TypeKind2["Unknown"] = "unknown";
23
+ TypeKind2["Any"] = "any";
24
+ TypeKind2["Void"] = "void";
25
+ })(TypeKind = TypeInference2.TypeKind || (TypeInference2.TypeKind = {}));
26
+ let InferenceReason;
27
+ ((InferenceReason2) => {
28
+ InferenceReason2["Declaration"] = "declaration";
29
+ InferenceReason2["Assignment"] = "assignment";
30
+ InferenceReason2["FunctionCall"] = "function_call";
31
+ InferenceReason2["MethodCall"] = "method_call";
32
+ InferenceReason2["ControlFlow"] = "control_flow";
33
+ InferenceReason2["GenericInstantiation"] = "generic_instantiation";
34
+ InferenceReason2["TypeAssertion"] = "type_assertion";
35
+ InferenceReason2["Destructuring"] = "destructuring";
36
+ InferenceReason2["Import"] = "import";
37
+ })(InferenceReason = TypeInference2.InferenceReason || (TypeInference2.InferenceReason = {}));
38
+ class InferenceContext {
39
+ variableTypes = /* @__PURE__ */ new Map();
40
+ functionTypes = /* @__PURE__ */ new Map();
41
+ classTypes = /* @__PURE__ */ new Map();
42
+ scopeStack = [];
43
+ language;
44
+ filePath;
45
+ constructor(language, filePath) {
46
+ this.language = language;
47
+ this.filePath = filePath;
48
+ this.initializeBuiltinTypes();
49
+ }
50
+ initializeBuiltinTypes() {
51
+ switch (this.language) {
52
+ case "typescript":
53
+ case "javascript":
54
+ this.initializeJavaScriptTypes();
55
+ break;
56
+ case "python":
57
+ this.initializePythonTypes();
58
+ break;
59
+ case "java":
60
+ this.initializeJavaTypes();
61
+ break;
62
+ case "rust":
63
+ this.initializeRustTypes();
64
+ break;
65
+ case "cpp":
66
+ this.initializeCppTypes();
67
+ break;
68
+ case "csharp":
69
+ this.initializeCSharpTypes();
70
+ break;
71
+ default:
72
+ this.initializeGenericTypes();
73
+ }
74
+ }
75
+ initializeJavaScriptTypes() {
76
+ const jsTypes = ["string", "number", "boolean", "object", "undefined", "null", "symbol", "bigint"];
77
+ jsTypes.forEach((type) => {
78
+ this.classTypes.set(type, {
79
+ name: type,
80
+ kind: "primitive" /* Primitive */,
81
+ confidence: 1,
82
+ inferredAt: []
83
+ });
84
+ });
85
+ this.classTypes.set("Array", {
86
+ name: "Array",
87
+ kind: "class" /* Class */,
88
+ genericArgs: [this.getUnknownType()],
89
+ confidence: 1,
90
+ inferredAt: []
91
+ });
92
+ this.classTypes.set("Promise", {
93
+ name: "Promise",
94
+ kind: "class" /* Class */,
95
+ genericArgs: [this.getUnknownType()],
96
+ confidence: 1,
97
+ inferredAt: []
98
+ });
99
+ }
100
+ initializePythonTypes() {
101
+ const pythonTypes = ["int", "float", "str", "bool", "list", "dict", "tuple", "set", "None"];
102
+ pythonTypes.forEach((type) => {
103
+ this.classTypes.set(type, {
104
+ name: type,
105
+ kind: type === "None" ? "literal" /* Literal */ : "primitive" /* Primitive */,
106
+ confidence: 1,
107
+ inferredAt: []
108
+ });
109
+ });
110
+ }
111
+ initializeJavaTypes() {
112
+ const javaTypes = ["int", "long", "double", "float", "boolean", "char", "byte", "short", "String", "Object"];
113
+ javaTypes.forEach((type) => {
114
+ this.classTypes.set(type, {
115
+ name: type,
116
+ kind: ["String", "Object"].includes(type) ? "class" /* Class */ : "primitive" /* Primitive */,
117
+ confidence: 1,
118
+ inferredAt: []
119
+ });
120
+ });
121
+ }
122
+ initializeRustTypes() {
123
+ const rustTypes = ["i32", "i64", "f32", "f64", "bool", "char", "str", "String", "Vec", "Option", "Result"];
124
+ rustTypes.forEach((type) => {
125
+ this.classTypes.set(type, {
126
+ name: type,
127
+ kind: ["Vec", "Option", "Result"].includes(type) ? "generic" /* Generic */ : ["String"].includes(type) ? "class" /* Class */ : "primitive" /* Primitive */,
128
+ confidence: 1,
129
+ inferredAt: []
130
+ });
131
+ });
132
+ }
133
+ initializeCppTypes() {
134
+ const cppTypes = ["int", "long", "double", "float", "bool", "char", "void", "std::string", "std::vector"];
135
+ cppTypes.forEach((type) => {
136
+ this.classTypes.set(type, {
137
+ name: type,
138
+ kind: type.startsWith("std::") ? "class" /* Class */ : "primitive" /* Primitive */,
139
+ confidence: 1,
140
+ inferredAt: []
141
+ });
142
+ });
143
+ }
144
+ initializeCSharpTypes() {
145
+ const csharpTypes = ["int", "long", "double", "float", "bool", "char", "string", "object", "decimal"];
146
+ csharpTypes.forEach((type) => {
147
+ this.classTypes.set(type, {
148
+ name: type,
149
+ kind: ["string", "object"].includes(type) ? "class" /* Class */ : "primitive" /* Primitive */,
150
+ confidence: 1,
151
+ inferredAt: []
152
+ });
153
+ });
154
+ }
155
+ initializeGenericTypes() {
156
+ ["int", "string", "bool", "object"].forEach((type) => {
157
+ this.classTypes.set(type, {
158
+ name: type,
159
+ kind: "primitive" /* Primitive */,
160
+ confidence: 0.8,
161
+ inferredAt: []
162
+ });
163
+ });
164
+ }
165
+ // Type inference methods
166
+ inferVariableType(varName, assignmentNode, reason) {
167
+ const scopedName = this.getScopedName(varName);
168
+ const inferredType = this.analyzeExpression(assignmentNode);
169
+ inferredType.inferredAt.push({
170
+ filePath: this.filePath,
171
+ range: this.nodeToRange(assignmentNode),
172
+ reason
173
+ });
174
+ this.variableTypes.set(scopedName, inferredType);
175
+ return inferredType;
176
+ }
177
+ inferFunctionReturnType(funcName, bodyNode) {
178
+ const returnStatements = this.findReturnStatements(bodyNode);
179
+ if (returnStatements.length === 0) {
180
+ return this.getVoidType();
181
+ }
182
+ if (returnStatements.length === 1) {
183
+ return this.analyzeExpression(returnStatements[0]);
184
+ }
185
+ const returnTypes = returnStatements.map((stmt) => this.analyzeExpression(stmt));
186
+ return this.createUnionType(returnTypes);
187
+ }
188
+ inferMethodCallType(objectExpr, methodName) {
189
+ const objectType = this.analyzeExpression(objectExpr);
190
+ if (objectType.methods?.has(methodName)) {
191
+ return objectType.methods.get(methodName).returnType;
192
+ }
193
+ return this.inferMethodFromPatterns(objectType, methodName);
194
+ }
195
+ inferGenericInstantiation(genericType, typeArgs) {
196
+ return {
197
+ ...genericType,
198
+ genericArgs: typeArgs,
199
+ confidence: Math.min(genericType.confidence, ...typeArgs.map((t) => t.confidence)),
200
+ inferredAt: [...genericType.inferredAt]
201
+ };
202
+ }
203
+ // Expression analysis
204
+ analyzeExpression(node) {
205
+ switch (node.type) {
206
+ case "number":
207
+ case "integer_literal":
208
+ case "float_literal":
209
+ return this.getNumberType();
210
+ case "string":
211
+ case "string_literal":
212
+ case "template_literal":
213
+ return this.getStringType();
214
+ case "boolean":
215
+ case "true":
216
+ case "false":
217
+ return this.getBooleanType();
218
+ case "null":
219
+ case "nil":
220
+ case "None":
221
+ return this.getNullType();
222
+ case "identifier":
223
+ case "variable":
224
+ return this.lookupVariableType(node.text);
225
+ case "call_expression":
226
+ case "function_call":
227
+ return this.analyzeFunctionCall(node);
228
+ case "member_expression":
229
+ case "field_expression":
230
+ return this.analyzeMemberAccess(node);
231
+ case "array_expression":
232
+ case "list_expression":
233
+ return this.analyzeArrayExpression(node);
234
+ case "object_expression":
235
+ case "dict_expression":
236
+ return this.analyzeObjectExpression(node);
237
+ case "binary_expression":
238
+ return this.analyzeBinaryExpression(node);
239
+ case "conditional_expression":
240
+ case "ternary_expression":
241
+ return this.analyzeConditionalExpression(node);
242
+ default:
243
+ return this.getUnknownType();
244
+ }
245
+ }
246
+ analyzeFunctionCall(node) {
247
+ const functionNode = node.childForFieldName("function") || node.childForFieldName("name");
248
+ if (!functionNode) return this.getUnknownType();
249
+ const functionName = functionNode.text;
250
+ if (functionNode.type === "member_expression") {
251
+ const objectNode = functionNode.childForFieldName("object");
252
+ const propertyNode = functionNode.childForFieldName("property");
253
+ if (objectNode && propertyNode) {
254
+ return this.inferMethodCallType(objectNode, propertyNode.text);
255
+ }
256
+ }
257
+ const signature = this.functionTypes.get(functionName);
258
+ if (signature) {
259
+ return signature.returnType;
260
+ }
261
+ if (this.isConstructorCall(functionName)) {
262
+ const className = this.extractClassName(functionName);
263
+ return this.classTypes.get(className) || this.getUnknownType();
264
+ }
265
+ return this.getUnknownType();
266
+ }
267
+ analyzeMemberAccess(node) {
268
+ const objectNode = node.childForFieldName("object") || node.childForFieldName("expression");
269
+ const propertyNode = node.childForFieldName("property") || node.childForFieldName("field");
270
+ if (!objectNode || !propertyNode) return this.getUnknownType();
271
+ const objectType = this.analyzeExpression(objectNode);
272
+ const propertyName = propertyNode.text;
273
+ if (objectType.properties?.has(propertyName)) {
274
+ return objectType.properties.get(propertyName);
275
+ }
276
+ if (objectType.methods?.has(propertyName)) {
277
+ return {
278
+ name: `${objectType.name}.${propertyName}`,
279
+ kind: "function" /* Function */,
280
+ confidence: objectType.confidence * 0.8,
281
+ inferredAt: []
282
+ };
283
+ }
284
+ return this.getUnknownType();
285
+ }
286
+ analyzeArrayExpression(node) {
287
+ const elements = this.getArrayElements(node);
288
+ if (elements.length === 0) {
289
+ return {
290
+ name: "Array",
291
+ kind: "array" /* Array */,
292
+ genericArgs: [this.getUnknownType()],
293
+ confidence: 0.9,
294
+ inferredAt: []
295
+ };
296
+ }
297
+ const elementTypes = elements.map((elem) => this.analyzeExpression(elem));
298
+ const elementType = this.mergeTypes(elementTypes);
299
+ return {
300
+ name: "Array",
301
+ kind: "array" /* Array */,
302
+ genericArgs: [elementType],
303
+ confidence: elementType.confidence * 0.9,
304
+ inferredAt: []
305
+ };
306
+ }
307
+ analyzeObjectExpression(node) {
308
+ const properties = /* @__PURE__ */ new Map();
309
+ const children = node.namedChildren;
310
+ for (let i = 0; i < children.length; i++) {
311
+ const child = children[i];
312
+ if (child && (child.type === "pair" || child.type === "property")) {
313
+ const key = this.getObjectKey(child);
314
+ const value = this.getObjectValue(child);
315
+ if (key && value) {
316
+ properties.set(key, this.analyzeExpression(value));
317
+ }
318
+ }
319
+ }
320
+ return {
321
+ name: "Object",
322
+ kind: "object" /* Object */,
323
+ properties,
324
+ confidence: 0.9,
325
+ inferredAt: []
326
+ };
327
+ }
328
+ analyzeBinaryExpression(node) {
329
+ const operator = this.getBinaryOperator(node);
330
+ const leftNode = node.childForFieldName("left");
331
+ const rightNode = node.childForFieldName("right");
332
+ if (!leftNode || !rightNode) return this.getUnknownType();
333
+ const leftType = this.analyzeExpression(leftNode);
334
+ const rightType = this.analyzeExpression(rightNode);
335
+ if (["+", "-", "*", "/", "%", "**"].includes(operator)) {
336
+ if (leftType.name === "string" || rightType.name === "string") {
337
+ return operator === "+" ? this.getStringType() : this.getUnknownType();
338
+ }
339
+ return this.getNumberType();
340
+ }
341
+ if (["<", ">", "<=", ">=", "==", "!=", "===", "!=="].includes(operator)) {
342
+ return this.getBooleanType();
343
+ }
344
+ if (["&&", "||"].includes(operator)) {
345
+ return this.mergeTypes([leftType, rightType]);
346
+ }
347
+ return this.getUnknownType();
348
+ }
349
+ analyzeConditionalExpression(node) {
350
+ const consequentNode = node.childForFieldName("consequence") || node.childForFieldName("then");
351
+ const alternateNode = node.childForFieldName("alternative") || node.childForFieldName("else");
352
+ if (!consequentNode || !alternateNode) return this.getUnknownType();
353
+ const consequentType = this.analyzeExpression(consequentNode);
354
+ const alternateType = this.analyzeExpression(alternateNode);
355
+ return this.mergeTypes([consequentType, alternateType]);
356
+ }
357
+ // Flow-sensitive analysis
358
+ analyzeControlFlow(node) {
359
+ const flowTypes = /* @__PURE__ */ new Map();
360
+ switch (node.type) {
361
+ case "if_statement":
362
+ return this.analyzeIfStatement(node);
363
+ case "while_statement":
364
+ case "for_statement":
365
+ return this.analyzeLoopStatement(node);
366
+ case "try_statement":
367
+ return this.analyzeTryStatement(node);
368
+ case "match_expression":
369
+ // Rust
370
+ case "switch_statement":
371
+ return this.analyzeMatchStatement(node);
372
+ }
373
+ return flowTypes;
374
+ }
375
+ analyzeIfStatement(node) {
376
+ const conditionNode = node.childForFieldName("condition");
377
+ const thenNode = node.childForFieldName("consequence") || node.childForFieldName("then");
378
+ const elseNode = node.childForFieldName("alternative") || node.childForFieldName("else");
379
+ const flowTypes = /* @__PURE__ */ new Map();
380
+ if (conditionNode) {
381
+ const typeGuards = this.extractTypeGuards(conditionNode);
382
+ typeGuards.forEach((type, variable) => {
383
+ flowTypes.set(variable, type);
384
+ });
385
+ }
386
+ return flowTypes;
387
+ }
388
+ extractTypeGuards(conditionNode) {
389
+ const guards = /* @__PURE__ */ new Map();
390
+ if (this.isTypeofCheck(conditionNode)) {
391
+ const variable = this.getTypeofVariable(conditionNode);
392
+ const typeString = this.getTypeofType(conditionNode);
393
+ if (variable && typeString) {
394
+ guards.set(variable, this.stringToType(typeString));
395
+ }
396
+ }
397
+ if (this.isInstanceofCheck(conditionNode)) {
398
+ const variable = this.getInstanceofVariable(conditionNode);
399
+ const className = this.getInstanceofClass(conditionNode);
400
+ if (variable && className) {
401
+ const classType = this.classTypes.get(className);
402
+ if (classType) {
403
+ guards.set(variable, classType);
404
+ }
405
+ }
406
+ }
407
+ if (this.isNullCheck(conditionNode)) {
408
+ const variable = this.getNullCheckVariable(conditionNode);
409
+ if (variable) {
410
+ const currentType = this.lookupVariableType(variable);
411
+ guards.set(variable, this.makeNonNullable(currentType));
412
+ }
413
+ }
414
+ return guards;
415
+ }
416
+ // Helper methods for type system
417
+ lookupVariableType(varName) {
418
+ const scopedName = this.getScopedName(varName);
419
+ return this.variableTypes.get(scopedName) || this.getUnknownType();
420
+ }
421
+ getScopedName(varName) {
422
+ if (this.scopeStack.length === 0) return varName;
423
+ return `${this.scopeStack.join(".")}.${varName}`;
424
+ }
425
+ mergeTypes(types) {
426
+ if (types.length === 0) return this.getUnknownType();
427
+ if (types.length === 1) return types[0];
428
+ const uniqueTypes = Array.from(new Set(types.map((t) => t.name)));
429
+ if (uniqueTypes.length === 1) {
430
+ return {
431
+ ...types[0],
432
+ confidence: Math.max(...types.map((t) => t.confidence))
433
+ };
434
+ }
435
+ return this.createUnionType(types);
436
+ }
437
+ createUnionType(types) {
438
+ return {
439
+ name: types.map((t) => t.name).join(" | "),
440
+ kind: "union" /* Union */,
441
+ unionTypes: types,
442
+ confidence: Math.max(...types.map((t) => t.confidence)) * 0.8,
443
+ inferredAt: []
444
+ };
445
+ }
446
+ // Built-in type getters
447
+ getUnknownType() {
448
+ return { name: "unknown", kind: "unknown" /* Unknown */, confidence: 0, inferredAt: [] };
449
+ }
450
+ getVoidType() {
451
+ return { name: "void", kind: "void" /* Void */, confidence: 1, inferredAt: [] };
452
+ }
453
+ getStringType() {
454
+ return { name: "string", kind: "primitive" /* Primitive */, confidence: 1, inferredAt: [] };
455
+ }
456
+ getNumberType() {
457
+ return { name: "number", kind: "primitive" /* Primitive */, confidence: 1, inferredAt: [] };
458
+ }
459
+ getBooleanType() {
460
+ return { name: "boolean", kind: "primitive" /* Primitive */, confidence: 1, inferredAt: [] };
461
+ }
462
+ getNullType() {
463
+ return { name: "null", kind: "literal" /* Literal */, confidence: 1, inferredAt: [] };
464
+ }
465
+ // Utility methods for AST navigation
466
+ nodeToRange(node) {
467
+ return {
468
+ startLine: node.startPosition.row + 1,
469
+ startColumn: node.startPosition.column + 1,
470
+ endLine: node.endPosition.row + 1,
471
+ endColumn: node.endPosition.column + 1,
472
+ startIndex: node.startIndex,
473
+ endIndex: node.endIndex
474
+ };
475
+ }
476
+ findReturnStatements(node) {
477
+ const returns = [];
478
+ const traverse = (n) => {
479
+ if (n.type === "return_statement") {
480
+ const expression = n.childForFieldName("expression") || n.namedChild(0);
481
+ if (expression) returns.push(expression);
482
+ }
483
+ const children = n.namedChildren;
484
+ for (let i = 0; i < children.length; i++) {
485
+ traverse(children[i]);
486
+ }
487
+ };
488
+ traverse(node);
489
+ return returns;
490
+ }
491
+ getArrayElements(node) {
492
+ const elements = [];
493
+ const children = node.namedChildren;
494
+ for (let i = 0; i < children.length; i++) {
495
+ const child = children[i];
496
+ if (child) elements.push(child);
497
+ }
498
+ return elements;
499
+ }
500
+ getObjectKey(pairNode) {
501
+ const keyNode = pairNode.childForFieldName("key") || pairNode.childForFieldName("name");
502
+ return keyNode ? keyNode.text : null;
503
+ }
504
+ getObjectValue(pairNode) {
505
+ return pairNode.childForFieldName("value") || pairNode.childForFieldName("expression");
506
+ }
507
+ getBinaryOperator(node) {
508
+ for (let i = 0; i < node.childCount; i++) {
509
+ const child = node.child(i);
510
+ if (child && ["operator", "+", "-", "*", "/", "==", "!=", "<", ">"].includes(child.type)) {
511
+ return child.text;
512
+ }
513
+ }
514
+ return "";
515
+ }
516
+ isConstructorCall(functionName) {
517
+ return /^[A-Z]/.test(functionName) || functionName === "new";
518
+ }
519
+ extractClassName(functionName) {
520
+ return functionName.replace(/^new\s+/, "");
521
+ }
522
+ isTypeofCheck(node) {
523
+ return node.text.includes("typeof");
524
+ }
525
+ isInstanceofCheck(node) {
526
+ return node.text.includes("instanceof");
527
+ }
528
+ isNullCheck(node) {
529
+ return node.text.includes("!= null") || node.text.includes("!== undefined");
530
+ }
531
+ getTypeofVariable(node) {
532
+ const match = node.text.match(/typeof\s+(\w+)/);
533
+ return match ? match[1] : null;
534
+ }
535
+ getTypeofType(node) {
536
+ const match = node.text.match(/===\s*['"](\w+)['"]/);
537
+ return match ? match[1] : null;
538
+ }
539
+ getInstanceofVariable(node) {
540
+ const match = node.text.match(/(\w+)\s+instanceof/);
541
+ return match ? match[1] : null;
542
+ }
543
+ getInstanceofClass(node) {
544
+ const match = node.text.match(/instanceof\s+(\w+)/);
545
+ return match ? match[1] : null;
546
+ }
547
+ getNullCheckVariable(node) {
548
+ const match = node.text.match(/(\w+)\s*!==?\s*(null|undefined)/);
549
+ return match ? match[1] : null;
550
+ }
551
+ stringToType(typeString) {
552
+ return this.classTypes.get(typeString) || {
553
+ name: typeString,
554
+ kind: "primitive" /* Primitive */,
555
+ confidence: 0.9,
556
+ inferredAt: []
557
+ };
558
+ }
559
+ makeNonNullable(type) {
560
+ return {
561
+ ...type,
562
+ nullable: false,
563
+ confidence: type.confidence * 0.95
564
+ };
565
+ }
566
+ inferMethodFromPatterns(objectType, methodName) {
567
+ const commonPatterns = {
568
+ // Array methods
569
+ "push": this.getNumberType(),
570
+ "pop": this.getUnknownType(),
571
+ "length": this.getNumberType(),
572
+ "size": this.getNumberType(),
573
+ "count": this.getNumberType(),
574
+ // String methods
575
+ "toString": this.getStringType(),
576
+ "toLowerCase": this.getStringType(),
577
+ "toUpperCase": this.getStringType(),
578
+ "substring": this.getStringType(),
579
+ "charAt": this.getStringType(),
580
+ // Boolean methods
581
+ "isEmpty": this.getBooleanType(),
582
+ "isNull": this.getBooleanType(),
583
+ "hasValue": this.getBooleanType()
584
+ };
585
+ return commonPatterns[methodName] || this.getUnknownType();
586
+ }
587
+ analyzeLoopStatement(node) {
588
+ return /* @__PURE__ */ new Map();
589
+ }
590
+ analyzeTryStatement(node) {
591
+ return /* @__PURE__ */ new Map();
592
+ }
593
+ analyzeMatchStatement(node) {
594
+ return /* @__PURE__ */ new Map();
595
+ }
596
+ // Scope management
597
+ enterScope(scopeName) {
598
+ this.scopeStack.push(scopeName);
599
+ }
600
+ exitScope() {
601
+ this.scopeStack.pop();
602
+ }
603
+ getCurrentScope() {
604
+ return this.scopeStack.join(".");
605
+ }
606
+ // Type registration for classes and functions
607
+ registerClass(className, classInfo) {
608
+ this.classTypes.set(className, classInfo);
609
+ }
610
+ registerFunction(functionName, signature) {
611
+ this.functionTypes.set(functionName, signature);
612
+ }
613
+ // Export current state for inter-procedural analysis
614
+ getTypeSnapshot() {
615
+ return {
616
+ variables: new Map(this.variableTypes),
617
+ functions: new Map(this.functionTypes),
618
+ classes: new Map(this.classTypes)
619
+ };
620
+ }
621
+ }
622
+ TypeInference2.InferenceContext = InferenceContext;
623
+ class TypeInferenceEngine {
624
+ contexts = /* @__PURE__ */ new Map();
625
+ createContext(filePath, language) {
626
+ const context = new InferenceContext(language, filePath);
627
+ this.contexts.set(filePath, context);
628
+ return context;
629
+ }
630
+ getContext(filePath) {
631
+ return this.contexts.get(filePath) || null;
632
+ }
633
+ inferTypesForFile(rootNode, content, filePath, language) {
634
+ const context = this.createContext(filePath, language);
635
+ const inferredTypes = /* @__PURE__ */ new Map();
636
+ this.traverseAndInferTypes(rootNode, context, inferredTypes);
637
+ return inferredTypes;
638
+ }
639
+ traverseAndInferTypes(node, context, inferredTypes) {
640
+ if (this.isVariableDeclaration(node)) {
641
+ const varName = this.getVariableName(node);
642
+ const initExpr = this.getVariableInitializer(node);
643
+ if (varName && initExpr) {
644
+ const inferredType = context.inferVariableType(
645
+ varName,
646
+ initExpr,
647
+ "declaration" /* Declaration */
648
+ );
649
+ inferredTypes.set(varName, inferredType);
650
+ }
651
+ }
652
+ if (this.isFunctionDeclaration(node)) {
653
+ const funcName = this.getFunctionName(node);
654
+ const bodyNode = this.getFunctionBody(node);
655
+ if (funcName && bodyNode) {
656
+ context.enterScope(funcName);
657
+ const returnType = context.inferFunctionReturnType(funcName, bodyNode);
658
+ context.exitScope();
659
+ inferredTypes.set(`${funcName}:return`, returnType);
660
+ }
661
+ }
662
+ const flowTypes = context.analyzeControlFlow(node);
663
+ flowTypes.forEach((type, variable) => {
664
+ inferredTypes.set(variable, type);
665
+ });
666
+ const children = node.namedChildren;
667
+ for (let i = 0; i < children.length; i++) {
668
+ const child = children[i];
669
+ if (child) {
670
+ this.traverseAndInferTypes(child, context, inferredTypes);
671
+ }
672
+ }
673
+ }
674
+ // Cross-file type resolution
675
+ resolveTypesAcrossFiles(filePaths) {
676
+ const globalTypes = /* @__PURE__ */ new Map();
677
+ filePaths.forEach((filePath) => {
678
+ const context = this.getContext(filePath);
679
+ if (context) {
680
+ const snapshot = context.getTypeSnapshot();
681
+ snapshot.classes.forEach((classInfo, className) => {
682
+ if (!globalTypes.has(className) || classInfo.confidence > globalTypes.get(className).confidence) {
683
+ globalTypes.set(className, classInfo);
684
+ }
685
+ });
686
+ }
687
+ });
688
+ filePaths.forEach((filePath) => {
689
+ const context = this.getContext(filePath);
690
+ if (context) {
691
+ globalTypes.forEach((typeInfo, typeName) => {
692
+ context.registerClass(typeName, typeInfo);
693
+ });
694
+ }
695
+ });
696
+ return globalTypes;
697
+ }
698
+ // Language-agnostic AST node detection
699
+ isVariableDeclaration(node) {
700
+ const varDeclarationTypes = [
701
+ "variable_declaration",
702
+ "let_declaration",
703
+ "const_declaration",
704
+ "var_declaration",
705
+ "local_variable_declaration",
706
+ "assignment_statement"
707
+ ];
708
+ return varDeclarationTypes.includes(node.type);
709
+ }
710
+ isFunctionDeclaration(node) {
711
+ const funcDeclarationTypes = [
712
+ "function_declaration",
713
+ "function_definition",
714
+ "method_declaration",
715
+ "def",
716
+ "defn",
717
+ "fn",
718
+ "func"
719
+ ];
720
+ return funcDeclarationTypes.includes(node.type);
721
+ }
722
+ getVariableName(node) {
723
+ const nameNode = node.childForFieldName("name") || node.childForFieldName("identifier") || node.childForFieldName("pattern");
724
+ return nameNode ? nameNode.text : null;
725
+ }
726
+ getVariableInitializer(node) {
727
+ return node.childForFieldName("value") || node.childForFieldName("initializer") || node.childForFieldName("expression");
728
+ }
729
+ getFunctionName(node) {
730
+ const nameNode = node.childForFieldName("name") || node.childForFieldName("identifier");
731
+ return nameNode ? nameNode.text : null;
732
+ }
733
+ getFunctionBody(node) {
734
+ return node.childForFieldName("body") || node.childForFieldName("block") || node.childForFieldName("compound_statement");
735
+ }
736
+ }
737
+ TypeInference2.TypeInferenceEngine = TypeInferenceEngine;
738
+ function enhanceAnalyzerWithTypeInference(analyzer, language) {
739
+ const engine = new TypeInferenceEngine();
740
+ return {
741
+ analyze(rootNode, content, filePath, context) {
742
+ const result = analyzer.analyze(rootNode, content, filePath, context);
743
+ const inferredTypes = engine.inferTypesForFile(rootNode, content, filePath, language);
744
+ result.symbols.forEach((symbol) => {
745
+ const typeInfo = inferredTypes.get(symbol.name);
746
+ if (typeInfo) {
747
+ symbol.metadata = {
748
+ ...symbol.metadata,
749
+ inferredType: typeInfo,
750
+ typeConfidence: typeInfo.confidence,
751
+ typeInferenceReasons: typeInfo.inferredAt.map((loc) => loc.reason)
752
+ };
753
+ }
754
+ });
755
+ const typeRelationships = [];
756
+ inferredTypes.forEach((typeInfo, symbolName) => {
757
+ if (typeInfo.superTypes) {
758
+ typeInfo.superTypes.forEach((superType) => {
759
+ typeRelationships.push({
760
+ source: symbolName,
761
+ target: superType.name,
762
+ type: ASTEngine.RelationshipType.Extends,
763
+ confidence: typeInfo.confidence,
764
+ metadata: {
765
+ inferredFromTypes: true,
766
+ typeInference: true
767
+ }
768
+ });
769
+ });
770
+ }
771
+ });
772
+ result.relationships.push(...typeRelationships);
773
+ return result;
774
+ }
775
+ };
776
+ }
777
+ TypeInference2.enhanceAnalyzerWithTypeInference = enhanceAnalyzerWithTypeInference;
778
+ })(TypeInference || (TypeInference = {}));
779
+
780
+ export {
781
+ TypeInference
782
+ };