@scriptc/compiler 0.2.3 → 0.2.5

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 (1124) hide show
  1. package/ambient/scriptc-node-fallback.d.ts +915 -215
  2. package/ambient/scriptc-overrides.d.ts +5 -1
  3. package/ambient/scriptc.d.ts +22 -2
  4. package/dist/backend/build-cache.d.ts +4 -0
  5. package/dist/backend/build-cache.js +16 -2
  6. package/dist/backend/build-cache.js.map +1 -1
  7. package/dist/backend/cycle-analysis.js +17 -5
  8. package/dist/backend/cycle-analysis.js.map +1 -1
  9. package/dist/backend/cycle-analysis.test.js +50 -11
  10. package/dist/backend/cycle-analysis.test.js.map +1 -1
  11. package/dist/backend/debug-symbols.js.map +1 -1
  12. package/dist/backend/executable-features.js +2 -1
  13. package/dist/backend/executable-features.js.map +1 -1
  14. package/dist/backend/external-c.d.ts +13 -6
  15. package/dist/backend/external-c.js +15 -3
  16. package/dist/backend/external-c.js.map +1 -1
  17. package/dist/backend/ffi-callbacks.js +6 -9
  18. package/dist/backend/ffi-callbacks.js.map +1 -1
  19. package/dist/backend/library-identity-markers.js.map +1 -1
  20. package/dist/backend/library-pack.d.ts +1 -1
  21. package/dist/backend/library-pack.js +81 -24
  22. package/dist/backend/library-pack.js.map +1 -1
  23. package/dist/backend/link-plan-core.js +9 -2
  24. package/dist/backend/link-plan-core.js.map +1 -1
  25. package/dist/backend/link-plan.d.ts +1 -1
  26. package/dist/backend/link-plan.js +4 -5
  27. package/dist/backend/link-plan.js.map +1 -1
  28. package/dist/backend/linker.d.ts +1 -1
  29. package/dist/backend/linker.js +42 -23
  30. package/dist/backend/linker.js.map +1 -1
  31. package/dist/backend/literals.js +5 -4
  32. package/dist/backend/literals.js.map +1 -1
  33. package/dist/backend/literals.test.js +30 -5
  34. package/dist/backend/literals.test.js.map +1 -1
  35. package/dist/backend/llvm/blocks.test.js +5 -2
  36. package/dist/backend/llvm/blocks.test.js.map +1 -1
  37. package/dist/backend/llvm/borrowed-inputs.d.ts +15 -0
  38. package/dist/backend/llvm/borrowed-inputs.js +28 -0
  39. package/dist/backend/llvm/borrowed-inputs.js.map +1 -0
  40. package/dist/backend/llvm/borrowed-receivers.js +43 -19
  41. package/dist/backend/llvm/borrowed-receivers.js.map +1 -1
  42. package/dist/backend/llvm/byte-numbers.d.ts +10 -0
  43. package/dist/backend/llvm/byte-numbers.js +240 -0
  44. package/dist/backend/llvm/byte-numbers.js.map +1 -0
  45. package/dist/backend/llvm/bytes-bounds.d.ts +9 -0
  46. package/dist/backend/llvm/bytes-bounds.js +240 -0
  47. package/dist/backend/llvm/bytes-bounds.js.map +1 -0
  48. package/dist/backend/llvm/call-lifetimes.d.ts +10 -0
  49. package/dist/backend/llvm/call-lifetimes.js +83 -20
  50. package/dist/backend/llvm/call-lifetimes.js.map +1 -1
  51. package/dist/backend/llvm/call-lifetimes.test.js +203 -18
  52. package/dist/backend/llvm/call-lifetimes.test.js.map +1 -1
  53. package/dist/backend/llvm/checked-value-lifetimes.d.ts +13 -0
  54. package/dist/backend/llvm/checked-value-lifetimes.js +45 -0
  55. package/dist/backend/llvm/checked-value-lifetimes.js.map +1 -0
  56. package/dist/backend/llvm/classes.js +16 -12
  57. package/dist/backend/llvm/classes.js.map +1 -1
  58. package/dist/backend/llvm/common.js +4 -1
  59. package/dist/backend/llvm/common.js.map +1 -1
  60. package/dist/backend/llvm/counted-loops.d.ts +6 -0
  61. package/dist/backend/llvm/counted-loops.js +35 -0
  62. package/dist/backend/llvm/counted-loops.js.map +1 -0
  63. package/dist/backend/llvm/debug-info.js +33 -13
  64. package/dist/backend/llvm/debug-info.js.map +1 -1
  65. package/dist/backend/llvm/debug-info.test.js +28 -6
  66. package/dist/backend/llvm/debug-info.test.js.map +1 -1
  67. package/dist/backend/llvm/dyn.js +68 -22
  68. package/dist/backend/llvm/dyn.js.map +1 -1
  69. package/dist/backend/llvm/emitter.d.ts +34 -12
  70. package/dist/backend/llvm/emitter.js +357 -124
  71. package/dist/backend/llvm/emitter.js.map +1 -1
  72. package/dist/backend/llvm/emitter.test.js +237 -46
  73. package/dist/backend/llvm/emitter.test.js.map +1 -1
  74. package/dist/backend/llvm/expr-async.js +28 -8
  75. package/dist/backend/llvm/expr-async.js.map +1 -1
  76. package/dist/backend/llvm/expr-bytes.d.ts +4 -4
  77. package/dist/backend/llvm/expr-bytes.js +78 -36
  78. package/dist/backend/llvm/expr-bytes.js.map +1 -1
  79. package/dist/backend/llvm/expr-callbacks.js +10 -4
  80. package/dist/backend/llvm/expr-callbacks.js.map +1 -1
  81. package/dist/backend/llvm/expr-calls.js +40 -21
  82. package/dist/backend/llvm/expr-calls.js.map +1 -1
  83. package/dist/backend/llvm/expr-containers.d.ts +4 -1
  84. package/dist/backend/llvm/expr-containers.js +157 -76
  85. package/dist/backend/llvm/expr-containers.js.map +1 -1
  86. package/dist/backend/llvm/expr-context.d.ts +11 -0
  87. package/dist/backend/llvm/expr-control.js +27 -8
  88. package/dist/backend/llvm/expr-control.js.map +1 -1
  89. package/dist/backend/llvm/expr-dispatch.js +3 -1
  90. package/dist/backend/llvm/expr-dispatch.js.map +1 -1
  91. package/dist/backend/llvm/expr-dynamic.js +50 -33
  92. package/dist/backend/llvm/expr-dynamic.js.map +1 -1
  93. package/dist/backend/llvm/expr-island.js +26 -6
  94. package/dist/backend/llvm/expr-island.js.map +1 -1
  95. package/dist/backend/llvm/expr-primitives.js +139 -37
  96. package/dist/backend/llvm/expr-primitives.js.map +1 -1
  97. package/dist/backend/llvm/expr-primitives.test.js +43 -1
  98. package/dist/backend/llvm/expr-primitives.test.js.map +1 -1
  99. package/dist/backend/llvm/expr-records.js +16 -9
  100. package/dist/backend/llvm/expr-records.js.map +1 -1
  101. package/dist/backend/llvm/expr-stream-bridges.js +44 -26
  102. package/dist/backend/llvm/expr-stream-bridges.js.map +1 -1
  103. package/dist/backend/llvm/expr-stream-bridges.test.js +51 -14
  104. package/dist/backend/llvm/expr-stream-bridges.test.js.map +1 -1
  105. package/dist/backend/llvm/expr-stream-callbacks.js +34 -14
  106. package/dist/backend/llvm/expr-stream-callbacks.js.map +1 -1
  107. package/dist/backend/llvm/integer-values.d.ts +10 -0
  108. package/dist/backend/llvm/integer-values.js +52 -0
  109. package/dist/backend/llvm/integer-values.js.map +1 -0
  110. package/dist/backend/llvm/integer-views.d.ts +7 -0
  111. package/dist/backend/llvm/integer-views.js +83 -0
  112. package/dist/backend/llvm/integer-views.js.map +1 -0
  113. package/dist/backend/llvm/integer-views.test.d.ts +1 -0
  114. package/dist/backend/llvm/integer-views.test.js +69 -0
  115. package/dist/backend/llvm/integer-views.test.js.map +1 -0
  116. package/dist/backend/llvm/lib-abi.js +13 -4
  117. package/dist/backend/llvm/lib-abi.js.map +1 -1
  118. package/dist/backend/llvm/lib-connect.js +7 -1
  119. package/dist/backend/llvm/lib-connect.js.map +1 -1
  120. package/dist/backend/llvm/lib-datagram.js +35 -10
  121. package/dist/backend/llvm/lib-datagram.js.map +1 -1
  122. package/dist/backend/llvm/lib-dispatch.js +36 -15
  123. package/dist/backend/llvm/lib-dispatch.js.map +1 -1
  124. package/dist/backend/llvm/lib-filesystem.js +38 -23
  125. package/dist/backend/llvm/lib-filesystem.js.map +1 -1
  126. package/dist/backend/llvm/lib-http2.js +60 -15
  127. package/dist/backend/llvm/lib-http2.js.map +1 -1
  128. package/dist/backend/llvm/lib-lookup.js +12 -5
  129. package/dist/backend/llvm/lib-lookup.js.map +1 -1
  130. package/dist/backend/llvm/lib-network.js +97 -31
  131. package/dist/backend/llvm/lib-network.js.map +1 -1
  132. package/dist/backend/llvm/lib-process.js +57 -14
  133. package/dist/backend/llvm/lib-process.js.map +1 -1
  134. package/dist/backend/llvm/lib-shared.js +107 -31
  135. package/dist/backend/llvm/lib-shared.js.map +1 -1
  136. package/dist/backend/llvm/lib-stream.js +33 -14
  137. package/dist/backend/llvm/lib-stream.js.map +1 -1
  138. package/dist/backend/llvm/lib-test.js +21 -7
  139. package/dist/backend/llvm/lib-test.js.map +1 -1
  140. package/dist/backend/llvm/lib-tls.js +69 -20
  141. package/dist/backend/llvm/lib-tls.js.map +1 -1
  142. package/dist/backend/llvm/local-array-reads.d.ts +3 -4
  143. package/dist/backend/llvm/local-array-reads.js +100 -121
  144. package/dist/backend/llvm/local-array-reads.js.map +1 -1
  145. package/dist/backend/llvm/local-array-reads.test.js +379 -71
  146. package/dist/backend/llvm/local-array-reads.test.js.map +1 -1
  147. package/dist/backend/llvm/local-union-storage.d.ts +25 -0
  148. package/dist/backend/llvm/local-union-storage.js +109 -0
  149. package/dist/backend/llvm/local-union-storage.js.map +1 -0
  150. package/dist/backend/llvm/local-union-storage.test.d.ts +1 -0
  151. package/dist/backend/llvm/local-union-storage.test.js +210 -0
  152. package/dist/backend/llvm/local-union-storage.test.js.map +1 -0
  153. package/dist/backend/llvm/map-read-lifetimes.d.ts +6 -2
  154. package/dist/backend/llvm/map-read-lifetimes.js +46 -16
  155. package/dist/backend/llvm/map-read-lifetimes.js.map +1 -1
  156. package/dist/backend/llvm/map-read-lifetimes.test.js +93 -17
  157. package/dist/backend/llvm/map-read-lifetimes.test.js.map +1 -1
  158. package/dist/backend/llvm/reference-effects.d.ts +23 -0
  159. package/dist/backend/llvm/reference-effects.js +179 -0
  160. package/dist/backend/llvm/reference-effects.js.map +1 -0
  161. package/dist/backend/llvm/reference-effects.test.d.ts +1 -0
  162. package/dist/backend/llvm/reference-effects.test.js +157 -0
  163. package/dist/backend/llvm/reference-effects.test.js.map +1 -0
  164. package/dist/backend/llvm/shapes.d.ts +7 -4
  165. package/dist/backend/llvm/shapes.js +82 -22
  166. package/dist/backend/llvm/shapes.js.map +1 -1
  167. package/dist/backend/llvm/shapes.test.js +3 -1
  168. package/dist/backend/llvm/shapes.test.js.map +1 -1
  169. package/dist/backend/llvm/split.js +4 -4
  170. package/dist/backend/llvm/split.js.map +1 -1
  171. package/dist/backend/llvm/split.test.js +14 -6
  172. package/dist/backend/llvm/split.test.js.map +1 -1
  173. package/dist/backend/llvm/stack-unions.js +14 -5
  174. package/dist/backend/llvm/stack-unions.js.map +1 -1
  175. package/dist/backend/llvm/stack-unions.test.js +172 -32
  176. package/dist/backend/llvm/stack-unions.test.js.map +1 -1
  177. package/dist/backend/llvm/string-construction.d.ts +10 -0
  178. package/dist/backend/llvm/string-construction.js +38 -0
  179. package/dist/backend/llvm/string-construction.js.map +1 -0
  180. package/dist/backend/llvm/string-construction.test.d.ts +1 -0
  181. package/dist/backend/llvm/string-construction.test.js +90 -0
  182. package/dist/backend/llvm/string-construction.test.js.map +1 -0
  183. package/dist/backend/llvm/string-lifetimes.d.ts +2 -2
  184. package/dist/backend/llvm/string-lifetimes.js +19 -11
  185. package/dist/backend/llvm/string-lifetimes.js.map +1 -1
  186. package/dist/backend/llvm/string-lifetimes.test.js +127 -32
  187. package/dist/backend/llvm/string-lifetimes.test.js.map +1 -1
  188. package/dist/backend/llvm/switch-dispatch.d.ts +9 -0
  189. package/dist/backend/llvm/switch-dispatch.js +114 -0
  190. package/dist/backend/llvm/switch-dispatch.js.map +1 -0
  191. package/dist/backend/llvm/switch-dispatch.test.d.ts +1 -0
  192. package/dist/backend/llvm/switch-dispatch.test.js +83 -0
  193. package/dist/backend/llvm/switch-dispatch.test.js.map +1 -0
  194. package/dist/backend/llvm/unsupported.js.map +1 -1
  195. package/dist/backend/llvm/walkers.js +6 -3
  196. package/dist/backend/llvm/walkers.js.map +1 -1
  197. package/dist/backend/mangle.js +9 -3
  198. package/dist/backend/mangle.js.map +1 -1
  199. package/dist/backend/may-throw.js +18 -8
  200. package/dist/backend/may-throw.js.map +1 -1
  201. package/dist/backend/may-throw.test.js +118 -22
  202. package/dist/backend/may-throw.test.js.map +1 -1
  203. package/dist/backend/native/artifact-stamps.d.ts +39 -0
  204. package/dist/backend/native/artifact-stamps.js +371 -0
  205. package/dist/backend/native/artifact-stamps.js.map +1 -0
  206. package/dist/backend/native/cache-warm.d.ts +24 -0
  207. package/dist/backend/native/cache-warm.js +80 -0
  208. package/dist/backend/native/cache-warm.js.map +1 -0
  209. package/dist/backend/native/compiler-fingerprint.d.ts +19 -0
  210. package/dist/backend/native/compiler-fingerprint.js +357 -0
  211. package/dist/backend/native/compiler-fingerprint.js.map +1 -0
  212. package/dist/backend/native/contracts.d.ts +314 -0
  213. package/dist/backend/native/contracts.js +2 -0
  214. package/dist/backend/native/contracts.js.map +1 -0
  215. package/dist/backend/native/dependency-files.d.ts +5 -0
  216. package/dist/backend/native/dependency-files.js +83 -0
  217. package/dist/backend/native/dependency-files.js.map +1 -0
  218. package/dist/backend/native/driver.d.ts +50 -0
  219. package/dist/backend/native/driver.js +294 -0
  220. package/dist/backend/native/driver.js.map +1 -0
  221. package/dist/backend/native/executable.d.ts +18 -0
  222. package/dist/backend/native/executable.js +1267 -0
  223. package/dist/backend/native/executable.js.map +1 -0
  224. package/dist/backend/native/library.d.ts +2 -0
  225. package/dist/backend/native/library.js +614 -0
  226. package/dist/backend/native/library.js.map +1 -0
  227. package/dist/backend/native/linker-fingerprint.d.ts +8 -0
  228. package/dist/backend/native/linker-fingerprint.js +174 -0
  229. package/dist/backend/native/linker-fingerprint.js.map +1 -0
  230. package/dist/backend/native/object-merge.d.ts +2 -0
  231. package/dist/backend/native/object-merge.js +154 -0
  232. package/dist/backend/native/object-merge.js.map +1 -0
  233. package/dist/backend/native/process.d.ts +17 -0
  234. package/dist/backend/native/process.js +42 -0
  235. package/dist/backend/native/process.js.map +1 -0
  236. package/dist/backend/native/program-shards.d.ts +21 -0
  237. package/dist/backend/native/program-shards.js +99 -0
  238. package/dist/backend/native/program-shards.js.map +1 -0
  239. package/dist/backend/native/runtime-inputs.d.ts +12 -0
  240. package/dist/backend/native/runtime-inputs.js +163 -0
  241. package/dist/backend/native/runtime-inputs.js.map +1 -0
  242. package/dist/backend/native/runtime-inputs.test.d.ts +1 -0
  243. package/dist/backend/native/runtime-inputs.test.js +64 -0
  244. package/dist/backend/native/runtime-inputs.test.js.map +1 -0
  245. package/dist/backend/native/runtime-objects.d.ts +16 -0
  246. package/dist/backend/native/runtime-objects.js +122 -0
  247. package/dist/backend/native/runtime-objects.js.map +1 -0
  248. package/dist/backend/native/session.d.ts +12 -0
  249. package/dist/backend/native/session.js +31 -0
  250. package/dist/backend/native/session.js.map +1 -0
  251. package/dist/backend/native/tool-identity.d.ts +37 -0
  252. package/dist/backend/native/tool-identity.js +310 -0
  253. package/dist/backend/native/tool-identity.js.map +1 -0
  254. package/dist/backend/native/trace-paths.d.ts +12 -0
  255. package/dist/backend/native/trace-paths.js +73 -0
  256. package/dist/backend/native/trace-paths.js.map +1 -0
  257. package/dist/backend/native/vendor.d.ts +1 -0
  258. package/dist/backend/native/vendor.js +12 -0
  259. package/dist/backend/native/vendor.js.map +1 -0
  260. package/dist/backend/native-codegen-core.js +2 -1
  261. package/dist/backend/native-codegen-core.js.map +1 -1
  262. package/dist/backend/native-codegen.d.ts +1 -1
  263. package/dist/backend/native-codegen.js +24 -13
  264. package/dist/backend/native-codegen.js.map +1 -1
  265. package/dist/backend/native-codegen.test.js +12 -9
  266. package/dist/backend/native-codegen.test.js.map +1 -1
  267. package/dist/backend/native-link-info-core.js +9 -5
  268. package/dist/backend/native-link-info-core.js.map +1 -1
  269. package/dist/backend/native-link-info.js +14 -5
  270. package/dist/backend/native-link-info.js.map +1 -1
  271. package/dist/backend/native-link-info.test.js +58 -13
  272. package/dist/backend/native-link-info.test.js.map +1 -1
  273. package/dist/backend/native-toolchain.d.ts +17 -450
  274. package/dist/backend/native-toolchain.js +17 -3971
  275. package/dist/backend/native-toolchain.js.map +1 -1
  276. package/dist/backend/native-toolchain.test.js +103 -72
  277. package/dist/backend/native-toolchain.test.js.map +1 -1
  278. package/dist/backend/native-tools.js +27 -8
  279. package/dist/backend/native-tools.js.map +1 -1
  280. package/dist/backend/object-localize.js +17 -14
  281. package/dist/backend/object-localize.js.map +1 -1
  282. package/dist/backend/object-localize.test.js +59 -12
  283. package/dist/backend/object-localize.test.js.map +1 -1
  284. package/dist/backend/runtime-pack-core.js +96 -49
  285. package/dist/backend/runtime-pack-core.js.map +1 -1
  286. package/dist/backend/runtime-pack-native.js +5 -3
  287. package/dist/backend/runtime-pack-native.js.map +1 -1
  288. package/dist/backend/runtime-pack-targets.test.js +87 -15
  289. package/dist/backend/runtime-pack-targets.test.js.map +1 -1
  290. package/dist/backend/runtime-pack.d.ts +1 -1
  291. package/dist/backend/runtime-pack.js +11 -12
  292. package/dist/backend/runtime-pack.js.map +1 -1
  293. package/dist/backend/runtime-pack.test.js +40 -24
  294. package/dist/backend/runtime-pack.test.js.map +1 -1
  295. package/dist/backend/source-locations.js.map +1 -1
  296. package/dist/backend/source-locations.test.js +7 -2
  297. package/dist/backend/source-locations.test.js.map +1 -1
  298. package/dist/backend/target-diagnostics.js +44 -14
  299. package/dist/backend/target-diagnostics.js.map +1 -1
  300. package/dist/backend/target-diagnostics.test.js +93 -20
  301. package/dist/backend/target-diagnostics.test.js.map +1 -1
  302. package/dist/backend/targets.js +230 -86
  303. package/dist/backend/targets.js.map +1 -1
  304. package/dist/backend/targets.test.js +32 -18
  305. package/dist/backend/targets.test.js.map +1 -1
  306. package/dist/backend/toolchain-environment.js +5 -1
  307. package/dist/backend/toolchain-environment.js.map +1 -1
  308. package/dist/backend/vendor-archives.d.ts +2 -2
  309. package/dist/backend/vendor-archives.js +84 -35
  310. package/dist/backend/vendor-archives.js.map +1 -1
  311. package/dist/backend/vendor-inputs.js +13 -1
  312. package/dist/backend/vendor-inputs.js.map +1 -1
  313. package/dist/backend/warm-cache.d.ts +1 -1
  314. package/dist/backend/warm-cache.js +33 -9
  315. package/dist/backend/warm-cache.js.map +1 -1
  316. package/dist/cli/command.js +39 -9
  317. package/dist/cli/command.js.map +1 -1
  318. package/dist/cli/output-options.js +14 -4
  319. package/dist/cli/output-options.js.map +1 -1
  320. package/dist/cli/paths.js.map +1 -1
  321. package/dist/cli/wasi-runner.js.map +1 -1
  322. package/dist/compat/fetch-profile.js +36 -35
  323. package/dist/compat/fetch-profile.js.map +1 -1
  324. package/dist/coverage/report.js +16 -17
  325. package/dist/coverage/report.js.map +1 -1
  326. package/dist/coverage/surface-manifest.js +112 -26
  327. package/dist/coverage/surface-manifest.js.map +1 -1
  328. package/dist/diagnostics/diagnostic.js +55 -16
  329. package/dist/diagnostics/diagnostic.js.map +1 -1
  330. package/dist/executable/executable-cache.d.ts +1 -1
  331. package/dist/executable/executable-cache.js +78 -48
  332. package/dist/executable/executable-cache.js.map +1 -1
  333. package/dist/executable/executable-cache.test.js +75 -26
  334. package/dist/executable/executable-cache.test.js.map +1 -1
  335. package/dist/executable/prepare.js +2 -2
  336. package/dist/executable/prepare.js.map +1 -1
  337. package/dist/ffi/ffi-manifest.js +78 -20
  338. package/dist/ffi/ffi-manifest.js.map +1 -1
  339. package/dist/ffi/ffi-manifest.test.js +96 -16
  340. package/dist/ffi/ffi-manifest.test.js.map +1 -1
  341. package/dist/format-integer.js.map +1 -1
  342. package/dist/frontend/analysis.js +12 -2
  343. package/dist/frontend/analysis.js.map +1 -1
  344. package/dist/frontend/arguments-usage.js.map +1 -1
  345. package/dist/frontend/binding-source.js +9 -3
  346. package/dist/frontend/binding-source.js.map +1 -1
  347. package/dist/frontend/builtin-modules.js +46 -2
  348. package/dist/frontend/builtin-modules.js.map +1 -1
  349. package/dist/frontend/cjs-resolve.js +40 -17
  350. package/dist/frontend/cjs-resolve.js.map +1 -1
  351. package/dist/frontend/cjs-syntax.js +31 -10
  352. package/dist/frontend/cjs-syntax.js.map +1 -1
  353. package/dist/frontend/comptime-node.test.js +10 -11
  354. package/dist/frontend/comptime-node.test.js.map +1 -1
  355. package/dist/frontend/dts-paths.js +7 -3
  356. package/dist/frontend/dts-paths.js.map +1 -1
  357. package/dist/frontend/fork-target.js +17 -12
  358. package/dist/frontend/fork-target.js.map +1 -1
  359. package/dist/frontend/function-completion.js +11 -6
  360. package/dist/frontend/function-completion.js.map +1 -1
  361. package/dist/frontend/helper-tokens.js +53 -6
  362. package/dist/frontend/helper-tokens.js.map +1 -1
  363. package/dist/frontend/helper-tokens.test.js +18 -2
  364. package/dist/frontend/helper-tokens.test.js.map +1 -1
  365. package/dist/frontend/inferred-js-diagnostics.js +32 -12
  366. package/dist/frontend/inferred-js-diagnostics.js.map +1 -1
  367. package/dist/frontend/inferred-js-diagnostics.test.js +11 -15
  368. package/dist/frontend/inferred-js-diagnostics.test.js.map +1 -1
  369. package/dist/frontend/input-tracker.js +11 -11
  370. package/dist/frontend/input-tracker.js.map +1 -1
  371. package/dist/frontend/input-tracker.test.js +4 -1
  372. package/dist/frontend/input-tracker.test.js.map +1 -1
  373. package/dist/frontend/lib-contract.js +38 -9
  374. package/dist/frontend/lib-contract.js.map +1 -1
  375. package/dist/frontend/literal-values.js.map +1 -1
  376. package/dist/frontend/literal-values.test.js +28 -8
  377. package/dist/frontend/literal-values.test.js.map +1 -1
  378. package/dist/frontend/lowering/abstract-equality.js +53 -10
  379. package/dist/frontend/lowering/abstract-equality.js.map +1 -1
  380. package/dist/frontend/lowering/array-indexed-mutation.d.ts +1 -1
  381. package/dist/frontend/lowering/array-indexed-mutation.js +108 -106
  382. package/dist/frontend/lowering/array-indexed-mutation.js.map +1 -1
  383. package/dist/frontend/lowering/array-values.js +37 -14
  384. package/dist/frontend/lowering/array-values.js.map +1 -1
  385. package/dist/frontend/lowering/binding-analysis.d.ts +50 -0
  386. package/dist/frontend/lowering/binding-analysis.js +376 -0
  387. package/dist/frontend/lowering/binding-analysis.js.map +1 -0
  388. package/dist/frontend/lowering/builtin-calls.d.ts +9 -0
  389. package/dist/frontend/lowering/builtin-calls.js +60 -0
  390. package/dist/frontend/lowering/builtin-calls.js.map +1 -0
  391. package/dist/frontend/lowering/builtins/arguments.d.ts +43 -0
  392. package/dist/frontend/lowering/builtins/arguments.js +247 -0
  393. package/dist/frontend/lowering/builtins/arguments.js.map +1 -0
  394. package/dist/frontend/lowering/builtins/async-context.d.ts +52 -0
  395. package/dist/frontend/lowering/builtins/async-context.js +436 -0
  396. package/dist/frontend/lowering/builtins/async-context.js.map +1 -0
  397. package/dist/frontend/lowering/builtins/atomics.d.ts +15 -0
  398. package/dist/frontend/lowering/builtins/atomics.js +46 -0
  399. package/dist/frontend/lowering/builtins/atomics.js.map +1 -0
  400. package/dist/frontend/lowering/builtins/callable-aliases.d.ts +13 -0
  401. package/dist/frontend/lowering/builtins/callable-aliases.js +87 -0
  402. package/dist/frontend/lowering/builtins/callable-aliases.js.map +1 -0
  403. package/dist/frontend/lowering/builtins/child-process-async.d.ts +18 -0
  404. package/dist/frontend/lowering/builtins/child-process-async.js +245 -0
  405. package/dist/frontend/lowering/builtins/child-process-async.js.map +1 -0
  406. package/dist/frontend/lowering/builtins/child-process-methods.d.ts +21 -0
  407. package/dist/frontend/lowering/builtins/child-process-methods.js +362 -0
  408. package/dist/frontend/lowering/builtins/child-process-methods.js.map +1 -0
  409. package/dist/frontend/lowering/builtins/child-process-sync.d.ts +4 -0
  410. package/dist/frontend/lowering/builtins/child-process-sync.js +639 -0
  411. package/dist/frontend/lowering/builtins/child-process-sync.js.map +1 -0
  412. package/dist/frontend/lowering/builtins/child-process.d.ts +55 -0
  413. package/dist/frontend/lowering/builtins/child-process.js +669 -0
  414. package/dist/frontend/lowering/builtins/child-process.js.map +1 -0
  415. package/dist/frontend/lowering/builtins/compression.d.ts +7 -0
  416. package/dist/frontend/lowering/builtins/compression.js +115 -0
  417. package/dist/frontend/lowering/builtins/compression.js.map +1 -0
  418. package/dist/frontend/lowering/builtins/console.d.ts +10 -0
  419. package/dist/frontend/lowering/builtins/console.js +38 -0
  420. package/dist/frontend/lowering/builtins/console.js.map +1 -0
  421. package/dist/frontend/lowering/builtins/constants.d.ts +24 -0
  422. package/dist/frontend/lowering/builtins/constants.js +141 -0
  423. package/dist/frontend/lowering/builtins/constants.js.map +1 -0
  424. package/dist/frontend/lowering/builtins/crypto.d.ts +22 -0
  425. package/dist/frontend/lowering/builtins/crypto.js +517 -0
  426. package/dist/frontend/lowering/builtins/crypto.js.map +1 -0
  427. package/dist/frontend/lowering/builtins/dates.d.ts +7 -0
  428. package/dist/frontend/lowering/builtins/dates.js +101 -0
  429. package/dist/frontend/lowering/builtins/dates.js.map +1 -0
  430. package/dist/frontend/lowering/builtins/environment.d.ts +34 -0
  431. package/dist/frontend/lowering/builtins/environment.js +95 -0
  432. package/dist/frontend/lowering/builtins/environment.js.map +1 -0
  433. package/dist/frontend/lowering/builtins/errors.d.ts +14 -0
  434. package/dist/frontend/lowering/builtins/errors.js +83 -0
  435. package/dist/frontend/lowering/builtins/errors.js.map +1 -0
  436. package/dist/frontend/lowering/builtins/filesystem-calls.d.ts +32 -0
  437. package/dist/frontend/lowering/builtins/filesystem-calls.js +678 -0
  438. package/dist/frontend/lowering/builtins/filesystem-calls.js.map +1 -0
  439. package/dist/frontend/lowering/builtins/filesystem.d.ts +108 -0
  440. package/dist/frontend/lowering/builtins/filesystem.js +1061 -0
  441. package/dist/frontend/lowering/builtins/filesystem.js.map +1 -0
  442. package/dist/frontend/lowering/builtins/ipc.d.ts +8 -0
  443. package/dist/frontend/lowering/builtins/ipc.js +76 -0
  444. package/dist/frontend/lowering/builtins/ipc.js.map +1 -0
  445. package/dist/frontend/lowering/builtins/json.d.ts +12 -0
  446. package/dist/frontend/lowering/builtins/json.js +387 -0
  447. package/dist/frontend/lowering/builtins/json.js.map +1 -0
  448. package/dist/frontend/lowering/builtins/module-bindings.d.ts +85 -0
  449. package/dist/frontend/lowering/builtins/module-bindings.js +346 -0
  450. package/dist/frontend/lowering/builtins/module-bindings.js.map +1 -0
  451. package/dist/frontend/lowering/builtins/module-calls.d.ts +8 -0
  452. package/dist/frontend/lowering/builtins/module-calls.js +303 -0
  453. package/dist/frontend/lowering/builtins/module-calls.js.map +1 -0
  454. package/dist/frontend/lowering/builtins/module-resolution.d.ts +38 -0
  455. package/dist/frontend/lowering/builtins/module-resolution.js +344 -0
  456. package/dist/frontend/lowering/builtins/module-resolution.js.map +1 -0
  457. package/dist/frontend/lowering/builtins/numbers.d.ts +15 -0
  458. package/dist/frontend/lowering/builtins/numbers.js +124 -0
  459. package/dist/frontend/lowering/builtins/numbers.js.map +1 -0
  460. package/dist/frontend/lowering/builtins/operating-system.d.ts +13 -0
  461. package/dist/frontend/lowering/builtins/operating-system.js +148 -0
  462. package/dist/frontend/lowering/builtins/operating-system.js.map +1 -0
  463. package/dist/frontend/lowering/builtins/performance.d.ts +13 -0
  464. package/dist/frontend/lowering/builtins/performance.js +100 -0
  465. package/dist/frontend/lowering/builtins/performance.js.map +1 -0
  466. package/dist/frontend/lowering/builtins/process.d.ts +50 -0
  467. package/dist/frontend/lowering/builtins/process.js +1138 -0
  468. package/dist/frontend/lowering/builtins/process.js.map +1 -0
  469. package/dist/frontend/lowering/builtins/promises.d.ts +14 -0
  470. package/dist/frontend/lowering/builtins/promises.js +356 -0
  471. package/dist/frontend/lowering/builtins/promises.js.map +1 -0
  472. package/dist/frontend/lowering/builtins/properties.d.ts +11 -0
  473. package/dist/frontend/lowering/builtins/properties.js +186 -0
  474. package/dist/frontend/lowering/builtins/properties.js.map +1 -0
  475. package/dist/frontend/lowering/builtins/querystring.d.ts +19 -0
  476. package/dist/frontend/lowering/builtins/querystring.js +150 -0
  477. package/dist/frontend/lowering/builtins/querystring.js.map +1 -0
  478. package/dist/frontend/lowering/builtins/readline.d.ts +13 -0
  479. package/dist/frontend/lowering/builtins/readline.js +138 -0
  480. package/dist/frontend/lowering/builtins/readline.js.map +1 -0
  481. package/dist/frontend/lowering/builtins/receiver-types.d.ts +5 -0
  482. package/dist/frontend/lowering/builtins/receiver-types.js +15 -0
  483. package/dist/frontend/lowering/builtins/receiver-types.js.map +1 -0
  484. package/dist/frontend/lowering/builtins/reflection.d.ts +13 -0
  485. package/dist/frontend/lowering/builtins/reflection.js +95 -0
  486. package/dist/frontend/lowering/builtins/reflection.js.map +1 -0
  487. package/dist/frontend/lowering/builtins/strings.d.ts +14 -0
  488. package/dist/frontend/lowering/builtins/strings.js +121 -0
  489. package/dist/frontend/lowering/builtins/strings.js.map +1 -0
  490. package/dist/frontend/lowering/builtins/text-codecs.d.ts +29 -0
  491. package/dist/frontend/lowering/builtins/text-codecs.js +590 -0
  492. package/dist/frontend/lowering/builtins/text-codecs.js.map +1 -0
  493. package/dist/frontend/lowering/builtins/timers.d.ts +22 -0
  494. package/dist/frontend/lowering/builtins/timers.js +180 -0
  495. package/dist/frontend/lowering/builtins/timers.js.map +1 -0
  496. package/dist/frontend/lowering/builtins/url.d.ts +37 -0
  497. package/dist/frontend/lowering/builtins/url.js +596 -0
  498. package/dist/frontend/lowering/builtins/url.js.map +1 -0
  499. package/dist/frontend/lowering/builtins/util-types.d.ts +7 -0
  500. package/dist/frontend/lowering/builtins/util-types.js +31 -0
  501. package/dist/frontend/lowering/builtins/util-types.js.map +1 -0
  502. package/dist/frontend/lowering/call-arguments.d.ts +72 -0
  503. package/dist/frontend/lowering/call-arguments.js +618 -0
  504. package/dist/frontend/lowering/call-arguments.js.map +1 -0
  505. package/dist/frontend/lowering/call-signatures.d.ts +115 -0
  506. package/dist/frontend/lowering/call-signatures.js +719 -0
  507. package/dist/frontend/lowering/call-signatures.js.map +1 -0
  508. package/dist/frontend/lowering/callback-arg.js.map +1 -1
  509. package/dist/frontend/lowering/checked-iterable-spread.js +53 -10
  510. package/dist/frontend/lowering/checked-iterable-spread.js.map +1 -1
  511. package/dist/frontend/lowering/checked-promise-all.js +41 -9
  512. package/dist/frontend/lowering/checked-promise-all.js.map +1 -1
  513. package/dist/frontend/lowering/class-callbacks.d.ts +1 -1
  514. package/dist/frontend/lowering/class-callbacks.js +130 -27
  515. package/dist/frontend/lowering/class-callbacks.js.map +1 -1
  516. package/dist/frontend/lowering/class-construction.d.ts +1 -1
  517. package/dist/frontend/lowering/class-construction.js +247 -50
  518. package/dist/frontend/lowering/class-construction.js.map +1 -1
  519. package/dist/frontend/lowering/class-descriptors.js +109 -29
  520. package/dist/frontend/lowering/class-descriptors.js.map +1 -1
  521. package/dist/frontend/lowering/class-dynamic-dispatch.d.ts +6 -1
  522. package/dist/frontend/lowering/class-dynamic-dispatch.js +2471 -465
  523. package/dist/frontend/lowering/class-dynamic-dispatch.js.map +1 -1
  524. package/dist/frontend/lowering/class-dynamic-dispatch.test.js +284 -44
  525. package/dist/frontend/lowering/class-dynamic-dispatch.test.js.map +1 -1
  526. package/dist/frontend/lowering/class-instance-constructor.js +17 -5
  527. package/dist/frontend/lowering/class-instance-constructor.js.map +1 -1
  528. package/dist/frontend/lowering/class-method-values.js +199 -51
  529. package/dist/frontend/lowering/class-method-values.js.map +1 -1
  530. package/dist/frontend/lowering/class-prototypes.js +345 -86
  531. package/dist/frontend/lowering/class-prototypes.js.map +1 -1
  532. package/dist/frontend/lowering/class-runtime-statics.d.ts +1 -1
  533. package/dist/frontend/lowering/class-runtime-statics.js +80 -17
  534. package/dist/frontend/lowering/class-runtime-statics.js.map +1 -1
  535. package/dist/frontend/lowering/class-static-data.js +76 -16
  536. package/dist/frontend/lowering/class-static-data.js.map +1 -1
  537. package/dist/frontend/lowering/coercions/builders.d.ts +13 -0
  538. package/dist/frontend/lowering/coercions/builders.js +77 -0
  539. package/dist/frontend/lowering/coercions/builders.js.map +1 -0
  540. package/dist/frontend/lowering/coercions/function-adapters.d.ts +58 -0
  541. package/dist/frontend/lowering/coercions/function-adapters.js +430 -0
  542. package/dist/frontend/lowering/coercions/function-adapters.js.map +1 -0
  543. package/dist/frontend/lowering/coercions/island.d.ts +37 -0
  544. package/dist/frontend/lowering/coercions/island.js +350 -0
  545. package/dist/frontend/lowering/coercions/island.js.map +1 -0
  546. package/dist/frontend/lowering/coercions/state.d.ts +14 -0
  547. package/dist/frontend/lowering/coercions/state.js +16 -0
  548. package/dist/frontend/lowering/coercions/state.js.map +1 -0
  549. package/dist/frontend/lowering/coercions/structural-plans.d.ts +40 -0
  550. package/dist/frontend/lowering/coercions/structural-plans.js +447 -0
  551. package/dist/frontend/lowering/coercions/structural-plans.js.map +1 -0
  552. package/dist/frontend/lowering/coercions/structural.d.ts +63 -0
  553. package/dist/frontend/lowering/coercions/structural.js +616 -0
  554. package/dist/frontend/lowering/coercions/structural.js.map +1 -0
  555. package/dist/frontend/lowering/coercions/unions.d.ts +65 -0
  556. package/dist/frontend/lowering/coercions/unions.js +318 -0
  557. package/dist/frontend/lowering/coercions/unions.js.map +1 -0
  558. package/dist/frontend/lowering/collection-ingestion.js +359 -67
  559. package/dist/frontend/lowering/collection-ingestion.js.map +1 -1
  560. package/dist/frontend/lowering/containers/array-callbacks.d.ts +92 -0
  561. package/dist/frontend/lowering/containers/array-callbacks.js +1646 -0
  562. package/dist/frontend/lowering/containers/array-callbacks.js.map +1 -0
  563. package/dist/frontend/lowering/containers/array-construction.d.ts +42 -0
  564. package/dist/frontend/lowering/containers/array-construction.js +1044 -0
  565. package/dist/frontend/lowering/containers/array-construction.js.map +1 -0
  566. package/dist/frontend/lowering/containers/array-iteration.d.ts +16 -0
  567. package/dist/frontend/lowering/containers/array-iteration.js +95 -0
  568. package/dist/frontend/lowering/containers/array-iteration.js.map +1 -0
  569. package/dist/frontend/lowering/containers/array-methods.d.ts +27 -0
  570. package/dist/frontend/lowering/containers/array-methods.js +1854 -0
  571. package/dist/frontend/lowering/containers/array-methods.js.map +1 -0
  572. package/dist/frontend/lowering/containers/bytes.d.ts +17 -17
  573. package/dist/frontend/lowering/containers/bytes.js +419 -105
  574. package/dist/frontend/lowering/containers/bytes.js.map +1 -1
  575. package/dist/frontend/lowering/containers/callback-arguments.d.ts +26 -0
  576. package/dist/frontend/lowering/containers/callback-arguments.js +179 -0
  577. package/dist/frontend/lowering/containers/callback-arguments.js.map +1 -0
  578. package/dist/frontend/lowering/containers/collection-grouping.d.ts +19 -0
  579. package/dist/frontend/lowering/containers/collection-grouping.js +297 -0
  580. package/dist/frontend/lowering/containers/collection-grouping.js.map +1 -0
  581. package/dist/frontend/lowering/containers/collection-methods.d.ts +57 -0
  582. package/dist/frontend/lowering/containers/collection-methods.js +1314 -0
  583. package/dist/frontend/lowering/containers/collection-methods.js.map +1 -0
  584. package/dist/frontend/lowering/containers/dynamic-receivers.d.ts +18 -0
  585. package/dist/frontend/lowering/containers/dynamic-receivers.js +114 -0
  586. package/dist/frontend/lowering/containers/dynamic-receivers.js.map +1 -0
  587. package/dist/frontend/lowering/containers/for-of.d.ts +60 -0
  588. package/dist/frontend/lowering/containers/for-of.js +643 -0
  589. package/dist/frontend/lowering/containers/for-of.js.map +1 -0
  590. package/dist/frontend/lowering/containers/indexed-objects.d.ts +132 -0
  591. package/dist/frontend/lowering/containers/indexed-objects.js +1743 -0
  592. package/dist/frontend/lowering/containers/indexed-objects.js.map +1 -0
  593. package/dist/frontend/lowering/containers/iterator-helpers.d.ts +20 -0
  594. package/dist/frontend/lowering/containers/iterator-helpers.js +809 -0
  595. package/dist/frontend/lowering/containers/iterator-helpers.js.map +1 -0
  596. package/dist/frontend/lowering/containers/string-and-regexp.js +585 -157
  597. package/dist/frontend/lowering/containers/string-and-regexp.js.map +1 -1
  598. package/dist/frontend/lowering/containers/string-replacement.js +213 -63
  599. package/dist/frontend/lowering/containers/string-replacement.js.map +1 -1
  600. package/dist/frontend/lowering/crypto-tables.js +263 -64
  601. package/dist/frontend/lowering/crypto-tables.js.map +1 -1
  602. package/dist/frontend/lowering/deferred-module-initializers.js +172 -68
  603. package/dist/frontend/lowering/deferred-module-initializers.js.map +1 -1
  604. package/dist/frontend/lowering/deferred-module-initializers.test.js +41 -8
  605. package/dist/frontend/lowering/deferred-module-initializers.test.js.map +1 -1
  606. package/dist/frontend/lowering/error-methods.js +339 -65
  607. package/dist/frontend/lowering/error-methods.js.map +1 -1
  608. package/dist/frontend/lowering/expressions/evaluation-safety.js +3 -2
  609. package/dist/frontend/lowering/expressions/evaluation-safety.js.map +1 -1
  610. package/dist/frontend/lowering/expressions/global-symbols.js +2 -1
  611. package/dist/frontend/lowering/expressions/global-symbols.js.map +1 -1
  612. package/dist/frontend/lowering/expressions/native-proxy.js +11 -5
  613. package/dist/frontend/lowering/expressions/native-proxy.js.map +1 -1
  614. package/dist/frontend/lowering/expressions/nullish-assignment.js +67 -13
  615. package/dist/frontend/lowering/expressions/nullish-assignment.js.map +1 -1
  616. package/dist/frontend/lowering/expressions/object-literals.js +589 -162
  617. package/dist/frontend/lowering/expressions/object-literals.js.map +1 -1
  618. package/dist/frontend/lowering/expressions/optional-chains.d.ts +1 -1
  619. package/dist/frontend/lowering/expressions/optional-chains.js +68 -17
  620. package/dist/frontend/lowering/expressions/optional-chains.js.map +1 -1
  621. package/dist/frontend/lowering/expressions/union-field-write.js +45 -18
  622. package/dist/frontend/lowering/expressions/union-field-write.js.map +1 -1
  623. package/dist/frontend/lowering/function-context.js +5 -1
  624. package/dist/frontend/lowering/function-context.js.map +1 -1
  625. package/dist/frontend/lowering/function-returns.d.ts +67 -0
  626. package/dist/frontend/lowering/function-returns.js +392 -0
  627. package/dist/frontend/lowering/function-returns.js.map +1 -0
  628. package/dist/frontend/lowering/generator-delegation.d.ts +1 -1
  629. package/dist/frontend/lowering/generator-delegation.js +171 -39
  630. package/dist/frontend/lowering/generator-delegation.js.map +1 -1
  631. package/dist/frontend/lowering/generator-dynamic-dispatch.d.ts +1 -1
  632. package/dist/frontend/lowering/generator-dynamic-dispatch.js +176 -36
  633. package/dist/frontend/lowering/generator-dynamic-dispatch.js.map +1 -1
  634. package/dist/frontend/lowering/generic-functions.d.ts +274 -0
  635. package/dist/frontend/lowering/generic-functions.js +1727 -0
  636. package/dist/frontend/lowering/generic-functions.js.map +1 -0
  637. package/dist/frontend/lowering/import-meta.d.ts +1 -1
  638. package/dist/frontend/lowering/import-meta.js +37 -14
  639. package/dist/frontend/lowering/import-meta.js.map +1 -1
  640. package/dist/frontend/lowering/indexed-comparison.js +6 -2
  641. package/dist/frontend/lowering/indexed-comparison.js.map +1 -1
  642. package/dist/frontend/lowering/iterator-consumption.d.ts +9 -0
  643. package/dist/frontend/lowering/iterator-consumption.js +91 -0
  644. package/dist/frontend/lowering/iterator-consumption.js.map +1 -0
  645. package/dist/frontend/lowering/lib-boundary.js +40 -17
  646. package/dist/frontend/lowering/lib-boundary.js.map +1 -1
  647. package/dist/frontend/lowering/lib-boundary.test.js +49 -11
  648. package/dist/frontend/lowering/lib-boundary.test.js.map +1 -1
  649. package/dist/frontend/lowering/lower-array-sort.d.ts +0 -19
  650. package/dist/frontend/lowering/lower-array-sort.js +331 -566
  651. package/dist/frontend/lowering/lower-array-sort.js.map +1 -1
  652. package/dist/frontend/lowering/lower-assert.js +248 -43
  653. package/dist/frontend/lowering/lower-assert.js.map +1 -1
  654. package/dist/frontend/lowering/lower-async-iteration.js +71 -16
  655. package/dist/frontend/lowering/lower-async-iteration.js.map +1 -1
  656. package/dist/frontend/lowering/lower-builtin-values.js +420 -71
  657. package/dist/frontend/lowering/lower-builtin-values.js.map +1 -1
  658. package/dist/frontend/lowering/lower-calls.d.ts +39 -558
  659. package/dist/frontend/lowering/lower-calls.js +2593 -5667
  660. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  661. package/dist/frontend/lowering/lower-classes.d.ts +243 -242
  662. package/dist/frontend/lowering/lower-classes.js +1704 -727
  663. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  664. package/dist/frontend/lowering/lower-comptime.d.ts +35 -35
  665. package/dist/frontend/lowering/lower-comptime.js +39 -37
  666. package/dist/frontend/lowering/lower-comptime.js.map +1 -1
  667. package/dist/frontend/lowering/lower-dgram.js +59 -31
  668. package/dist/frontend/lowering/lower-dgram.js.map +1 -1
  669. package/dist/frontend/lowering/lower-enums.js +5 -2
  670. package/dist/frontend/lowering/lower-enums.js.map +1 -1
  671. package/dist/frontend/lowering/lower-event-emitter.js +322 -85
  672. package/dist/frontend/lowering/lower-event-emitter.js.map +1 -1
  673. package/dist/frontend/lowering/lower-expando.js +19 -7
  674. package/dist/frontend/lowering/lower-expando.js.map +1 -1
  675. package/dist/frontend/lowering/lower-exprs.d.ts +194 -194
  676. package/dist/frontend/lowering/lower-exprs.js +3455 -1153
  677. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  678. package/dist/frontend/lowering/lower-functions.d.ts +23 -0
  679. package/dist/frontend/lowering/lower-functions.js +449 -0
  680. package/dist/frontend/lowering/lower-functions.js.map +1 -0
  681. package/dist/frontend/lowering/lower-generators.js +121 -32
  682. package/dist/frontend/lowering/lower-generators.js.map +1 -1
  683. package/dist/frontend/lowering/lower-global-value.js +15 -4
  684. package/dist/frontend/lowering/lower-global-value.js.map +1 -1
  685. package/dist/frontend/lowering/lower-inspect.js +479 -89
  686. package/dist/frontend/lowering/lower-inspect.js.map +1 -1
  687. package/dist/frontend/lowering/lower-island.d.ts +79 -79
  688. package/dist/frontend/lowering/lower-island.js +365 -273
  689. package/dist/frontend/lowering/lower-island.js.map +1 -1
  690. package/dist/frontend/lowering/lower-island.test.js +7 -2
  691. package/dist/frontend/lowering/lower-island.test.js.map +1 -1
  692. package/dist/frontend/lowering/lower-mixins.js +17 -8
  693. package/dist/frontend/lowering/lower-mixins.js.map +1 -1
  694. package/dist/frontend/lowering/lower-modules.d.ts +94 -94
  695. package/dist/frontend/lowering/lower-modules.js +612 -321
  696. package/dist/frontend/lowering/lower-modules.js.map +1 -1
  697. package/dist/frontend/lowering/lower-modules.test.js +91 -20
  698. package/dist/frontend/lowering/lower-modules.test.js.map +1 -1
  699. package/dist/frontend/lowering/lower-namespaces.js +25 -8
  700. package/dist/frontend/lowering/lower-namespaces.js.map +1 -1
  701. package/dist/frontend/lowering/lower-node-module.js +115 -34
  702. package/dist/frontend/lowering/lower-node-module.js.map +1 -1
  703. package/dist/frontend/lowering/lower-server.js +1210 -290
  704. package/dist/frontend/lowering/lower-server.js.map +1 -1
  705. package/dist/frontend/lowering/lower-stmts.d.ts +148 -148
  706. package/dist/frontend/lowering/lower-stmts.js +2312 -984
  707. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  708. package/dist/frontend/lowering/lower-stmts.test.js +13 -5
  709. package/dist/frontend/lowering/lower-stmts.test.js.map +1 -1
  710. package/dist/frontend/lowering/lower-stream.js +362 -90
  711. package/dist/frontend/lowering/lower-stream.js.map +1 -1
  712. package/dist/frontend/lowering/lower-system-errors.js +30 -8
  713. package/dist/frontend/lowering/lower-system-errors.js.map +1 -1
  714. package/dist/frontend/lowering/lower-test.js +40 -13
  715. package/dist/frontend/lowering/lower-test.js.map +1 -1
  716. package/dist/frontend/lowering/lower-timers.d.ts +31 -0
  717. package/dist/frontend/lowering/lower-timers.js +336 -0
  718. package/dist/frontend/lowering/lower-timers.js.map +1 -0
  719. package/dist/frontend/lowering/lower-url.d.ts +1 -1
  720. package/dist/frontend/lowering/lower-url.js +46 -13
  721. package/dist/frontend/lowering/lower-url.js.map +1 -1
  722. package/dist/frontend/lowering/lowerer.d.ts +21 -351
  723. package/dist/frontend/lowering/lowerer.js +1031 -2704
  724. package/dist/frontend/lowering/lowerer.js.map +1 -1
  725. package/dist/frontend/lowering/lowerer.test.js +85 -17
  726. package/dist/frontend/lowering/lowerer.test.js.map +1 -1
  727. package/dist/frontend/lowering/module-namespace-elements.js +43 -8
  728. package/dist/frontend/lowering/module-namespace-elements.js.map +1 -1
  729. package/dist/frontend/lowering/native-ffi.d.ts +21 -1
  730. package/dist/frontend/lowering/native-ffi.js +487 -18
  731. package/dist/frontend/lowering/native-ffi.js.map +1 -1
  732. package/dist/frontend/lowering/object-enumeration-receiver.js +55 -10
  733. package/dist/frontend/lowering/object-enumeration-receiver.js.map +1 -1
  734. package/dist/frontend/lowering/object-factory-new.d.ts +1 -1
  735. package/dist/frontend/lowering/object-factory-new.js +36 -11
  736. package/dist/frontend/lowering/object-factory-new.js.map +1 -1
  737. package/dist/frontend/lowering/optional-arguments.js +49 -20
  738. package/dist/frontend/lowering/optional-arguments.js.map +1 -1
  739. package/dist/frontend/lowering/pairs-snapshot.js +66 -14
  740. package/dist/frontend/lowering/pairs-snapshot.js.map +1 -1
  741. package/dist/frontend/lowering/runtime-optional-locals.js +3 -1
  742. package/dist/frontend/lowering/runtime-optional-locals.js.map +1 -1
  743. package/dist/frontend/lowering/runtime-optional-locals.test.js.map +1 -1
  744. package/dist/frontend/lowering/sanitize-class-types.js +4 -1
  745. package/dist/frontend/lowering/sanitize-class-types.js.map +1 -1
  746. package/dist/frontend/lowering/sanitize-class-types.test.js +86 -18
  747. package/dist/frontend/lowering/sanitize-class-types.test.js.map +1 -1
  748. package/dist/frontend/lowering/static-this.js +13 -6
  749. package/dist/frontend/lowering/static-this.js.map +1 -1
  750. package/dist/frontend/lowering/string-index.js +32 -10
  751. package/dist/frontend/lowering/string-index.js.map +1 -1
  752. package/dist/frontend/lowering/surfaces.d.ts +42 -42
  753. package/dist/frontend/lowering/surfaces.js +1094 -249
  754. package/dist/frontend/lowering/surfaces.js.map +1 -1
  755. package/dist/frontend/lowering/symbol-fields.js +40 -15
  756. package/dist/frontend/lowering/symbol-fields.js.map +1 -1
  757. package/dist/frontend/lowering/symbol-methods.js.map +1 -1
  758. package/dist/frontend/lowering/text-decoder-encoding.js +236 -24
  759. package/dist/frontend/lowering/text-decoder-encoding.js.map +1 -1
  760. package/dist/frontend/lowering/text-decoder-encoding.test.js +84 -12
  761. package/dist/frontend/lowering/text-decoder-encoding.test.js.map +1 -1
  762. package/dist/frontend/lowering/union-narrow.js +59 -16
  763. package/dist/frontend/lowering/union-narrow.js.map +1 -1
  764. package/dist/frontend/lowering/union-narrow.test.js +24 -7
  765. package/dist/frontend/lowering/union-narrow.test.js.map +1 -1
  766. package/dist/frontend/lowering/union-retag.js +155 -40
  767. package/dist/frontend/lowering/union-retag.js.map +1 -1
  768. package/dist/frontend/lowering/union-retag.test.js +131 -33
  769. package/dist/frontend/lowering/union-retag.test.js.map +1 -1
  770. package/dist/frontend/lowering/unregistered-class-types.js.map +1 -1
  771. package/dist/frontend/lowering/unregistered-class-types.test.js +34 -8
  772. package/dist/frontend/lowering/unregistered-class-types.test.js.map +1 -1
  773. package/dist/frontend/module-syntax.js +21 -8
  774. package/dist/frontend/module-syntax.js.map +1 -1
  775. package/dist/frontend/module-syntax.test.js +37 -13
  776. package/dist/frontend/module-syntax.test.js.map +1 -1
  777. package/dist/frontend/npm-fetch-analysis.js +13 -4
  778. package/dist/frontend/npm-fetch-analysis.js.map +1 -1
  779. package/dist/frontend/npm-fetch-analysis.test.js +33 -10
  780. package/dist/frontend/npm-fetch-analysis.test.js.map +1 -1
  781. package/dist/frontend/npm-fetch-node.js.map +1 -1
  782. package/dist/frontend/npm-fetch-syntax.js +4 -9
  783. package/dist/frontend/npm-fetch-syntax.js.map +1 -1
  784. package/dist/frontend/npm-node.js +3 -1
  785. package/dist/frontend/npm-node.js.map +1 -1
  786. package/dist/frontend/npm-static-bundled-cjs.js +88 -29
  787. package/dist/frontend/npm-static-bundled-cjs.js.map +1 -1
  788. package/dist/frontend/npm-static-bundled-cjs.test.js +29 -10
  789. package/dist/frontend/npm-static-bundled-cjs.test.js.map +1 -1
  790. package/dist/frontend/npm-static-declaration-syntax.js +148 -56
  791. package/dist/frontend/npm-static-declaration-syntax.js.map +1 -1
  792. package/dist/frontend/npm-static-declarations.d.ts +1 -1
  793. package/dist/frontend/npm-static-declarations.js.map +1 -1
  794. package/dist/frontend/npm-static-declarations.test.js +33 -7
  795. package/dist/frontend/npm-static-declarations.test.js.map +1 -1
  796. package/dist/frontend/npm-static-prune.js +26 -12
  797. package/dist/frontend/npm-static-prune.js.map +1 -1
  798. package/dist/frontend/npm-static-prune.test.js +17 -3
  799. package/dist/frontend/npm-static-prune.test.js.map +1 -1
  800. package/dist/frontend/npm-static-rewrite-host.js +2 -3
  801. package/dist/frontend/npm-static-rewrite-host.js.map +1 -1
  802. package/dist/frontend/npm-static-rewrite-syntax.js +64 -21
  803. package/dist/frontend/npm-static-rewrite-syntax.js.map +1 -1
  804. package/dist/frontend/npm-static-rewrite.js.map +1 -1
  805. package/dist/frontend/npm-static-subtyping.js +9 -4
  806. package/dist/frontend/npm-static-subtyping.js.map +1 -1
  807. package/dist/frontend/npm-static-subtyping.test.js +30 -6
  808. package/dist/frontend/npm-static-subtyping.test.js.map +1 -1
  809. package/dist/frontend/npm-static.js +15 -4
  810. package/dist/frontend/npm-static.js.map +1 -1
  811. package/dist/frontend/npm.js +122 -36
  812. package/dist/frontend/npm.js.map +1 -1
  813. package/dist/frontend/npm.test.js +30 -10
  814. package/dist/frontend/npm.test.js.map +1 -1
  815. package/dist/frontend/pipeline-native.js.map +1 -1
  816. package/dist/frontend/pipeline.js +25 -8
  817. package/dist/frontend/pipeline.js.map +1 -1
  818. package/dist/frontend/pipeline.test.js +21 -7
  819. package/dist/frontend/pipeline.test.js.map +1 -1
  820. package/dist/frontend/program-node.js +5 -3
  821. package/dist/frontend/program-node.js.map +1 -1
  822. package/dist/frontend/program.d.ts +2 -2
  823. package/dist/frontend/program.js +234 -101
  824. package/dist/frontend/program.js.map +1 -1
  825. package/dist/frontend/program.test.js +27 -27
  826. package/dist/frontend/program.test.js.map +1 -1
  827. package/dist/frontend/provenance-core.js +8 -4
  828. package/dist/frontend/provenance-core.js.map +1 -1
  829. package/dist/frontend/provenance-registry.js +1 -4
  830. package/dist/frontend/provenance-registry.js.map +1 -1
  831. package/dist/frontend/resolve.js +32 -20
  832. package/dist/frontend/resolve.js.map +1 -1
  833. package/dist/frontend/resolve.test.js +1 -1
  834. package/dist/frontend/resolve.test.js.map +1 -1
  835. package/dist/frontend/runtime-resolve.js +13 -4
  836. package/dist/frontend/runtime-resolve.js.map +1 -1
  837. package/dist/frontend/runtime-resolve.test.js +25 -9
  838. package/dist/frontend/runtime-resolve.test.js.map +1 -1
  839. package/dist/frontend/services-node.js +6 -2
  840. package/dist/frontend/services-node.js.map +1 -1
  841. package/dist/frontend/services-node.test.js +18 -6
  842. package/dist/frontend/services-node.test.js.map +1 -1
  843. package/dist/frontend/services.js +8 -4
  844. package/dist/frontend/services.js.map +1 -1
  845. package/dist/frontend/services.test.js +6 -2
  846. package/dist/frontend/services.test.js.map +1 -1
  847. package/dist/frontend/ts7/api.js +12 -4
  848. package/dist/frontend/ts7/api.js.map +1 -1
  849. package/dist/frontend/ts7/ast-bytes.js +10 -3
  850. package/dist/frontend/ts7/ast-bytes.js.map +1 -1
  851. package/dist/frontend/ts7/ast-bytes.test.js +23 -4
  852. package/dist/frontend/ts7/ast-bytes.test.js.map +1 -1
  853. package/dist/frontend/ts7/ast-guards.test.js +14 -5
  854. package/dist/frontend/ts7/ast-guards.test.js.map +1 -1
  855. package/dist/frontend/ts7/ast-node.d.ts +6 -1
  856. package/dist/frontend/ts7/ast-node.js +484 -164
  857. package/dist/frontend/ts7/ast-node.js.map +1 -1
  858. package/dist/frontend/ts7/ast-node.test.js +109 -36
  859. package/dist/frontend/ts7/ast-node.test.js.map +1 -1
  860. package/dist/frontend/ts7/ast-text.js +13 -3
  861. package/dist/frontend/ts7/ast-text.js.map +1 -1
  862. package/dist/frontend/ts7/ast-text.test.js.map +1 -1
  863. package/dist/frontend/ts7/ast-types.js.map +1 -1
  864. package/dist/frontend/ts7/ast-wire.d.ts +1 -1
  865. package/dist/frontend/ts7/ast-wire.js +55 -20
  866. package/dist/frontend/ts7/ast-wire.js.map +1 -1
  867. package/dist/frontend/ts7/ast-wire.test.js +53 -8
  868. package/dist/frontend/ts7/ast-wire.test.js.map +1 -1
  869. package/dist/frontend/ts7/ast.js +47 -28
  870. package/dist/frontend/ts7/ast.js.map +1 -1
  871. package/dist/frontend/ts7/census-check.js +1 -1
  872. package/dist/frontend/ts7/census-check.js.map +1 -1
  873. package/dist/frontend/ts7/checker-cache.js.map +1 -1
  874. package/dist/frontend/ts7/checker.js +5 -3
  875. package/dist/frontend/ts7/checker.js.map +1 -1
  876. package/dist/frontend/ts7/checker.test.js +54 -17
  877. package/dist/frontend/ts7/checker.test.js.map +1 -1
  878. package/dist/frontend/ts7/enums.test.js +9 -4
  879. package/dist/frontend/ts7/enums.test.js.map +1 -1
  880. package/dist/frontend/ts7/native-api.js.map +1 -1
  881. package/dist/frontend/ts7/native-host.js.map +1 -1
  882. package/dist/frontend/ts7/native-process.js +9 -3
  883. package/dist/frontend/ts7/native-process.js.map +1 -1
  884. package/dist/frontend/ts7/program-adapter.js +1 -1
  885. package/dist/frontend/ts7/program-adapter.js.map +1 -1
  886. package/dist/frontend/ts7/program-host.js +7 -4
  887. package/dist/frontend/ts7/program-host.js.map +1 -1
  888. package/dist/frontend/ts7/program-host.test.js +43 -11
  889. package/dist/frontend/ts7/program-host.test.js.map +1 -1
  890. package/dist/frontend/ts7/rpc-api.js +3 -1
  891. package/dist/frontend/ts7/rpc-api.js.map +1 -1
  892. package/dist/frontend/ts7/rpc-client.js +15 -5
  893. package/dist/frontend/ts7/rpc-client.js.map +1 -1
  894. package/dist/frontend/ts7/rpc-client.test.js +26 -8
  895. package/dist/frontend/ts7/rpc-client.test.js.map +1 -1
  896. package/dist/frontend/ts7/rpc-filesystem.js.map +1 -1
  897. package/dist/frontend/ts7/rpc-filesystem.test.js +43 -10
  898. package/dist/frontend/ts7/rpc-filesystem.test.js.map +1 -1
  899. package/dist/frontend/ts7/rpc-process.js +16 -6
  900. package/dist/frontend/ts7/rpc-process.js.map +1 -1
  901. package/dist/frontend/ts7/rpc-process.test.js.map +1 -1
  902. package/dist/frontend/ts7/rpc-wire.d.ts +1 -0
  903. package/dist/frontend/ts7/rpc-wire.js +41 -14
  904. package/dist/frontend/ts7/rpc-wire.js.map +1 -1
  905. package/dist/frontend/ts7/rpc-wire.test.js +36 -6
  906. package/dist/frontend/ts7/rpc-wire.test.js.map +1 -1
  907. package/dist/frontend/ts7/semantic-checker.js +209 -68
  908. package/dist/frontend/ts7/semantic-checker.js.map +1 -1
  909. package/dist/frontend/ts7/semantic-checker.test.js +29 -14
  910. package/dist/frontend/ts7/semantic-checker.test.js.map +1 -1
  911. package/dist/frontend/ts7/semantic-json.js +7 -1
  912. package/dist/frontend/ts7/semantic-json.js.map +1 -1
  913. package/dist/frontend/ts7/semantic-json.test.js +17 -3
  914. package/dist/frontend/ts7/semantic-json.test.js.map +1 -1
  915. package/dist/frontend/ts7/semantic-model.js +147 -51
  916. package/dist/frontend/ts7/semantic-model.js.map +1 -1
  917. package/dist/frontend/ts7/semantic-model.test.js +72 -19
  918. package/dist/frontend/ts7/semantic-model.test.js.map +1 -1
  919. package/dist/frontend/ts7/semantic-types.d.ts +2 -2
  920. package/dist/frontend/ts7/session-cache.js +10 -3
  921. package/dist/frontend/ts7/session-cache.js.map +1 -1
  922. package/dist/frontend/ts7/session-cache.test.js +13 -4
  923. package/dist/frontend/ts7/session-cache.test.js.map +1 -1
  924. package/dist/frontend/ts7/session-path.js +25 -10
  925. package/dist/frontend/ts7/session-path.js.map +1 -1
  926. package/dist/frontend/ts7/session-path.test.js +47 -4
  927. package/dist/frontend/ts7/session-path.test.js.map +1 -1
  928. package/dist/frontend/ts7/session-timing.js +22 -3
  929. package/dist/frontend/ts7/session-timing.js.map +1 -1
  930. package/dist/frontend/ts7/session-timing.test.js +12 -3
  931. package/dist/frontend/ts7/session-timing.test.js.map +1 -1
  932. package/dist/frontend/ts7/session.d.ts +1 -0
  933. package/dist/frontend/ts7/session.js +109 -35
  934. package/dist/frontend/ts7/session.js.map +1 -1
  935. package/dist/frontend/ts7/session.test.js +69 -15
  936. package/dist/frontend/ts7/session.test.js.map +1 -1
  937. package/dist/frontend/ts7/source-parser.js +17 -6
  938. package/dist/frontend/ts7/source-parser.js.map +1 -1
  939. package/dist/frontend/ts7/source-parser.test.js +32 -9
  940. package/dist/frontend/ts7/source-parser.test.js.map +1 -1
  941. package/dist/frontend/tsc-codes.js +56 -11
  942. package/dist/frontend/tsc-codes.js.map +1 -1
  943. package/dist/frontend/tsc-codes.test.d.ts +1 -0
  944. package/dist/frontend/tsc-codes.test.js +16 -0
  945. package/dist/frontend/tsc-codes.test.js.map +1 -0
  946. package/dist/frontend/type-mapper.js +547 -206
  947. package/dist/frontend/type-mapper.js.map +1 -1
  948. package/dist/frontend/type-mapper.test.js +108 -33
  949. package/dist/frontend/type-mapper.test.js.map +1 -1
  950. package/dist/frontend/union-discriminants.js +8 -2
  951. package/dist/frontend/union-discriminants.js.map +1 -1
  952. package/dist/frontend/union-discriminants.test.js +77 -20
  953. package/dist/frontend/union-discriminants.test.js.map +1 -1
  954. package/dist/index.d.ts +9 -8
  955. package/dist/index.js +150 -81
  956. package/dist/index.js.map +1 -1
  957. package/dist/ir/analysis.js +97 -38
  958. package/dist/ir/analysis.js.map +1 -1
  959. package/dist/ir/analysis.test.js +91 -15
  960. package/dist/ir/analysis.test.js.map +1 -1
  961. package/dist/ir/api.d.ts +4 -0
  962. package/dist/ir/api.js +6 -0
  963. package/dist/ir/api.js.map +1 -0
  964. package/dist/ir/build.d.ts +7 -0
  965. package/dist/ir/build.js +27 -1
  966. package/dist/ir/build.js.map +1 -1
  967. package/dist/ir/builtin-effects.d.ts +9 -0
  968. package/dist/ir/builtin-effects.js +631 -0
  969. package/dist/ir/builtin-effects.js.map +1 -0
  970. package/dist/ir/builtin-signatures.d.ts +15 -0
  971. package/dist/ir/builtin-signatures.js +3396 -0
  972. package/dist/ir/builtin-signatures.js.map +1 -0
  973. package/dist/ir/byte-numbers.d.ts +20 -0
  974. package/dist/ir/byte-numbers.js +116 -0
  975. package/dist/ir/byte-numbers.js.map +1 -0
  976. package/dist/ir/byte-numbers.test.d.ts +1 -0
  977. package/dist/ir/byte-numbers.test.js +55 -0
  978. package/dist/ir/byte-numbers.test.js.map +1 -0
  979. package/dist/ir/constant-tables.js +13 -5
  980. package/dist/ir/constant-tables.js.map +1 -1
  981. package/dist/ir/constant-tables.test.js +47 -7
  982. package/dist/ir/constant-tables.test.js.map +1 -1
  983. package/dist/ir/control-flow.js +2 -1
  984. package/dist/ir/control-flow.js.map +1 -1
  985. package/dist/ir/control-flow.test.js +35 -11
  986. package/dist/ir/control-flow.test.js.map +1 -1
  987. package/dist/ir/initializer-bindings.d.ts +9 -0
  988. package/dist/ir/initializer-bindings.js +115 -0
  989. package/dist/ir/initializer-bindings.js.map +1 -0
  990. package/dist/ir/initializer-bindings.test.d.ts +1 -0
  991. package/dist/ir/initializer-bindings.test.js +118 -0
  992. package/dist/ir/initializer-bindings.test.js.map +1 -0
  993. package/dist/ir/integer-loop-facts.d.ts +12 -0
  994. package/dist/ir/integer-loop-facts.js +137 -0
  995. package/dist/ir/integer-loop-facts.js.map +1 -0
  996. package/dist/ir/integer-loops.d.ts +19 -0
  997. package/dist/ir/integer-loops.js +172 -11
  998. package/dist/ir/integer-loops.js.map +1 -1
  999. package/dist/ir/integer-loops.test.js +122 -9
  1000. package/dist/ir/integer-loops.test.js.map +1 -1
  1001. package/dist/ir/integer-ranges.d.ts +8 -6
  1002. package/dist/ir/integer-ranges.js +416 -90
  1003. package/dist/ir/integer-ranges.js.map +1 -1
  1004. package/dist/ir/integer-ranges.test.js +239 -10
  1005. package/dist/ir/integer-ranges.test.js.map +1 -1
  1006. package/dist/ir/intrinsic-signatures.d.ts +20 -0
  1007. package/dist/ir/intrinsic-signatures.js +57 -0
  1008. package/dist/ir/intrinsic-signatures.js.map +1 -0
  1009. package/dist/ir/ir.d.ts +14 -2155
  1010. package/dist/ir/ir.js +169 -1394
  1011. package/dist/ir/ir.js.map +1 -1
  1012. package/dist/ir/ir.test.js +98 -77
  1013. package/dist/ir/ir.test.js.map +1 -1
  1014. package/dist/ir/runtime-features.d.ts +221 -0
  1015. package/dist/ir/runtime-features.js +551 -0
  1016. package/dist/ir/runtime-features.js.map +1 -0
  1017. package/dist/ir/runtime-features.test.d.ts +1 -0
  1018. package/dist/ir/runtime-features.test.js +98 -0
  1019. package/dist/ir/runtime-features.test.js.map +1 -0
  1020. package/dist/ir/scalar-records.js +130 -40
  1021. package/dist/ir/scalar-records.js.map +1 -1
  1022. package/dist/ir/scalar-records.test.js +146 -27
  1023. package/dist/ir/scalar-records.test.js.map +1 -1
  1024. package/dist/ir/serialize.js +4 -2
  1025. package/dist/ir/serialize.js.map +1 -1
  1026. package/dist/ir/serialize.test.js +44 -9
  1027. package/dist/ir/serialize.test.js.map +1 -1
  1028. package/dist/ir/traverse.js +156 -43
  1029. package/dist/ir/traverse.js.map +1 -1
  1030. package/dist/ir/traverse.test.js +99 -24
  1031. package/dist/ir/traverse.test.js.map +1 -1
  1032. package/dist/ir/validate.d.ts +1 -31
  1033. package/dist/ir/validate.js +826 -1915
  1034. package/dist/ir/validate.js.map +1 -1
  1035. package/dist/ir/validate.test.js +627 -111
  1036. package/dist/ir/validate.test.js.map +1 -1
  1037. package/dist/library/cache-primitives.js +9 -10
  1038. package/dist/library/cache-primitives.js.map +1 -1
  1039. package/dist/library/cache-reset.test.js +2 -1
  1040. package/dist/library/cache-reset.test.js.map +1 -1
  1041. package/dist/library/compiler-self-identity.js +11 -5
  1042. package/dist/library/compiler-self-identity.js.map +1 -1
  1043. package/dist/library/compiler-self-identity.test.js +10 -3
  1044. package/dist/library/compiler-self-identity.test.js.map +1 -1
  1045. package/dist/library/fence-eval.js +24 -7
  1046. package/dist/library/fence-eval.js.map +1 -1
  1047. package/dist/library/fence-eval.test.js +31 -7
  1048. package/dist/library/fence-eval.test.js.map +1 -1
  1049. package/dist/library/int-infer.js +199 -59
  1050. package/dist/library/int-infer.js.map +1 -1
  1051. package/dist/library/int-infer.test.js +133 -57
  1052. package/dist/library/int-infer.test.js.map +1 -1
  1053. package/dist/library/ir-policy.d.ts +27 -0
  1054. package/dist/library/ir-policy.js +232 -0
  1055. package/dist/library/ir-policy.js.map +1 -0
  1056. package/dist/library/library-cache.js +40 -17
  1057. package/dist/library/library-cache.js.map +1 -1
  1058. package/dist/library/library-cache.test.js +24 -13
  1059. package/dist/library/library-cache.test.js.map +1 -1
  1060. package/dist/library/library-profile.js +68 -13
  1061. package/dist/library/library-profile.js.map +1 -1
  1062. package/dist/library/prepare.js +48 -20
  1063. package/dist/library/prepare.js.map +1 -1
  1064. package/dist/library/semantic-source.js +16 -14
  1065. package/dist/library/semantic-source.js.map +1 -1
  1066. package/dist/library/semantic-source.test.js +9 -14
  1067. package/dist/library/semantic-source.test.js.map +1 -1
  1068. package/dist/library/sidecar-validate.js +53 -12
  1069. package/dist/library/sidecar-validate.js.map +1 -1
  1070. package/dist/library/sidecar.js +85 -24
  1071. package/dist/library/sidecar.js.map +1 -1
  1072. package/dist/library/trap-teaching.js +11 -2
  1073. package/dist/library/trap-teaching.js.map +1 -1
  1074. package/dist/native/cache.js +10 -4
  1075. package/dist/native/cache.js.map +1 -1
  1076. package/dist/native/cli.js +34 -9
  1077. package/dist/native/cli.js.map +1 -1
  1078. package/dist/native/compiler.js +167 -43
  1079. package/dist/native/compiler.js.map +1 -1
  1080. package/dist/native/compiler.test.js +129 -32
  1081. package/dist/native/compiler.test.js.map +1 -1
  1082. package/dist/native/comptime.js +23 -7
  1083. package/dist/native/comptime.js.map +1 -1
  1084. package/dist/native/comptime.test.js +26 -6
  1085. package/dist/native/comptime.test.js.map +1 -1
  1086. package/dist/native/executable-cache.js +77 -27
  1087. package/dist/native/executable-cache.js.map +1 -1
  1088. package/dist/native/executable-cache.test.js +41 -6
  1089. package/dist/native/executable-cache.test.js.map +1 -1
  1090. package/dist/native/file-identity.js +9 -2
  1091. package/dist/native/file-identity.js.map +1 -1
  1092. package/dist/native/file-identity.test.js.map +1 -1
  1093. package/dist/native/library.js +50 -12
  1094. package/dist/native/library.js.map +1 -1
  1095. package/dist/native/prepare.js +119 -34
  1096. package/dist/native/prepare.js.map +1 -1
  1097. package/dist/native/prepare.test.js +22 -6
  1098. package/dist/native/prepare.test.js.map +1 -1
  1099. package/dist/native/runtime-typescript.js +24 -11
  1100. package/dist/native/runtime-typescript.js.map +1 -1
  1101. package/dist/native/runtime-typescript.test.js.map +1 -1
  1102. package/dist/native/sanitizer.js +71 -18
  1103. package/dist/native/sanitizer.js.map +1 -1
  1104. package/dist/native/sanitizer.test.js +77 -20
  1105. package/dist/native/sanitizer.test.js.map +1 -1
  1106. package/dist/native/task.js.map +1 -1
  1107. package/dist/native/task.test.js +7 -2
  1108. package/dist/native/task.test.js.map +1 -1
  1109. package/dist/native/toolchain.js +74 -29
  1110. package/dist/native/toolchain.js.map +1 -1
  1111. package/dist/native/toolchain.test.js +95 -18
  1112. package/dist/native/toolchain.test.js.map +1 -1
  1113. package/dist/startup-cache.d.ts +1 -1
  1114. package/dist/startup-cache.js +1 -1
  1115. package/dist/startup-cache.js.map +1 -1
  1116. package/dist/timing.js.map +1 -1
  1117. package/package.json +20 -20
  1118. package/surface-manifest.json +1 -1
  1119. package/dist/frontend/lowering/lower-builtins.d.ts +0 -601
  1120. package/dist/frontend/lowering/lower-builtins.js +0 -8984
  1121. package/dist/frontend/lowering/lower-builtins.js.map +0 -1
  1122. package/dist/frontend/lowering/lower-containers.d.ts +0 -382
  1123. package/dist/frontend/lowering/lower-containers.js +0 -7366
  1124. package/dist/frontend/lowering/lower-containers.js.map +0 -1
