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,288 @@
1
+ "use strict";
2
+ // ============================================================================
3
+ // Parsing façade — the single place where a JavaScript parser is invoked
4
+ //
5
+ // WHAT THIS FILE DOES (in plain language): before the type checker can say
6
+ // anything about a piece of JavaScript, the text has to be turned into a
7
+ // tree structure (an AST). This module is the only door through which that
8
+ // happens. The concrete parser library lives behind a small `ParserBackend`
9
+ // interface with four operations:
10
+ //
11
+ // - `parseStrict` — normal parsing; throws on a syntax error.
12
+ // - `parseLoose` — forgiving parsing that produces a best-effort tree
13
+ // for half-typed / broken sources. Essential for an
14
+ // editor: files are broken most of the time while the
15
+ // user is typing.
16
+ // - `parseExpression` — parse a single standalone expression (used for
17
+ // synthesized snippets like `new Function(...)` bodies).
18
+ // - `describeParseError` — translates the parser's own error object into
19
+ // a plain { message, start, end } record, stripping
20
+ // parser-specific decorations.
21
+ //
22
+ // TWO BACKENDS exist today:
23
+ // - acorn (+ acorn-loose) — the default fast path for plain JavaScript.
24
+ // - @babel/parser — shipped with the extension since JSX support:
25
+ // its `jsx` plugin is always on, so the façade
26
+ // routes JSX sources to it (see below). It can
27
+ // also be selected for EVERYTHING with the
28
+ // environment variable HINMIL_PARSER=babel
29
+ // (see `parsing-babel.ts`).
30
+ //
31
+ // JSX DISPATCH: acorn has no JSX support (and acorn-loose cannot take
32
+ // plugins), so the façade decides per call:
33
+ // - `parseStrict`: try acorn first (hot path unchanged); when it throws,
34
+ // retry with the Babel backend — if that succeeds the source was JSX.
35
+ // - `parseLoose`: acorn-loose never throws, it would silently mangle JSX —
36
+ // so a cheap sniff (`</` or `/>` — every JSX element must close one of
37
+ // those two ways) routes likely-JSX sources to Babel's loose parser.
38
+ // False positives (e.g. `"</div>"` in a string) are harmless: Babel is
39
+ // a fully correct JS parser too, just marginally slower.
40
+ // - `parseExpression`: stays acorn — synthesized snippets never hold JSX.
41
+ //
42
+ // No other src module may import a parser library for PARSING. (Importing
43
+ // the AST *types* is done via `estree.ts`; typed traversal via `walking.ts`.)
44
+ // Adding/replacing a parser therefore means writing one backend object that
45
+ // honours the contract documented in `estree.ts` and enforced by
46
+ // tests/parserContract.test.ts.
47
+ // ============================================================================
48
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
49
+ if (k2 === undefined) k2 = k;
50
+ var desc = Object.getOwnPropertyDescriptor(m, k);
51
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
52
+ desc = { enumerable: true, get: function() { return m[k]; } };
53
+ }
54
+ Object.defineProperty(o, k2, desc);
55
+ }) : (function(o, m, k, k2) {
56
+ if (k2 === undefined) k2 = k;
57
+ o[k2] = m[k];
58
+ }));
59
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
60
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
61
+ }) : function(o, v) {
62
+ o["default"] = v;
63
+ });
64
+ var __importStar = (this && this.__importStar) || (function () {
65
+ var ownKeys = function(o) {
66
+ ownKeys = Object.getOwnPropertyNames || function (o) {
67
+ var ar = [];
68
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
69
+ return ar;
70
+ };
71
+ return ownKeys(o);
72
+ };
73
+ return function (mod) {
74
+ if (mod && mod.__esModule) return mod;
75
+ var result = {};
76
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
77
+ __setModuleDefault(result, mod);
78
+ return result;
79
+ };
80
+ })();
81
+ Object.defineProperty(exports, "__esModule", { value: true });
82
+ exports.getParserBackend = getParserBackend;
83
+ exports.setParserBackend = setParserBackend;
84
+ exports.builtinBackends = builtinBackends;
85
+ exports.looksLikeJsx = looksLikeJsx;
86
+ exports.parseStrict = parseStrict;
87
+ exports.parseLoose = parseLoose;
88
+ exports.parseExpression = parseExpression;
89
+ exports.describeParseError = describeParseError;
90
+ const acorn = __importStar(require("acorn"));
91
+ const acornLoose = __importStar(require("acorn-loose"));
92
+ // ---------------------------------------------------------------------------
93
+ // The acorn backend (production default)
94
+ // ---------------------------------------------------------------------------
95
+ /** Shared acorn parse options for ES-module source code. */
96
+ const ACORN_OPTS = {
97
+ ecmaVersion: 'latest',
98
+ sourceType: 'module',
99
+ locations: true,
100
+ };
101
+ const acornBackend = {
102
+ name: 'acorn',
103
+ parseStrict(source, onComment) {
104
+ return acorn.parse(source, onComment ? { ...ACORN_OPTS, onComment: onComment } : ACORN_OPTS);
105
+ },
106
+ parseLoose(source, onComment) {
107
+ return acornLoose.parse(source, onComment ? { ...ACORN_OPTS, onComment: onComment } : ACORN_OPTS);
108
+ },
109
+ parseExpression(source) {
110
+ return acorn.parseExpressionAt(source, 0, { ecmaVersion: 'latest' });
111
+ },
112
+ // Acorn attaches `pos` / `raisedAt` offsets and a trailing "(line:col)"
113
+ // suffix on the message. Babel errors (possible here via the JSX retry in
114
+ // the façade's parseStrict) carry `pos` / `loc.index` and the same message
115
+ // suffix, so the fallbacks below handle both shapes.
116
+ describeParseError(e, source) {
117
+ const msg = e instanceof Error ? e.message : String(e);
118
+ const errAny = e;
119
+ let start = typeof errAny.pos === 'number' ? errAny.pos
120
+ : typeof errAny.loc?.index === 'number' ? errAny.loc.index : 0;
121
+ let end = typeof errAny.raisedAt === 'number' ? errAny.raisedAt : start;
122
+ if (end <= start)
123
+ end = Math.min(start + 1, source.length);
124
+ if (start === 0 && end === 0)
125
+ end = source.length;
126
+ // Strip trailing "(line:col)" — the LSP conveys the location through the
127
+ // diagnostic range instead.
128
+ const message = msg.replace(/\s*\(\d+:\d+\)\s*$/, '');
129
+ return { message, start, end };
130
+ },
131
+ };
132
+ // ---------------------------------------------------------------------------
133
+ // Backend selection
134
+ // ---------------------------------------------------------------------------
135
+ /**
136
+ * Pick the initial backend. Setting HINMIL_PARSER=babel selects the Babel
137
+ * backend for ALL parsing (used by the parser contract tests to verify
138
+ * parser independence). The require is lazy so the acorn hot path never
139
+ * pays for it.
140
+ */
141
+ function selectInitialBackend() {
142
+ if (process.env.HINMIL_PARSER === 'babel') {
143
+ try {
144
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
145
+ const { babelBackend } = require('./parsing-babel');
146
+ return babelBackend;
147
+ }
148
+ catch (e) {
149
+ throw new Error('HINMIL_PARSER=babel requires the @babel/parser devDependency (npm install). ' +
150
+ `Underlying error: ${e instanceof Error ? e.message : String(e)}`);
151
+ }
152
+ }
153
+ return acornBackend;
154
+ }
155
+ let activeBackend = selectInitialBackend();
156
+ /** The currently active parser backend (mainly for test output). */
157
+ function getParserBackend() {
158
+ return activeBackend;
159
+ }
160
+ /** Test hook: swap the active parser backend. Returns the previous one. */
161
+ function setParserBackend(backend) {
162
+ const prev = activeBackend;
163
+ activeBackend = backend;
164
+ return prev;
165
+ }
166
+ /** The built-in backends, exported for the parser contract test. */
167
+ function builtinBackends() {
168
+ const backends = [acornBackend];
169
+ try {
170
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
171
+ const { babelBackend } = require('./parsing-babel');
172
+ backends.push(babelBackend);
173
+ }
174
+ catch {
175
+ // @babel/parser not installed (production) — acorn only.
176
+ }
177
+ return backends;
178
+ }
179
+ // ---------------------------------------------------------------------------
180
+ // JSX routing helpers
181
+ // ---------------------------------------------------------------------------
182
+ let cachedJsxBackend;
183
+ /**
184
+ * The Babel backend doubles as the JSX parser (its `jsx` plugin is always
185
+ * enabled). Loaded lazily and cached; returns null when @babel/parser is
186
+ * unavailable (JSX support then degrades to acorn's behaviour).
187
+ */
188
+ function jsxBackend() {
189
+ if (cachedJsxBackend === undefined) {
190
+ try {
191
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
192
+ const { babelBackend } = require('./parsing-babel');
193
+ cachedJsxBackend = babelBackend;
194
+ }
195
+ catch {
196
+ cachedJsxBackend = null;
197
+ }
198
+ }
199
+ return cachedJsxBackend;
200
+ }
201
+ /**
202
+ * Cheap textual sniff for JSX: every JSX element ends with either a
203
+ * self-closing `/>` or a closing tag starting with `</` (fragments close
204
+ * with `</>`), so one of the two substrings is guaranteed to appear in any
205
+ * source that uses JSX. False positives only cost a Babel (still correct)
206
+ * parse.
207
+ */
208
+ function looksLikeJsx(source) {
209
+ return source.includes('</') || source.includes('/>');
210
+ }
211
+ // ---------------------------------------------------------------------------
212
+ // Public parsing API (delegates to the active backend)
213
+ // ---------------------------------------------------------------------------
214
+ /**
215
+ * Parse `source` strictly; throws on the first syntax error.
216
+ * Pass an array as `onComment` to collect every comment encountered
217
+ * (HM annotations live in comments, so most callers want them).
218
+ *
219
+ * When the default acorn backend rejects the source, a JSX retry with the
220
+ * Babel backend happens transparently (each attempt gets a fresh comment
221
+ * array so a failed attempt cannot leave partial comments behind).
222
+ */
223
+ function parseStrict(source, onComment) {
224
+ if (activeBackend !== acornBackend)
225
+ return activeBackend.parseStrict(source, onComment);
226
+ const acornComments = onComment ? [] : undefined;
227
+ try {
228
+ const ast = acornBackend.parseStrict(source, acornComments);
229
+ if (onComment && acornComments)
230
+ onComment.push(...acornComments);
231
+ return ast;
232
+ }
233
+ catch (acornError) {
234
+ const jsx = jsxBackend();
235
+ if (jsx) {
236
+ const jsxComments = onComment ? [] : undefined;
237
+ try {
238
+ const ast = jsx.parseStrict(source, jsxComments);
239
+ if (onComment && jsxComments)
240
+ onComment.push(...jsxComments);
241
+ return ast;
242
+ }
243
+ catch (babelError) {
244
+ // A JSX-looking source with a real syntax error: Babel's error points
245
+ // at the actual problem, acorn's at the first (valid) JSX token.
246
+ if (looksLikeJsx(source))
247
+ throw babelError;
248
+ }
249
+ }
250
+ throw acornError;
251
+ }
252
+ }
253
+ /**
254
+ * Parse `source` with the error-tolerant parser: syntax errors are patched
255
+ * over so a best-effort tree is still produced for the valid portions.
256
+ * Used as the fallback when `parseStrict` throws, so hover / completion /
257
+ * diagnostics keep working while the user is mid-edit.
258
+ *
259
+ * Likely-JSX sources are routed to the Babel loose parser (acorn-loose
260
+ * would silently mangle JSX instead of failing).
261
+ */
262
+ function parseLoose(source, onComment) {
263
+ if (activeBackend !== acornBackend)
264
+ return activeBackend.parseLoose(source, onComment);
265
+ if (looksLikeJsx(source)) {
266
+ const jsx = jsxBackend();
267
+ if (jsx)
268
+ return jsx.parseLoose(source, onComment);
269
+ }
270
+ return acornBackend.parseLoose(source, onComment);
271
+ }
272
+ /**
273
+ * Parse a single standalone EXPRESSION (not a whole module) and return its
274
+ * node. Used for synthesized snippets, e.g. inferring the body passed to
275
+ * `new Function('a', 'b', 'return a + b')`. Throws on a syntax error.
276
+ */
277
+ function parseExpression(source) {
278
+ return activeBackend.parseExpression(source);
279
+ }
280
+ /**
281
+ * Convert the exception thrown by {@link parseStrict} into a normalized
282
+ * `{ message, start, end }` record. The backend is the ONE place that knows
283
+ * the shape of its parser's error objects.
284
+ */
285
+ function describeParseError(e, source) {
286
+ return activeBackend.describeParseError(e, source);
287
+ }
288
+ //# sourceMappingURL=parsing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parsing.js","sourceRoot":"","sources":["../src/parsing.ts"],"names":[],"mappings":";AAAA,+EAA+E;AAC/E,yEAAyE;AACzE,EAAE;AACF,2EAA2E;AAC3E,yEAAyE;AACzE,4EAA4E;AAC5E,6EAA6E;AAC7E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irement {
4
+ /** Method name, e.g. "map" */
5
+ name: string;
6
+ /** Raw signature text, e.g. "f a ~> (a -> b) -> f b" */
7
+ signature: string;
8
+ /** Type variable of the constraint that DECLARES the method (set by
9
+ * `getEffectiveMethods`). An inherited method keeps its owner's variable:
10
+ * `map` reached through `Monad m` is still written `f a ~> …` (Functor f). */
11
+ ownerTypeVar?: string;
12
+ }
13
+ /** Expected kind of the type parameter in a constraint definition. */
14
+ export type ConstraintKind = '*' | '* -> *';
15
+ export interface ConstraintDef {
16
+ /** Constraint name, e.g. "Functor" */
17
+ name: string;
18
+ /** Type variable name used in the definition, e.g. "f" */
19
+ typeVar: string;
20
+ /** Required methods */
21
+ methods: MethodRequirement[];
22
+ /** Parent constraint names (inheritance), e.g. ["Functor", "Chain"] */
23
+ extends?: string[];
24
+ /** Expected kind of the type parameter, inferred from method signatures.
25
+ * `'* -> *'` when the type var is applied (e.g. `f a`), `'*'` when bare.
26
+ * Computed automatically from method signatures if not provided. */
27
+ expectedKind?: ConstraintKind;
28
+ /** Structural constraint header parameters, in declaration order.
29
+ * Set when the def was written as `::constraint Name p1 p2 … pN = …`.
30
+ * Mutually exclusive with `methods`/nominal form. */
31
+ headerParams?: string[];
32
+ /** Structural constraint self-clauses (one or more `<self> is <body>`).
33
+ * Each `selfParam` MUST be one of `headerParams`. The body's free
34
+ * variables that are not in `headerParams` are existential: every
35
+ * use-site instantiation gets fresh ids. The body uses parser-allocated
36
+ * TVar ids; resolution maps them per instantiation. */
37
+ selfClauses?: {
38
+ selfParam: string;
39
+ body: Type;
40
+ }[];
41
+ /** Source location of the originating `// ::constraint` directive.
42
+ * Populated by the registration call-site (per-file or sidecar) so
43
+ * hover / go-to-definition can navigate users back to the definition.
44
+ * All three fields are set together; `uri` may be `undefined` for
45
+ * in-memory directives without a backing file. */
46
+ uri?: string;
47
+ commentStart?: number;
48
+ commentEnd?: number;
49
+ /** Pretty body text between the outermost `{ … }` of the directive,
50
+ * trimmed. Used by hover to show the constraint's body inline. */
51
+ bodyText?: string;
52
+ }
53
+ /** Parsed constraint reference from a type signature, e.g. `Functor f` */
54
+ export interface Constraint {
55
+ /** Constraint name, e.g. "Functor" */
56
+ className: string;
57
+ /** Type variable name it applies to, e.g. "f" */
58
+ typeVarName: string;
59
+ }
60
+ /** Encapsulates constraint registry state and operations. */
61
+ export declare class ConstraintRegistry {
62
+ private registry;
63
+ /** Register a constraint definition. Computes expectedKind if not provided. */
64
+ register(def: ConstraintDef): void;
65
+ /** Look up a constraint definition by name. */
66
+ lookup(name: string): ConstraintDef | null;
67
+ /**
68
+ * Extends-only constraints (e.g. `::constraint Alternative f
69
+ * { f :: Applicative, f :: Plus }`) have no method signatures of their own,
70
+ * so parse-time kind inference defaults them to `*`. Their true kind is the
71
+ * kind of their parents. Resolved lazily (parents may be registered after
72
+ * the child) and memoized by upgrading `def.expectedKind` in place.
73
+ */
74
+ private resolveInheritedKind;
75
+ /** Get all registered constraint names. */
76
+ getNames(): string[];
77
+ /** Clear all constraint definitions. */
78
+ clear(): void;
79
+ /** Save a snapshot of all constraint registrations. */
80
+ snapshot(): ConstraintRegistrySnapshot;
81
+ /** Restore constraint registrations from a snapshot. */
82
+ restore(snap: ConstraintRegistrySnapshot): void;
83
+ /** Merge a snapshot's registrations (non-destructive). */
84
+ merge(snap: ConstraintRegistrySnapshot): void;
85
+ /**
86
+ * Collect all effective methods for a constraint, including inherited ones.
87
+ * Child methods override parent methods of the same name.
88
+ * Uses a visited set to prevent infinite loops in case of cycles.
89
+ */
90
+ getEffectiveMethods(constraintName: string): MethodRequirement[];
91
+ /**
92
+ * Collect the superclass closure of a constraint: the constraint itself
93
+ * plus every ancestor reachable through `extends` (transitively). Used to
94
+ * decide whether a DECLARED (given) constraint entails a REQUIRED (wanted)
95
+ * one — e.g. a signature declaring `Applicative f` also provides `Apply f`
96
+ * and `Functor f`.
97
+ */
98
+ superclassClosure(constraintName: string): Set<string>;
99
+ /**
100
+ * Check whether a concrete type satisfies a constraint.
101
+ * A type satisfies a constraint if it has all required methods registered
102
+ * in the method registry. Includes inherited methods.
103
+ */
104
+ checkConstraint(constraintName: string, typeName: string): {
105
+ satisfied: boolean;
106
+ missing: string[];
107
+ };
108
+ }
109
+ /**
110
+ * Register a constraint definition.
111
+ */
112
+ export declare function registerConstraint(def: ConstraintDef): void;
113
+ /**
114
+ * Look up a constraint definition by name.
115
+ */
116
+ export declare function lookupConstraint(name: string): ConstraintDef | null;
117
+ /**
118
+ * Get all registered constraint names.
119
+ */
120
+ export declare function getConstraintNames(): string[];
121
+ /**
122
+ * Get all effective methods for a constraint, including inherited ones.
123
+ */
124
+ export declare function getEffectiveMethods(constraintName: string): MethodRequirement[];
125
+ /**
126
+ * Get the superclass closure of a constraint (itself + all `extends`
127
+ * ancestors, transitively).
128
+ */
129
+ export declare function constraintSuperclassClosure(constraintName: string): Set<string>;
130
+ /**
131
+ * Clear all constraint definitions.
132
+ * Called at the start of each inference run.
133
+ */
134
+ export declare function clearConstraints(): void;
135
+ /** Snapshot type for saving/restoring constraint state. */
136
+ export type ConstraintRegistrySnapshot = Map<string, ConstraintDef>;
137
+ /** Save a snapshot of all constraint registrations. */
138
+ export declare function snapshotConstraintRegistry(): ConstraintRegistrySnapshot;
139
+ /** Restore constraint registrations from a snapshot. */
140
+ export declare function restoreConstraintRegistry(snap: ConstraintRegistrySnapshot): void;
141
+ /** Merge a snapshot's registrations into the current registry (non-destructive). */
142
+ export declare function mergeConstraintRegistry(snap: ConstraintRegistrySnapshot): void;
143
+ /**
144
+ * Check whether a concrete type (by name) satisfies a constraint.
145
+ */
146
+ export declare function checkConstraint(constraintName: string, typeName: string): {
147
+ satisfied: boolean;
148
+ missing: string[];
149
+ };
150
+ /**
151
+ * Parse a `// ::constraint` comment body into a ConstraintDef using the
152
+ * unified syntax. Returns null if the comment doesn't match.
153
+ */
154
+ export declare function parseConstraintDirective(commentText: string): ConstraintDef | null;
155
+ /**
156
+ * Infer the expected kind of a constraint's type variable from its method
157
+ * signatures and structural body types. `* -> *` if applied anywhere
158
+ * (e.g. `f a`); `*` otherwise.
159
+ */
160
+ export declare function inferExpectedKind(typeVar: string, methods: MethodRequirement[]): ConstraintKind;
161
+ /**
162
+ * Validate a constraint definition for kind consistency and completeness.
163
+ * Returns an array of human-readable warning/error messages (empty if valid).
164
+ */
165
+ export declare function validateConstraintDef(def: ConstraintDef): string[];
166
+ /**
167
+ * Check that a registered method's signature shape matches the constraint's
168
+ * required shape. Wherever the constraint's type variable (`f`, `m`, etc.)
169
+ * appears in the constraint signature, the registered method must use the
170
+ * concrete type constructor.
171
+ *
172
+ * Returns a human-readable mismatch description, or null if the shape is OK.
173
+ */
174
+ export declare function checkConstraintMethodShape(constraintTypeVar: string, constraintMethodSig: string, concreteName: string, registeredEntry: MethodEntry): string | null;
175
+ /**
176
+ * Shape-check a *static* constraint method (one whose constraint signature
177
+ * carries no `~>` receiver, e.g. Foldable's `off :: a -> f a`) against a
178
+ * representing local annotation (also receiver-less, e.g. `off :: a -> Array a`).
179
+ *
180
+ * Both sides are plain types. We parse the constraint requirement with the
181
+ * constraint variable known so applied positions like `f a` become kind-var
182
+ * constructors, parse the local signature normally, then run the same
183
+ * structural / linkage check used for instance methods. Returns a
184
+ * human-readable mismatch description, or null if the shape is OK.
185
+ */
186
+ export declare function checkStaticConstraintMethodShape(constraintTypeVar: string, constraintMethodSig: string, concreteName: string, registeredSig: string): string | null;
187
+ /**
188
+ * Optional context threaded through {@link matchesConstraintShape} to enforce
189
+ * *type-variable linkage*. Each distinct constraint-signature type variable
190
+ * (the inner `a`, `b`, … — not the constraint's own kind-variable) is recorded
191
+ * the first time it is matched against a registered sub-type; on every later
192
+ * occurrence the registered side must agree (structurally) with that first
193
+ * binding. This turns the previously unconditional wildcard match for type
194
+ * variables into a consistent one, so e.g. a `Functor` method required as
195
+ * `f a ~> (a -> b) -> f b` is no longer satisfied by a registered
196
+ * `Array a ~> (a -> b) -> Array a` (which conflates `b` with `a` in its
197
+ * return position).
198
+ */
199
+ export interface ConstraintShapeContext {
200
+ /** constraint TVar id → the registered sub-type it first matched. */
201
+ varMap: Map<number, Type>;
202
+ /**
203
+ * When set, forces the constraint's kind-variable application (`f a`) to
204
+ * align with the registered constructor's argument starting at THIS slot
205
+ * index (0 = leftmost) instead of the default rightmost alignment. This lets
206
+ * a constraint that operates on a non-rightmost type parameter — e.g.
207
+ * Contravariant's `contramap` on `Arrow a b` transforms the LEFT parameter,
208
+ * whereas Functor's `map` transforms the rightmost — be matched. A given
209
+ * offset that cannot be honoured at some occurrence fails the whole attempt,
210
+ * so the caller can enumerate offsets and rely on the type-variable linkage
211
+ * check to accept at most the single consistent alignment.
212
+ */
213
+ slotOffset?: number;
214
+ /**
215
+ * Inner constructor-variable linkage: constraint-side kv var id (e.g. the
216
+ * `f` of a method-local `Applicative f =>` prefix) → the registered-side
217
+ * kv head name it first matched. Both signatures parse their OWN prefix
218
+ * vars to kv-TCons with unrelated ids, so they can never be equal by name;
219
+ * they are instead paired by consistent co-occurrence (every `f …` on the
220
+ * constraint side must meet the SAME registered constructor var).
221
+ */
222
+ kvHeadMap?: Map<number, string>;
223
+ }
224
+ /**
225
+ * Recursively check that wherever the constraint's type variable appears as a
226
+ * type constructor in `constraintType`, the corresponding position in
227
+ * `registeredType` uses `concreteName`.
228
+ *
229
+ * When a {@link ConstraintShapeContext} is supplied, inner type variables are
230
+ * additionally checked for *linkage* consistency (see the interface docs).
231
+ */
232
+ export declare function matchesConstraintShape(constraintType: Type, registeredType: Type, constraintVar: string, concreteName: string, ctx?: ConstraintShapeContext, inFunctionParam?: boolean): boolean;
233
+ //# sourceMappingURL=constraintRegistry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constraintRegistry.d.ts","sourceRoot":"","sources":["../../src/registries/constraintRegistry.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAgB,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAqG,MAAM,aAAa,CAAC;AAOtI,MAAM,WAAW,i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