hinmil 0.0.0-stage → 0.2.0

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 (301) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2306 -2
  3. package/dist/cli.d.ts +15 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +338 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/commentParser.d.ts +384 -0
  8. package/dist/commentParser.d.ts.map +1 -0
  9. package/dist/commentParser.js +2487 -0
  10. package/dist/commentParser.js.map +1 -0
  11. package/dist/config.d.ts +203 -0
  12. package/dist/config.d.ts.map +1 -0
  13. package/dist/config.js +375 -0
  14. package/dist/config.js.map +1 -0
  15. package/dist/debugLog.d.ts +13 -0
  16. package/dist/debugLog.d.ts.map +1 -0
  17. package/dist/debugLog.js +44 -0
  18. package/dist/debugLog.js.map +1 -0
  19. package/dist/estree.d.ts +100 -0
  20. package/dist/estree.d.ts.map +1 -0
  21. package/dist/estree.js +34 -0
  22. package/dist/estree.js.map +1 -0
  23. package/dist/hm/env.d.ts +134 -0
  24. package/dist/hm/env.d.ts.map +1 -0
  25. package/dist/hm/env.js +939 -0
  26. package/dist/hm/env.js.map +1 -0
  27. package/dist/hm/index.d.ts +7 -0
  28. package/dist/hm/index.d.ts.map +1 -0
  29. package/dist/hm/index.js +26 -0
  30. package/dist/hm/index.js.map +1 -0
  31. package/dist/hm/substitution.d.ts +57 -0
  32. package/dist/hm/substitution.d.ts.map +1 -0
  33. package/dist/hm/substitution.js +546 -0
  34. package/dist/hm/substitution.js.map +1 -0
  35. package/dist/hm/typeParser.d.ts +39 -0
  36. package/dist/hm/typeParser.d.ts.map +1 -0
  37. package/dist/hm/typeParser.js +1285 -0
  38. package/dist/hm/typeParser.js.map +1 -0
  39. package/dist/hm/typeUtils.d.ts +248 -0
  40. package/dist/hm/typeUtils.d.ts.map +1 -0
  41. package/dist/hm/typeUtils.js +905 -0
  42. package/dist/hm/typeUtils.js.map +1 -0
  43. package/dist/hm/types.d.ts +738 -0
  44. package/dist/hm/types.d.ts.map +1 -0
  45. package/dist/hm/types.js +1853 -0
  46. package/dist/hm/types.js.map +1 -0
  47. package/dist/hm/unify.d.ts +59 -0
  48. package/dist/hm/unify.d.ts.map +1 -0
  49. package/dist/hm/unify.js +1700 -0
  50. package/dist/hm/unify.js.map +1 -0
  51. package/dist/index.d.ts +20 -0
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/index.js +196 -0
  54. package/dist/index.js.map +1 -0
  55. package/dist/infer/annotation-rigid.d.ts +76 -0
  56. package/dist/infer/annotation-rigid.d.ts.map +1 -0
  57. package/dist/infer/annotation-rigid.js +542 -0
  58. package/dist/infer/annotation-rigid.js.map +1 -0
  59. package/dist/infer/annotation-validation.d.ts +109 -0
  60. package/dist/infer/annotation-validation.d.ts.map +1 -0
  61. package/dist/infer/annotation-validation.js +1078 -0
  62. package/dist/infer/annotation-validation.js.map +1 -0
  63. package/dist/infer/annotations.d.ts +277 -0
  64. package/dist/infer/annotations.d.ts.map +1 -0
  65. package/dist/infer/annotations.js +1343 -0
  66. package/dist/infer/annotations.js.map +1 -0
  67. package/dist/infer/call-overloads.d.ts +24 -0
  68. package/dist/infer/call-overloads.d.ts.map +1 -0
  69. package/dist/infer/call-overloads.js +900 -0
  70. package/dist/infer/call-overloads.js.map +1 -0
  71. package/dist/infer/call-rows.d.ts +154 -0
  72. package/dist/infer/call-rows.d.ts.map +1 -0
  73. package/dist/infer/call-rows.js +2162 -0
  74. package/dist/infer/call-rows.js.map +1 -0
  75. package/dist/infer/calls.d.ts +20 -0
  76. package/dist/infer/calls.d.ts.map +1 -0
  77. package/dist/infer/calls.js +1468 -0
  78. package/dist/infer/calls.js.map +1 -0
  79. package/dist/infer/constraints.d.ts +99 -0
  80. package/dist/infer/constraints.d.ts.map +1 -0
  81. package/dist/infer/constraints.js +1208 -0
  82. package/dist/infer/constraints.js.map +1 -0
  83. package/dist/infer/expr-assignment.d.ts +20 -0
  84. package/dist/infer/expr-assignment.d.ts.map +1 -0
  85. package/dist/infer/expr-assignment.js +620 -0
  86. package/dist/infer/expr-assignment.js.map +1 -0
  87. package/dist/infer/expr-constraint-lookup.d.ts +44 -0
  88. package/dist/infer/expr-constraint-lookup.d.ts.map +1 -0
  89. package/dist/infer/expr-constraint-lookup.js +207 -0
  90. package/dist/infer/expr-constraint-lookup.js.map +1 -0
  91. package/dist/infer/expr-functions.d.ts +20 -0
  92. package/dist/infer/expr-functions.d.ts.map +1 -0
  93. package/dist/infer/expr-functions.js +1359 -0
  94. package/dist/infer/expr-functions.js.map +1 -0
  95. package/dist/infer/expr-jsx.d.ts +19 -0
  96. package/dist/infer/expr-jsx.d.ts.map +1 -0
  97. package/dist/infer/expr-jsx.js +310 -0
  98. package/dist/infer/expr-jsx.js.map +1 -0
  99. package/dist/infer/expr-member.d.ts +40 -0
  100. package/dist/infer/expr-member.d.ts.map +1 -0
  101. package/dist/infer/expr-member.js +1154 -0
  102. package/dist/infer/expr-member.js.map +1 -0
  103. package/dist/infer/expr-prototype.d.ts +11 -0
  104. package/dist/infer/expr-prototype.d.ts.map +1 -0
  105. package/dist/infer/expr-prototype.js +202 -0
  106. package/dist/infer/expr-prototype.js.map +1 -0
  107. package/dist/infer/expressions.d.ts +40 -0
  108. package/dist/infer/expressions.d.ts.map +1 -0
  109. package/dist/infer/expressions.js +1497 -0
  110. package/dist/infer/expressions.js.map +1 -0
  111. package/dist/infer/functionPatterns.d.ts +229 -0
  112. package/dist/infer/functionPatterns.d.ts.map +1 -0
  113. package/dist/infer/functionPatterns.js +1035 -0
  114. package/dist/infer/functionPatterns.js.map +1 -0
  115. package/dist/infer/helpers.d.ts +73 -0
  116. package/dist/infer/helpers.d.ts.map +1 -0
  117. package/dist/infer/helpers.js +187 -0
  118. package/dist/infer/helpers.js.map +1 -0
  119. package/dist/infer/index.d.ts +551 -0
  120. package/dist/infer/index.d.ts.map +1 -0
  121. package/dist/infer/index.js +1127 -0
  122. package/dist/infer/index.js.map +1 -0
  123. package/dist/infer/jsx-dom.d.ts +26 -0
  124. package/dist/infer/jsx-dom.d.ts.map +1 -0
  125. package/dist/infer/jsx-dom.js +303 -0
  126. package/dist/infer/jsx-dom.js.map +1 -0
  127. package/dist/infer/moduleReps.d.ts +7 -0
  128. package/dist/infer/moduleReps.d.ts.map +1 -0
  129. package/dist/infer/moduleReps.js +48 -0
  130. package/dist/infer/moduleReps.js.map +1 -0
  131. package/dist/infer/modules.d.ts +10 -0
  132. package/dist/infer/modules.d.ts.map +1 -0
  133. package/dist/infer/modules.js +775 -0
  134. package/dist/infer/modules.js.map +1 -0
  135. package/dist/infer/narrowing.d.ts +199 -0
  136. package/dist/infer/narrowing.d.ts.map +1 -0
  137. package/dist/infer/narrowing.js +1428 -0
  138. package/dist/infer/narrowing.js.map +1 -0
  139. package/dist/infer/results.d.ts +24 -0
  140. package/dist/infer/results.d.ts.map +1 -0
  141. package/dist/infer/results.js +611 -0
  142. package/dist/infer/results.js.map +1 -0
  143. package/dist/infer/setupPass.d.ts +11 -0
  144. package/dist/infer/setupPass.d.ts.map +1 -0
  145. package/dist/infer/setupPass.js +524 -0
  146. package/dist/infer/setupPass.js.map +1 -0
  147. package/dist/infer/statements.d.ts +26 -0
  148. package/dist/infer/statements.d.ts.map +1 -0
  149. package/dist/infer/statements.js +750 -0
  150. package/dist/infer/statements.js.map +1 -0
  151. package/dist/infer/stmt-bindings.d.ts +22 -0
  152. package/dist/infer/stmt-bindings.d.ts.map +1 -0
  153. package/dist/infer/stmt-bindings.js +1482 -0
  154. package/dist/infer/stmt-bindings.js.map +1 -0
  155. package/dist/infer/stmt-destructure.d.ts +29 -0
  156. package/dist/infer/stmt-destructure.d.ts.map +1 -0
  157. package/dist/infer/stmt-destructure.js +490 -0
  158. package/dist/infer/stmt-destructure.js.map +1 -0
  159. package/dist/infer/types.d.ts +220 -0
  160. package/dist/infer/types.d.ts.map +1 -0
  161. package/dist/infer/types.js +46 -0
  162. package/dist/infer/types.js.map +1 -0
  163. package/dist/infer/unifyDiag.d.ts +46 -0
  164. package/dist/infer/unifyDiag.d.ts.map +1 -0
  165. package/dist/infer/unifyDiag.js +642 -0
  166. package/dist/infer/unifyDiag.js.map +1 -0
  167. package/dist/parsing-babel.d.ts +3 -0
  168. package/dist/parsing-babel.d.ts.map +1 -0
  169. package/dist/parsing-babel.js +353 -0
  170. package/dist/parsing-babel.js.map +1 -0
  171. package/dist/parsing.d.ts +69 -0
  172. package/dist/parsing.d.ts.map +1 -0
  173. package/dist/parsing.js +288 -0
  174. package/dist/parsing.js.map +1 -0
  175. package/dist/registries/constraintRegistry.d.ts +233 -0
  176. package/dist/registries/constraintRegistry.d.ts.map +1 -0
  177. package/dist/registries/constraintRegistry.js +803 -0
  178. package/dist/registries/constraintRegistry.js.map +1 -0
  179. package/dist/registries/dataTypeRegistry.d.ts +63 -0
  180. package/dist/registries/dataTypeRegistry.d.ts.map +1 -0
  181. package/dist/registries/dataTypeRegistry.js +180 -0
  182. package/dist/registries/dataTypeRegistry.js.map +1 -0
  183. package/dist/registries/domGlobals.d.ts +33 -0
  184. package/dist/registries/domGlobals.d.ts.map +1 -0
  185. package/dist/registries/domGlobals.js +309 -0
  186. package/dist/registries/domGlobals.js.map +1 -0
  187. package/dist/registries/methodRegistry.d.ts +277 -0
  188. package/dist/registries/methodRegistry.d.ts.map +1 -0
  189. package/dist/registries/methodRegistry.js +2074 -0
  190. package/dist/registries/methodRegistry.js.map +1 -0
  191. package/dist/registries/session.d.ts +38 -0
  192. package/dist/registries/session.d.ts.map +1 -0
  193. package/dist/registries/session.js +75 -0
  194. package/dist/registries/session.js.map +1 -0
  195. package/dist/server.d.ts +2 -0
  196. package/dist/server.d.ts.map +1 -0
  197. package/dist/server.js +1896 -0
  198. package/dist/server.js.map +1 -0
  199. package/dist/services/codeActions.d.ts +22 -0
  200. package/dist/services/codeActions.d.ts.map +1 -0
  201. package/dist/services/codeActions.js +465 -0
  202. package/dist/services/codeActions.js.map +1 -0
  203. package/dist/services/completion.d.ts +259 -0
  204. package/dist/services/completion.d.ts.map +1 -0
  205. package/dist/services/completion.js +2794 -0
  206. package/dist/services/completion.js.map +1 -0
  207. package/dist/services/definitions.d.ts +37 -0
  208. package/dist/services/definitions.d.ts.map +1 -0
  209. package/dist/services/definitions.js +605 -0
  210. package/dist/services/definitions.js.map +1 -0
  211. package/dist/services/diagnosticCodes.d.ts +70 -0
  212. package/dist/services/diagnosticCodes.d.ts.map +1 -0
  213. package/dist/services/diagnosticCodes.js +239 -0
  214. package/dist/services/diagnosticCodes.js.map +1 -0
  215. package/dist/services/diagnostics.d.ts +86 -0
  216. package/dist/services/diagnostics.d.ts.map +1 -0
  217. package/dist/services/diagnostics.js +665 -0
  218. package/dist/services/diagnostics.js.map +1 -0
  219. package/dist/services/documentCache.d.ts +88 -0
  220. package/dist/services/documentCache.d.ts.map +1 -0
  221. package/dist/services/documentCache.js +108 -0
  222. package/dist/services/documentCache.js.map +1 -0
  223. package/dist/services/documentSymbols.d.ts +20 -0
  224. package/dist/services/documentSymbols.d.ts.map +1 -0
  225. package/dist/services/documentSymbols.js +381 -0
  226. package/dist/services/documentSymbols.js.map +1 -0
  227. package/dist/services/fileSelection.d.ts +24 -0
  228. package/dist/services/fileSelection.d.ts.map +1 -0
  229. package/dist/services/fileSelection.js +154 -0
  230. package/dist/services/fileSelection.js.map +1 -0
  231. package/dist/services/fileSelectionRefresh.d.ts +26 -0
  232. package/dist/services/fileSelectionRefresh.d.ts.map +1 -0
  233. package/dist/services/fileSelectionRefresh.js +77 -0
  234. package/dist/services/fileSelectionRefresh.js.map +1 -0
  235. package/dist/services/files.d.ts +342 -0
  236. package/dist/services/files.d.ts.map +1 -0
  237. package/dist/services/files.js +1712 -0
  238. package/dist/services/files.js.map +1 -0
  239. package/dist/services/fsProbe.d.ts +14 -0
  240. package/dist/services/fsProbe.d.ts.map +1 -0
  241. package/dist/services/fsProbe.js +112 -0
  242. package/dist/services/fsProbe.js.map +1 -0
  243. package/dist/services/globalsLoader.d.ts +20 -0
  244. package/dist/services/globalsLoader.d.ts.map +1 -0
  245. package/dist/services/globalsLoader.js +122 -0
  246. package/dist/services/globalsLoader.js.map +1 -0
  247. package/dist/services/hmFileServices.d.ts +113 -0
  248. package/dist/services/hmFileServices.d.ts.map +1 -0
  249. package/dist/services/hmFileServices.js +686 -0
  250. package/dist/services/hmFileServices.js.map +1 -0
  251. package/dist/services/hover.d.ts +280 -0
  252. package/dist/services/hover.d.ts.map +1 -0
  253. package/dist/services/hover.js +1687 -0
  254. package/dist/services/hover.js.map +1 -0
  255. package/dist/services/importContext.d.ts +396 -0
  256. package/dist/services/importContext.d.ts.map +1 -0
  257. package/dist/services/importContext.js +1999 -0
  258. package/dist/services/importContext.js.map +1 -0
  259. package/dist/services/projectChecker.d.ts +50 -0
  260. package/dist/services/projectChecker.d.ts.map +1 -0
  261. package/dist/services/projectChecker.js +228 -0
  262. package/dist/services/projectChecker.js.map +1 -0
  263. package/dist/services/references.d.ts +41 -0
  264. package/dist/services/references.d.ts.map +1 -0
  265. package/dist/services/references.js +757 -0
  266. package/dist/services/references.js.map +1 -0
  267. package/dist/services/rename.d.ts +22 -0
  268. package/dist/services/rename.d.ts.map +1 -0
  269. package/dist/services/rename.js +101 -0
  270. package/dist/services/rename.js.map +1 -0
  271. package/dist/services/shortCircuit.d.ts +27 -0
  272. package/dist/services/shortCircuit.d.ts.map +1 -0
  273. package/dist/services/shortCircuit.js +28 -0
  274. package/dist/services/shortCircuit.js.map +1 -0
  275. package/dist/services/sidecarPerf.d.ts +19 -0
  276. package/dist/services/sidecarPerf.d.ts.map +1 -0
  277. package/dist/services/sidecarPerf.js +59 -0
  278. package/dist/services/sidecarPerf.js.map +1 -0
  279. package/dist/services/signatureHelp.d.ts +27 -0
  280. package/dist/services/signatureHelp.d.ts.map +1 -0
  281. package/dist/services/signatureHelp.js +984 -0
  282. package/dist/services/signatureHelp.js.map +1 -0
  283. package/dist/walking.d.ts +25 -0
  284. package/dist/walking.d.ts.map +1 -0
  285. package/dist/walking.js +107 -0
  286. package/dist/walking.js.map +1 -0
  287. package/hm-types-builtin/assert.hm +20 -0
  288. package/hm-types-builtin/buffer.hm +8 -0
  289. package/hm-types-builtin/child_process.hm +16 -0
  290. package/hm-types-builtin/crypto.hm +17 -0
  291. package/hm-types-builtin/fs.hm +15 -0
  292. package/hm-types-builtin/http.hm +14 -0
  293. package/hm-types-builtin/os.hm +19 -0
  294. package/hm-types-builtin/path.hm +18 -0
  295. package/hm-types-builtin/react-dom.hm +27 -0
  296. package/hm-types-builtin/react.hm +113 -0
  297. package/hm-types-builtin/url.hm +7 -0
  298. package/hm-types-builtin/zlib.hm +12 -0
  299. package/package.json +53 -4
  300. package/schemas/hinmil.config.schema.json +261 -0
  301. package/schemas/package-hinmil.schema.json +59 -0