@@ -0,0 +1,1727 @@
1
+ import * as ts from "../ts7/adapter.js";
2
+ import { bodyReadsArguments } from "../arguments-usage.js";
3
+ import { DYN, isUnitType, typeEquals, } from "../../ir/ir.js";
4
+ import { isJsSourceFile, locOf } from "../program.js";
5
+ import { typeKey } from "../type-mapper.js";
6
+ import { PoisonError, dynFallbackType, neverTaintedJsType, newFnCtx } from "./lowerer.js";
7
+ import { tryLowerExpression } from "./expressions/try-lower-expression.js";
8
+ import { findGenericMethodOn } from "./lower-classes.js";
9
+ import { nsPathPrefix } from "./lower-namespaces.js";
10
+ import { declSymbolOf } from "./lower-modules.js";
11
+ import { npmStaticPackageOfPath } from "../npm-static.js";
12
+ import { rejectStaticThis } from "./static-this.js";
13
+ import { jsBindingHasOpenWrites } from "./lower-stmts.js";
14
+ import { paramShapes, generatorMeta, funcTypeFromParamShapes, } from "./call-signatures.js";
15
+ import { fenceGenericSignatureResult, blockBodyOf, resolveInferredReturn, appendImplicitUndefinedReturn, hasExplicitJsDocReturn, promiseCarriesDyn, } from "./function-returns.js";
16
+ import { bindingNeverReassigned, stripValueWrappers } from "./binding-analysis.js";
17
+ /** Instantiation cap per generic function: same-key recursion (`len<T>`
18
+ * calling itself) converges, but POLYMORPHIC recursion (`f<T>` calling
19
+ * `f<T[]>`) would request new instances forever — the cap turns that into a
20
+ * diagnostic instead of a hang. */
21
+ export const MAX_GENERIC_INSTANCES = 100;
22
+ /** Defaults bind during inference; collection only resolves symbols in
23
+ * declaration order and preserves each declaration form's diagnostic. */
24
+ function declaredTypeParameterSymbols(lowerer, parameters, blame, detail) {
25
+ return parameters.map((parameter) => {
26
+ const symbol = lowerer.checker.getSymbolAtLocation(parameter.name);
27
+ if (!symbol)
28
+ lowerer.unsupported("SC1090", blame, detail);
29
+ return symbol;
30
+ });
31
+ }
32
+ /** Pattern parameters are admitted by declarations and value bindings;
33
+ * object-literal generic methods retain their identifier-only boundary. */
34
+ function checkGenericParameterNames(lowerer, parameters, allowPatterns) {
35
+ for (const parameter of parameters) {
36
+ if (!ts.isIdentifier(parameter.name) &&
37
+ !(allowPatterns &&
38
+ (ts.isObjectBindingPattern(parameter.name) || ts.isArrayBindingPattern(parameter.name)))) {
39
+ lowerer.unsupported("SC1031", parameter);
40
+ }
41
+ }
42
+ }
43
+ /** Static generic values must keep their initializer for their lifetime.
44
+ * Merged var declarations count as writes even when the assignment scan
45
+ * cannot see them; const bindings need no whole-file write scan. */
46
+ function requireStableGenericBinding(lowerer, decl, symbol, name) {
47
+ const isConst = (ts.getCombinedNodeFlags(decl) & ts.NodeFlags.Const) !== 0;
48
+ const redeclared = lowerer.checker
49
+ .declarationsOf(symbol)
50
+ .some((d) => d !== decl && ts.isVariableDeclaration(d) && d.initializer !== undefined);
51
+ if (!isConst && (redeclared || !bindingNeverReassigned(lowerer, symbol, decl))) {
52
+ lowerer.unsupported("SC1090", decl.name, `generic function values in reassigned bindings (calls of '${name}' resolve statically against this initializer, so the binding must provably hold it — a const, or a let/var nothing in its declaring file writes)`);
53
+ }
54
+ }
55
+ /** Registers a top-level generic function. Only the SYNTAX is checked
56
+ * here — parameter/return types mention the type parameters and cannot
57
+ * map yet; the body is lowered per instantiation, on demand (an unused
58
+ * generic function requires no body lowering). Called inside
59
+ * collectSignature's poison catch. */
60
+ export function collectGenericSignature(lowerer, decl) {
61
+ const typeParams = declaredTypeParameterSymbols(lowerer, decl.typeParameters, decl, "this function form");
62
+ checkGenericParameterNames(lowerer, decl.parameters, true);
63
+ const nameText = decl.name?.text ?? "%default"; // nameless = the default export (checked by collectSignatureInner)
64
+ const symbol = declSymbolOf(lowerer, decl);
65
+ if (!symbol)
66
+ lowerer.unsupported("SC1090", decl, "this function form");
67
+ lowerer.genericFnsBySymbol.set(symbol, {
68
+ decl,
69
+ baseName: nameText,
70
+ qualifiedName: lowerer.qualify(decl.getSourceFile(), nsPathPrefix(decl) + nameText),
71
+ typeParams,
72
+ instances: new Map(),
73
+ });
74
+ }
75
+ export function genericFnOf(lowerer, ident) {
76
+ const symbol = lowerer.resolveValueSymbol(ident);
77
+ return symbol ? (lowerer.genericFnsBySymbol.get(symbol) ?? null) : null;
78
+ }
79
+ /** Call of a generic top-level function. The checker already inferred (or
80
+ * was told, via explicit type arguments) the concrete signature —
81
+ * getResolvedSignature returns it with type arguments substituted. The
82
+ * mapped param+return IR types form the INSTANTIATION KEY; the first call
83
+ * with a new key queues the body for monomorphic lowering as
84
+ * `<qualifiedName>%<n>`, and every call lowers to a direct `call` of that
85
+ * instance. */
86
+ export function lowerGenericCall(lowerer, expr, info) {
87
+ const loc = locOf(expr);
88
+ const instance = info.implicitParams
89
+ ? implicitCallInstance(lowerer, expr, info)
90
+ : genericCallInstance(lowerer, expr, info);
91
+ const args = lowerer.completeArgs(expr.arguments, instance.params, loc, expr);
92
+ return { kind: "call", callee: instance.name, args, type: instance.returnType, loc };
93
+ }
94
+ /** The instance a CALL of a generic function-like names: resolved
95
+ * signature → mapped param shapes/return → interned instance. Shared by
96
+ * top-level generic calls, class generic-method calls (the caller
97
+ * prepends the receiver), and object-literal generic-method calls. */
98
+ export function genericCallInstance(lowerer, expr, info) {
99
+ const rsig = lowerer.checker.getResolvedSignature(expr);
100
+ // A GENERIC function with overload signatures: the call resolved to a
101
+ // signature that is not the implementation's, so the per-instantiation
102
+ // body lowering would type the body against parameter/return types it
103
+ // was never checked under. Named fence until generic overloads get an
104
+ // honest story (monomorphize per implementation signature with the
105
+ // reconcile bridge, like the non-generic path).
106
+ {
107
+ const rdecl = rsig ? lowerer.checker.signatureDeclaration(rsig) : undefined;
108
+ if (rdecl &&
109
+ (ts.isFunctionDeclaration(rdecl) || ts.isMethodDeclaration(rdecl)) &&
110
+ !rdecl.body) {
111
+ lowerer.unsupported("SC1090", expr, `calls selecting an overload signature of a generic ${ts.isMethodDeclaration(rdecl) ? "method" : "function"} (only the implementation signature monomorphizes)`);
112
+ }
113
+ }
114
+ if (!rsig || rsig.getParameters().length !== info.decl.parameters.length) {
115
+ lowerer.unsupported("SC1090", expr, "this call form");
116
+ }
117
+ // Per-param shapes from the RESOLVED signature (types substituted) plus
118
+ // the declaration's modes: rest stays the resolved array, a default's
119
+ // ABI union is synthesized over the resolved body type — exactly the
120
+ // paramShape rules, applied to post-substitution types.
121
+ const params = paramShapes(lowerer, info.decl.parameters, rsig, (_param, i) => expr.arguments[i] ?? expr);
122
+ const retTs = lowerer.checker.getReturnTypeOfSignature(rsig);
123
+ const returnType = lowerer.mapTypeOf(retTs);
124
+ if (!returnType) {
125
+ fenceGenericSignatureResult(lowerer, expr, retTs);
126
+ lowerer.badType(expr, retTs);
127
+ }
128
+ // keyof-constrained type parameters (`K extends keyof T`): the bound
129
+ // LITERAL is semantic — the instance body reads the named field — so
130
+ // the bindings compute EAGERLY (the key needs them) and each literal
131
+ // keys its own instance (`pick(o, "a")` and `pick(o, "b")` map to the
132
+ // same IR signature when the fields agree, but their bodies read
133
+ // different fields). Non-literal bindings (a key union, plain string)
134
+ // share one runtime-keyed instance per IR signature, exactly the
135
+ // widened discipline.
136
+ const keyofTps = keyofConstrainedTypeParams(info);
137
+ if (keyofTps.size > 0) {
138
+ const tsBindings = new Map();
139
+ const bindings = lowerer.inferTypeParamBindings(expr, info, rsig, tsBindings);
140
+ const litKey = info.typeParams
141
+ .filter((tp) => keyofTps.has(tp))
142
+ .map((tp) => {
143
+ const bound = tsBindings.get(tp);
144
+ return bound?.isStringLiteralType()
145
+ ? JSON.stringify(bound.value)
146
+ : bound?.isNumberLiteralType()
147
+ ? String(bound.value)
148
+ : "*";
149
+ })
150
+ .join(",");
151
+ return internGenericInstance(lowerer, expr, info, params, returnType, () => bindings, {
152
+ extraKey: `@${litKey}`,
153
+ tsBindings,
154
+ });
155
+ }
156
+ return internGenericInstance(lowerer, expr, info, params, returnType, (tsBindings) => lowerer.inferTypeParamBindings(expr, info, rsig, tsBindings));
157
+ }
158
+ /** The one instance table both instantiation routes share: key identity IS
159
+ * signature identity, so a call (`identity(1)`) and a pinned VALUE
160
+ * (`const f: (x: number) => number = identity`) reuse one compiled
161
+ * instance. `makeBindings` runs only for a NEW key (binding inference
162
+ * costs checker walks). */
163
+ function internGenericInstance(lowerer, blame, info, params, returnType, makeBindings, opts) {
164
+ // keyof-constrained instantiations append their literal keys
165
+ // (extraKey): the IR signature alone under-discriminates there — two
166
+ // literals can map to one IR signature while their bodies read
167
+ // different fields.
168
+ const key = `${params.map((s) => typeKey(s.type)).join(",")}=>${typeKey(returnType)}${opts?.extraKey ?? ""}`;
169
+ let inst = info.instances.get(key);
170
+ if (!inst) {
171
+ if (info.instances.size >= MAX_GENERIC_INSTANCES) {
172
+ lowerer.unsupported("SC1090", blame, `unbounded generic instantiation ('${info.baseName}' exceeded ` +
173
+ `${MAX_GENERIC_INSTANCES} instances — polymorphic recursion?)`);
174
+ }
175
+ const tsBindings = opts?.tsBindings ?? new Map();
176
+ const bindings = makeBindings(tsBindings);
177
+ const rendered = info.typeParams
178
+ .map((tp) => {
179
+ // A literal-bound keyof parameter renders its literal — the
180
+ // instance is per-literal, and '<…, string>' would misname it.
181
+ const tsBound = tsBindings.get(tp);
182
+ if (info.keyofTps?.has(tp) && tsBound?.isStringLiteralType()) {
183
+ return JSON.stringify(tsBound.value);
184
+ }
185
+ const bound = bindings.get(tp);
186
+ return bound ? lowerer.fmt(bound) : tp.name;
187
+ })
188
+ .join(", ");
189
+ // Deep polymorphic recursion renders unbounded types — keep messages sane.
190
+ const typeArgsText = `<${rendered.length > 80 ? rendered.slice(0, 77) + "..." : rendered}>`;
191
+ inst = {
192
+ name: `${info.qualifiedName}%${info.instances.size}`,
193
+ ordinal: info.instances.size,
194
+ params,
195
+ returnType,
196
+ bindings,
197
+ tsBindings,
198
+ typeArgsText,
199
+ };
200
+ info.instances.set(key, inst);
201
+ lowerer.instantiationQueue.push({ info, inst });
202
+ }
203
+ lowerer.noteGenericInstanceDemand(inst);
204
+ return inst;
205
+ }
206
+ /** The type parameters of `info` declared with a `keyof` CONSTRAINT
207
+ * (`K extends keyof T`) — the parameters whose bound literal is semantic
208
+ * (the body's `o[k]` reads the named field), computed once per info from
209
+ * the declaration's syntax. */
210
+ function keyofConstrainedTypeParams(info) {
211
+ if (info.keyofTps)
212
+ return info.keyofTps;
213
+ const out = new Set();
214
+ info.decl.typeParameters?.forEach((tpDecl, i) => {
215
+ const sym = info.typeParams[i];
216
+ if (!sym || tpDecl.constraint === undefined)
217
+ return;
218
+ if (ts.isTypeOperatorNode(tpDecl.constraint) &&
219
+ tpDecl.constraint.operator === ts.SyntaxKind.KeyOfKeyword) {
220
+ out.add(sym);
221
+ }
222
+ });
223
+ info.keyofTps = out;
224
+ return out;
225
+ }
226
+ /** Type-parameter symbol → concrete IR type for one instantiation.
227
+ * Explicit type arguments bind directly; the rest come from structurally
228
+ * matching each DECLARED param/return type (which mentions the type
229
+ * parameters) against the checker's INSTANTIATED one — the latter is the
230
+ * former with the substitution applied, so the shapes are parallel by
231
+ * construction. A type parameter left unbound only matters if the body
232
+ * mentions it, where mapType fails and badType names the shape
233
+ * (carrying the instantiation context). */
234
+ export function inferTypeParamBindings(lowerer, expr, info, rsig, tsBindings) {
235
+ const bindings = new Map();
236
+ expr.typeArguments?.forEach((ta, i) => {
237
+ const tp = info.typeParams[i];
238
+ if (!tp)
239
+ return;
240
+ const taT = lowerer.checker.getTypeFromTypeNode(ta);
241
+ const mapped = lowerer.mapTypeOf(taT);
242
+ if (mapped) {
243
+ bindings.set(tp, mapped);
244
+ tsBindings?.set(tp, taT);
245
+ }
246
+ });
247
+ unifySignatureBindings(lowerer, info, rsig, bindings, tsBindings);
248
+ bindDefaultTypeParams(lowerer, info.typeParams, info.decl.typeParameters, bindings, tsBindings);
249
+ return bindings;
250
+ }
251
+ /** Type parameters still unbound after unification take their declared
252
+ * DEFAULT (`<T = number>`), mapped — the checker already substituted the
253
+ * default into every resolved signature, so this only fills the bindings
254
+ * an instance body's mapType consults. */
255
+ function bindDefaultTypeParams(lowerer, typeParams, typeParamDecls, bindings, tsBindings) {
256
+ typeParamDecls?.forEach((tpDecl, i) => {
257
+ const tp = typeParams[i];
258
+ if (!tp || bindings.has(tp) || !tpDecl.defaultType)
259
+ return;
260
+ const defT = lowerer.checker.getTypeFromTypeNode(tpDecl.defaultType);
261
+ const mapped = lowerer.mapTypeOf(defT);
262
+ if (mapped) {
263
+ bindings.set(tp, mapped);
264
+ tsBindings?.set(tp, defT);
265
+ }
266
+ });
267
+ }
268
+ /** The structural half of binding inference: unify the DECLARED signature
269
+ * (whose types mention the type parameters) against a TARGET signature
270
+ * with the substitution applied — a call's resolved signature, or the
271
+ * completed signature a VALUE reference is pinned to (the contextual
272
+ * type's one call signature). Mutates `bindings`; already-bound
273
+ * parameters (explicit type arguments) win. */
274
+ function unifySignatureBindings(lowerer, info, rsig, bindings, tsBindings) {
275
+ const tpSet = new Set(info.typeParams);
276
+ const seen = new Set(); // recursive declared types must not loop
277
+ // The identity-keyed set cannot catch LAZILY INFINITE anonymous types
278
+ // (`function rec<T>(x: T) { return { deeper: <U>(y: U) => rec<[T, U]>(...) }; }`
279
+ // — every property/signature walk instantiates FRESH type objects, and
280
+ // no Reference target exists to shortcut on), so a depth cap bounds the
281
+ // walk. Stopping only stops INFERENCE: a type parameter left unbound
282
+ // surfaces as an ordinary mapping diagnostic later, never a wrong
283
+ // binding — and every practical signature binds its parameters within
284
+ // a few levels.
285
+ const MAX_UNIFY_DEPTH = 24;
286
+ const unify = (declared, inst, depth = 0) => {
287
+ if (depth > MAX_UNIFY_DEPTH)
288
+ return;
289
+ if (declared.flags & ts.TypeFlags.TypeParameter) {
290
+ const sym = declared.getSymbol();
291
+ if (sym && tpSet.has(sym)) {
292
+ // The checker type records even when an explicit type argument
293
+ // already bound the IrType: the raw type is the SAME binding
294
+ // pre-widening, and first-hit-wins keeps the two maps parallel.
295
+ // A generic body FORWARDING its own parameter (`pluck`'s
296
+ // `pick(it, key)` binds pick's K to pluck's K) resolves through
297
+ // the enclosing instantiation's ts bindings first — the literal
298
+ // carries through the chain.
299
+ if (tsBindings && !tsBindings.has(sym)) {
300
+ tsBindings.set(sym, lowerer.typeParamTsResolver(inst) ?? inst);
301
+ }
302
+ if (!bindings.has(sym)) {
303
+ const mapped = lowerer.mapTypeOf(inst);
304
+ // A visitor's inferred T can be void. It still binds the
305
+ // return convention of `(node) => T`; discarding it leaves
306
+ // the callback's return type spuriously uninstantiated.
307
+ if (mapped)
308
+ bindings.set(sym, mapped);
309
+ }
310
+ }
311
+ return;
312
+ }
313
+ if (seen.has(declared))
314
+ return;
315
+ seen.add(declared);
316
+ // Optional-flavored unions (`x?: T` declares `T | undefined`): strip
317
+ // the unit parts from both sides and unify the lone remaining pair.
318
+ // Multi-part unions have no positional correspondence — skipped (an
319
+ // unbound type parameter surfaces as a mapping diagnostic later).
320
+ if (declared.isUnionType()) {
321
+ const unitFlags = ts.TypeFlags.Undefined | ts.TypeFlags.Null;
322
+ const declaredParts = ts.constituentTypes(declared);
323
+ const declaredUnits = declaredParts.reduce((flags, t) => flags | (t.flags & unitFlags), 0);
324
+ const dParts = declaredParts.filter((t) => !(t.flags & unitFlags));
325
+ const iParts = inst.isUnionType()
326
+ ? ts.constituentTypes(inst).filter((t) => !(t.flags & declaredUnits))
327
+ : [inst];
328
+ if (dParts.length === 1 && iParts.length === 1)
329
+ unify(dParts[0], iParts[0], depth + 1);
330
+ else if (dParts.length === 1 &&
331
+ iParts.length > 1 &&
332
+ iParts.every((t) => (t.flags & unitFlags) === 0)) {
333
+ // T | undefined can receive boolean | undefined: boolean itself
334
+ // has two literal arms. There is still one declared data slot,
335
+ // so match it against the whole remaining union. Removing null
336
+ // too is safe only when no undeclared null arm remains.
337
+ unify(dParts[0], lowerer.checker.getNonNullableType(inst), depth + 1);
338
+ }
339
+ return;
340
+ }
341
+ // Instantiations of the SAME generic ALIAS (Partial<T> vs
342
+ // Partial<Config>) unify by alias arguments: instantiation preserves
343
+ // aliasSymbol/aliasTypeArguments, and the two argument lists are
344
+ // parallel by construction. Without this, a mapped-type parameter
345
+ // leaves T unbound — the declared `Partial<T>` has no resolvable
346
+ // members for the property walk below (keyof T is unknown).
347
+ const dAlias = declared.getAliasSymbol();
348
+ const dAliasArgs = declared.getAliasTypeArguments();
349
+ const iAliasArgs = inst.getAliasTypeArguments();
350
+ if (dAlias &&
351
+ dAlias === inst.getAliasSymbol() &&
352
+ dAliasArgs.length &&
353
+ iAliasArgs.length === dAliasArgs.length) {
354
+ dAliasArgs.forEach((da, i) => {
355
+ const ia = iAliasArgs[i];
356
+ if (ia)
357
+ unify(da, ia, depth + 1);
358
+ });
359
+ return;
360
+ }
361
+ // References to the SAME generic (Promise<T> vs Promise<string>, or
362
+ // any interface reference) unify by type ARGUMENTS only. Walking
363
+ // members instead diverges: a self-referential member like Promise's
364
+ // `then<U>(...): Promise<U>` instantiates a FRESH type object on
365
+ // every property read, so an identity-keyed visited set never trips.
366
+ const dRef = declared;
367
+ const iRef = inst;
368
+ if (declared.flags & ts.TypeFlags.Object &&
369
+ inst.flags & ts.TypeFlags.Object &&
370
+ declared.objectFlags & ts.ObjectFlags.Reference &&
371
+ inst.objectFlags & ts.ObjectFlags.Reference &&
372
+ dRef.getTarget() === iRef.getTarget()) {
373
+ const dArgs = lowerer.checker.getTypeArguments(dRef);
374
+ const iArgs = lowerer.checker.getTypeArguments(iRef);
375
+ dArgs.forEach((da, i) => {
376
+ const ia = iArgs[i];
377
+ if (ia)
378
+ unify(da, ia, depth + 1);
379
+ });
380
+ return;
381
+ }
382
+ if (lowerer.checker.isArrayType(declared) && lowerer.checker.isArrayType(inst)) {
383
+ const dElem = lowerer.checker.getTypeArguments(declared)[0];
384
+ const iElem = lowerer.checker.getTypeArguments(inst)[0];
385
+ if (dElem && iElem)
386
+ unify(dElem, iElem, depth + 1);
387
+ return;
388
+ }
389
+ const dSigs = lowerer.checker.getCallSignatures(declared);
390
+ const iSigs = lowerer.checker.getCallSignatures(inst);
391
+ if (dSigs.length === 1 && iSigs.length === 1) {
392
+ const ds = dSigs[0];
393
+ const is = iSigs[0];
394
+ const instanceParams = is.getParameters();
395
+ ds.getParameters().forEach((dp, i) => {
396
+ const ip = instanceParams[i];
397
+ if (ip)
398
+ unify(lowerer.checker.getTypeOfSymbol(dp), lowerer.checker.getTypeOfSymbol(ip), depth + 1);
399
+ });
400
+ unify(lowerer.checker.getReturnTypeOfSignature(ds), lowerer.checker.getReturnTypeOfSignature(is), depth + 1);
401
+ return;
402
+ }
403
+ if (declared.flags & ts.TypeFlags.Object) {
404
+ for (const dp of lowerer.checker.getPropertiesOfType(declared)) {
405
+ const ip = lowerer.checker.getPropertyOfType(inst, dp.name);
406
+ if (ip)
407
+ unify(lowerer.checker.getTypeOfSymbol(dp), lowerer.checker.getTypeOfSymbol(ip), depth + 1);
408
+ }
409
+ }
410
+ };
411
+ const declSig = lowerer.checker.getSignatureFromDeclaration(info.decl);
412
+ if (declSig) {
413
+ const instanceParams = rsig.getParameters();
414
+ declSig.getParameters().forEach((dp, i) => {
415
+ const ip = instanceParams[i];
416
+ if (ip)
417
+ unify(lowerer.checker.getTypeOfSymbol(dp), lowerer.checker.getTypeOfSymbol(ip));
418
+ });
419
+ unify(lowerer.checker.getReturnTypeOfSignature(declSig), lowerer.checker.getReturnTypeOfSignature(rsig));
420
+ }
421
+ }
422
+ /** Lowers ONE monomorphic instance of a generic function: the same body
423
+ * AST, re-lowered with the type parameters bound (threaded into every
424
+ * mapType call via typeParamResolver — the checker keeps reporting the
425
+ * unsubstituted `T`s inside the body). Coverage stats count a base
426
+ * function's statements once: only the FIRST instance contributes. */
427
+ export function lowerGenericInstance(lowerer, info, inst) {
428
+ const decl = info.decl;
429
+ const cls = info.member?.cls ?? null;
430
+ const prevBindings = lowerer.typeParamBindings;
431
+ const prevContext = lowerer.instantiationContext;
432
+ const prevSuppress = lowerer.suppressStats;
433
+ const prevClass = lowerer.currentClass;
434
+ const prevImplicit = lowerer.implicitParamTypes;
435
+ // A generic METHOD of a generic-class INSTANTIATION lowers under BOTH
436
+ // binding sets: the receiver instantiation's class type parameters
437
+ // underneath, the method instantiation's own on top (disjoint symbol
438
+ // sets — tsc rejects shadowing a class type parameter in a method).
439
+ const clsBindings = cls?.genericInstance?.bindings;
440
+ lowerer.typeParamBindings = clsBindings
441
+ ? new Map([...clsBindings, ...inst.bindings])
442
+ : inst.bindings;
443
+ // The ts-level bindings ride along: `T[K]` and literal-keyed `o[k]`
444
+ // reads inside the body resolve through the bound CHECKER types
445
+ // (typeParamTsResolver). Generic-class instantiations carry no
446
+ // ts-level bindings (their type arguments widened at the reference),
447
+ // so only the method instantiation's own map installs.
448
+ const prevTsBindings = lowerer.typeParamTsBindings;
449
+ lowerer.typeParamTsBindings = inst.tsBindings ?? null;
450
+ // Implicit-any instances thread their param bindings through typeOf
451
+ // (the checker reports `any` inside the body — there is no T for
452
+ // mapType to substitute); see the implicit-monomorphization section.
453
+ lowerer.implicitParamTypes =
454
+ info.implicitParams !== undefined ? (inst.implicitArgTypes ?? new Map()) : null;
455
+ lowerer.instantiationContext = `instantiating '${info.baseName}' with ${inst.typeArgsText}`;
456
+ // Coverage counts a generic source body once: re-instantiations of the
457
+ // method AND re-instantiations of the declaring generic class re-visit
458
+ // the same source lines.
459
+ lowerer.suppressStats = inst.ordinal > 0 || (cls?.genericInstance?.ordinal ?? 0) > 0;
460
+ // A generic ASYNC instance is an async IrFunction like any other: the
461
+ // body returns the resolved promise's INNER type, calls enter through
462
+ // the instance's own spawn wrapper (the emitter routes by fn.async),
463
+ // and awaits park this instance's fibers.
464
+ const isAsync = decl.modifiers?.some((m) => m.kind === ts.SyntaxKind.AsyncKeyword) === true;
465
+ const nameBlame = (ts.isArrowFunction(decl) ? undefined : decl.name) ?? decl;
466
+ const isGenerator = decl.asteriskToken !== undefined;
467
+ if (isAsync && !isGenerator && inst.returnType.kind !== "promise") {
468
+ lowerer.badType(nameBlame, lowerer.checker.getTypeAtLocation(nameBlame));
469
+ }
470
+ // A generic GENERATOR instance mirrors async: the body returns the
471
+ // resolved TReturn channel, calls enter through the instance's own
472
+ // gen-spawn wrapper (the emitter routes by fn.generator).
473
+ if (isGenerator &&
474
+ (inst.returnType.kind !== "generator" || (inst.returnType.async === true) !== isAsync)) {
475
+ lowerer.badType(nameBlame, lowerer.checker.getTypeAtLocation(nameBlame));
476
+ }
477
+ let bodyReturn = isGenerator
478
+ ? lowerer.genBodyReturnType(inst.returnType)
479
+ : lowerer.bodyReturnType(isAsync, inst.returnType);
480
+ const fnCtx = newFnCtx(false, null, null, bodyReturn);
481
+ fnCtx.isAsync = isAsync;
482
+ // Implicit-any instances whose declared return did not map lower in
483
+ // return-INFERENCE mode: `return` statements record here bare, and the
484
+ // post-pass (resolveInferredReturn) settles the type and wraps them.
485
+ if (inst.implicitInferReturn)
486
+ fnCtx.inferReturn = { entries: [] };
487
+ if (cls && info.member.kind === "method")
488
+ lowerer.currentClass = cls;
489
+ if (isGenerator && inst.returnType.kind === "generator") {
490
+ fnCtx.generator = generatorMeta(lowerer, inst.returnType);
491
+ }
492
+ lowerer.fnStack.push(fnCtx);
493
+ lowerer.localClassInstantiations.push({ owner: decl, name: inst.name });
494
+ try {
495
+ // Static specializations bind lexical this only when the caller
496
+ // proved its exact receiver. Other instances retain the fence;
497
+ // super remains unsupported. Arrows inherit the lexical receiver.
498
+ if (info.member?.kind === "static" && decl.body) {
499
+ rejectStaticThis(lowerer, decl.body, (keyword) => `'${keyword}' in static methods (it names the RECEIVER class — a dynamic value; reference the class by name instead)`, false, info.staticReceiver !== undefined);
500
+ }
501
+ const params = [];
502
+ const receiverInit = [];
503
+ if (info.staticReceiver) {
504
+ const value = lowerer.classValueRef(info.staticReceiver, decl);
505
+ const local = lowerer.declareThis(value.type);
506
+ receiverInit.push({ kind: "varDecl", localId: local.id, init: value, loc: locOf(decl) });
507
+ }
508
+ if (cls && info.member.kind === "method") {
509
+ // Instance methods take `this` as param 0, exactly like plain
510
+ // `%C.method` functions (lowerClassMethodMemberInner).
511
+ const thisType = { kind: "object", className: cls.def.name };
512
+ const thisLocal = lowerer.declareThis(thisType);
513
+ params.push({ localId: thisLocal.id, name: "this", type: thisType });
514
+ }
515
+ // Default-param initializers lower per instance, with the bindings
516
+ // threaded — a default mentioning T resolves like any body expression.
517
+ const declared = lowerer.declareParams(decl.parameters, inst.params);
518
+ params.push(...declared.params);
519
+ const body = [...receiverInit, ...declared.prologue];
520
+ const bodyBlock = blockBodyOf(decl);
521
+ if (bodyBlock) {
522
+ body.push(...lowerer.lowerStmts(bodyBlock.statements));
523
+ if (fnCtx.inferReturn) {
524
+ bodyReturn = resolveInferredReturn(lowerer, inst, fnCtx.inferReturn, body, decl);
525
+ inst.returnType = bodyReturn;
526
+ }
527
+ appendImplicitUndefinedReturn(lowerer, body, bodyReturn, locOf(decl));
528
+ }
529
+ else if (ts.isArrowFunction(decl) && decl.body !== undefined && !ts.isBlock(decl.body)) {
530
+ // A concise arrow body: the expression IS the return value —
531
+ // generic properties (`id: <T>(x: T) => x`), and implicit-any
532
+ // local arrows (`(cmd) => [cmd.name()].concat(cmd.aliases())`),
533
+ // whose inferred return is simply the expression's own type.
534
+ if (fnCtx.inferReturn) {
535
+ const value = lowerer.lowerExpr(decl.body);
536
+ if (value.type.kind === "void") {
537
+ body.push({ kind: "exprStmt", expr: value, loc: locOf(decl.body) });
538
+ bodyReturn = resolveInferredReturn(lowerer, inst, fnCtx.inferReturn, body, decl);
539
+ inst.returnType = bodyReturn;
540
+ appendImplicitUndefinedReturn(lowerer, body, bodyReturn, locOf(decl));
541
+ }
542
+ else {
543
+ const stmt = { kind: "return", value, loc: locOf(decl.body) };
544
+ fnCtx.inferReturn.entries.push({ stmt, node: decl.body });
545
+ body.push(stmt);
546
+ bodyReturn = resolveInferredReturn(lowerer, inst, fnCtx.inferReturn, body, decl);
547
+ inst.returnType = bodyReturn;
548
+ }
549
+ }
550
+ else {
551
+ const value = lowerer.lowerExprExpecting(decl.body, bodyReturn);
552
+ if (bodyReturn.kind === "void") {
553
+ body.push({ kind: "exprStmt", expr: value, loc: locOf(decl.body) });
554
+ }
555
+ else {
556
+ body.push({ kind: "return", value, loc: locOf(decl.body) });
557
+ }
558
+ }
559
+ }
560
+ else {
561
+ lowerer.unsupported("SC1090", decl, "function declarations whose block body the frontend cannot locate");
562
+ }
563
+ const fn = {
564
+ name: inst.name,
565
+ sourceName: info.baseName,
566
+ ...(!isAsync &&
567
+ !decl.asteriskToken &&
568
+ (ts.isFunctionDeclaration(decl) || ts.isFunctionExpression(decl))
569
+ ? { ownsPrototype: true }
570
+ : {}),
571
+ params,
572
+ returnType: bodyReturn,
573
+ locals: lowerer.ctx.locals,
574
+ body,
575
+ loc: locOf(decl),
576
+ };
577
+ if (isAsync)
578
+ fn.async = true;
579
+ if (fnCtx.generator)
580
+ fn.generator = fnCtx.generator;
581
+ return fn;
582
+ }
583
+ finally {
584
+ lowerer.fnStack.pop();
585
+ lowerer.currentClass = prevClass;
586
+ lowerer.typeParamBindings = prevBindings;
587
+ lowerer.typeParamTsBindings = prevTsBindings;
588
+ lowerer.implicitParamTypes = prevImplicit;
589
+ lowerer.instantiationContext = prevContext;
590
+ lowerer.localClassInstantiations.pop();
591
+ lowerer.suppressStats = prevSuppress;
592
+ }
593
+ }
594
+ /** A generic function taken as a VALUE, monomorphized by flow. A function
595
+ * value needs ONE concrete signature; tsc pins one at exactly two
596
+ * reference shapes — an instantiation EXPRESSION (`identity<number>`,
597
+ * whose own checker type is the substituted signature) and a reference
598
+ * whose CONTEXTUAL type completes the signature (`const f: (x: number) =>
599
+ * number = identity`, `take(identity)`). The declared signature unifies
600
+ * against the pinned one to recover the bindings; the instance then
601
+ * registers in the SAME table call sites use (one compiled copy per
602
+ * signature however it is reached), and the value is the instance's
603
+ * zero-capture closure — `f === f` holds within an instantiation, the
604
+ * declared-function identity rule. References with no pinning context
605
+ * (the slot keeps `<T>(x: T) => T`) fence by name. */
606
+ export function lowerGenericFnValue(lowerer, ref, info) {
607
+ const loc = locOf(ref);
608
+ // An IMPLICIT-ANY function taken as a VALUE: indirect calls carry no
609
+ // per-site types to bind, so the value is the all-dyn DEFAULT
610
+ // instance's closure — today's compiled body exactly (one interned
611
+ // closure per function, so `f === f` holds like any declaration).
612
+ if (info.implicitParams) {
613
+ const inst = implicitDefaultInstance(lowerer, ref, info);
614
+ const funcType = funcTypeFromParamShapes(inst.params, inst.returnType);
615
+ lowerer.requireExactArityValue(ref, ref, inst.params, funcType);
616
+ lowerer.noteEdge(inst.name);
617
+ return { kind: "closure", fnName: inst.name, captures: [], type: funcType, loc };
618
+ }
619
+ const fenceUnpinned = () => lowerer.unsupported("SC1090", ref, `generic functions as values without a pinned concrete signature (annotate the destination — e.g. 'const f: (x: number) => number = ${info.baseName}' — instantiate explicitly ('${info.baseName}<number>'), or call '${info.baseName}' directly)`);
620
+ // The PINNING type: an instantiation expression's own checker type
621
+ // (explicit type arguments applied), else the reference's contextual
622
+ // type — the slot or argument the value flows into. Namespace/CJS
623
+ // member paths delegate the member NAME here (`lib.tag` hands over
624
+ // `tag`), and the checker hangs the contextual type on the whole
625
+ // property access — hop to it.
626
+ const ctxNode = ref.parent !== undefined && ts.isPropertyAccessExpression(ref.parent) && ref.parent.name === ref
627
+ ? ref.parent
628
+ : ref;
629
+ const pinT = ts.isExpressionWithTypeArguments(ref)
630
+ ? lowerer.typeOf(ref)
631
+ : lowerer.checker.getContextualType(ctxNode);
632
+ let target = null;
633
+ if (pinT) {
634
+ const sigs = lowerer.checker.getCallSignatures(pinT);
635
+ if (sigs.length === 1)
636
+ target = sigs[0];
637
+ else if (sigs.length === 0 && pinT.isUnionType()) {
638
+ // A `Fn | undefined`-flavored slot: the value can only inhabit the
639
+ // one callable arm — judge by it (the requireExactArityValue union
640
+ // rule).
641
+ const callable = ts
642
+ .constituentTypes(pinT)
643
+ .map((t) => lowerer.checker.getCallSignatures(t))
644
+ .filter((s) => s.length === 1);
645
+ if (callable.length === 1)
646
+ target = callable[0][0];
647
+ }
648
+ }
649
+ if (!target)
650
+ fenceUnpinned();
651
+ const bindings = new Map();
652
+ unifySignatureBindings(lowerer, info, target, bindings);
653
+ const hofBinding = runtimeOptionalHofGenericBinding(lowerer, ref, info);
654
+ if (hofBinding)
655
+ bindings.set(hofBinding.typeParam, hofBinding.type);
656
+ bindDefaultTypeParams(lowerer, info.typeParams, info.decl.typeParameters, bindings);
657
+ // A pinning signature that itself keeps type parameters (`let g: <T>(x:
658
+ // T) => T = identity` — storing the generic signature as such) binds
659
+ // nothing: mapType answers null for an unsubstituted parameter.
660
+ if (info.typeParams.some((tp) => !bindings.get(tp)))
661
+ fenceUnpinned();
662
+ const inst = genericValueInstance(lowerer, ref, info, bindings);
663
+ // The value's type is the completed ABI signature. Typed rest keeps its
664
+ // packed-array slot; dynRest stays hidden behind the rest marker.
665
+ const funcType = funcTypeFromParamShapes(inst.params, inst.returnType);
666
+ lowerer.requireExactArityValue(ref, ref, inst.params, funcType);
667
+ lowerer.noteEdge(inst.name);
668
+ return { kind: "closure", fnName: inst.name, captures: [], type: funcType, loc };
669
+ }
670
+ function runtimeOptionalHofGenericBinding(lowerer, ref, info) {
671
+ let argument = ref;
672
+ while (argument.parent && ts.isParenthesizedExpression(argument.parent))
673
+ argument = argument.parent;
674
+ const call = argument.parent;
675
+ if (!ts.isCallExpression(call) || call.arguments[0] !== argument)
676
+ return null;
677
+ if (!ts.isPropertyAccessExpression(call.expression) || call.expression.name.text !== "map")
678
+ return null;
679
+ if (!lowerer.isStdlibMember(call.expression))
680
+ return null;
681
+ const receiver = lowerer.mapTypeOf(lowerer.typeOf(call.expression.expression));
682
+ if (receiver?.kind !== "array")
683
+ return null;
684
+ const parameter = info.decl.parameters[0];
685
+ if (!parameter || !ts.isIdentifier(parameter.name))
686
+ return null;
687
+ const parameterType = lowerer.typeOf(parameter.name);
688
+ if ((parameterType.flags & ts.TypeFlags.TypeParameter) === 0)
689
+ return null;
690
+ const typeParam = parameterType.getSymbol();
691
+ if (!typeParam || !info.typeParams.includes(typeParam))
692
+ return null;
693
+ return { typeParam, type: lowerer.runtimeOptionalType(receiver.elem) };
694
+ }
695
+ /** The instance a pinned VALUE reference names: the declaration's modes
696
+ * over the DECLARED types mapped under the bindings (mapType's resolver
697
+ * substitutes — the instance-body trick), which is the same result the
698
+ * call path computes from the resolved signature, so both routes land on
699
+ * one instance per key. */
700
+ function genericValueInstance(lowerer, ref, info, bindings) {
701
+ const prevBindings = lowerer.typeParamBindings;
702
+ const prevContext = lowerer.instantiationContext;
703
+ const rendered = info.typeParams
704
+ .map((tp) => {
705
+ const bound = bindings.get(tp);
706
+ return bound ? lowerer.fmt(bound) : tp.name;
707
+ })
708
+ .join(", ");
709
+ lowerer.typeParamBindings = bindings;
710
+ lowerer.instantiationContext = `instantiating '${info.baseName}' with <${rendered.length > 80 ? rendered.slice(0, 77) + "..." : rendered}>`;
711
+ try {
712
+ const declSig = lowerer.checker.getSignatureFromDeclaration(info.decl);
713
+ if (!declSig)
714
+ lowerer.unsupported("SC1090", ref, "this function form");
715
+ const params = paramShapes(lowerer, info.decl.parameters, declSig);
716
+ const retTs = lowerer.checker.getReturnTypeOfSignature(declSig);
717
+ const returnType = lowerer.mapTypeOf(retTs);
718
+ if (!returnType) {
719
+ fenceGenericSignatureResult(lowerer, ref, retTs);
720
+ lowerer.badType(ref, retTs);
721
+ }
722
+ return internGenericInstance(lowerer, ref, info, params, returnType, () => bindings);
723
+ }
724
+ finally {
725
+ lowerer.typeParamBindings = prevBindings;
726
+ lowerer.instantiationContext = prevContext;
727
+ }
728
+ }
729
+ /* ── implicit-any monomorphization (npm-static JS) ─────────────────────
730
+ *
731
+ * A JS function whose signature carries UNTYPED parameters is, morally, a
732
+ * generic function: the author wrote it for whatever the call sites pass.
733
+ * Inside an opted-in npm-static package the frontend treats each bindable
734
+ * implicit-any parameter as an implicit TYPE parameter and instantiates
735
+ * the body per call site over the WIDENED checker types of the arguments —
736
+ * the generic-binding machinery verbatim, with two twists:
737
+ *
738
+ * 1. The checker reports `any` INSIDE the body (there is no `T` for
739
+ * mapType to substitute), so the binding threads through the
740
+ * Lowerer's typeOf instead: an identifier reference to a bound param
741
+ * whose checker answer is still `any` answers the bound ts.Type, and
742
+ * every receiver-typed lowering downstream (field targets, method
743
+ * dispatch, narrowing) sees the concrete type. Where tsc's own
744
+ * flow analysis DID narrow the `any` (typeof/instanceof guards), a
745
+ * narrow CONSISTENT with the binding wins (it is the binding, or an
746
+ * arm of it); a contradicting narrow — the statically-dead branch of
747
+ * a typeof dispatch this instantiation cannot take — answers the
748
+ * bound type, so dead branches fence honestly instead of lowering
749
+ * the live value under a lying type.
750
+ * 2. The instance's RETURN type cannot come from the checker when the
751
+ * params poisoned it to `any`: instances lower EAGERLY at first
752
+ * demand (nested body lowering, the lambda discipline) and infer the
753
+ * return from the lowered return statements; same-key recursion
754
+ * observes the checker-fallback type ("pinned") and the post-pass
755
+ * coerces every return to the settled type — per-return fences where
756
+ * a value cannot ride it. Bounded: MAX_GENERIC_INSTANCES per
757
+ * function, the polymorphic-recursion cap.
758
+ *
759
+ * Bindings are SOUND by construction: the bound type is the argument's own
760
+ * checker type at the call site (never a guess), a param the body ever
761
+ * WRITES is not bindable (it stays checked-dynamic — `options = options
762
+ * || {}` keeps today's story), and an argument whose type does not map
763
+ * statically binds the checked-dynamic DYN — the all-dyn instance IS
764
+ * today's compiled body, so nothing regresses where nothing binds. */
765
+ /** The npm-static gate: implicit-any monomorphization applies to functions
766
+ * DECLARED in an opted-in package's JS files (user JS keeps today's
767
+ * checked-dynamic story until the corpus is re-baselined). */
768
+ export function implicitMonoFile(sf) {
769
+ return isJsSourceFile(sf) && npmStaticPackageOfPath(sf.fileName) !== null;
770
+ }
771
+ /** True when the body (or a nested function capturing it) ever WRITES the
772
+ * parameter symbol — assignment, compound assignment, ++/--, a
773
+ * destructuring-assignment target, or a for-in/of cursor. A written
774
+ * param's binding could lie after the write, so it stays dyn. */
775
+ function paramWrittenInBody(lowerer, body, sym, name) {
776
+ let written = false;
777
+ const targetsSym = (e) => {
778
+ let n = e;
779
+ while (ts.isParenthesizedExpression(n))
780
+ n = n.expression;
781
+ if (ts.isIdentifier(n) && n.text === name) {
782
+ return lowerer.checker.getSymbolAtLocation(n) === sym;
783
+ }
784
+ // Destructuring-assignment patterns ([a] = xs, {a} = o): any
785
+ // identifier inside the target literal counts (conservative — a
786
+ // nested `a.b` member write through the pattern is a write THROUGH,
787
+ // not a rebind, but patterns are rare enough to over-approximate).
788
+ if (ts.isArrayLiteralExpression(n) || ts.isObjectLiteralExpression(n)) {
789
+ let hit = false;
790
+ const scan = (m) => {
791
+ if (hit)
792
+ return;
793
+ if (ts.isIdentifier(m) &&
794
+ m.text === name &&
795
+ lowerer.checker.getSymbolAtLocation(m) === sym) {
796
+ hit = true;
797
+ return;
798
+ }
799
+ m.forEachChild(scan);
800
+ };
801
+ scan(n);
802
+ return hit;
803
+ }
804
+ return false;
805
+ };
806
+ const walk = (n) => {
807
+ if (written)
808
+ return;
809
+ if (ts.isBinaryExpression(n)) {
810
+ const k = n.operatorToken.kind;
811
+ const isAssign = k >= ts.SyntaxKind.FirstAssignment && k <= ts.SyntaxKind.LastAssignment;
812
+ if (isAssign && targetsSym(n.left)) {
813
+ written = true;
814
+ return;
815
+ }
816
+ }
817
+ if ((ts.isPrefixUnaryExpression(n) || ts.isPostfixUnaryExpression(n)) &&
818
+ (n.operator === ts.SyntaxKind.PlusPlusToken ||
819
+ n.operator === ts.SyntaxKind.MinusMinusToken) &&
820
+ targetsSym(n.operand)) {
821
+ written = true;
822
+ return;
823
+ }
824
+ if ((ts.isForInStatement(n) || ts.isForOfStatement(n)) &&
825
+ !ts.isVariableDeclarationList(n.initializer) &&
826
+ ts.isExpression(n.initializer) &&
827
+ targetsSym(n.initializer)) {
828
+ written = true;
829
+ return;
830
+ }
831
+ n.forEachChild(walk);
832
+ };
833
+ walk(body);
834
+ return written;
835
+ }
836
+ function broadPromiseParam(lowerer, type) {
837
+ const mapped = lowerer.mapTypeOf(type);
838
+ const arms = mapped?.kind === "union"
839
+ ? lowerer.unions.get(mapped.unionId)?.arms
840
+ : mapped === null
841
+ ? undefined
842
+ : [mapped];
843
+ return (!!arms &&
844
+ arms.some((arm) => arm.kind === "promise" && arm.inner.kind === "dyn") &&
845
+ arms.every((arm) => isUnitType(arm) || (arm.kind === "promise" && arm.inner.kind === "dyn")));
846
+ }
847
+ /** The implicit-type-parameter slots of a JS function-like: parallel to
848
+ * decl.parameters, the param SYMBOL where the slot is a bindable
849
+ * implicit param (identifier-named, broad inferred/JSDoc type, not
850
+ * rest/optional/defaulted, never written), null elsewhere. Package JS
851
+ * methods may also specialize class parameters: JSDoc names a nominal
852
+ * class even when the body accepts other objects with the same members.
853
+ * Null overall when nothing qualifies — the declaration keeps its ABI. */
854
+ export function implicitAnyParamSymbolsOf(lowerer, decl, classParams = false) {
855
+ if (!decl.body)
856
+ return null;
857
+ if (decl.asteriskToken)
858
+ return null;
859
+ if (decl.modifiers?.some((m) => m.kind === ts.SyntaxKind.AsyncKeyword))
860
+ return null;
861
+ if (decl.typeParameters !== undefined)
862
+ return null; // real generics own the machinery
863
+ if (decl.parameters.length === 0)
864
+ return null;
865
+ // The variadic-`arguments` form keeps its dynRest story whole.
866
+ if (bodyReadsArguments(decl))
867
+ return null;
868
+ let hasImplicitParams = false;
869
+ const out = decl.parameters.map((param) => {
870
+ if (!ts.isIdentifier(param.name))
871
+ return null;
872
+ if (param.dotDotDotToken || param.questionToken || param.initializer)
873
+ return null;
874
+ if (param.name.text === "this")
875
+ return null;
876
+ const t = lowerer.typeOf(param.name);
877
+ const broadFunction = lowerer.checker.typeToString(t) === "Function";
878
+ const broadArray = lowerer.checkerAnyArrayType(t);
879
+ const broadPromise = broadPromiseParam(lowerer, t);
880
+ const declaredKind = classParams ? lowerer.mapTypeOf(t)?.kind : undefined;
881
+ const classParam = classParams && (declaredKind === "object" || declaredKind === "array");
882
+ if ((t.flags & ts.TypeFlags.Any) === 0 &&
883
+ !broadFunction &&
884
+ !broadArray &&
885
+ !broadPromise &&
886
+ !classParam)
887
+ return null;
888
+ const sym = lowerer.checker.getSymbolAtLocation(param.name);
889
+ if (!sym)
890
+ return null;
891
+ if (paramWrittenInBody(lowerer, decl.body, sym, param.name.text))
892
+ return null;
893
+ hasImplicitParams = true;
894
+ return sym;
895
+ });
896
+ return hasImplicitParams ? out : null;
897
+ }
898
+ /** The checker-fallback return type an implicit instance PROMISES before
899
+ * its body lowers: the declared/inferred return when it maps statically
900
+ * (JSDoc @returns, `void`, concrete inference the any-params didn't
901
+ * poison) — used as the expected return, no inference — or null, which
902
+ * selects return INFERENCE with DYN as the recursion pin. */
903
+ function implicitDeclaredReturn(lowerer, info) {
904
+ try {
905
+ // Static JS helpers can accept a structurally compatible class despite
906
+ // narrower JSDoc (for example a Vector2 target documented as Vector3).
907
+ // Infer their result from the specialized body as well.
908
+ if (info.member?.kind === "static" &&
909
+ info.decl.parameters.some((param, index) => info.implicitParams?.[index] &&
910
+ lowerer.mapTypeOf(lowerer.typeOf(param.name))?.kind === "object"))
911
+ return null;
912
+ const broadCallbackSymbols = new Set(info.decl.parameters.flatMap((param, index) => {
913
+ const symbol = info.implicitParams?.[index];
914
+ return symbol !== null &&
915
+ symbol !== undefined &&
916
+ lowerer.checker.typeToString(lowerer.typeOf(param.name)) === "Function"
917
+ ? [symbol]
918
+ : [];
919
+ }));
920
+ let returnsBroadCallback = false;
921
+ if (broadCallbackSymbols.size > 0 && info.decl.body !== undefined) {
922
+ ts.walkPreorder(info.decl.body, (node) => {
923
+ if (node !== info.decl.body && ts.isFunctionLike(node))
924
+ return "skip";
925
+ if (!ts.isReturnStatement(node) || node.expression === undefined)
926
+ return undefined;
927
+ let expression = node.expression;
928
+ while (ts.isParenthesizedExpression(expression))
929
+ expression = expression.expression;
930
+ if (ts.isCallExpression(expression) &&
931
+ ts.isIdentifier(expression.expression) &&
932
+ (() => {
933
+ const symbol = lowerer.checker.getSymbolAtLocation(expression.expression);
934
+ return symbol !== undefined && broadCallbackSymbols.has(symbol);
935
+ })()) {
936
+ returnsBroadCallback = true;
937
+ return "stop";
938
+ }
939
+ return undefined;
940
+ });
941
+ }
942
+ if (returnsBroadCallback)
943
+ return null;
944
+ const declSig = lowerer.checker.getSignatureFromDeclaration(info.decl);
945
+ if (!declSig)
946
+ return null;
947
+ const retTs = lowerer.checker.getReturnTypeOfSignature(declSig);
948
+ if (retTs.flags & ts.TypeFlags.Any)
949
+ return null;
950
+ if (retTs.flags & (ts.TypeFlags.Null | ts.TypeFlags.Undefined))
951
+ return DYN;
952
+ if (lowerer.checker.isArrayType(retTs)) {
953
+ // Inferred JavaScript arrays can hold values selected through a
954
+ // mutable constructor registry. The checker may retain only one
955
+ // constructor's element type; settle the result from the lowered
956
+ // container instead of checking every element against that guess.
957
+ if (!hasExplicitJsDocReturn(info.decl))
958
+ return null;
959
+ if (info.decl.parameters.some((param, index) => info.implicitParams?.[index] &&
960
+ lowerer.mapTypeOf(lowerer.typeOf(param.name))?.kind === "array"))
961
+ return null;
962
+ const elem = lowerer.checker.getTypeArguments(retTs)[0];
963
+ // An implicit-any parameter poisons an inferred array result to
964
+ // any[] even when this instance's body produces one concrete
965
+ // element type (`knownBy(cmd)` in commander). Let the existing
966
+ // lowered-return unifier recover that type. Explicit unknown[]
967
+ // remains a declared checked-dynamic contract and stays pinned.
968
+ if (elem && (elem.flags & ts.TypeFlags.Any) !== 0)
969
+ return null;
970
+ }
971
+ const mapped = lowerer.mapTypeOf(retTs);
972
+ // Mixed inferred results can select a closure or a class instance.
973
+ // Their callable ABI is settled by the lowered body, including native
974
+ // classes whose reflected calls return checked values.
975
+ if (mapped?.kind === "union" &&
976
+ !hasExplicitJsDocReturn(info.decl) &&
977
+ lowerer.unions.get(mapped.unionId)?.arms.some((arm) => arm.kind === "func"))
978
+ return null;
979
+ if (mapped?.kind === "symbol" && !hasExplicitJsDocReturn(info.decl))
980
+ return null;
981
+ if (mapped?.kind === "date" && !hasExplicitJsDocReturn(info.decl))
982
+ return DYN;
983
+ if (!hasExplicitJsDocReturn(info.decl) && info.decl.body) {
984
+ let openReturn = false;
985
+ ts.walkPreorder(info.decl.body, (node) => {
986
+ if (node !== info.decl.body && ts.isFunctionLike(node))
987
+ return "skip";
988
+ if (!ts.isReturnStatement(node) || !node.expression || !ts.isIdentifier(node.expression))
989
+ return undefined;
990
+ const symbol = lowerer.resolveValueSymbol(node.expression);
991
+ if (symbol &&
992
+ lowerer.checker
993
+ .declarationsOf(symbol)
994
+ .some((decl) => ts.isVariableDeclaration(decl) && jsBindingHasOpenWrites(lowerer, decl)))
995
+ openReturn = true;
996
+ return undefined;
997
+ });
998
+ if (openReturn)
999
+ return null;
1000
+ }
1001
+ // A JavaScript result inferred from an initial record can later
1002
+ // carry additional fields. Settle its representation from the
1003
+ // lowered returns instead of copying it back into that initial shape.
1004
+ const resultArms = mapped?.kind === "union" ? lowerer.unions.get(mapped.unionId)?.arms : mapped ? [mapped] : [];
1005
+ if (resultArms?.some((arm) => arm.kind === "record" || arm.kind === "object" || arm.kind === "classval") &&
1006
+ resultArms.every((arm) => isUnitType(arm) ||
1007
+ arm.kind === "record" ||
1008
+ arm.kind === "object" ||
1009
+ arm.kind === "classval") &&
1010
+ !hasExplicitJsDocReturn(info.decl))
1011
+ return null;
1012
+ // Inferred variadic results carry runtime argument packs. Their
1013
+ // factory must retain the lowered callable rather than extracting a
1014
+ // fixed native signature from a checked value.
1015
+ if (mapped?.kind === "func" &&
1016
+ mapped.rest === true &&
1017
+ mapped.restAbi === undefined &&
1018
+ !hasExplicitJsDocReturn(info.decl))
1019
+ return null;
1020
+ if (mapped !== null && promiseCarriesDyn(lowerer, mapped) && !hasExplicitJsDocReturn(info.decl))
1021
+ return null;
1022
+ return mapped;
1023
+ }
1024
+ catch (e) {
1025
+ if (!(e instanceof PoisonError))
1026
+ throw e;
1027
+ return null;
1028
+ }
1029
+ }
1030
+ /** True when a `this.method(...)` call targets an implicit npm-static
1031
+ * method whose result is settled from its lowered body rather than the
1032
+ * checker declaration. Uninitialized-local inference uses this to avoid
1033
+ * freezing an evolving `any` slot to stale JSDoc. */
1034
+ export function implicitMethodCallInfersReturn(lowerer, call) {
1035
+ if (!ts.isPropertyAccessExpression(call.expression) ||
1036
+ call.expression.expression.kind !== ts.SyntaxKind.ThisKeyword ||
1037
+ lowerer.currentClass === null) {
1038
+ return false;
1039
+ }
1040
+ const found = findGenericMethodOn(lowerer, lowerer.currentClass, call.expression.name.text);
1041
+ return (found?.info.implicitParams !== undefined && implicitDeclaredReturn(lowerer, found.info) === null);
1042
+ }
1043
+ /** True when an IR type may BIND an implicit param (a concrete static
1044
+ * type — the checked-dynamic kinds keep the dyn slot, units have no
1045
+ * standalone representation). */
1046
+ function bindableImplicitIr(t) {
1047
+ return (t !== null &&
1048
+ t.kind !== "void" &&
1049
+ t.kind !== "dyn" &&
1050
+ t.kind !== "jsval" &&
1051
+ t.kind !== "caught" &&
1052
+ t.kind !== "undefinedT" &&
1053
+ t.kind !== "nullT");
1054
+ }
1055
+ /** A represented binding or direct callable result can be wider than the
1056
+ * checker's inferred shape. Preserve that boundary when specializing JS. */
1057
+ function storedImplicitArgumentType(lowerer, arg) {
1058
+ while (ts.isParenthesizedExpression(arg))
1059
+ arg = arg.expression;
1060
+ if (isJsSourceFile(arg.getSourceFile()) &&
1061
+ (ts.isArrowFunction(arg) || ts.isFunctionExpression(arg))) {
1062
+ const saved = lowerer.diagSink;
1063
+ const diagnostics = [];
1064
+ lowerer.diagSink = diagnostics;
1065
+ let value;
1066
+ try {
1067
+ value = tryLowerExpression(lowerer, arg);
1068
+ }
1069
+ finally {
1070
+ lowerer.diagSink = saved;
1071
+ }
1072
+ // Direct inferred helpers can receive native callbacks even when their
1073
+ // result is an opaque handle that cannot cross checked storage.
1074
+ if (diagnostics.length === 0 && value?.type.kind === "func")
1075
+ return value.type;
1076
+ }
1077
+ if (arg.kind === ts.SyntaxKind.ThisKeyword)
1078
+ return lowerer.resolveThis()?.type ?? null;
1079
+ if (ts.isAwaitExpression(arg)) {
1080
+ const awaited = storedImplicitArgumentType(lowerer, arg.expression);
1081
+ return awaited?.kind === "promise" ? awaited.inner : awaited;
1082
+ }
1083
+ if (ts.isObjectLiteralExpression(arg) &&
1084
+ isJsSourceFile(arg.getSourceFile()) &&
1085
+ (arg.properties.length === 0 ||
1086
+ arg.properties.some((property) => ts.isMethodDeclaration(property) ||
1087
+ ts.isAccessor(property) ||
1088
+ (!ts.isSpreadAssignment(property) &&
1089
+ property.name !== undefined &&
1090
+ ts.isComputedPropertyName(property.name)))))
1091
+ return DYN;
1092
+ if (ts.isIdentifier(arg))
1093
+ return lowerer.peekLocal(arg)?.type ?? lowerer.globalOf(arg)?.type ?? null;
1094
+ if (isJsSourceFile(arg.getSourceFile()) &&
1095
+ (ts.isPropertyAccessExpression(arg) || ts.isElementAccessExpression(arg))) {
1096
+ // Mutable JS members can retain an initializer-only checker type (for
1097
+ // example a linked-list slot initially null). Specialize to the value
1098
+ // we actually represent, rather than checking it back into that type.
1099
+ const represented = tryLowerExpression(lowerer, arg);
1100
+ if (represented)
1101
+ return represented.type;
1102
+ }
1103
+ if (isJsSourceFile(arg.getSourceFile()) &&
1104
+ (ts.isCallExpression(arg) ||
1105
+ ts.isConditionalExpression(arg) ||
1106
+ (ts.isBinaryExpression(arg) &&
1107
+ (arg.operatorToken.kind === ts.SyntaxKind.BarBarToken ||
1108
+ arg.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken ||
1109
+ arg.operatorToken.kind === ts.SyntaxKind.QuestionQuestionToken)))) {
1110
+ // Calls and fallback expressions can retain checked storage wider than
1111
+ // the checker's inference (for example Object.assign on a JS instance).
1112
+ const represented = tryLowerExpression(lowerer, arg);
1113
+ if (represented?.type.kind === "dyn" || represented?.type.kind === "func")
1114
+ return represented.type;
1115
+ }
1116
+ if (ts.isCallExpression(arg) && ts.isIdentifier(arg.expression)) {
1117
+ const callee = storedImplicitArgumentType(lowerer, arg.expression);
1118
+ if (callee?.kind === "dyn")
1119
+ return DYN;
1120
+ if (callee?.kind === "func")
1121
+ return callee.ret;
1122
+ return lowerer.fnSigOf(arg.expression)?.returnType ?? null;
1123
+ }
1124
+ return null;
1125
+ }
1126
+ /** The instance a CALL of an implicit-any function-like names: each
1127
+ * bindable implicit param takes the call's WIDENED argument checker type
1128
+ * when it maps statically (DYN otherwise — today's slot), typed params
1129
+ * keep their declared shapes, and the param-type tuple is the
1130
+ * instantiation key. New keys lower EAGERLY (return inference — see the
1131
+ * section comment); a same-key re-demand mid-lowering pins the fallback
1132
+ * return type. */
1133
+ export function implicitCallInstance(lowerer, call, info) {
1134
+ const shapes = [];
1135
+ const argTypes = new Map();
1136
+ info.decl.parameters.forEach((param, i) => {
1137
+ const sym = info.implicitParams[i];
1138
+ if (!sym) {
1139
+ shapes.push(lowerer.paramShape(param));
1140
+ return;
1141
+ }
1142
+ let bound = DYN;
1143
+ const declared = lowerer.paramShape(param);
1144
+ if ((lowerer.typeOf(param.name).flags & ts.TypeFlags.Any) === 0)
1145
+ bound = declared.type;
1146
+ const arg = call.arguments[i];
1147
+ if (arg && !ts.isSpreadElement(arg)) {
1148
+ const stored = storedImplicitArgumentType(lowerer, arg);
1149
+ if (stored?.kind === "dyn") {
1150
+ bound = DYN;
1151
+ argTypes.set(sym, lowerer.checker.getUnknownType());
1152
+ shapes.push({ type: bound, mode: "required" });
1153
+ return;
1154
+ }
1155
+ // A represented native array must keep its storage when a direct
1156
+ // inferred helper receives it. Re-boxing a checker-any array would
1157
+ // copy it, losing writes (and attempting to read unfilled slots).
1158
+ if (stored?.kind === "array") {
1159
+ argTypes.set(sym, lowerer.typeOf(arg));
1160
+ shapes.push({ type: stored, mode: "required" });
1161
+ return;
1162
+ }
1163
+ if (stored?.kind === "func") {
1164
+ // The lowered closure may have an inferred JS destructuring
1165
+ // parameter widened from the checker's exact tuple to dyn.
1166
+ // Preserve that signature throughout the specialization.
1167
+ const checkerType = lowerer.mapTypeOf(lowerer.typeOf(arg));
1168
+ argTypes.set(sym, checkerType && typeEquals(checkerType, stored)
1169
+ ? lowerer.typeOf(arg)
1170
+ : lowerer.checker.getUnknownType());
1171
+ shapes.push({ type: stored, mode: "required" });
1172
+ return;
1173
+ }
1174
+ // The argument's own checker type, literal-widened ('add' binds
1175
+ // string) — typeOf consults the ACTIVE instance's bindings, so a
1176
+ // bound param forwarded into another implicit call transitively
1177
+ // instantiates it (this._initCommandGroup(command)).
1178
+ const t = lowerer.checker.getBaseTypeOfLiteralType(lowerer.typeOf(arg));
1179
+ const mapped = (neverTaintedJsType(lowerer, arg, t) ? null : lowerer.mapTypeOf(t)) ??
1180
+ dynFallbackType(lowerer, arg, t);
1181
+ if (isJsSourceFile(arg.getSourceFile()) &&
1182
+ ts.isArrayLiteralExpression(arg) &&
1183
+ mapped?.kind === "array" &&
1184
+ (mapped.elem.kind === "classval" ||
1185
+ (mapped.elem.kind === "union" &&
1186
+ lowerer.unions.get(mapped.elem.unionId)?.arms.every((arm) => arm.kind === "classval")))) {
1187
+ argTypes.set(sym, lowerer.checker.getUnknownType());
1188
+ shapes.push({ type: DYN, mode: "required" });
1189
+ return;
1190
+ }
1191
+ // JavaScript arguments-based callables travel as checked functions.
1192
+ // Specializing a parameter to the inferred rest signature would
1193
+ // require extracting a native variadic ABI that the value does not
1194
+ // expose. Its checked invocation preserves the complete argument pack.
1195
+ if (mapped?.kind === "func" && mapped.rest === true && mapped.restAbi === undefined) {
1196
+ argTypes.set(sym, lowerer.checker.getUnknownType());
1197
+ shapes.push({ type: DYN, mode: "required" });
1198
+ return;
1199
+ }
1200
+ // JS inference can absorb heterogeneous loop values into `{}`.
1201
+ // That checker supertype is not an empty-record runtime layout:
1202
+ // preserve represented arms through the checked boundary instead
1203
+ // of specializing a call to a union that would discard them.
1204
+ if (isJsSourceFile(arg.getSourceFile()) &&
1205
+ mapped?.kind === "func" &&
1206
+ !lowerer.dynConvertible(mapped)) {
1207
+ argTypes.set(sym, lowerer.checker.getUnknownType());
1208
+ shapes.push({ type: DYN, mode: "required" });
1209
+ return;
1210
+ }
1211
+ const mappedArms = mapped?.kind === "union"
1212
+ ? (lowerer.unions.get(mapped.unionId)?.arms ?? [])
1213
+ : mapped
1214
+ ? [mapped]
1215
+ : [];
1216
+ const hasTopObject = mappedArms.some((arm) => {
1217
+ const shape = arm.kind === "record" ? lowerer.shapes.get(arm.shapeId) : undefined;
1218
+ return shape && !shape.tuple && !shape.indexValue && shape.fields.length === 0;
1219
+ });
1220
+ if (stored?.kind === "union" &&
1221
+ hasTopObject &&
1222
+ lowerer.dynConvertible(stored) &&
1223
+ lowerer.unions
1224
+ .get(stored.unionId)
1225
+ ?.arms.some((arm) => !isUnitType(arm) &&
1226
+ !mappedArms.some((target) => lowerer.widthLiftPlan(arm, target) !== null))) {
1227
+ argTypes.set(sym, lowerer.checker.getUnknownType());
1228
+ shapes.push({ type: DYN, mode: "required" });
1229
+ return;
1230
+ }
1231
+ if (ts.isArrowFunction(arg) &&
1232
+ arg.type === undefined &&
1233
+ mapped?.kind === "func" &&
1234
+ promiseCarriesDyn(lowerer, mapped.ret)) {
1235
+ bound = { ...mapped, ret: DYN };
1236
+ lowerer.runtimeOptionalFunctionReturns.set(arg, DYN);
1237
+ argTypes.set(sym, t);
1238
+ }
1239
+ else if (mapped?.kind === "dyn") {
1240
+ bound = DYN;
1241
+ argTypes.set(sym, t);
1242
+ }
1243
+ else if (bindableImplicitIr(mapped)) {
1244
+ bound = mapped;
1245
+ argTypes.set(sym, t);
1246
+ }
1247
+ }
1248
+ shapes.push({ type: bound, mode: "required" });
1249
+ });
1250
+ return internImplicitInstance(lowerer, call, info, shapes, argTypes);
1251
+ }
1252
+ /** The all-dyn DEFAULT instance — today's compiled body exactly: what a
1253
+ * VALUE reference of an implicit-any function names (indirect calls
1254
+ * carry no per-site types to bind). */
1255
+ export function implicitDefaultInstance(lowerer, blame, info) {
1256
+ const shapes = info.decl.parameters.map((param, i) => info.implicitParams[i] ? { type: DYN, mode: "required" } : lowerer.paramShape(param));
1257
+ const argTypes = new Map();
1258
+ // Newly bindable nominal class parameters must not retain their JSDoc
1259
+ // receiver type in the checked fallback. Keep existing broad JS inference.
1260
+ for (let i = 0; i < info.decl.parameters.length; i++) {
1261
+ const symbol = info.implicitParams?.[i];
1262
+ const kind = lowerer.mapTypeOf(lowerer.typeOf(info.decl.parameters[i].name))?.kind;
1263
+ if (symbol && (kind === "object" || kind === "array")) {
1264
+ argTypes.set(symbol, lowerer.checker.getUnknownType());
1265
+ }
1266
+ }
1267
+ return internImplicitInstance(lowerer, blame, info, shapes, argTypes);
1268
+ }
1269
+ function internImplicitInstance(lowerer, blame, info, shapes, argTypes) {
1270
+ const key = shapes.map((s) => typeKey(s.type)).join(",");
1271
+ let inst = info.instances.get(key);
1272
+ if (inst?.implicitState === "failed")
1273
+ lowerer.unsupported("SC1090", blame, `the failed specialization of '${info.baseName}'`);
1274
+ if (inst) {
1275
+ // A recursive caller has observed this ABI before inference settles.
1276
+ // Keep the promised return slot and coerce the completed body's returns.
1277
+ if (inst.implicitState === "lowering")
1278
+ inst.returnPinned = true;
1279
+ return inst;
1280
+ }
1281
+ if (info.instances.size >= MAX_GENERIC_INSTANCES) {
1282
+ lowerer.unsupported("SC1090", blame, `unbounded implicit-any instantiation ('${info.baseName}' exceeded ` +
1283
+ `${MAX_GENERIC_INSTANCES} instances — polymorphic recursion?)`);
1284
+ }
1285
+ const rendered = shapes.map((s) => lowerer.fmt(s.type)).join(", ");
1286
+ const dynamicBroadPromise = info.decl.parameters.some((param, index) => info.implicitParams?.[index] !== null &&
1287
+ info.implicitParams?.[index] !== undefined &&
1288
+ shapes[index]?.type.kind === "dyn" &&
1289
+ broadPromiseParam(lowerer, lowerer.typeOf(param.name)));
1290
+ const declared = dynamicBroadPromise ? null : implicitDeclaredReturn(lowerer, info);
1291
+ inst = {
1292
+ name: `${info.qualifiedName}%${info.instances.size}`,
1293
+ ordinal: info.instances.size,
1294
+ params: shapes,
1295
+ // The promise callers rely on before the body settles it: the
1296
+ // declared truth when it maps, else DYN (the recursion pin — and
1297
+ // exactly today's checked-dynamic result slot).
1298
+ returnType: declared ?? DYN,
1299
+ bindings: new Map(),
1300
+ typeArgsText: `(${rendered.length > 80 ? rendered.slice(0, 77) + "..." : rendered})`,
1301
+ implicitArgTypes: argTypes,
1302
+ implicitState: "lowering",
1303
+ ...(declared === null ? { implicitInferReturn: true } : {}),
1304
+ };
1305
+ info.instances.set(key, inst);
1306
+ // Eager lowering settles the return ABI before callers use it. A failed
1307
+ // JS body must still have a throwing implementation: later references
1308
+ // (including recursive ones) can already hold its cached signature.
1309
+ const diagsBefore = lowerer.diags.length;
1310
+ // The instance is cached even when a receiver probe requested it.
1311
+ // Its body must retain statement fences instead of dropping failures
1312
+ // into that probe's temporary diagnostic sink and caching empty code.
1313
+ const previousSink = lowerer.diagSink;
1314
+ lowerer.diagSink = null;
1315
+ try {
1316
+ // Implicit-any instances lower EAGERLY at the call site so their
1317
+ // inferred return type is available immediately. They therefore do
1318
+ // not pass through emitReachable's queued generic-instance wave,
1319
+ // which normally batches checker work before lowering a body. Prime
1320
+ // this exact committed instance body here; repeated instantiations of
1321
+ // the same declaration find the facade memos warm.
1322
+ lowerer.checker.prefetchRoots([
1323
+ ...info.decl.parameters.flatMap((param) => (param.initializer ? [param.initializer] : [])),
1324
+ ...(info.decl.body ? [info.decl.body] : []),
1325
+ ]);
1326
+ const fn = lowerer.lowerGenericInstance(info, inst);
1327
+ lowerer.implicitFns.push(fn);
1328
+ }
1329
+ catch (e) {
1330
+ if (!(e instanceof PoisonError))
1331
+ throw e;
1332
+ inst.implicitState = "failed";
1333
+ const types = shapes.map((shape) => shape.type);
1334
+ if (info.member?.kind === "method")
1335
+ types.unshift({ kind: "object", className: info.member.cls.def.name });
1336
+ const fn = lowerer.deferToRuntimeFence(diagsBefore, info.decl, {
1337
+ kind: "function",
1338
+ name: inst.name,
1339
+ returnType: inst.returnType,
1340
+ params: types.map((type, index) => ({ localId: `p.${index}`, name: `p${index}`, type })),
1341
+ });
1342
+ if (!fn)
1343
+ throw e;
1344
+ lowerer.implicitFns.push(fn);
1345
+ }
1346
+ finally {
1347
+ lowerer.diagSink = previousSink;
1348
+ }
1349
+ inst.implicitState = "done";
1350
+ return inst;
1351
+ }
1352
+ /** The implicit-any twin of bindingGenericFnNodeOf, for LOCAL and module
1353
+ * bindings alike (`const knownBy = (cmd) => [cmd.name()].concat(...)`
1354
+ * inside a method body — commander's _registerCommand shape): the
1355
+ * initializer function-like when the WHOLE declaration qualifies for
1356
+ * implicit monomorphization, else null — non-qualifying shapes keep
1357
+ * today's closure story silently (never a fence: the flag must not make
1358
+ * working code worse). Qualification: an npm-static JS file, a const (or
1359
+ * never-reassigned, never-redeclared) identifier binding, an
1360
+ * arrow/function-expression initializer with bindable implicit-any
1361
+ * params, and a body with NO captures — no `this`/`super`, and no
1362
+ * reference to a function-scoped declaration outside itself (compiled
1363
+ * instances are module functions; module-scope references are fine).
1364
+ * Cached per declaration on lowerer.implicitLocalFns. */
1365
+ export function implicitLocalFnNodeOf(lowerer, decl) {
1366
+ const cached = lowerer.implicitLocalFns.get(decl);
1367
+ if (cached !== undefined)
1368
+ return cached ? cached.decl : null;
1369
+ const probe = () => {
1370
+ if (!implicitMonoFile(decl.getSourceFile()))
1371
+ return null;
1372
+ if (!ts.isIdentifier(decl.name) || decl.initializer === undefined)
1373
+ return null;
1374
+ let init = decl.initializer;
1375
+ while (ts.isParenthesizedExpression(init))
1376
+ init = init.expression;
1377
+ if (!ts.isArrowFunction(init) && !ts.isFunctionExpression(init))
1378
+ return null;
1379
+ if (init.typeParameters !== undefined || init.body === undefined)
1380
+ return null;
1381
+ if (!implicitAnyParamSymbolsOf(lowerer, init))
1382
+ return null;
1383
+ const sym = lowerer.checker.getSymbolAtLocation(decl.name);
1384
+ if (!sym)
1385
+ return null;
1386
+ const isConst = (ts.getCombinedNodeFlags(decl) & ts.NodeFlags.Const) !== 0;
1387
+ const redeclared = lowerer.checker
1388
+ .declarationsOf(sym)
1389
+ .some((d) => d !== decl && ts.isVariableDeclaration(d) && d.initializer !== undefined);
1390
+ if (redeclared)
1391
+ return null;
1392
+ if (!isConst && !bindingNeverReassigned(lowerer, sym, decl))
1393
+ return null;
1394
+ // The capture scan: instances are module functions with no frame.
1395
+ let captures = false;
1396
+ const scan = (n) => {
1397
+ if (captures)
1398
+ return;
1399
+ if (n.kind === ts.SyntaxKind.ThisKeyword || n.kind === ts.SyntaxKind.SuperKeyword) {
1400
+ // Arrow bodies see the ENCLOSING this; function expressions
1401
+ // rebind their own — but a bare `this` there is untyped JS
1402
+ // dynamism either way. Reject both, cheaply and soundly.
1403
+ captures = true;
1404
+ return;
1405
+ }
1406
+ if (ts.isIdentifier(n)) {
1407
+ const s = lowerer.checker.getSymbolAtLocation(n);
1408
+ const d = s ? lowerer.checker.valueDeclarationOf(s) : undefined;
1409
+ if (d &&
1410
+ d.getSourceFile() === decl.getSourceFile() &&
1411
+ !(d.pos >= init.pos && d.end <= init.end)) {
1412
+ // Declared outside the initializer, in this file: a capture
1413
+ // exactly when some enclosing FUNCTION scope declares it —
1414
+ // module-scope declarations are reachable from any module
1415
+ // function.
1416
+ for (let p = d.parent; p !== undefined && !ts.isSourceFile(p); p = p.parent) {
1417
+ if (ts.isFunctionLike(p)) {
1418
+ captures = true;
1419
+ return;
1420
+ }
1421
+ }
1422
+ }
1423
+ }
1424
+ n.forEachChild(scan);
1425
+ };
1426
+ scan(init.body);
1427
+ return captures ? null : init;
1428
+ };
1429
+ const node = probe();
1430
+ if (node === null) {
1431
+ lowerer.implicitLocalFns.set(decl, null);
1432
+ return null;
1433
+ }
1434
+ return node;
1435
+ }
1436
+ /** Registers (or returns) the GenericFnInfo of a qualifying implicit-any
1437
+ * function-value binding — implicitLocalFnNodeOf's companion, the
1438
+ * bindingGenericFnInfoOf shape: the info enters genericFnsBySymbol under
1439
+ * the binding's symbol (and a named function expression's inner name),
1440
+ * so calls and value references resolve through genericFnOf; the
1441
+ * declaration statement emits nothing and the binding has no runtime
1442
+ * value. The declaration's source position joins the qualified name —
1443
+ * two same-named locals in one file stay distinct. */
1444
+ export function implicitLocalFnInfoOf(lowerer, decl, fnNode) {
1445
+ const existing = lowerer.implicitLocalFns.get(decl);
1446
+ if (existing)
1447
+ return existing;
1448
+ const name = decl.name.text;
1449
+ const sym = lowerer.checker.getSymbolAtLocation(decl.name);
1450
+ if (!sym)
1451
+ lowerer.unsupported("SC1090", decl.name, "this binding form");
1452
+ const implicit = implicitAnyParamSymbolsOf(lowerer, fnNode);
1453
+ if (!implicit)
1454
+ lowerer.unsupported("SC1090", fnNode, "this function form"); // defensive: the probe proved it
1455
+ const stmt = decl.parent?.parent;
1456
+ const info = {
1457
+ decl: fnNode,
1458
+ baseName: name,
1459
+ qualifiedName: lowerer.qualify(decl.getSourceFile(), nsPathPrefix(stmt ?? decl, decl) + `${name}%l${decl.getStart()}`),
1460
+ typeParams: [],
1461
+ instances: new Map(),
1462
+ implicitParams: implicit,
1463
+ };
1464
+ lowerer.implicitLocalFns.set(decl, info);
1465
+ lowerer.genericFnsBySymbol.set(sym, info);
1466
+ if (ts.isFunctionExpression(fnNode) && fnNode.name !== undefined) {
1467
+ const inner = lowerer.checker.getSymbolAtLocation(fnNode.name);
1468
+ if (inner)
1469
+ lowerer.genericFnsBySymbol.set(inner, info);
1470
+ }
1471
+ return info;
1472
+ }
1473
+ /** The function-like node behind an object-literal generic-method member:
1474
+ * the MethodDeclaration itself (`{ m<T>(x: T) {...} }`) or a generic
1475
+ * arrow/function-expression property's initializer (`{ m: <T>(x: T) =>
1476
+ * ... }`). Null when the property's declaration isn't that shape. */
1477
+ export function objLitGenericFnNodeOf(lowerer, propSym) {
1478
+ const decl = lowerer.checker.valueDeclarationOf(propSym);
1479
+ if (!decl)
1480
+ return null;
1481
+ if (ts.isMethodDeclaration(decl) && ts.isObjectLiteralExpression(decl.parent)) {
1482
+ return decl.typeParameters !== undefined && decl.body !== undefined
1483
+ ? { fnNode: decl, literal: decl.parent }
1484
+ : null;
1485
+ }
1486
+ if (ts.isPropertyAssignment(decl) && ts.isObjectLiteralExpression(decl.parent)) {
1487
+ let init = decl.initializer;
1488
+ while (ts.isParenthesizedExpression(init))
1489
+ init = init.expression;
1490
+ if ((ts.isArrowFunction(init) || ts.isFunctionExpression(init)) &&
1491
+ init.typeParameters !== undefined &&
1492
+ init.body !== undefined) {
1493
+ return { fnNode: init, literal: decl.parent };
1494
+ }
1495
+ }
1496
+ return null;
1497
+ }
1498
+ /** The interned GenericFnInfo for one object-literal generic method, with
1499
+ * the supportability fences applied ONCE per declaration: the defining
1500
+ * literal must sit at module scope (the compiled instance is a plain
1501
+ * module function — an enclosing frame would need captures), and
1502
+ * async/generator forms keep the method fences. The name is source-
1503
+ * position-derived (`%ol<start>.<name>`, qualified per file) —
1504
+ * deterministic across the discovery and emit passes. */
1505
+ export function objLitGenericFnInfoOf(lowerer, blame, name, found) {
1506
+ const { fnNode, literal } = found;
1507
+ const existing = lowerer.objLitGenericFns.get(fnNode);
1508
+ if (existing)
1509
+ return existing;
1510
+ if (fnNode.asteriskToken)
1511
+ lowerer.unsupported("SC1071", blame);
1512
+ if (fnNode.modifiers?.some((m) => m.kind === ts.SyntaxKind.AsyncKeyword)) {
1513
+ lowerer.unsupported("SC1090", blame, "async object-literal generic methods");
1514
+ }
1515
+ // `this` is the receiver object — records don't model it (the
1516
+ // lowerObjectLiteral fence, applied at registration because
1517
+ // arrow/function-expression properties skip that walk and the compiled
1518
+ // instances are plain module functions).
1519
+ if (fnNode.body)
1520
+ lowerer.rejectThisInObjectMethod(fnNode.body);
1521
+ for (let n = literal.parent; n && !ts.isSourceFile(n); n = n.parent) {
1522
+ if (ts.isFunctionLike(n)) {
1523
+ lowerer.unsupported("SC1090", blame, `object-literal generic methods declared inside functions (the compiled instantiations of '${name}' are module functions and cannot capture the enclosing frame — declare the object at module scope)`);
1524
+ }
1525
+ }
1526
+ const typeParams = declaredTypeParameterSymbols(lowerer, fnNode.typeParameters, blame, "this method form");
1527
+ checkGenericParameterNames(lowerer, fnNode.parameters, false);
1528
+ const info = {
1529
+ decl: fnNode,
1530
+ baseName: name,
1531
+ qualifiedName: lowerer.qualify(fnNode.getSourceFile(), `%ol${fnNode.getStart()}.${name}`),
1532
+ typeParams,
1533
+ instances: new Map(),
1534
+ objectLiteral: true,
1535
+ };
1536
+ lowerer.objLitGenericFns.set(fnNode, info);
1537
+ return info;
1538
+ }
1539
+ /** The generic function-like INITIALIZER behind a binding declaration —
1540
+ * `const f = <T>(x: T) => x` or `const f = function g<T>(x: T) {...}`
1541
+ * (parens stripped). Null when the declaration isn't that shape; the
1542
+ * SHAPE only — whether the binding qualifies (module scope, never
1543
+ * reassigned) is bindingGenericFnInfoOf's business. */
1544
+ export function bindingGenericFnNodeOf(decl) {
1545
+ if (!ts.isIdentifier(decl.name) || decl.initializer === undefined)
1546
+ return null;
1547
+ // Assertion wrappers strip like parens: `const r = (<T>(x: T) => x) as
1548
+ // Mapper` evaluates the arrow — the cast only renames its type.
1549
+ const init = stripValueWrappers(decl.initializer);
1550
+ if ((ts.isArrowFunction(init) || ts.isFunctionExpression(init)) &&
1551
+ init.typeParameters !== undefined &&
1552
+ init.body !== undefined) {
1553
+ return init;
1554
+ }
1555
+ return null;
1556
+ }
1557
+ /** The CONTEXTUAL twin of bindingGenericFnNodeOf: `const g: Mapper = (x)
1558
+ * => x` where `type Mapper = <T>(x: T) => T` — the initializer declares
1559
+ * no type parameters of its own, but the ANNOTATION's one call signature
1560
+ * does, and the checker types the arrow's parameters by those (`x: T`).
1561
+ * Such a binding monomorphizes exactly like `const g = <T>(x: T) => x`;
1562
+ * bindingGenericFnInfoOf reads the type parameters off the annotation's
1563
+ * signature. Null when the shape doesn't match (a concrete annotation, a
1564
+ * generic arrow — the syntactic probe's case, an overloaded alias). */
1565
+ export function bindingContextualGenericFnNodeOf(lowerer, decl) {
1566
+ if (!ts.isIdentifier(decl.name) || decl.initializer === undefined)
1567
+ return null;
1568
+ // The generic signature can arrive as an ANNOTATION or as a type
1569
+ // ASSERTION on the initializer (`var r = < <T>(x: T) => T >((x) => x)`
1570
+ // — the checker contextually types the operand's parameters by the
1571
+ // asserted signature exactly like an annotation would).
1572
+ const asserted = ts.isAsExpression(decl.initializer) || ts.isTypeAssertion(decl.initializer);
1573
+ if (decl.type === undefined && !asserted)
1574
+ return null;
1575
+ const init = stripValueWrappers(decl.initializer);
1576
+ if (!(ts.isArrowFunction(init) || ts.isFunctionExpression(init)) ||
1577
+ init.typeParameters !== undefined ||
1578
+ init.body === undefined) {
1579
+ return null;
1580
+ }
1581
+ const sigs = lowerer.checker.getCallSignatures(lowerer.typeOf(decl.name));
1582
+ if (sigs.length !== 1 || sigs[0].getTypeParameters().length === 0)
1583
+ return null;
1584
+ return init;
1585
+ }
1586
+ /** The interned GenericFnInfo for one generic arrow/function-expression
1587
+ * binding initializer, with the supportability fences applied ONCE per
1588
+ * declaration: the binding must sit at module scope (the compiled
1589
+ * instances are plain module functions — an enclosing frame would need
1590
+ * captures) and must provably HOLD the initializer once initialized — a
1591
+ * const, or a let/var nothing in its declaring file ever writes (ESM
1592
+ * import bindings are read-only, so the file scan is the whole story;
1593
+ * observing the UNINITIALIZED state needs a hoisted early call, the
1594
+ * same temporal hole const TDZ leaves — the object-literal generic-
1595
+ * method receiver stance). Successful registration enters the info
1596
+ * in genericFnsBySymbol under the binding's symbol — and under a named
1597
+ * function expression's own inner name (it binds itself inside the
1598
+ * body, the class-expression rule) — so every genericFnOf consumer
1599
+ * (calls, pinned values, instantiation expressions, namespace and CJS
1600
+ * member paths) resolves it like a top-level generic declaration. */
1601
+ export function bindingGenericFnInfoOf(lowerer, decl, fnNode) {
1602
+ const existing = lowerer.bindingGenericFns.get(fnNode);
1603
+ if (existing)
1604
+ return existing;
1605
+ const name = decl.name.text;
1606
+ if (fnNode.asteriskToken)
1607
+ lowerer.unsupported("SC1071", fnNode);
1608
+ for (let n = decl.parent; n !== undefined && !ts.isSourceFile(n); n = n.parent) {
1609
+ if (ts.isFunctionLike(n)) {
1610
+ lowerer.unsupported("SC1090", fnNode, `generic arrow/function-expression bindings declared inside functions (the compiled instantiations of '${name}' are module functions and cannot capture the enclosing frame — declare the binding at module scope)`);
1611
+ }
1612
+ }
1613
+ const sym = lowerer.checker.getSymbolAtLocation(decl.name);
1614
+ if (!sym)
1615
+ lowerer.unsupported("SC1090", decl.name, "this binding form");
1616
+ requireStableGenericBinding(lowerer, decl, sym, name);
1617
+ const typeParams = [];
1618
+ if (fnNode.typeParameters !== undefined) {
1619
+ typeParams.push(...declaredTypeParameterSymbols(lowerer, fnNode.typeParameters, fnNode, "this function form"));
1620
+ }
1621
+ else {
1622
+ // The CONTEXTUAL shape (bindingContextualGenericFnNodeOf): the type
1623
+ // parameters live on the annotation's one call signature, and the
1624
+ // checker types the initializer's parameters by them — the same
1625
+ // symbols the instance bodies resolve through.
1626
+ const sigs = lowerer.checker.getCallSignatures(lowerer.typeOf(decl.name));
1627
+ const tps = sigs.length === 1 ? sigs[0].getTypeParameters() : [];
1628
+ if (tps.length === 0)
1629
+ lowerer.unsupported("SC1090", fnNode, "this function form");
1630
+ for (const tp of tps) {
1631
+ const tpSym = tp.getSymbol();
1632
+ if (!tpSym)
1633
+ lowerer.unsupported("SC1090", fnNode, "this function form");
1634
+ typeParams.push(tpSym);
1635
+ }
1636
+ }
1637
+ checkGenericParameterNames(lowerer, fnNode.parameters, true);
1638
+ const stmt = decl.parent?.parent; // declarator → list → statement (nsPathPrefix wants the statement)
1639
+ const info = {
1640
+ decl: fnNode,
1641
+ baseName: name,
1642
+ qualifiedName: lowerer.qualify(decl.getSourceFile(), nsPathPrefix(stmt ?? decl, decl) + name),
1643
+ typeParams,
1644
+ instances: new Map(),
1645
+ };
1646
+ lowerer.bindingGenericFns.set(fnNode, info);
1647
+ lowerer.genericFnsBySymbol.set(sym, info);
1648
+ if (ts.isFunctionExpression(fnNode) && fnNode.name !== undefined) {
1649
+ const inner = lowerer.checker.getSymbolAtLocation(fnNode.name);
1650
+ if (inner)
1651
+ lowerer.genericFnsBySymbol.set(inner, info);
1652
+ }
1653
+ return info;
1654
+ }
1655
+ /** `const h = id` — a binding ALIASING a generic function (a top-level
1656
+ * declaration, a registered generic binding, or another alias — resolved
1657
+ * left to right in declaration order). The alias registers the SAME info
1658
+ * under its own symbol, so calls (`h(3)`) and pinned values (`take(h)`)
1659
+ * resolve exactly like the target's own name, and the binding itself has
1660
+ * no runtime value (a generic function value cannot materialize). Claims
1661
+ * only bindings whose OWN type still keeps type parameters — a
1662
+ * concrete-annotated alias (`const h: (x: number) => number = id`) is a
1663
+ * pinned VALUE, the existing lowerGenericFnValue story. Null when the
1664
+ * shape doesn't match or the target isn't a registered generic; fences
1665
+ * (reassignment, var redeclaration) report by name inside. */
1666
+ export function bindingGenericFnAliasInfoOf(lowerer, decl) {
1667
+ if (!ts.isIdentifier(decl.name) || decl.initializer === undefined)
1668
+ return null;
1669
+ let init = decl.initializer;
1670
+ while (ts.isParenthesizedExpression(init))
1671
+ init = init.expression;
1672
+ if (!ts.isIdentifier(init))
1673
+ return null;
1674
+ const target = genericFnOf(lowerer, init);
1675
+ if (!target)
1676
+ return null;
1677
+ // A concrete annotation pins one signature — that value story
1678
+ // (lowerGenericFnValue at the reference) stays untouched.
1679
+ const ownSigs = lowerer.checker.getCallSignatures(lowerer.typeOf(decl.name));
1680
+ if (ownSigs.length === 0 || !ownSigs.every((s) => s.getTypeParameters().length > 0))
1681
+ return null;
1682
+ const sym = lowerer.checker.getSymbolAtLocation(decl.name);
1683
+ if (!sym)
1684
+ return null;
1685
+ const existing = lowerer.genericFnsBySymbol.get(sym);
1686
+ if (existing)
1687
+ return existing;
1688
+ const name = decl.name.text;
1689
+ requireStableGenericBinding(lowerer, decl, sym, name);
1690
+ lowerer.genericFnsBySymbol.set(sym, target);
1691
+ return target;
1692
+ }
1693
+ /** Static resolution stands in for the receiver's runtime value, so an
1694
+ * object-literal generic-method receiver must provably HOLD the defining
1695
+ * literal: a direct read of a binding whose initializer IS that literal
1696
+ * and that nothing ever reassigns — a const, or a let with no write in
1697
+ * its declaring file (ESM import bindings are read-only, so the file
1698
+ * scan is the whole story). The read is pure — call and value sites skip
1699
+ * evaluating it entirely. A reassignable binding could hold a
1700
+ * structurally identical literal with a DIFFERENT body, which static
1701
+ * resolution would silently miss. */
1702
+ export function requireObjLitGenericReceiver(lowerer, blame, recvExpr, literal, name) {
1703
+ let recv = recvExpr;
1704
+ while (ts.isParenthesizedExpression(recv))
1705
+ recv = recv.expression;
1706
+ const fenceReceiver = () => lowerer.unsupported("SC1090", blame, `reaching the object-literal generic method '${name}' through this receiver (resolution is static, so the receiver must be a never-reassigned binding initialized with the defining literal)`);
1707
+ if (!ts.isIdentifier(recv))
1708
+ fenceReceiver();
1709
+ const recvSym = lowerer.resolveValueSymbol(recv);
1710
+ const recvDecl = recvSym ? lowerer.checker.valueDeclarationOf(recvSym) : undefined;
1711
+ if (!recvDecl ||
1712
+ !ts.isVariableDeclaration(recvDecl) ||
1713
+ !ts.isVariableDeclarationList(recvDecl.parent) ||
1714
+ recvDecl.initializer === undefined) {
1715
+ fenceReceiver();
1716
+ }
1717
+ if ((recvDecl.parent.flags & ts.NodeFlags.Const) === 0 &&
1718
+ !bindingNeverReassigned(lowerer, recvSym, recvDecl)) {
1719
+ fenceReceiver();
1720
+ }
1721
+ let init = recvDecl.initializer;
1722
+ while (ts.isParenthesizedExpression(init))
1723
+ init = init.expression;
1724
+ if (init !== literal)
1725
+ fenceReceiver();
1726
+ }
1727
+ //# sourceMappingURL=generic-functions.js.map