@@ -0,0 +1,757 @@
1
+ "use strict";
2
+ // ============================================================================
3
+ // References & Rename — scope-aware identifier reference collection
4
+ //
5
+ // Performs a post-hoc AST walk (separate from inference) to build a map of
6
+ // every identifier back to its declaring binding. This powers:
7
+ // • textDocument/references — Find All References
8
+ // • textDocument/rename — Rename Symbol
9
+ // • textDocument/prepareRename
10
+ // ============================================================================
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.collectReferences = collectReferences;
13
+ exports.findReferencesAtOffset = findReferencesAtOffset;
14
+ exports.collectScopeBindings = collectScopeBindings;
15
+ const parsing_1 = require("../parsing");
16
+ /**
17
+ * Allocate a globally unique binding id. Each distinct binding in the source
18
+ * gets its own id — even if two bindings share the same name (shadowing).
19
+ */
20
+ let nextBindingId = 0;
21
+ function freshBindingId() {
22
+ return nextBindingId++;
23
+ }
24
+ // ---------------------------------------------------------------------------
25
+ // Core: collectReferences
26
+ // ---------------------------------------------------------------------------
27
+ /**
28
+ * Parse the source and walk the AST with scope tracking. Returns a Map
29
+ * keyed by **binding id** to all reference locations.
30
+ *
31
+ * The binding id is an ephemeral number that uniquely identifies a binding
32
+ * (i.e. a specific `const x`, `let y`, or function parameter). Two
33
+ * different `x` variables in nested scopes get different ids.
34
+ */
35
+ function collectReferences(source, result) {
36
+ nextBindingId = 0;
37
+ let ast;
38
+ try {
39
+ ast = (0, parsing_1.parseStrict)(source);
40
+ }
41
+ catch { /* parse error — no references to collect */
42
+ return new Map();
43
+ }
44
+ const groups = new Map();
45
+ const scopes = [{ bindings: new Map() }]; // global scope
46
+ // --- scope helpers -------------------------------------------------------
47
+ function currentScope() {
48
+ return scopes[scopes.length - 1];
49
+ }
50
+ function pushScope() {
51
+ const s = { bindings: new Map() };
52
+ scopes.push(s);
53
+ return s;
54
+ }
55
+ function popScope() {
56
+ scopes.pop();
57
+ }
58
+ /** Declare a new binding in the current scope and record the definition location. */
59
+ function declare(name, start, end) {
60
+ const id = freshBindingId();
61
+ currentScope().bindings.set(name, id);
62
+ const group = {
63
+ name,
64
+ locations: [{ start, end, isDefinition: true }],
65
+ };
66
+ // Attach annotation info if available
67
+ if (result) {
68
+ const ann = result.annotations.get(name);
69
+ if (ann && ann.commentStart !== undefined && ann.commentEnd !== undefined) {
70
+ // Find the name offset within the annotation comment text
71
+ const commentText = source.slice(ann.commentStart, ann.commentEnd);
72
+ const nameIdx = findAnnotationNameOffset(commentText, name);
73
+ if (nameIdx >= 0) {
74
+ group.annotationNameStart = ann.commentStart + nameIdx;
75
+ group.annotationNameEnd = ann.commentStart + nameIdx + name.length;
76
+ }
77
+ }
78
+ }
79
+ groups.set(id, group);
80
+ return id;
81
+ }
82
+ /** Look up a name in the scope chain (innermost first). */
83
+ function resolve(name) {
84
+ for (let i = scopes.length - 1; i >= 0; i--) {
85
+ const id = scopes[i].bindings.get(name);
86
+ if (id !== undefined)
87
+ return id;
88
+ }
89
+ return undefined;
90
+ }
91
+ /** Record a usage (non-definition) reference for an already-resolved binding. */
92
+ function recordUsage(id, start, end) {
93
+ const group = groups.get(id);
94
+ if (group) {
95
+ group.locations.push({ start, end, isDefinition: false });
96
+ }
97
+ }
98
+ // --- pattern helpers (destructuring) ------------------------------------
99
+ /** Declare all bindings introduced by a pattern node (Identifier, ObjectPattern, ArrayPattern, RestElement, AssignmentPattern). */
100
+ function declarePattern(node) {
101
+ if (!node)
102
+ return;
103
+ switch (node.type) {
104
+ case 'Identifier':
105
+ declare(node.name, node.start, node.end);
106
+ break;
107
+ case 'ObjectPattern':
108
+ for (const prop of node.properties) {
109
+ if (prop.type === 'RestElement') {
110
+ declarePattern(prop.argument);
111
+ }
112
+ else {
113
+ declarePattern(prop.value);
114
+ }
115
+ }
116
+ break;
117
+ case 'ArrayPattern':
118
+ for (const el of node.elements) {
119
+ if (el)
120
+ declarePattern(el);
121
+ }
122
+ break;
123
+ case 'RestElement':
124
+ declarePattern(node.argument);
125
+ break;
126
+ case 'AssignmentPattern':
127
+ declarePattern(node.left);
128
+ walkExpr(node.right);
129
+ break;
130
+ }
131
+ }
132
+ // --- expression walker ---------------------------------------------------
133
+ function walkExpr(node) {
134
+ if (!node)
135
+ return;
136
+ switch (node.type) {
137
+ case 'Identifier': {
138
+ const id = resolve(node.name);
139
+ if (id !== undefined) {
140
+ recordUsage(id, node.start, node.end);
141
+ }
142
+ break;
143
+ }
144
+ case 'MemberExpression':
145
+ walkExpr(node.object);
146
+ if (node.computed)
147
+ walkExpr(node.property);
148
+ break;
149
+ case 'CallExpression':
150
+ case 'NewExpression':
151
+ walkExpr(node.callee);
152
+ for (const arg of node.arguments)
153
+ walkExpr(arg);
154
+ break;
155
+ case 'ArrayExpression':
156
+ for (const el of node.elements) {
157
+ if (el) {
158
+ if (el.type === 'SpreadElement')
159
+ walkExpr(el.argument);
160
+ else
161
+ walkExpr(el);
162
+ }
163
+ }
164
+ break;
165
+ case 'ObjectExpression':
166
+ for (const prop of node.properties) {
167
+ if (prop.type === 'SpreadElement') {
168
+ walkExpr(prop.argument);
169
+ }
170
+ else {
171
+ if (prop.computed)
172
+ walkExpr(prop.key);
173
+ walkExpr(prop.value);
174
+ }
175
+ }
176
+ break;
177
+ case 'ArrowFunctionExpression':
178
+ case 'FunctionExpression': {
179
+ pushScope();
180
+ if (node.id)
181
+ declare(node.id.name, node.id.start, node.id.end);
182
+ for (const param of node.params)
183
+ declarePattern(param);
184
+ if (node.body.type === 'BlockStatement') {
185
+ walkBlock(node.body);
186
+ }
187
+ else {
188
+ walkExpr(node.body);
189
+ }
190
+ popScope();
191
+ break;
192
+ }
193
+ case 'AssignmentExpression':
194
+ // Left side: if it's an identifier, it's a usage (write), not a declaration
195
+ if (node.left.type === 'Identifier') {
196
+ const id = resolve(node.left.name);
197
+ if (id !== undefined)
198
+ recordUsage(id, node.left.start, node.left.end);
199
+ }
200
+ else {
201
+ walkExpr(node.left);
202
+ }
203
+ walkExpr(node.right);
204
+ break;
205
+ case 'UpdateExpression':
206
+ walkExpr(node.argument);
207
+ break;
208
+ case 'UnaryExpression':
209
+ walkExpr(node.argument);
210
+ break;
211
+ case 'BinaryExpression':
212
+ case 'LogicalExpression':
213
+ walkExpr(node.left);
214
+ walkExpr(node.right);
215
+ break;
216
+ case 'ConditionalExpression':
217
+ walkExpr(node.test);
218
+ walkExpr(node.consequent);
219
+ walkExpr(node.alternate);
220
+ break;
221
+ case 'SequenceExpression':
222
+ for (const expr of node.expressions)
223
+ walkExpr(expr);
224
+ break;
225
+ case 'TemplateLiteral':
226
+ for (const expr of node.expressions)
227
+ walkExpr(expr);
228
+ break;
229
+ case 'TaggedTemplateExpression':
230
+ walkExpr(node.tag);
231
+ for (const expr of node.quasi.expressions)
232
+ walkExpr(expr);
233
+ break;
234
+ case 'SpreadElement':
235
+ walkExpr(node.argument);
236
+ break;
237
+ case 'YieldExpression':
238
+ if (node.argument)
239
+ walkExpr(node.argument);
240
+ break;
241
+ case 'AwaitExpression':
242
+ if (node.argument)
243
+ walkExpr(node.argument);
244
+ break;
245
+ case 'ClassExpression': {
246
+ pushScope();
247
+ if (node.id)
248
+ declare(node.id.name, node.id.start, node.id.end);
249
+ if (node.superClass)
250
+ walkExpr(node.superClass);
251
+ walkClassBody(node.body);
252
+ popScope();
253
+ break;
254
+ }
255
+ // Literals, ThisExpression, MetaProperty — no identifiers
256
+ default:
257
+ break;
258
+ }
259
+ }
260
+ // --- statement walker ----------------------------------------------------
261
+ function walkStmt(node) {
262
+ if (!node)
263
+ return;
264
+ switch (node.type) {
265
+ case 'VariableDeclaration':
266
+ for (const decl of node.declarations) {
267
+ // Walk initializer first (it can't reference `decl.id` in const)
268
+ if (decl.init)
269
+ walkExpr(decl.init);
270
+ declarePattern(decl.id);
271
+ }
272
+ break;
273
+ case 'FunctionDeclaration': {
274
+ // Function declarations are hoisted — declare in current scope
275
+ if (node.id)
276
+ declare(node.id.name, node.id.start, node.id.end);
277
+ pushScope();
278
+ for (const param of node.params)
279
+ declarePattern(param);
280
+ if (node.body)
281
+ walkBlock(node.body);
282
+ popScope();
283
+ break;
284
+ }
285
+ case 'ClassDeclaration': {
286
+ if (node.id)
287
+ declare(node.id.name, node.id.start, node.id.end);
288
+ pushScope();
289
+ if (node.superClass)
290
+ walkExpr(node.superClass);
291
+ walkClassBody(node.body);
292
+ popScope();
293
+ break;
294
+ }
295
+ case 'ExpressionStatement':
296
+ walkExpr(node.expression);
297
+ break;
298
+ case 'ReturnStatement':
299
+ if (node.argument)
300
+ walkExpr(node.argument);
301
+ break;
302
+ case 'ThrowStatement':
303
+ if (node.argument)
304
+ walkExpr(node.argument);
305
+ break;
306
+ case 'IfStatement':
307
+ walkExpr(node.test);
308
+ walkStmt(node.consequent);
309
+ if (node.alternate)
310
+ walkStmt(node.alternate);
311
+ break;
312
+ case 'WhileStatement':
313
+ case 'DoWhileStatement':
314
+ walkExpr(node.test);
315
+ walkStmt(node.body);
316
+ break;
317
+ case 'ForStatement': {
318
+ pushScope();
319
+ if (node.init) {
320
+ if (node.init.type === 'VariableDeclaration')
321
+ walkStmt(node.init);
322
+ else
323
+ walkExpr(node.init);
324
+ }
325
+ if (node.test)
326
+ walkExpr(node.test);
327
+ if (node.update)
328
+ walkExpr(node.update);
329
+ walkStmt(node.body);
330
+ popScope();
331
+ break;
332
+ }
333
+ case 'ForInStatement':
334
+ case 'ForOfStatement': {
335
+ pushScope();
336
+ if (node.left.type === 'VariableDeclaration')
337
+ walkStmt(node.left);
338
+ else
339
+ walkExpr(node.left);
340
+ walkExpr(node.right);
341
+ walkStmt(node.body);
342
+ popScope();
343
+ break;
344
+ }
345
+ case 'SwitchStatement': {
346
+ walkExpr(node.discriminant);
347
+ for (const c of node.cases) {
348
+ if (c.test)
349
+ walkExpr(c.test);
350
+ for (const s of c.consequent)
351
+ walkStmt(s);
352
+ }
353
+ break;
354
+ }
355
+ case 'TryStatement': {
356
+ walkBlock(node.block);
357
+ if (node.handler) {
358
+ pushScope();
359
+ if (node.handler.param)
360
+ declarePattern(node.handler.param);
361
+ walkBlock(node.handler.body);
362
+ popScope();
363
+ }
364
+ if (node.finalizer)
365
+ walkBlock(node.finalizer);
366
+ break;
367
+ }
368
+ case 'BlockStatement':
369
+ walkBlock(node);
370
+ break;
371
+ case 'LabeledStatement':
372
+ walkStmt(node.body);
373
+ break;
374
+ // Import/Export
375
+ case 'ImportDeclaration':
376
+ for (const spec of node.specifiers) {
377
+ if (spec.local)
378
+ declare(spec.local.name, spec.local.start, spec.local.end);
379
+ }
380
+ break;
381
+ case 'ExportNamedDeclaration':
382
+ if (node.declaration)
383
+ walkStmt(node.declaration);
384
+ // export { x, y } — these are usages of existing bindings
385
+ if (node.specifiers) {
386
+ for (const spec of node.specifiers) {
387
+ if (spec.local) {
388
+ const id = resolve(spec.local.name);
389
+ if (id !== undefined)
390
+ recordUsage(id, spec.local.start, spec.local.end);
391
+ }
392
+ }
393
+ }
394
+ break;
395
+ case 'ExportDefaultDeclaration':
396
+ if (node.declaration) {
397
+ if (node.declaration.type === 'FunctionDeclaration' || node.declaration.type === 'ClassDeclaration') {
398
+ walkStmt(node.declaration);
399
+ }
400
+ else {
401
+ walkExpr(node.declaration);
402
+ }
403
+ }
404
+ break;
405
+ case 'ExportAllDeclaration':
406
+ // no local identifiers
407
+ break;
408
+ // Skip empty, debugger, break, continue
409
+ default:
410
+ break;
411
+ }
412
+ }
413
+ function walkBlock(block) {
414
+ if (!block || !block.body)
415
+ return;
416
+ // Hoist function declarations first
417
+ for (const stmt of block.body) {
418
+ if (stmt.type === 'FunctionDeclaration' && stmt.id) {
419
+ declare(stmt.id.name, stmt.id.start, stmt.id.end);
420
+ }
421
+ }
422
+ for (const stmt of block.body) {
423
+ // Skip hoisted function declarations (already declared above)
424
+ if (stmt.type === 'FunctionDeclaration') {
425
+ pushScope();
426
+ for (const param of stmt.params)
427
+ declarePattern(param);
428
+ if (stmt.body)
429
+ walkBlock(stmt.body);
430
+ popScope();
431
+ continue;
432
+ }
433
+ walkStmt(stmt);
434
+ }
435
+ }
436
+ function walkClassBody(body) {
437
+ if (!body || !body.body)
438
+ return;
439
+ for (const node of body.body) {
440
+ if (node.type === 'MethodDefinition' || node.type === 'PropertyDefinition') {
441
+ if (node.computed && node.key)
442
+ walkExpr(node.key);
443
+ if (node.value)
444
+ walkExpr(node.value);
445
+ }
446
+ }
447
+ }
448
+ // --- Run the walker on top-level body -------
449
+ // Hoist function declarations at the top level
450
+ for (const stmt of ast.body) {
451
+ if (stmt.type === 'FunctionDeclaration' && stmt.id) {
452
+ declare(stmt.id.name, stmt.id.start, stmt.id.end);
453
+ }
454
+ }
455
+ for (const node of ast.body) {
456
+ if (node.type === 'FunctionDeclaration') {
457
+ // Already declared above; just walk the body
458
+ pushScope();
459
+ for (const param of node.params)
460
+ declarePattern(param);
461
+ if (node.body)
462
+ walkBlock(node.body);
463
+ popScope();
464
+ continue;
465
+ }
466
+ walkStmt(node);
467
+ }
468
+ return groups;
469
+ }
470
+ // ---------------------------------------------------------------------------
471
+ // findReferencesAtOffset
472
+ // ---------------------------------------------------------------------------
473
+ /**
474
+ * Given a source offset (cursor position), find the reference group that
475
+ * the identifier at that offset belongs to. Returns null if the offset
476
+ * does not land on a known identifier.
477
+ */
478
+ function findReferencesAtOffset(source, offset, result) {
479
+ const groups = collectReferences(source, result);
480
+ for (const [, group] of groups) {
481
+ for (const loc of group.locations) {
482
+ if (offset >= loc.start && offset <= loc.end) {
483
+ return group;
484
+ }
485
+ }
486
+ }
487
+ return null;
488
+ }
489
+ // ---------------------------------------------------------------------------
490
+ // collectScopeBindings — all identifiers visible at a given offset
491
+ // ---------------------------------------------------------------------------
492
+ /**
493
+ * Return the names of all bindings that are in scope at the given source
494
+ * offset, mapped to their declaration start offset. This includes module-level
495
+ * declarations, function parameters, local variables, and imports.
496
+ */
497
+ function collectScopeBindings(source, offset) {
498
+ let ast;
499
+ try {
500
+ ast = (0, parsing_1.parseStrict)(source);
501
+ }
502
+ catch { /* parse error — no scope bindings available */
503
+ return new Map();
504
+ }
505
+ const names = new Map();
506
+ /** Collect names from a pattern node (Identifier, destructuring). */
507
+ function collectPattern(node) {
508
+ if (!node)
509
+ return;
510
+ switch (node.type) {
511
+ case 'Identifier':
512
+ names.set(node.name, node.start);
513
+ break;
514
+ case 'ObjectPattern':
515
+ for (const prop of node.properties) {
516
+ if (prop.type === 'RestElement')
517
+ collectPattern(prop.argument);
518
+ else
519
+ collectPattern(prop.value);
520
+ }
521
+ break;
522
+ case 'ArrayPattern':
523
+ for (const el of node.elements) {
524
+ if (el)
525
+ collectPattern(el);
526
+ }
527
+ break;
528
+ case 'RestElement':
529
+ collectPattern(node.argument);
530
+ break;
531
+ case 'AssignmentPattern':
532
+ collectPattern(node.left);
533
+ break;
534
+ }
535
+ }
536
+ function contains(node) {
537
+ return node.start <= offset && offset <= node.end;
538
+ }
539
+ /** Walk a block, collecting declarations and recursing into containing scopes. */
540
+ function walkBlock(body) {
541
+ // Hoist function declarations
542
+ for (const stmt of body) {
543
+ if (stmt.type === 'FunctionDeclaration' && stmt.id) {
544
+ names.set(stmt.id.name, stmt.id.start);
545
+ }
546
+ }
547
+ for (const stmt of body) {
548
+ walkStmt(stmt);
549
+ }
550
+ }
551
+ function walkStmt(node) {
552
+ if (!node)
553
+ return;
554
+ switch (node.type) {
555
+ case 'VariableDeclaration':
556
+ for (const decl of node.declarations) {
557
+ if (decl.init && contains(decl.init)) {
558
+ // Cursor is in the initializer — the variable itself isn't in scope yet
559
+ walkExpr(decl.init);
560
+ }
561
+ else {
562
+ collectPattern(decl.id);
563
+ }
564
+ }
565
+ break;
566
+ case 'FunctionDeclaration':
567
+ // Already hoisted; only recurse into body if cursor is inside
568
+ if (contains(node)) {
569
+ for (const param of node.params)
570
+ collectPattern(param);
571
+ if (node.body)
572
+ walkBlock(node.body.body ?? []);
573
+ }
574
+ break;
575
+ case 'ClassDeclaration':
576
+ if (node.id)
577
+ names.set(node.id.name, node.id.start);
578
+ if (contains(node) && node.body)
579
+ walkClassBody(node.body);
580
+ break;
581
+ case 'ExpressionStatement':
582
+ if (contains(node))
583
+ walkExpr(node.expression);
584
+ break;
585
+ case 'ReturnStatement':
586
+ if (node.argument && contains(node))
587
+ walkExpr(node.argument);
588
+ break;
589
+ case 'IfStatement':
590
+ if (contains(node)) {
591
+ walkExpr(node.test);
592
+ walkStmt(node.consequent);
593
+ if (node.alternate)
594
+ walkStmt(node.alternate);
595
+ }
596
+ break;
597
+ case 'ForStatement':
598
+ if (contains(node)) {
599
+ if (node.init) {
600
+ if (node.init.type === 'VariableDeclaration')
601
+ walkStmt(node.init);
602
+ else
603
+ walkExpr(node.init);
604
+ }
605
+ walkStmt(node.body);
606
+ }
607
+ break;
608
+ case 'ForInStatement':
609
+ case 'ForOfStatement':
610
+ if (contains(node)) {
611
+ if (node.left.type === 'VariableDeclaration')
612
+ walkStmt(node.left);
613
+ walkStmt(node.body);
614
+ }
615
+ break;
616
+ case 'WhileStatement':
617
+ case 'DoWhileStatement':
618
+ if (contains(node))
619
+ walkStmt(node.body);
620
+ break;
621
+ case 'TryStatement':
622
+ if (contains(node)) {
623
+ if (node.block && contains(node.block))
624
+ walkBlock(node.block.body ?? []);
625
+ if (node.handler && contains(node.handler)) {
626
+ if (node.handler.param)
627
+ collectPattern(node.handler.param);
628
+ walkBlock(node.handler.body.body ?? []);
629
+ }
630
+ if (node.finalizer && contains(node.finalizer))
631
+ walkBlock(node.finalizer.body ?? []);
632
+ }
633
+ break;
634
+ case 'SwitchStatement':
635
+ if (contains(node)) {
636
+ for (const c of node.cases) {
637
+ for (const s of c.consequent)
638
+ walkStmt(s);
639
+ }
640
+ }
641
+ break;
642
+ case 'BlockStatement':
643
+ if (contains(node))
644
+ walkBlock(node.body ?? []);
645
+ break;
646
+ case 'LabeledStatement':
647
+ walkStmt(node.body);
648
+ break;
649
+ case 'ImportDeclaration':
650
+ for (const spec of node.specifiers) {
651
+ if (spec.local)
652
+ names.set(spec.local.name, spec.local.start);
653
+ }
654
+ break;
655
+ case 'ExportNamedDeclaration':
656
+ if (node.declaration)
657
+ walkStmt(node.declaration);
658
+ break;
659
+ case 'ExportDefaultDeclaration':
660
+ if (node.declaration) {
661
+ if (node.declaration.type === 'FunctionDeclaration' || node.declaration.type === 'ClassDeclaration') {
662
+ walkStmt(node.declaration);
663
+ }
664
+ else if (contains(node)) {
665
+ walkExpr(node.declaration);
666
+ }
667
+ }
668
+ break;
669
+ default:
670
+ break;
671
+ }
672
+ }
673
+ function walkExpr(node) {
674
+ if (!node)
675
+ return;
676
+ switch (node.type) {
677
+ case 'ArrowFunctionExpression':
678
+ case 'FunctionExpression':
679
+ if (contains(node)) {
680
+ if (node.id)
681
+ names.set(node.id.name, node.id.start);
682
+ for (const param of node.params)
683
+ collectPattern(param);
684
+ if (node.body.type === 'BlockStatement') {
685
+ walkBlock(node.body.body ?? []);
686
+ }
687
+ else {
688
+ walkExpr(node.body);
689
+ }
690
+ }
691
+ break;
692
+ case 'ClassExpression':
693
+ if (contains(node)) {
694
+ if (node.id)
695
+ names.set(node.id.name, node.id.start);
696
+ if (node.body)
697
+ walkClassBody(node.body);
698
+ }
699
+ break;
700
+ default:
701
+ // For other expressions, recurse into sub-expressions that contain the offset
702
+ for (const key of Object.keys(node)) {
703
+ if (key === 'type' || key === 'start' || key === 'end' || key === 'loc')
704
+ continue;
705
+ const val = node[key];
706
+ if (val && typeof val === 'object' && typeof val.type === 'string' && typeof val.start === 'number') {
707
+ if (contains(val))
708
+ walkExpr(val);
709
+ }
710
+ else if (Array.isArray(val)) {
711
+ for (const el of val) {
712
+ if (el && typeof el === 'object' && typeof el.type === 'string' && typeof el.start === 'number') {
713
+ if (contains(el))
714
+ walkExpr(el);
715
+ }
716
+ }
717
+ }
718
+ }
719
+ break;
720
+ }
721
+ }
722
+ function walkClassBody(body) {
723
+ if (!body || !body.body)
724
+ return;
725
+ for (const node of body.body) {
726
+ if ((node.type === 'MethodDefinition' || node.type === 'PropertyDefinition') && node.value && contains(node.value)) {
727
+ walkExpr(node.value);
728
+ }
729
+ }
730
+ }
731
+ // Walk top-level statements
732
+ walkBlock(ast.body);
733
+ return names;
734
+ }
735
+ // ---------------------------------------------------------------------------
736
+ // Helpers
737
+ // ---------------------------------------------------------------------------
738
+ /**
739
+ * Find the offset of a declaration name inside an HM annotation comment.
740
+ * E.g. for "// add :: Number -> Number" and name "add", returns the index
741
+ * of "add" within the comment text.
742
+ */
743
+ function findAnnotationNameOffset(commentText, name) {
744
+ // Pattern: optional leading `//` or `/*`, optional `*`, whitespace, then `name ::`
745
+ const pattern = new RegExp(`(?:^|[\\s*/])${escapeRegExp(name)}\\s+::`);
746
+ const m = pattern.exec(commentText);
747
+ if (!m)
748
+ return -1;
749
+ // The match might start with a delimiter character; find exact name start
750
+ const matchStart = m.index;
751
+ const nameIdx = commentText.indexOf(name, matchStart);
752
+ return nameIdx;
753
+ }
754
+ function escapeRegExp(s) {
755
+ return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
756
+ }
757
+ //# sourceMappingURL=references.js.map