@scriptc/compiler 0.4.6 → 0.4.8

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 (1082) hide show
  1. package/ambient/node-fallback/child_process.d.ts +71 -22
  2. package/ambient/node-fallback/crypto.d.ts +15 -7
  3. package/ambient/node-fallback/events.d.ts +29 -6
  4. package/ambient/node-fallback/fs-promises.d.ts +1 -1
  5. package/ambient/node-fallback/fs.d.ts +57 -12
  6. package/ambient/node-fallback/http.d.ts +26 -18
  7. package/ambient/node-fallback/https.d.ts +5 -2
  8. package/ambient/node-fallback/net.d.ts +25 -0
  9. package/ambient/node-fallback/os.d.ts +11 -1
  10. package/ambient/node-fallback/path-posix.d.ts +6 -0
  11. package/ambient/node-fallback/path-win32.d.ts +5 -0
  12. package/ambient/node-fallback/path.d.ts +2 -0
  13. package/ambient/node-fallback/querystring.d.ts +3 -3
  14. package/ambient/node-fallback/zlib.d.ts +31 -2
  15. package/ambient/scriptc-node-fallback.d.ts +95 -20
  16. package/ambient/scriptc.d.ts +7 -2
  17. package/dist/backend/executable-features.js +22 -1
  18. package/dist/backend/executable-features.js.map +1 -1
  19. package/dist/backend/immutability.d.ts +12 -1
  20. package/dist/backend/immutability.js +50 -4
  21. package/dist/backend/immutability.js.map +1 -1
  22. package/dist/backend/immutability.test.js +95 -1
  23. package/dist/backend/immutability.test.js.map +1 -1
  24. package/dist/backend/library-pack.d.ts +6 -0
  25. package/dist/backend/library-pack.js +18 -5
  26. package/dist/backend/library-pack.js.map +1 -1
  27. package/dist/backend/library-pack.test.d.ts +1 -0
  28. package/dist/backend/library-pack.test.js +28 -0
  29. package/dist/backend/library-pack.test.js.map +1 -0
  30. package/dist/backend/linker.d.ts +20 -2
  31. package/dist/backend/linker.js +221 -35
  32. package/dist/backend/linker.js.map +1 -1
  33. package/dist/backend/lld.d.ts +15 -6
  34. package/dist/backend/lld.js +24 -16
  35. package/dist/backend/lld.js.map +1 -1
  36. package/dist/backend/lld.test.js +13 -5
  37. package/dist/backend/lld.test.js.map +1 -1
  38. package/dist/backend/llvm/alloc.d.ts +15 -2
  39. package/dist/backend/llvm/alloc.js +172 -36
  40. package/dist/backend/llvm/alloc.js.map +1 -1
  41. package/dist/backend/llvm/alloc.test.js +69 -1
  42. package/dist/backend/llvm/alloc.test.js.map +1 -1
  43. package/dist/backend/llvm/arenas.d.ts +17 -4
  44. package/dist/backend/llvm/arenas.js +105 -10
  45. package/dist/backend/llvm/arenas.js.map +1 -1
  46. package/dist/backend/llvm/arenas.test.js +229 -0
  47. package/dist/backend/llvm/arenas.test.js.map +1 -1
  48. package/dist/backend/llvm/bytes-alias.js +10 -1
  49. package/dist/backend/llvm/bytes-alias.js.map +1 -1
  50. package/dist/backend/llvm/bytes-headers.js +6 -0
  51. package/dist/backend/llvm/bytes-headers.js.map +1 -1
  52. package/dist/backend/llvm/bytes-loop-versions.test.js +25 -0
  53. package/dist/backend/llvm/bytes-loop-versions.test.js.map +1 -1
  54. package/dist/backend/llvm/call-lifetimes.js +10 -0
  55. package/dist/backend/llvm/call-lifetimes.js.map +1 -1
  56. package/dist/backend/llvm/classes.d.ts +16 -9
  57. package/dist/backend/llvm/classes.js +142 -37
  58. package/dist/backend/llvm/classes.js.map +1 -1
  59. package/dist/backend/llvm/classes.test.js +42 -0
  60. package/dist/backend/llvm/classes.test.js.map +1 -1
  61. package/dist/backend/llvm/constant-callbacks.test.js +50 -1
  62. package/dist/backend/llvm/constant-callbacks.test.js.map +1 -1
  63. package/dist/backend/llvm/cpu-dispatch.d.ts +15 -5
  64. package/dist/backend/llvm/cpu-dispatch.js +34 -9
  65. package/dist/backend/llvm/cpu-dispatch.js.map +1 -1
  66. package/dist/backend/llvm/dyn.d.ts +64 -3
  67. package/dist/backend/llvm/dyn.js +251 -15
  68. package/dist/backend/llvm/dyn.js.map +1 -1
  69. package/dist/backend/llvm/emit-function.js +68 -5
  70. package/dist/backend/llvm/emit-function.js.map +1 -1
  71. package/dist/backend/llvm/emit-module.js +226 -77
  72. package/dist/backend/llvm/emit-module.js.map +1 -1
  73. package/dist/backend/llvm/emit-module.test.d.ts +1 -0
  74. package/dist/backend/llvm/emit-module.test.js +52 -0
  75. package/dist/backend/llvm/emit-module.test.js.map +1 -0
  76. package/dist/backend/llvm/emit-statements.js +138 -34
  77. package/dist/backend/llvm/emit-statements.js.map +1 -1
  78. package/dist/backend/llvm/emitter.d.ts +142 -10
  79. package/dist/backend/llvm/emitter.js +523 -73
  80. package/dist/backend/llvm/emitter.js.map +1 -1
  81. package/dist/backend/llvm/emitter.test.js +31 -3
  82. package/dist/backend/llvm/emitter.test.js.map +1 -1
  83. package/dist/backend/llvm/expr-async.js +19 -1
  84. package/dist/backend/llvm/expr-async.js.map +1 -1
  85. package/dist/backend/llvm/expr-bytes.js +16 -1
  86. package/dist/backend/llvm/expr-bytes.js.map +1 -1
  87. package/dist/backend/llvm/expr-calls.d.ts +4 -1
  88. package/dist/backend/llvm/expr-calls.js +38 -6
  89. package/dist/backend/llvm/expr-calls.js.map +1 -1
  90. package/dist/backend/llvm/expr-dynamic.js +237 -23
  91. package/dist/backend/llvm/expr-dynamic.js.map +1 -1
  92. package/dist/backend/llvm/expr-primitives.js +123 -12
  93. package/dist/backend/llvm/expr-primitives.js.map +1 -1
  94. package/dist/backend/llvm/expr-records.d.ts +1 -1
  95. package/dist/backend/llvm/expr-records.js +124 -56
  96. package/dist/backend/llvm/expr-records.js.map +1 -1
  97. package/dist/backend/llvm/expr-stream-bridges.d.ts +8 -0
  98. package/dist/backend/llvm/expr-stream-bridges.js +59 -2
  99. package/dist/backend/llvm/expr-stream-bridges.js.map +1 -1
  100. package/dist/backend/llvm/expr-stream-callbacks.d.ts +16 -0
  101. package/dist/backend/llvm/expr-stream-callbacks.js +206 -20
  102. package/dist/backend/llvm/expr-stream-callbacks.js.map +1 -1
  103. package/dist/backend/llvm/integer-values.d.ts +2 -0
  104. package/dist/backend/llvm/integer-values.js +6 -0
  105. package/dist/backend/llvm/integer-values.js.map +1 -1
  106. package/dist/backend/llvm/js-groups.d.ts +21 -0
  107. package/dist/backend/llvm/js-groups.js +277 -0
  108. package/dist/backend/llvm/js-groups.js.map +1 -0
  109. package/dist/backend/llvm/js-ic.d.ts +57 -1
  110. package/dist/backend/llvm/js-ic.js +389 -22
  111. package/dist/backend/llvm/js-ic.js.map +1 -1
  112. package/dist/backend/llvm/lib-dispatch.js +152 -1
  113. package/dist/backend/llvm/lib-dispatch.js.map +1 -1
  114. package/dist/backend/llvm/lib-filesystem.js +116 -11
  115. package/dist/backend/llvm/lib-filesystem.js.map +1 -1
  116. package/dist/backend/llvm/lib-network.js +33 -6
  117. package/dist/backend/llvm/lib-network.js.map +1 -1
  118. package/dist/backend/llvm/lib-process.js +180 -27
  119. package/dist/backend/llvm/lib-process.js.map +1 -1
  120. package/dist/backend/llvm/lib-shared.js +139 -2
  121. package/dist/backend/llvm/lib-shared.js.map +1 -1
  122. package/dist/backend/llvm/lib-stream.js +67 -0
  123. package/dist/backend/llvm/lib-stream.js.map +1 -1
  124. package/dist/backend/llvm/local-union-storage.test.js +32 -0
  125. package/dist/backend/llvm/local-union-storage.test.js.map +1 -1
  126. package/dist/backend/llvm/loop-entry-versions.d.ts +2 -2
  127. package/dist/backend/llvm/loop-entry-versions.js +43 -21
  128. package/dist/backend/llvm/loop-entry-versions.js.map +1 -1
  129. package/dist/backend/llvm/loop-state.d.ts +7 -1
  130. package/dist/backend/llvm/loop-state.js +26 -3
  131. package/dist/backend/llvm/loop-state.js.map +1 -1
  132. package/dist/backend/llvm/map-entry-fusion.d.ts +8 -0
  133. package/dist/backend/llvm/map-entry-fusion.js +3 -3
  134. package/dist/backend/llvm/map-entry-fusion.js.map +1 -1
  135. package/dist/backend/llvm/map-number-lookup.d.ts +3 -1
  136. package/dist/backend/llvm/map-number-lookup.js +7 -3
  137. package/dist/backend/llvm/map-number-lookup.js.map +1 -1
  138. package/dist/backend/llvm/map-number-lookup.test.js +58 -17
  139. package/dist/backend/llvm/map-number-lookup.test.js.map +1 -1
  140. package/dist/backend/llvm/nullable-unions.js +7 -6
  141. package/dist/backend/llvm/nullable-unions.js.map +1 -1
  142. package/dist/backend/llvm/nullable-unions.test.js +4 -1
  143. package/dist/backend/llvm/nullable-unions.test.js.map +1 -1
  144. package/dist/backend/llvm/receiver-brackets.test.d.ts +1 -0
  145. package/dist/backend/llvm/receiver-brackets.test.js +68 -0
  146. package/dist/backend/llvm/receiver-brackets.test.js.map +1 -0
  147. package/dist/backend/llvm/receivers.js +3 -0
  148. package/dist/backend/llvm/receivers.js.map +1 -1
  149. package/dist/backend/llvm/record-entry-fusion.d.ts +32 -0
  150. package/dist/backend/llvm/record-entry-fusion.js +217 -0
  151. package/dist/backend/llvm/record-entry-fusion.js.map +1 -0
  152. package/dist/backend/llvm/record-results.d.ts +5 -2
  153. package/dist/backend/llvm/record-results.js +13 -12
  154. package/dist/backend/llvm/record-results.js.map +1 -1
  155. package/dist/backend/llvm/record-views.d.ts +22 -2
  156. package/dist/backend/llvm/record-views.js +147 -12
  157. package/dist/backend/llvm/record-views.js.map +1 -1
  158. package/dist/backend/llvm/record-views.test.js +76 -0
  159. package/dist/backend/llvm/record-views.test.js.map +1 -1
  160. package/dist/backend/llvm/reference-effects.js +1 -0
  161. package/dist/backend/llvm/reference-effects.js.map +1 -1
  162. package/dist/backend/llvm/reference-writes.js +4 -0
  163. package/dist/backend/llvm/reference-writes.js.map +1 -1
  164. package/dist/backend/llvm/region-ir.js +1 -0
  165. package/dist/backend/llvm/region-ir.js.map +1 -1
  166. package/dist/backend/llvm/region-sites.d.ts +18 -0
  167. package/dist/backend/llvm/region-sites.js +79 -1
  168. package/dist/backend/llvm/region-sites.js.map +1 -1
  169. package/dist/backend/llvm/runtime-registries.test.js +53 -6
  170. package/dist/backend/llvm/runtime-registries.test.js.map +1 -1
  171. package/dist/backend/llvm/serialized-ir-emission.test.js +3 -1
  172. package/dist/backend/llvm/serialized-ir-emission.test.js.map +1 -1
  173. package/dist/backend/llvm/shapes.d.ts +36 -3
  174. package/dist/backend/llvm/shapes.js +201 -16
  175. package/dist/backend/llvm/shapes.js.map +1 -1
  176. package/dist/backend/llvm/shapes.test.js +4 -0
  177. package/dist/backend/llvm/shapes.test.js.map +1 -1
  178. package/dist/backend/llvm/speculative-integers.d.ts +10 -1
  179. package/dist/backend/llvm/speculative-integers.js +59 -8
  180. package/dist/backend/llvm/speculative-integers.js.map +1 -1
  181. package/dist/backend/llvm/stack-objects.d.ts +1 -2
  182. package/dist/backend/llvm/stack-objects.js +8 -5
  183. package/dist/backend/llvm/stack-objects.js.map +1 -1
  184. package/dist/backend/llvm/unwind-abi.d.ts +3 -3
  185. package/dist/backend/llvm/unwind-abi.js +8 -3
  186. package/dist/backend/llvm/unwind-abi.js.map +1 -1
  187. package/dist/backend/llvm/walkers.d.ts +12 -0
  188. package/dist/backend/llvm/walkers.js +47 -3
  189. package/dist/backend/llvm/walkers.js.map +1 -1
  190. package/dist/backend/may-throw.js +12 -2
  191. package/dist/backend/may-throw.js.map +1 -1
  192. package/dist/backend/may-throw.test.js +13 -0
  193. package/dist/backend/may-throw.test.js.map +1 -1
  194. package/dist/backend/native/contracts.d.ts +94 -0
  195. package/dist/backend/native/executable.js +134 -10
  196. package/dist/backend/native/executable.js.map +1 -1
  197. package/dist/backend/native/helper-identity-record.d.ts +11 -0
  198. package/dist/backend/native/helper-identity-record.js +76 -0
  199. package/dist/backend/native/helper-identity-record.js.map +1 -0
  200. package/dist/backend/native/helper-identity-record.test.d.ts +1 -0
  201. package/dist/backend/native/helper-identity-record.test.js +101 -0
  202. package/dist/backend/native/helper-identity-record.test.js.map +1 -0
  203. package/dist/backend/native/library.js +10 -2
  204. package/dist/backend/native/library.js.map +1 -1
  205. package/dist/backend/native/runtime-inputs.js +8 -1
  206. package/dist/backend/native/runtime-inputs.js.map +1 -1
  207. package/dist/backend/native/vendor.d.ts +1 -1
  208. package/dist/backend/native/vendor.js +1 -1
  209. package/dist/backend/native/vendor.js.map +1 -1
  210. package/dist/backend/native-codegen-core.d.ts +13 -10
  211. package/dist/backend/native-codegen-core.js +26 -13
  212. package/dist/backend/native-codegen-core.js.map +1 -1
  213. package/dist/backend/native-codegen.js +30 -8
  214. package/dist/backend/native-codegen.js.map +1 -1
  215. package/dist/backend/native-codegen.test.js +110 -14
  216. package/dist/backend/native-codegen.test.js.map +1 -1
  217. package/dist/backend/native-link-info-core.d.ts +72 -0
  218. package/dist/backend/native-link-info-core.js.map +1 -1
  219. package/dist/backend/native-link-info.js +1 -0
  220. package/dist/backend/native-link-info.js.map +1 -1
  221. package/dist/backend/native-profile.d.ts +4 -1
  222. package/dist/backend/native-profile.js +12 -1
  223. package/dist/backend/native-profile.js.map +1 -1
  224. package/dist/backend/native-profile.test.js +10 -0
  225. package/dist/backend/native-profile.test.js.map +1 -1
  226. package/dist/backend/publication.d.ts +4 -1
  227. package/dist/backend/publication.js +4 -2
  228. package/dist/backend/publication.js.map +1 -1
  229. package/dist/backend/runtime-abi.d.ts +2 -2
  230. package/dist/backend/runtime-abi.js +2 -2
  231. package/dist/backend/runtime-pack-core.d.ts +46 -7
  232. package/dist/backend/runtime-pack-core.js +37 -2
  233. package/dist/backend/runtime-pack-core.js.map +1 -1
  234. package/dist/backend/runtime-pack-native.d.ts +18 -1
  235. package/dist/backend/runtime-pack-native.js +138 -29
  236. package/dist/backend/runtime-pack-native.js.map +1 -1
  237. package/dist/backend/runtime-pack-native.test.js +166 -4
  238. package/dist/backend/runtime-pack-native.test.js.map +1 -1
  239. package/dist/backend/runtime-pack-targets.test.js +3 -1
  240. package/dist/backend/runtime-pack-targets.test.js.map +1 -1
  241. package/dist/backend/runtime-pack.d.ts +7 -0
  242. package/dist/backend/runtime-pack.js +25 -3
  243. package/dist/backend/runtime-pack.js.map +1 -1
  244. package/dist/backend/runtime-pack.test.js +213 -12
  245. package/dist/backend/runtime-pack.test.js.map +1 -1
  246. package/dist/backend/tree-classes.d.ts +42 -0
  247. package/dist/backend/tree-classes.js +723 -0
  248. package/dist/backend/tree-classes.js.map +1 -0
  249. package/dist/backend/tree-classes.test.d.ts +1 -0
  250. package/dist/backend/tree-classes.test.js +338 -0
  251. package/dist/backend/tree-classes.test.js.map +1 -0
  252. package/dist/backend/vendor-archives.d.ts +8 -1
  253. package/dist/backend/vendor-archives.js +313 -8
  254. package/dist/backend/vendor-archives.js.map +1 -1
  255. package/dist/backend/vendor-inputs.d.ts +60 -3
  256. package/dist/backend/vendor-inputs.js +109 -3
  257. package/dist/backend/vendor-inputs.js.map +1 -1
  258. package/dist/backend/vendor-inputs.test.js +62 -1
  259. package/dist/backend/vendor-inputs.test.js.map +1 -1
  260. package/dist/backend/warm-cache.js +2 -0
  261. package/dist/backend/warm-cache.js.map +1 -1
  262. package/dist/compat/fetch-profile.d.ts +7 -1
  263. package/dist/compat/fetch-profile.js +25 -12
  264. package/dist/compat/fetch-profile.js.map +1 -1
  265. package/dist/compile-types.d.ts +7 -0
  266. package/dist/contracts/check.d.ts +3 -0
  267. package/dist/contracts/check.js +18 -5
  268. package/dist/contracts/check.js.map +1 -1
  269. package/dist/coverage/report.js +47 -0
  270. package/dist/coverage/report.js.map +1 -1
  271. package/dist/coverage/surface-manifest.js +1 -1
  272. package/dist/coverage/surface-manifest.js.map +1 -1
  273. package/dist/diagnostics/codes.d.ts +14 -0
  274. package/dist/diagnostics/codes.js +14 -0
  275. package/dist/diagnostics/codes.js.map +1 -1
  276. package/dist/diagnostics/diagnostic.d.ts +68 -0
  277. package/dist/diagnostics/diagnostic.js +186 -6
  278. package/dist/diagnostics/diagnostic.js.map +1 -1
  279. package/dist/diagnostics/dynamic-tier.js +3 -1
  280. package/dist/diagnostics/dynamic-tier.js.map +1 -1
  281. package/dist/diagnostics/envelope.d.ts +18 -0
  282. package/dist/diagnostics/envelope.js.map +1 -1
  283. package/dist/executable/executable-cache.d.ts +48 -0
  284. package/dist/executable/executable-cache.js +38 -0
  285. package/dist/executable/executable-cache.js.map +1 -1
  286. package/dist/executable/executable-cache.test.js +127 -1
  287. package/dist/executable/executable-cache.test.js.map +1 -1
  288. package/dist/executable/prepare.d.ts +13 -3
  289. package/dist/executable/prepare.js +438 -234
  290. package/dist/executable/prepare.js.map +1 -1
  291. package/dist/frontend/analysis.js +200 -18
  292. package/dist/frontend/analysis.js.map +1 -1
  293. package/dist/frontend/builtin-modules.d.ts +4 -0
  294. package/dist/frontend/builtin-modules.js +10 -0
  295. package/dist/frontend/builtin-modules.js.map +1 -1
  296. package/dist/frontend/early-errors.d.ts +24 -0
  297. package/dist/frontend/early-errors.js +836 -0
  298. package/dist/frontend/early-errors.js.map +1 -0
  299. package/dist/frontend/early-errors.test.d.ts +1 -0
  300. package/dist/frontend/early-errors.test.js +207 -0
  301. package/dist/frontend/early-errors.test.js.map +1 -0
  302. package/dist/frontend/inferred-js-diagnostics.test.js +88 -0
  303. package/dist/frontend/inferred-js-diagnostics.test.js.map +1 -1
  304. package/dist/frontend/input-tracker.d.ts +47 -0
  305. package/dist/frontend/input-tracker.js +173 -36
  306. package/dist/frontend/input-tracker.js.map +1 -1
  307. package/dist/frontend/input-tracker.test.js +86 -2
  308. package/dist/frontend/input-tracker.test.js.map +1 -1
  309. package/dist/frontend/js-inference.d.ts +2 -0
  310. package/dist/frontend/js-inference.js +18 -0
  311. package/dist/frontend/js-inference.js.map +1 -0
  312. package/dist/frontend/jsx-opinion-sites.test.d.ts +1 -0
  313. package/dist/frontend/jsx-opinion-sites.test.js +86 -0
  314. package/dist/frontend/jsx-opinion-sites.test.js.map +1 -0
  315. package/dist/frontend/lib-exports.d.ts +23 -4
  316. package/dist/frontend/lib-exports.js +98 -26
  317. package/dist/frontend/lib-exports.js.map +1 -1
  318. package/dist/frontend/lowering/binding-analysis.d.ts +2 -1
  319. package/dist/frontend/lowering/binding-analysis.js +86 -4
  320. package/dist/frontend/lowering/binding-analysis.js.map +1 -1
  321. package/dist/frontend/lowering/buffers.d.ts +8 -0
  322. package/dist/frontend/lowering/buffers.js +43 -0
  323. package/dist/frontend/lowering/buffers.js.map +1 -0
  324. package/dist/frontend/lowering/builtin-calls.js +13 -0
  325. package/dist/frontend/lowering/builtin-calls.js.map +1 -1
  326. package/dist/frontend/lowering/builtin-namespaces.d.ts +3 -2
  327. package/dist/frontend/lowering/builtin-namespaces.js +41 -3
  328. package/dist/frontend/lowering/builtin-namespaces.js.map +1 -1
  329. package/dist/frontend/lowering/builtin-statics.d.ts +24 -0
  330. package/dist/frontend/lowering/builtin-statics.js +407 -0
  331. package/dist/frontend/lowering/builtin-statics.js.map +1 -0
  332. package/dist/frontend/lowering/builtins/arguments.d.ts +4 -0
  333. package/dist/frontend/lowering/builtins/arguments.js +12 -0
  334. package/dist/frontend/lowering/builtins/arguments.js.map +1 -1
  335. package/dist/frontend/lowering/builtins/atomics.d.ts +6 -1
  336. package/dist/frontend/lowering/builtins/atomics.js +87 -1
  337. package/dist/frontend/lowering/builtins/atomics.js.map +1 -1
  338. package/dist/frontend/lowering/builtins/child-process-methods.d.ts +7 -0
  339. package/dist/frontend/lowering/builtins/child-process-methods.js +52 -12
  340. package/dist/frontend/lowering/builtins/child-process-methods.js.map +1 -1
  341. package/dist/frontend/lowering/builtins/child-process-sync.d.ts +13 -0
  342. package/dist/frontend/lowering/builtins/child-process-sync.js +1 -13
  343. package/dist/frontend/lowering/builtins/child-process-sync.js.map +1 -1
  344. package/dist/frontend/lowering/builtins/child-process.d.ts +10 -4
  345. package/dist/frontend/lowering/builtins/child-process.js +565 -28
  346. package/dist/frontend/lowering/builtins/child-process.js.map +1 -1
  347. package/dist/frontend/lowering/builtins/compression.d.ts +2 -2
  348. package/dist/frontend/lowering/builtins/compression.js +41 -21
  349. package/dist/frontend/lowering/builtins/compression.js.map +1 -1
  350. package/dist/frontend/lowering/builtins/constants.js +7 -2
  351. package/dist/frontend/lowering/builtins/constants.js.map +1 -1
  352. package/dist/frontend/lowering/builtins/dates.d.ts +1 -1
  353. package/dist/frontend/lowering/builtins/dates.js +23 -1
  354. package/dist/frontend/lowering/builtins/dates.js.map +1 -1
  355. package/dist/frontend/lowering/builtins/environment.d.ts +55 -0
  356. package/dist/frontend/lowering/builtins/environment.js +213 -2
  357. package/dist/frontend/lowering/builtins/environment.js.map +1 -1
  358. package/dist/frontend/lowering/builtins/filesystem-calls.d.ts +1 -0
  359. package/dist/frontend/lowering/builtins/filesystem-calls.js +75 -18
  360. package/dist/frontend/lowering/builtins/filesystem-calls.js.map +1 -1
  361. package/dist/frontend/lowering/builtins/filesystem.d.ts +25 -7
  362. package/dist/frontend/lowering/builtins/filesystem.js +185 -16
  363. package/dist/frontend/lowering/builtins/filesystem.js.map +1 -1
  364. package/dist/frontend/lowering/builtins/json.js +4 -0
  365. package/dist/frontend/lowering/builtins/json.js.map +1 -1
  366. package/dist/frontend/lowering/builtins/module-calls.js +42 -3
  367. package/dist/frontend/lowering/builtins/module-calls.js.map +1 -1
  368. package/dist/frontend/lowering/builtins/module-resolution.d.ts +8 -0
  369. package/dist/frontend/lowering/builtins/module-resolution.js +31 -5
  370. package/dist/frontend/lowering/builtins/module-resolution.js.map +1 -1
  371. package/dist/frontend/lowering/builtins/numbers.d.ts +4 -1
  372. package/dist/frontend/lowering/builtins/numbers.js +10 -2
  373. package/dist/frontend/lowering/builtins/numbers.js.map +1 -1
  374. package/dist/frontend/lowering/builtins/operating-system.d.ts +9 -5
  375. package/dist/frontend/lowering/builtins/operating-system.js +101 -20
  376. package/dist/frontend/lowering/builtins/operating-system.js.map +1 -1
  377. package/dist/frontend/lowering/builtins/process.d.ts +18 -2
  378. package/dist/frontend/lowering/builtins/process.js +386 -25
  379. package/dist/frontend/lowering/builtins/process.js.map +1 -1
  380. package/dist/frontend/lowering/builtins/promises.js +169 -8
  381. package/dist/frontend/lowering/builtins/promises.js.map +1 -1
  382. package/dist/frontend/lowering/builtins/properties.js +6 -2
  383. package/dist/frontend/lowering/builtins/properties.js.map +1 -1
  384. package/dist/frontend/lowering/builtins/querystring.d.ts +8 -0
  385. package/dist/frontend/lowering/builtins/querystring.js +202 -18
  386. package/dist/frontend/lowering/builtins/querystring.js.map +1 -1
  387. package/dist/frontend/lowering/builtins/readline.d.ts +6 -4
  388. package/dist/frontend/lowering/builtins/readline.js +200 -38
  389. package/dist/frontend/lowering/builtins/readline.js.map +1 -1
  390. package/dist/frontend/lowering/builtins/reflection.js +60 -1
  391. package/dist/frontend/lowering/builtins/reflection.js.map +1 -1
  392. package/dist/frontend/lowering/builtins/text-codecs.js +208 -59
  393. package/dist/frontend/lowering/builtins/text-codecs.js.map +1 -1
  394. package/dist/frontend/lowering/builtins/url.js +55 -13
  395. package/dist/frontend/lowering/builtins/url.js.map +1 -1
  396. package/dist/frontend/lowering/builtins/v8.d.ts +5 -5
  397. package/dist/frontend/lowering/builtins/v8.js +7 -5
  398. package/dist/frontend/lowering/builtins/v8.js.map +1 -1
  399. package/dist/frontend/lowering/builtins/web-streams-dyn.d.ts +17 -2
  400. package/dist/frontend/lowering/builtins/web-streams-dyn.js +97 -9
  401. package/dist/frontend/lowering/builtins/web-streams-dyn.js.map +1 -1
  402. package/dist/frontend/lowering/builtins/webassembly.js +2 -0
  403. package/dist/frontend/lowering/builtins/webassembly.js.map +1 -1
  404. package/dist/frontend/lowering/call-arguments.d.ts +10 -0
  405. package/dist/frontend/lowering/call-arguments.js +37 -2
  406. package/dist/frontend/lowering/call-arguments.js.map +1 -1
  407. package/dist/frontend/lowering/call-signatures.d.ts +10 -0
  408. package/dist/frontend/lowering/call-signatures.js +180 -0
  409. package/dist/frontend/lowering/call-signatures.js.map +1 -1
  410. package/dist/frontend/lowering/cjs-exports-object.d.ts +3 -0
  411. package/dist/frontend/lowering/cjs-exports-object.js +1 -1
  412. package/dist/frontend/lowering/cjs-exports-object.js.map +1 -1
  413. package/dist/frontend/lowering/cjs-inline-require.js +5 -0
  414. package/dist/frontend/lowering/cjs-inline-require.js.map +1 -1
  415. package/dist/frontend/lowering/class-construction.d.ts +14 -2
  416. package/dist/frontend/lowering/class-construction.js +99 -5
  417. package/dist/frontend/lowering/class-construction.js.map +1 -1
  418. package/dist/frontend/lowering/class-dynamic-dispatch.d.ts +14 -0
  419. package/dist/frontend/lowering/class-dynamic-dispatch.js +1376 -1009
  420. package/dist/frontend/lowering/class-dynamic-dispatch.js.map +1 -1
  421. package/dist/frontend/lowering/class-dynamic-dispatch.test.js +158 -0
  422. package/dist/frontend/lowering/class-dynamic-dispatch.test.js.map +1 -1
  423. package/dist/frontend/lowering/class-protocols.js +59 -10
  424. package/dist/frontend/lowering/class-protocols.js.map +1 -1
  425. package/dist/frontend/lowering/class-prototypes.js +20 -15
  426. package/dist/frontend/lowering/class-prototypes.js.map +1 -1
  427. package/dist/frontend/lowering/class-runtime-statics.d.ts +8 -0
  428. package/dist/frontend/lowering/class-runtime-statics.js +35 -1
  429. package/dist/frontend/lowering/class-runtime-statics.js.map +1 -1
  430. package/dist/frontend/lowering/class-unions.js +21 -4
  431. package/dist/frontend/lowering/class-unions.js.map +1 -1
  432. package/dist/frontend/lowering/class-views.d.ts +13 -0
  433. package/dist/frontend/lowering/class-views.js +51 -0
  434. package/dist/frontend/lowering/class-views.js.map +1 -0
  435. package/dist/frontend/lowering/coercions/function-adapters.d.ts +15 -1
  436. package/dist/frontend/lowering/coercions/function-adapters.js +63 -10
  437. package/dist/frontend/lowering/coercions/function-adapters.js.map +1 -1
  438. package/dist/frontend/lowering/coercions/state.d.ts +15 -0
  439. package/dist/frontend/lowering/coercions/state.js +24 -0
  440. package/dist/frontend/lowering/coercions/state.js.map +1 -1
  441. package/dist/frontend/lowering/coercions/structural-plans.js +75 -3
  442. package/dist/frontend/lowering/coercions/structural-plans.js.map +1 -1
  443. package/dist/frontend/lowering/coercions/structural.js +39 -2
  444. package/dist/frontend/lowering/coercions/structural.js.map +1 -1
  445. package/dist/frontend/lowering/coercions/unions.d.ts +2 -1
  446. package/dist/frontend/lowering/coercions/unions.js +54 -10
  447. package/dist/frontend/lowering/coercions/unions.js.map +1 -1
  448. package/dist/frontend/lowering/constructor-returns.d.ts +23 -2
  449. package/dist/frontend/lowering/constructor-returns.js +284 -58
  450. package/dist/frontend/lowering/constructor-returns.js.map +1 -1
  451. package/dist/frontend/lowering/containers/array-callbacks.d.ts +8 -1
  452. package/dist/frontend/lowering/containers/array-callbacks.js +288 -90
  453. package/dist/frontend/lowering/containers/array-callbacks.js.map +1 -1
  454. package/dist/frontend/lowering/containers/array-construction.js +37 -8
  455. package/dist/frontend/lowering/containers/array-construction.js.map +1 -1
  456. package/dist/frontend/lowering/containers/array-from-async.js +139 -3
  457. package/dist/frontend/lowering/containers/array-from-async.js.map +1 -1
  458. package/dist/frontend/lowering/containers/array-iteration.d.ts +14 -4
  459. package/dist/frontend/lowering/containers/array-iteration.js +24 -7
  460. package/dist/frontend/lowering/containers/array-iteration.js.map +1 -1
  461. package/dist/frontend/lowering/containers/array-methods.js +30 -11
  462. package/dist/frontend/lowering/containers/array-methods.js.map +1 -1
  463. package/dist/frontend/lowering/containers/bytes.d.ts +6 -0
  464. package/dist/frontend/lowering/containers/bytes.js +450 -86
  465. package/dist/frontend/lowering/containers/bytes.js.map +1 -1
  466. package/dist/frontend/lowering/containers/callback-arguments.d.ts +16 -0
  467. package/dist/frontend/lowering/containers/callback-arguments.js +74 -12
  468. package/dist/frontend/lowering/containers/callback-arguments.js.map +1 -1
  469. package/dist/frontend/lowering/containers/collection-grouping.js +421 -2
  470. package/dist/frontend/lowering/containers/collection-grouping.js.map +1 -1
  471. package/dist/frontend/lowering/containers/collection-methods.js +52 -17
  472. package/dist/frontend/lowering/containers/collection-methods.js.map +1 -1
  473. package/dist/frontend/lowering/containers/filter-predicates.d.ts +10 -0
  474. package/dist/frontend/lowering/containers/filter-predicates.js +69 -3
  475. package/dist/frontend/lowering/containers/filter-predicates.js.map +1 -1
  476. package/dist/frontend/lowering/containers/indexed-objects.js +46 -2
  477. package/dist/frontend/lowering/containers/indexed-objects.js.map +1 -1
  478. package/dist/frontend/lowering/containers/iterator-helpers.d.ts +23 -0
  479. package/dist/frontend/lowering/containers/iterator-helpers.js +176 -10
  480. package/dist/frontend/lowering/containers/iterator-helpers.js.map +1 -1
  481. package/dist/frontend/lowering/containers/string-and-regexp.d.ts +5 -2
  482. package/dist/frontend/lowering/containers/string-and-regexp.js +45 -11
  483. package/dist/frontend/lowering/containers/string-and-regexp.js.map +1 -1
  484. package/dist/frontend/lowering/crypto-tables.d.ts +3 -3
  485. package/dist/frontend/lowering/crypto-tables.js +5 -5
  486. package/dist/frontend/lowering/dispatch-sites.js +3 -0
  487. package/dist/frontend/lowering/dispatch-sites.js.map +1 -1
  488. package/dist/frontend/lowering/divergences.d.ts +40 -0
  489. package/dist/frontend/lowering/divergences.js +239 -20
  490. package/dist/frontend/lowering/divergences.js.map +1 -1
  491. package/dist/frontend/lowering/effect-free.d.ts +12 -0
  492. package/dist/frontend/lowering/effect-free.js +44 -0
  493. package/dist/frontend/lowering/effect-free.js.map +1 -0
  494. package/dist/frontend/lowering/expressions/array-literals.d.ts +24 -0
  495. package/dist/frontend/lowering/expressions/array-literals.js +88 -10
  496. package/dist/frontend/lowering/expressions/array-literals.js.map +1 -1
  497. package/dist/frontend/lowering/expressions/binary.js +216 -14
  498. package/dist/frontend/lowering/expressions/binary.js.map +1 -1
  499. package/dist/frontend/lowering/expressions/element-access.js +272 -11
  500. package/dist/frontend/lowering/expressions/element-access.js.map +1 -1
  501. package/dist/frontend/lowering/expressions/hosted-narrowing.d.ts +15 -0
  502. package/dist/frontend/lowering/expressions/hosted-narrowing.js +54 -1
  503. package/dist/frontend/lowering/expressions/hosted-narrowing.js.map +1 -1
  504. package/dist/frontend/lowering/expressions/identifiers.js +173 -4
  505. package/dist/frontend/lowering/expressions/identifiers.js.map +1 -1
  506. package/dist/frontend/lowering/expressions/keyed-field-targets.d.ts +11 -1
  507. package/dist/frontend/lowering/expressions/keyed-field-targets.js +22 -1
  508. package/dist/frontend/lowering/expressions/keyed-field-targets.js.map +1 -1
  509. package/dist/frontend/lowering/expressions/narrowing.d.ts +3 -0
  510. package/dist/frontend/lowering/expressions/narrowing.js +195 -18
  511. package/dist/frontend/lowering/expressions/narrowing.js.map +1 -1
  512. package/dist/frontend/lowering/expressions/object-literals.d.ts +5 -1
  513. package/dist/frontend/lowering/expressions/object-literals.js +951 -240
  514. package/dist/frontend/lowering/expressions/object-literals.js.map +1 -1
  515. package/dist/frontend/lowering/expressions/optional-chains.js +71 -21
  516. package/dist/frontend/lowering/expressions/optional-chains.js.map +1 -1
  517. package/dist/frontend/lowering/expressions/property-access.d.ts +39 -0
  518. package/dist/frontend/lowering/expressions/property-access.js +1141 -87
  519. package/dist/frontend/lowering/expressions/property-access.js.map +1 -1
  520. package/dist/frontend/lowering/expressions/relational.js +262 -4
  521. package/dist/frontend/lowering/expressions/relational.js.map +1 -1
  522. package/dist/frontend/lowering/expressions/typeof.js +25 -0
  523. package/dist/frontend/lowering/expressions/typeof.js.map +1 -1
  524. package/dist/frontend/lowering/expressions/union-fields.d.ts +20 -1
  525. package/dist/frontend/lowering/expressions/union-fields.js +103 -13
  526. package/dist/frontend/lowering/expressions/union-fields.js.map +1 -1
  527. package/dist/frontend/lowering/expressions/updates.js +156 -22
  528. package/dist/frontend/lowering/expressions/updates.js.map +1 -1
  529. package/dist/frontend/lowering/frozen-records.d.ts +6 -0
  530. package/dist/frontend/lowering/frozen-records.js +10 -4
  531. package/dist/frontend/lowering/frozen-records.js.map +1 -1
  532. package/dist/frontend/lowering/frozen-records.test.d.ts +1 -0
  533. package/dist/frontend/lowering/frozen-records.test.js +44 -0
  534. package/dist/frontend/lowering/frozen-records.test.js.map +1 -0
  535. package/dist/frontend/lowering/function-names.d.ts +9 -0
  536. package/dist/frontend/lowering/function-names.js +95 -0
  537. package/dist/frontend/lowering/function-names.js.map +1 -0
  538. package/dist/frontend/lowering/function-returns.js +42 -13
  539. package/dist/frontend/lowering/function-returns.js.map +1 -1
  540. package/dist/frontend/lowering/general-streams.js +5 -0
  541. package/dist/frontend/lowering/general-streams.js.map +1 -1
  542. package/dist/frontend/lowering/generator-delegation.d.ts +15 -7
  543. package/dist/frontend/lowering/generator-delegation.js +301 -118
  544. package/dist/frontend/lowering/generator-delegation.js.map +1 -1
  545. package/dist/frontend/lowering/generic-functions.d.ts +75 -0
  546. package/dist/frontend/lowering/generic-functions.js +790 -18
  547. package/dist/frontend/lowering/generic-functions.js.map +1 -1
  548. package/dist/frontend/lowering/global-function-values.d.ts +25 -0
  549. package/dist/frontend/lowering/global-function-values.js +193 -0
  550. package/dist/frontend/lowering/global-function-values.js.map +1 -0
  551. package/dist/frontend/lowering/global-values.d.ts +15 -4
  552. package/dist/frontend/lowering/global-values.js +67 -9
  553. package/dist/frontend/lowering/global-values.js.map +1 -1
  554. package/dist/frontend/lowering/handle-properties.js +34 -1
  555. package/dist/frontend/lowering/handle-properties.js.map +1 -1
  556. package/dist/frontend/lowering/host-global-values.d.ts +31 -0
  557. package/dist/frontend/lowering/host-global-values.js +121 -0
  558. package/dist/frontend/lowering/host-global-values.js.map +1 -0
  559. package/dist/frontend/lowering/host-globals.d.ts +74 -0
  560. package/dist/frontend/lowering/host-globals.js +344 -0
  561. package/dist/frontend/lowering/host-globals.js.map +1 -0
  562. package/dist/frontend/lowering/http2-constants.js +1 -1
  563. package/dist/frontend/lowering/iterator-adapters.js +46 -17
  564. package/dist/frontend/lowering/iterator-adapters.js.map +1 -1
  565. package/dist/frontend/lowering/iterator-prototype.d.ts +30 -0
  566. package/dist/frontend/lowering/iterator-prototype.js +160 -0
  567. package/dist/frontend/lowering/iterator-prototype.js.map +1 -0
  568. package/dist/frontend/lowering/key-order-witness.d.ts +54 -0
  569. package/dist/frontend/lowering/key-order-witness.js +571 -9
  570. package/dist/frontend/lowering/key-order-witness.js.map +1 -1
  571. package/dist/frontend/lowering/key-order-witness.test.js +1 -0
  572. package/dist/frontend/lowering/key-order-witness.test.js.map +1 -1
  573. package/dist/frontend/lowering/lib-boundary.js +25 -3
  574. package/dist/frontend/lowering/lib-boundary.js.map +1 -1
  575. package/dist/frontend/lowering/lower-assert.js +140 -16
  576. package/dist/frontend/lowering/lower-assert.js.map +1 -1
  577. package/dist/frontend/lowering/lower-async-iteration.d.ts +11 -0
  578. package/dist/frontend/lowering/lower-async-iteration.js +15 -0
  579. package/dist/frontend/lowering/lower-async-iteration.js.map +1 -1
  580. package/dist/frontend/lowering/lower-builtin-values.d.ts +36 -6
  581. package/dist/frontend/lowering/lower-builtin-values.js +342 -58
  582. package/dist/frontend/lowering/lower-builtin-values.js.map +1 -1
  583. package/dist/frontend/lowering/lower-calls.d.ts +47 -1
  584. package/dist/frontend/lowering/lower-calls.js +1354 -273
  585. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  586. package/dist/frontend/lowering/lower-calls.test.d.ts +1 -0
  587. package/dist/frontend/lowering/lower-calls.test.js +121 -0
  588. package/dist/frontend/lowering/lower-calls.test.js.map +1 -0
  589. package/dist/frontend/lowering/lower-classes.d.ts +36 -5
  590. package/dist/frontend/lowering/lower-classes.js +630 -89
  591. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  592. package/dist/frontend/lowering/lower-event-emitter.d.ts +15 -2
  593. package/dist/frontend/lowering/lower-event-emitter.js +610 -98
  594. package/dist/frontend/lowering/lower-event-emitter.js.map +1 -1
  595. package/dist/frontend/lowering/lower-exprs.d.ts +15 -1
  596. package/dist/frontend/lowering/lower-exprs.js +96 -20
  597. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  598. package/dist/frontend/lowering/lower-functions.js +27 -6
  599. package/dist/frontend/lowering/lower-functions.js.map +1 -1
  600. package/dist/frontend/lowering/lower-generators.js +57 -10
  601. package/dist/frontend/lowering/lower-generators.js.map +1 -1
  602. package/dist/frontend/lowering/lower-global-value.d.ts +6 -0
  603. package/dist/frontend/lowering/lower-global-value.js +14 -5
  604. package/dist/frontend/lowering/lower-global-value.js.map +1 -1
  605. package/dist/frontend/lowering/lower-inspect.d.ts +4 -0
  606. package/dist/frontend/lowering/lower-inspect.js +713 -92
  607. package/dist/frontend/lowering/lower-inspect.js.map +1 -1
  608. package/dist/frontend/lowering/lower-modules.js +135 -27
  609. package/dist/frontend/lowering/lower-modules.js.map +1 -1
  610. package/dist/frontend/lowering/lower-namespaces.js +18 -0
  611. package/dist/frontend/lowering/lower-namespaces.js.map +1 -1
  612. package/dist/frontend/lowering/lower-node-island.d.ts +35 -4
  613. package/dist/frontend/lowering/lower-node-island.js +472 -67
  614. package/dist/frontend/lowering/lower-node-island.js.map +1 -1
  615. package/dist/frontend/lowering/lower-server.js +463 -96
  616. package/dist/frontend/lowering/lower-server.js.map +1 -1
  617. package/dist/frontend/lowering/lower-shared-modules.js +13 -1
  618. package/dist/frontend/lowering/lower-shared-modules.js.map +1 -1
  619. package/dist/frontend/lowering/lower-stdlib.d.ts +3 -2
  620. package/dist/frontend/lowering/lower-stdlib.js +77 -18
  621. package/dist/frontend/lowering/lower-stdlib.js.map +1 -1
  622. package/dist/frontend/lowering/lower-stmts.d.ts +24 -4
  623. package/dist/frontend/lowering/lower-stmts.js +831 -136
  624. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  625. package/dist/frontend/lowering/lower-stream.js +126 -8
  626. package/dist/frontend/lowering/lower-stream.js.map +1 -1
  627. package/dist/frontend/lowering/lower-timers.js +243 -48
  628. package/dist/frontend/lowering/lower-timers.js.map +1 -1
  629. package/dist/frontend/lowering/lower-url.js +6 -3
  630. package/dist/frontend/lowering/lower-url.js.map +1 -1
  631. package/dist/frontend/lowering/lowerer.d.ts +363 -21
  632. package/dist/frontend/lowering/lowerer.js +1224 -129
  633. package/dist/frontend/lowering/lowerer.js.map +1 -1
  634. package/dist/frontend/lowering/lowerer.test.js +19 -1
  635. package/dist/frontend/lowering/lowerer.test.js.map +1 -1
  636. package/dist/frontend/lowering/lowering-facts.d.ts +110 -0
  637. package/dist/frontend/lowering/lowering-facts.js +323 -0
  638. package/dist/frontend/lowering/lowering-facts.js.map +1 -0
  639. package/dist/frontend/lowering/lowering-facts.test.d.ts +1 -0
  640. package/dist/frontend/lowering/lowering-facts.test.js +100 -0
  641. package/dist/frontend/lowering/lowering-facts.test.js.map +1 -0
  642. package/dist/frontend/lowering/module-namespace-elements.js +15 -0
  643. package/dist/frontend/lowering/module-namespace-elements.js.map +1 -1
  644. package/dist/frontend/lowering/nan-coded-reads.d.ts +27 -4
  645. package/dist/frontend/lowering/nan-coded-reads.js +112 -9
  646. package/dist/frontend/lowering/nan-coded-reads.js.map +1 -1
  647. package/dist/frontend/lowering/new-target.js +2 -2
  648. package/dist/frontend/lowering/nullish-empty-pattern.d.ts +17 -0
  649. package/dist/frontend/lowering/nullish-empty-pattern.js +118 -0
  650. package/dist/frontend/lowering/nullish-empty-pattern.js.map +1 -0
  651. package/dist/frontend/lowering/optional-arguments.d.ts +4 -0
  652. package/dist/frontend/lowering/optional-arguments.js +26 -2
  653. package/dist/frontend/lowering/optional-arguments.js.map +1 -1
  654. package/dist/frontend/lowering/partial-assertions.d.ts +36 -0
  655. package/dist/frontend/lowering/partial-assertions.js +189 -0
  656. package/dist/frontend/lowering/partial-assertions.js.map +1 -0
  657. package/dist/frontend/lowering/primitive-throws.d.ts +100 -0
  658. package/dist/frontend/lowering/primitive-throws.js +241 -0
  659. package/dist/frontend/lowering/primitive-throws.js.map +1 -0
  660. package/dist/frontend/lowering/primitive-wrappers.d.ts +34 -0
  661. package/dist/frontend/lowering/primitive-wrappers.js +221 -0
  662. package/dist/frontend/lowering/primitive-wrappers.js.map +1 -0
  663. package/dist/frontend/lowering/private-statics.d.ts +46 -0
  664. package/dist/frontend/lowering/private-statics.js +322 -0
  665. package/dist/frontend/lowering/private-statics.js.map +1 -0
  666. package/dist/frontend/lowering/record-inherited.d.ts +17 -1
  667. package/dist/frontend/lowering/record-inherited.js +16 -2
  668. package/dist/frontend/lowering/record-inherited.js.map +1 -1
  669. package/dist/frontend/lowering/record-links.d.ts +73 -0
  670. package/dist/frontend/lowering/record-links.js +797 -0
  671. package/dist/frontend/lowering/record-links.js.map +1 -0
  672. package/dist/frontend/lowering/record-sources.d.ts +12 -1
  673. package/dist/frontend/lowering/record-sources.js +60 -0
  674. package/dist/frontend/lowering/record-sources.js.map +1 -1
  675. package/dist/frontend/lowering/runtime-optional-provenance.d.ts +27 -7
  676. package/dist/frontend/lowering/runtime-optional-provenance.js +25 -11
  677. package/dist/frontend/lowering/runtime-optional-provenance.js.map +1 -1
  678. package/dist/frontend/lowering/runtime-optional-report.d.ts +40 -0
  679. package/dist/frontend/lowering/runtime-optional-report.js +300 -0
  680. package/dist/frontend/lowering/runtime-optional-report.js.map +1 -0
  681. package/dist/frontend/lowering/scoped-type-memo.test.d.ts +1 -0
  682. package/dist/frontend/lowering/scoped-type-memo.test.js +86 -0
  683. package/dist/frontend/lowering/scoped-type-memo.test.js.map +1 -0
  684. package/dist/frontend/lowering/static-typeof.d.ts +3 -1
  685. package/dist/frontend/lowering/static-typeof.js +6 -1
  686. package/dist/frontend/lowering/static-typeof.js.map +1 -1
  687. package/dist/frontend/lowering/strict-equality.d.ts +4 -0
  688. package/dist/frontend/lowering/strict-equality.js +14 -0
  689. package/dist/frontend/lowering/strict-equality.js.map +1 -1
  690. package/dist/frontend/lowering/strict-mode.d.ts +1 -5
  691. package/dist/frontend/lowering/strict-mode.js +4 -30
  692. package/dist/frontend/lowering/strict-mode.js.map +1 -1
  693. package/dist/frontend/lowering/structural-instances.d.ts +7 -0
  694. package/dist/frontend/lowering/structural-instances.js +23 -0
  695. package/dist/frontend/lowering/structural-instances.js.map +1 -1
  696. package/dist/frontend/lowering/surfaces.d.ts +42 -1
  697. package/dist/frontend/lowering/surfaces.js +212 -71
  698. package/dist/frontend/lowering/surfaces.js.map +1 -1
  699. package/dist/frontend/lowering/union-retag.d.ts +13 -1
  700. package/dist/frontend/lowering/union-retag.js +55 -1
  701. package/dist/frontend/lowering/union-retag.js.map +1 -1
  702. package/dist/frontend/lowering/union-retag.test.js +51 -0
  703. package/dist/frontend/lowering/union-retag.test.js.map +1 -1
  704. package/dist/frontend/lowering/unit-journal.d.ts +136 -17
  705. package/dist/frontend/lowering/unit-journal.js +324 -53
  706. package/dist/frontend/lowering/unit-journal.js.map +1 -1
  707. package/dist/frontend/lowering/unit-journal.test.js +126 -3
  708. package/dist/frontend/lowering/unit-journal.test.js.map +1 -1
  709. package/dist/frontend/lowering/unit-reuse.d.ts +92 -0
  710. package/dist/frontend/lowering/unit-reuse.js +1008 -0
  711. package/dist/frontend/lowering/unit-reuse.js.map +1 -0
  712. package/dist/frontend/lowering/width-lift.d.ts +12 -0
  713. package/dist/frontend/lowering/zlib-constants.js +3 -2
  714. package/dist/frontend/lowering/zlib-constants.js.map +1 -1
  715. package/dist/frontend/npm-file-import.test.d.ts +1 -0
  716. package/dist/frontend/npm-file-import.test.js +76 -0
  717. package/dist/frontend/npm-file-import.test.js.map +1 -0
  718. package/dist/frontend/npm-static.js +95 -11
  719. package/dist/frontend/npm-static.js.map +1 -1
  720. package/dist/frontend/npm-static.test.js +95 -2
  721. package/dist/frontend/npm-static.test.js.map +1 -1
  722. package/dist/frontend/npm.d.ts +9 -0
  723. package/dist/frontend/npm.js +82 -0
  724. package/dist/frontend/npm.js.map +1 -1
  725. package/dist/frontend/pipeline-native.js +2 -1
  726. package/dist/frontend/pipeline-native.js.map +1 -1
  727. package/dist/frontend/pipeline.d.ts +9 -4
  728. package/dist/frontend/pipeline.js +162 -38
  729. package/dist/frontend/pipeline.js.map +1 -1
  730. package/dist/frontend/pipeline.test.js +68 -11
  731. package/dist/frontend/pipeline.test.js.map +1 -1
  732. package/dist/frontend/program-node.d.ts +3 -0
  733. package/dist/frontend/program-node.js +13 -6
  734. package/dist/frontend/program-node.js.map +1 -1
  735. package/dist/frontend/program.d.ts +71 -2
  736. package/dist/frontend/program.js +836 -411
  737. package/dist/frontend/program.js.map +1 -1
  738. package/dist/frontend/program.test.js +37 -1
  739. package/dist/frontend/program.test.js.map +1 -1
  740. package/dist/frontend/provenance-core.js +4 -0
  741. package/dist/frontend/provenance-core.js.map +1 -1
  742. package/dist/frontend/services-node.d.ts +7 -0
  743. package/dist/frontend/services-node.js +32 -1
  744. package/dist/frontend/services-node.js.map +1 -1
  745. package/dist/frontend/services-node.test.js +51 -0
  746. package/dist/frontend/services-node.test.js.map +1 -1
  747. package/dist/frontend/services.d.ts +14 -0
  748. package/dist/frontend/services.js +52 -2
  749. package/dist/frontend/services.js.map +1 -1
  750. package/dist/frontend/services.test.js +61 -1
  751. package/dist/frontend/services.test.js.map +1 -1
  752. package/dist/frontend/shape-inference/analyze.d.ts +5 -0
  753. package/dist/frontend/shape-inference/analyze.js +104 -4
  754. package/dist/frontend/shape-inference/analyze.js.map +1 -1
  755. package/dist/frontend/shape-inference/domain.js +0 -1
  756. package/dist/frontend/shape-inference/domain.js.map +1 -1
  757. package/dist/frontend/shape-inference/index.js +5 -1
  758. package/dist/frontend/shape-inference/index.js.map +1 -1
  759. package/dist/frontend/shape-inference/memo.d.ts +2 -1
  760. package/dist/frontend/shape-inference/memo.js +6 -2
  761. package/dist/frontend/shape-inference/memo.js.map +1 -1
  762. package/dist/frontend/shape-inference/overlay.d.ts +1 -1
  763. package/dist/frontend/shape-inference/overlay.js +184 -4
  764. package/dist/frontend/shape-inference/overlay.js.map +1 -1
  765. package/dist/frontend/shape-inference/static-objects.js +11 -6
  766. package/dist/frontend/shape-inference/static-objects.js.map +1 -1
  767. package/dist/frontend/source-phase-imports.test.d.ts +1 -0
  768. package/dist/frontend/source-phase-imports.test.js +37 -0
  769. package/dist/frontend/source-phase-imports.test.js.map +1 -0
  770. package/dist/frontend/tier-analysis.d.ts +9 -0
  771. package/dist/frontend/tier-analysis.js +1 -0
  772. package/dist/frontend/tier-analysis.js.map +1 -1
  773. package/dist/frontend/ts7/ast-node.d.ts +6 -1
  774. package/dist/frontend/ts7/ast-node.js +12 -0
  775. package/dist/frontend/ts7/ast-node.js.map +1 -1
  776. package/dist/frontend/ts7/ast-wire-protocols.test.js +11 -3
  777. package/dist/frontend/ts7/ast-wire-protocols.test.js.map +1 -1
  778. package/dist/frontend/ts7/ast-wire.js +3 -5
  779. package/dist/frontend/ts7/ast-wire.js.map +1 -1
  780. package/dist/frontend/ts7/checker-backend.d.ts +13 -0
  781. package/dist/frontend/ts7/checker-backend.js +84 -2
  782. package/dist/frontend/ts7/checker-backend.js.map +1 -1
  783. package/dist/frontend/ts7/checker-backend.test.js +126 -2
  784. package/dist/frontend/ts7/checker-backend.test.js.map +1 -1
  785. package/dist/frontend/ts7/program-host.d.ts +22 -1
  786. package/dist/frontend/ts7/program-host.js +49 -4
  787. package/dist/frontend/ts7/program-host.js.map +1 -1
  788. package/dist/frontend/ts7/program-host.test.js +83 -0
  789. package/dist/frontend/ts7/program-host.test.js.map +1 -1
  790. package/dist/frontend/ts7/rpc-process.d.ts +16 -1
  791. package/dist/frontend/ts7/rpc-process.js +170 -92
  792. package/dist/frontend/ts7/rpc-process.js.map +1 -1
  793. package/dist/frontend/ts7/rpc-process.test.js +49 -21
  794. package/dist/frontend/ts7/rpc-process.test.js.map +1 -1
  795. package/dist/frontend/tsc-codes.d.ts +57 -3
  796. package/dist/frontend/tsc-codes.js +956 -101
  797. package/dist/frontend/tsc-codes.js.map +1 -1
  798. package/dist/frontend/tsc-codes.test.js +221 -12
  799. package/dist/frontend/tsc-codes.test.js.map +1 -1
  800. package/dist/frontend/type-mapper.d.ts +98 -11
  801. package/dist/frontend/type-mapper.js +770 -182
  802. package/dist/frontend/type-mapper.js.map +1 -1
  803. package/dist/index.d.ts +1 -1
  804. package/dist/index.js +224 -15
  805. package/dist/index.js.map +1 -1
  806. package/dist/index.test.d.ts +1 -0
  807. package/dist/index.test.js +60 -0
  808. package/dist/index.test.js.map +1 -0
  809. package/dist/ir/api.d.ts +1 -1
  810. package/dist/ir/api.js +1 -1
  811. package/dist/ir/api.js.map +1 -1
  812. package/dist/ir/build.d.ts +3 -2
  813. package/dist/ir/build.js +4 -2
  814. package/dist/ir/build.js.map +1 -1
  815. package/dist/ir/builtin-effects.js +96 -0
  816. package/dist/ir/builtin-effects.js.map +1 -1
  817. package/dist/ir/builtin-signatures.d.ts +1 -1
  818. package/dist/ir/builtin-signatures.js +453 -26
  819. package/dist/ir/builtin-signatures.js.map +1 -1
  820. package/dist/ir/callback-specialization.d.ts +3 -2
  821. package/dist/ir/callback-specialization.js +35 -25
  822. package/dist/ir/callback-specialization.js.map +1 -1
  823. package/dist/ir/capture-values.d.ts +8 -4
  824. package/dist/ir/capture-values.js +9 -6
  825. package/dist/ir/capture-values.js.map +1 -1
  826. package/dist/ir/char-unit-locals.d.ts +6 -2
  827. package/dist/ir/char-unit-locals.js +11 -2
  828. package/dist/ir/char-unit-locals.js.map +1 -1
  829. package/dist/ir/class-key-index.d.ts +18 -0
  830. package/dist/ir/class-key-index.js +29 -0
  831. package/dist/ir/class-key-index.js.map +1 -0
  832. package/dist/ir/class-key-index.test.d.ts +1 -0
  833. package/dist/ir/class-key-index.test.js +25 -0
  834. package/dist/ir/class-key-index.test.js.map +1 -0
  835. package/dist/ir/codec.d.ts +82 -0
  836. package/dist/ir/codec.generated.d.ts +13 -0
  837. package/dist/ir/codec.generated.js +5350 -0
  838. package/dist/ir/codec.generated.js.map +1 -0
  839. package/dist/ir/codec.js +325 -0
  840. package/dist/ir/codec.js.map +1 -0
  841. package/dist/ir/codec.test.d.ts +1 -0
  842. package/dist/ir/codec.test.js +225 -0
  843. package/dist/ir/codec.test.js.map +1 -0
  844. package/dist/ir/constant-globals.d.ts +5 -2
  845. package/dist/ir/constant-globals.js +25 -27
  846. package/dist/ir/constant-globals.js.map +1 -1
  847. package/dist/ir/expression-inlining.d.ts +4 -2
  848. package/dist/ir/expression-inlining.js +8 -2
  849. package/dist/ir/expression-inlining.js.map +1 -1
  850. package/dist/ir/field-values.d.ts +5 -2
  851. package/dist/ir/field-values.js +32 -21
  852. package/dist/ir/field-values.js.map +1 -1
  853. package/dist/ir/fields.generated.d.ts +29 -10
  854. package/dist/ir/fields.generated.js +1039 -11
  855. package/dist/ir/fields.generated.js.map +1 -1
  856. package/dist/ir/fields.test.js +46 -2
  857. package/dist/ir/fields.test.js.map +1 -1
  858. package/dist/ir/final-fields.js +1 -1
  859. package/dist/ir/final-fields.js.map +1 -1
  860. package/dist/ir/function-references.d.ts +6 -4
  861. package/dist/ir/function-references.js +11 -4
  862. package/dist/ir/function-references.js.map +1 -1
  863. package/dist/ir/function-references.test.js +14 -0
  864. package/dist/ir/function-references.test.js.map +1 -1
  865. package/dist/ir/init-only-globals.d.ts +4 -2
  866. package/dist/ir/init-only-globals.js +17 -18
  867. package/dist/ir/init-only-globals.js.map +1 -1
  868. package/dist/ir/inline-array-sources.js +4 -1
  869. package/dist/ir/inline-array-sources.js.map +1 -1
  870. package/dist/ir/inline-array-views.d.ts +13 -0
  871. package/dist/ir/inline-array-views.js +945 -0
  872. package/dist/ir/inline-array-views.js.map +1 -0
  873. package/dist/ir/inline-arrays.d.ts +7 -0
  874. package/dist/ir/inline-arrays.js +190 -55
  875. package/dist/ir/inline-arrays.js.map +1 -1
  876. package/dist/ir/inline-arrays.test.js +140 -2
  877. package/dist/ir/inline-arrays.test.js.map +1 -1
  878. package/dist/ir/int32-slots.js +7 -0
  879. package/dist/ir/int32-slots.js.map +1 -1
  880. package/dist/ir/integer-ranges.js +16 -6
  881. package/dist/ir/integer-ranges.js.map +1 -1
  882. package/dist/ir/ir.d.ts +130 -44
  883. package/dist/ir/ir.js +7 -0
  884. package/dist/ir/ir.js.map +1 -1
  885. package/dist/ir/js-groups.d.ts +51 -0
  886. package/dist/ir/js-groups.js +394 -0
  887. package/dist/ir/js-groups.js.map +1 -0
  888. package/dist/ir/js-groups.test.d.ts +1 -0
  889. package/dist/ir/js-groups.test.js +555 -0
  890. package/dist/ir/js-groups.test.js.map +1 -0
  891. package/dist/ir/js-ic.d.ts +10 -9
  892. package/dist/ir/js-ic.js +58 -25
  893. package/dist/ir/js-ic.js.map +1 -1
  894. package/dist/ir/js-ic.test.js +37 -3
  895. package/dist/ir/js-ic.test.js.map +1 -1
  896. package/dist/ir/jsval.js +374 -63
  897. package/dist/ir/jsval.js.map +1 -1
  898. package/dist/ir/jsval.test.js +96 -2
  899. package/dist/ir/jsval.test.js.map +1 -1
  900. package/dist/ir/loop-entry-ranges.js +112 -9
  901. package/dist/ir/loop-entry-ranges.js.map +1 -1
  902. package/dist/ir/loop-entry-ranges.test.js +40 -0
  903. package/dist/ir/loop-entry-ranges.test.js.map +1 -1
  904. package/dist/ir/node-index.d.ts +23 -6
  905. package/dist/ir/node-index.js +126 -49
  906. package/dist/ir/node-index.js.map +1 -1
  907. package/dist/ir/numeric-call-specialization.d.ts +4 -2
  908. package/dist/ir/numeric-call-specialization.js +40 -26
  909. package/dist/ir/numeric-call-specialization.js.map +1 -1
  910. package/dist/ir/paired-while-loops.d.ts +4 -2
  911. package/dist/ir/paired-while-loops.js +8 -2
  912. package/dist/ir/paired-while-loops.js.map +1 -1
  913. package/dist/ir/parameter-versions.d.ts +13 -3
  914. package/dist/ir/parameter-versions.js +63 -40
  915. package/dist/ir/parameter-versions.js.map +1 -1
  916. package/dist/ir/property-bags.d.ts +4 -2
  917. package/dist/ir/property-bags.js +22 -17
  918. package/dist/ir/property-bags.js.map +1 -1
  919. package/dist/ir/receiver-readers.js +58 -2
  920. package/dist/ir/receiver-readers.js.map +1 -1
  921. package/dist/ir/row-pairs.d.ts +4 -2
  922. package/dist/ir/row-pairs.js +12 -11
  923. package/dist/ir/row-pairs.js.map +1 -1
  924. package/dist/ir/runtime-features.d.ts +139 -5
  925. package/dist/ir/runtime-features.js +397 -19
  926. package/dist/ir/runtime-features.js.map +1 -1
  927. package/dist/ir/runtime-features.test.js +135 -1
  928. package/dist/ir/runtime-features.test.js.map +1 -1
  929. package/dist/ir/runtime-jam-loops.d.ts +35 -0
  930. package/dist/ir/runtime-jam-loops.js +604 -0
  931. package/dist/ir/runtime-jam-loops.js.map +1 -0
  932. package/dist/ir/runtime-jam-loops.test.d.ts +1 -0
  933. package/dist/ir/runtime-jam-loops.test.js +565 -0
  934. package/dist/ir/runtime-jam-loops.test.js.map +1 -0
  935. package/dist/ir/saturating-loop-jams.d.ts +11 -2
  936. package/dist/ir/saturating-loop-jams.js +56 -16
  937. package/dist/ir/saturating-loop-jams.js.map +1 -1
  938. package/dist/ir/saturating-loop-jams.test.js +39 -1
  939. package/dist/ir/saturating-loop-jams.test.js.map +1 -1
  940. package/dist/ir/scalar-records.d.ts +5 -2
  941. package/dist/ir/scalar-records.js +12 -2
  942. package/dist/ir/scalar-records.js.map +1 -1
  943. package/dist/ir/self-captures.d.ts +4 -2
  944. package/dist/ir/self-captures.js +40 -28
  945. package/dist/ir/self-captures.js.map +1 -1
  946. package/dist/ir/self-captures.test.js +15 -0
  947. package/dist/ir/self-captures.test.js.map +1 -1
  948. package/dist/ir/serialize.d.ts +8 -2
  949. package/dist/ir/serialize.js +92 -24
  950. package/dist/ir/serialize.js.map +1 -1
  951. package/dist/ir/serialize.test.js +26 -0
  952. package/dist/ir/serialize.test.js.map +1 -1
  953. package/dist/ir/tiers.js +1 -0
  954. package/dist/ir/tiers.js.map +1 -1
  955. package/dist/ir/traverse.js +4 -0
  956. package/dist/ir/traverse.js.map +1 -1
  957. package/dist/ir/typed-argument-clones.d.ts +30 -0
  958. package/dist/ir/typed-argument-clones.js +789 -0
  959. package/dist/ir/typed-argument-clones.js.map +1 -0
  960. package/dist/ir/union-arm-loops.d.ts +3 -0
  961. package/dist/ir/union-arm-loops.js +373 -0
  962. package/dist/ir/union-arm-loops.js.map +1 -0
  963. package/dist/ir/union-arm-loops.test.d.ts +1 -0
  964. package/dist/ir/union-arm-loops.test.js +230 -0
  965. package/dist/ir/union-arm-loops.test.js.map +1 -0
  966. package/dist/ir/validate.js +170 -22
  967. package/dist/ir/validate.js.map +1 -1
  968. package/dist/ir/validate.test.js +46 -0
  969. package/dist/ir/validate.test.js.map +1 -1
  970. package/dist/library/compiler-self-identity.d.ts +8 -2
  971. package/dist/library/compiler-self-identity.js +92 -18
  972. package/dist/library/compiler-self-identity.js.map +1 -1
  973. package/dist/library/compiler-self-identity.test.js +150 -3
  974. package/dist/library/compiler-self-identity.test.js.map +1 -1
  975. package/dist/library/int-infer.d.ts +5 -0
  976. package/dist/library/int-infer.js +15 -3
  977. package/dist/library/int-infer.js.map +1 -1
  978. package/dist/library/ir-policy.js +4 -0
  979. package/dist/library/ir-policy.js.map +1 -1
  980. package/dist/library/library-cache.d.ts +4 -0
  981. package/dist/library/library-cache.js +2 -0
  982. package/dist/library/library-cache.js.map +1 -1
  983. package/dist/library/library-cache.test.js +26 -0
  984. package/dist/library/library-cache.test.js.map +1 -1
  985. package/dist/library/prepare.js +99 -31
  986. package/dist/library/prepare.js.map +1 -1
  987. package/dist/native/cache.d.ts +7 -0
  988. package/dist/native/cache.js +49 -0
  989. package/dist/native/cache.js.map +1 -1
  990. package/dist/native/cache.test.js +13 -1
  991. package/dist/native/cache.test.js.map +1 -1
  992. package/dist/native/cli.js +2 -0
  993. package/dist/native/cli.js.map +1 -1
  994. package/dist/native/compiler.js +26 -5
  995. package/dist/native/compiler.js.map +1 -1
  996. package/dist/native/executable-cache-open.test.js +31 -5
  997. package/dist/native/executable-cache-open.test.js.map +1 -1
  998. package/dist/native/executable-cache.d.ts +6 -1
  999. package/dist/native/executable-cache.js +7 -1
  1000. package/dist/native/executable-cache.js.map +1 -1
  1001. package/dist/native/prepare.d.ts +3 -0
  1002. package/dist/native/prepare.js +74 -28
  1003. package/dist/native/prepare.js.map +1 -1
  1004. package/dist/native/prepare.test.js +25 -3
  1005. package/dist/native/prepare.test.js.map +1 -1
  1006. package/dist/native/sanitizer.js +63 -4
  1007. package/dist/native/sanitizer.js.map +1 -1
  1008. package/dist/native/sanitizer.test.js +93 -2
  1009. package/dist/native/sanitizer.test.js.map +1 -1
  1010. package/dist/native/toolchain.js +9 -2
  1011. package/dist/native/toolchain.js.map +1 -1
  1012. package/dist/node-islands/boundary.d.ts +37 -1
  1013. package/dist/node-islands/boundary.js +65 -7
  1014. package/dist/node-islands/boundary.js.map +1 -1
  1015. package/dist/node-islands/boundary.test.d.ts +1 -0
  1016. package/dist/node-islands/boundary.test.js +76 -0
  1017. package/dist/node-islands/boundary.test.js.map +1 -0
  1018. package/dist/node-islands/detect.d.ts +27 -1
  1019. package/dist/node-islands/detect.js +475 -40
  1020. package/dist/node-islands/detect.js.map +1 -1
  1021. package/dist/node-islands/detect.test.js +175 -4
  1022. package/dist/node-islands/detect.test.js.map +1 -1
  1023. package/dist/node-islands/effect-gate.js +30 -20
  1024. package/dist/node-islands/effect-gate.js.map +1 -1
  1025. package/dist/node-islands/effect-gate.test.js +4 -1
  1026. package/dist/node-islands/effect-gate.test.js.map +1 -1
  1027. package/dist/node-islands/graph-islands.d.ts +40 -0
  1028. package/dist/node-islands/graph-islands.js +128 -0
  1029. package/dist/node-islands/graph-islands.js.map +1 -0
  1030. package/dist/node-islands/growth.d.ts +57 -0
  1031. package/dist/node-islands/growth.js +205 -0
  1032. package/dist/node-islands/growth.js.map +1 -0
  1033. package/dist/node-islands/libnode.d.ts +1 -1
  1034. package/dist/node-islands/libnode.js +1 -1
  1035. package/dist/node-islands/libnode.js.map +1 -1
  1036. package/dist/node-islands/modules.d.ts +28 -0
  1037. package/dist/node-islands/modules.js +156 -0
  1038. package/dist/node-islands/modules.js.map +1 -1
  1039. package/dist/node-islands/modules.test.js +105 -1
  1040. package/dist/node-islands/modules.test.js.map +1 -1
  1041. package/dist/node-islands/policy.js +2 -3
  1042. package/dist/node-islands/policy.js.map +1 -1
  1043. package/dist/node-islands/probe-recorder.d.ts +1 -0
  1044. package/dist/node-islands/probe-recorder.js +596 -0
  1045. package/dist/node-islands/probe-recorder.js.map +1 -0
  1046. package/dist/node-islands/probe-recorder.test.d.ts +1 -0
  1047. package/dist/node-islands/probe-recorder.test.js +80 -0
  1048. package/dist/node-islands/probe-recorder.test.js.map +1 -0
  1049. package/dist/node-islands/report.d.ts +12 -0
  1050. package/dist/node-islands/report.js +28 -0
  1051. package/dist/node-islands/report.js.map +1 -1
  1052. package/dist/node-islands/report.test.js +4 -0
  1053. package/dist/node-islands/report.test.js.map +1 -1
  1054. package/dist/node-islands/rules.js +9 -0
  1055. package/dist/node-islands/rules.js.map +1 -1
  1056. package/dist/node-islands/scan.d.ts +16 -1
  1057. package/dist/node-islands/scan.js +110 -9
  1058. package/dist/node-islands/scan.js.map +1 -1
  1059. package/dist/node-islands/snapshot.d.ts +38 -1
  1060. package/dist/node-islands/snapshot.js +165 -161
  1061. package/dist/node-islands/snapshot.js.map +1 -1
  1062. package/dist/node-islands/snapshot.test.js +63 -2
  1063. package/dist/node-islands/snapshot.test.js.map +1 -1
  1064. package/dist/node-islands/summary.js +8 -0
  1065. package/dist/node-islands/summary.js.map +1 -1
  1066. package/dist/node-islands/type-strip.d.ts +11 -0
  1067. package/dist/node-islands/type-strip.js +157 -0
  1068. package/dist/node-islands/type-strip.js.map +1 -0
  1069. package/dist/node-islands/type-strip.test.d.ts +1 -0
  1070. package/dist/node-islands/type-strip.test.js +31 -0
  1071. package/dist/node-islands/type-strip.test.js.map +1 -0
  1072. package/dist/project-config.d.ts +4 -0
  1073. package/dist/project-config.js +19 -0
  1074. package/dist/project-config.js.map +1 -1
  1075. package/dist/project-config.test.js +10 -0
  1076. package/dist/project-config.test.js.map +1 -1
  1077. package/dist/wasm/translate.js +11 -5
  1078. package/dist/wasm/translate.js.map +1 -1
  1079. package/dist/wasm/translate.test.js +35 -0
  1080. package/dist/wasm/translate.test.js.map +1 -1
  1081. package/package.json +20 -20
  1082. package/surface-manifest.json +221 -122
@@ -1,6 +1,10 @@
1
+ import { lowerIteratorFromDyn } from "./iterator-prototype.js";
2
+ import { programCreatesWrappers } from "./primitive-wrappers.js";
1
3
  import { arrayClassMemberOwner, arrayClassReceiver, lowerArrayClassStaticCall, } from "./builtins/array-classes.js";
2
4
  import { structuralCallInstance } from "./structural-instances.js";
5
+ import { classViewOf } from "./class-views.js";
3
6
  import { checkedPrivateMethodReceiver, privateNameClass } from "./private-brands.js";
7
+ import { lowerStaticPrivateCall } from "./private-statics.js";
4
8
  import { assertFunctionAliasOf } from "./lower-assert.js";
5
9
  import { keyedHelperName } from "./stable-names.js";
6
10
  import { perKeyOrder } from "./key-order-witness.js";
@@ -8,7 +12,8 @@ import { lowerDateToPrimitiveCall } from "./builtins/dates.js";
8
12
  import { isForwardedTupleSpread, lowerForwardingApply } from "./typed-arguments.js";
9
13
  import { guardNullProto, nullProtoRecordShape } from "./null-prototype.js";
10
14
  import { lowerDynStreamMemberCall } from "./dyn-streams.js";
11
- import { lowerBuiltinClassCall } from "./builtins/builtin-class-dyn.js";
15
+ import { isPureReference } from "./effect-free.js";
16
+ import { builtinClassKind, builtinClassKindOf, builtinClassValue, lowerBuiltinClassCall, } from "./builtins/builtin-class-dyn.js";
12
17
  import { refuseModuleMemberThis } from "./module-member-this.js";
13
18
  import { lowerUnionEquality, tagEqualityMayMissAlias } from "./strict-equality.js";
14
19
  import { lowerHashStreamCall } from "./builtins/hash-stream.js";
@@ -38,13 +43,14 @@ import { lowerClassSymbolMethodCall } from "./symbol-methods.js";
38
43
  import { lowerReadlineDisposeCall } from "./builtins/readline.js";
39
44
  import { errorToStringCall } from "./error-methods.js";
40
45
  import { lowerClassPrototypeAssign, lowerClassPrototypeDescriptors } from "./class-prototypes.js";
41
- import { BYTES_ELEMENT_NAME, BYTES_U8, BIGINT_T, BOOL, CAUGHT, DYN, DYN_HANDLE_KINDS, F64, NULL_T, STRING, SYMBOL_T, UNDEFINED_T, VOID, arrayOf, canBoxFuncIntoDyn, canConvertToDyn, canDynCheckTo, funcOf, isDynTypedRefType, isUnitType, shapeHasAccessorSlots, shapeKeyOrders, typeEquals, RUNTIME_EMITTER_CLASS, } from "../../ir/ir.js";
46
+ import { BYTES_ELEMENT_NAME, BYTES_U8, BIGINT_T, BOOL, CAUGHT, DYN, DYN_HANDLE_KINDS, F64, NULL_T, STRING, SYMBOL_T, UNDEFINED_T, VOID, arrayOf, canBoxFuncIntoDyn, canConvertToDyn, canDynCheckTo, funcOf, isDynTypedRefType, isUnitType, recordTextCodecClass, shapeHasAccessorSlots, shapeKeyOrders, typeEquals, RUNTIME_EMITTER_CLASS, } from "../../ir/ir.js";
42
47
  import { lowerProtocolMethodCall } from "./class-protocol-dispatch.js";
48
+ import { MUTABLE_BUFFER_MEMBERS } from "./buffers.js";
43
49
  import { isJsSourceFile, locOf, requireSpecOf } from "../program.js";
44
50
  import { isPackageShimFile, isShimIntrinsicName } from "../package-shims.js";
45
51
  import { lowerJsonRequireCall } from "./json-require.js";
46
52
  import { lowerAssertInstanceCall } from "./assert-instances.js";
47
- import { isGenericCallableMemberType, isOverloadedCallableMemberType, typeKey, } from "../type-mapper.js";
53
+ import { erasedOverloadMemberType, isGenericCallableMemberType, isOverloadedCallableMemberType, typeKey, } from "../type-mapper.js";
48
54
  import { dynFallbackType, jsFuncNameOf, newFnCtx, staticImportNamespaceType } from "./lowerer.js";
49
55
  import { NARROW_FIRST, STRING_INDEX_METHODS, STR_METHODS, UTIL_TYPES_KEYS, stdlibGlobalNameOf, } from "./surfaces.js";
50
56
  import { dynStringReceiver } from "./containers/dynamic-receivers.js";
@@ -52,12 +58,13 @@ import { lowerArrayConstructor, lowerArrayFromCall, lowerArrayOfCall, } from "./
52
58
  import { lowerArrayFromAsyncCall } from "./containers/array-from-async.js";
53
59
  import { lowerDynArrayFilterCall, lowerDynArrayFlatMapCall } from "./containers/array-callbacks.js";
54
60
  import { lowerGroupByStaticCall } from "./containers/collection-grouping.js";
55
- import { lowerGeneratorHelperCall, lowerHelperReturnCall, lowerIteratorFromCall, lowerIteratorHelperCall, } from "./containers/iterator-helpers.js";
61
+ import { lowerGeneratorHelperCall, lowerHelperReturnCall, lowerIteratorFromCall, lowerIteratorHelperCall, lowerWidenedIteratorHelperCall, } from "./containers/iterator-helpers.js";
56
62
  import { lowerObjectAssignIndexShape, lowerObjectConstructor, lowerObjectFromEntriesCall, lowerObjectIterOverIndexShape, } from "./containers/indexed-objects.js";
57
63
  import { lowerTupleReadMethodCall } from "./containers/array-methods.js";
58
64
  import { tryFuseIndexRead } from "./array-values.js";
65
+ import { builtinGlobalValue, isPrimitivePrototypeRead } from "./expressions/property-access.js";
59
66
  import { lowerBufferConstruct, lowerBytesPrototypeSetCall, lowerBytesStaticCall, } from "./containers/bytes.js";
60
- import { lowerRegexMethodCall, lowerStringIndexCall, lowerStringMethodCall, lowerStringPaddingCall, lowerStringSplitCall, isDynPrimitiveKindMethod, lowerDynPrimitiveMethodCall, lowerExtraNumberMethodCall, } from "./containers/string-and-regexp.js";
67
+ import { EXTRA_STRING_METHODS, lowerRegexMethodCall, lowerStringIndexCall, lowerStringMethodCall, lowerStringPaddingCall, lowerStringSplitCall, isDynPrimitiveKindMethod, lowerDynPrimitiveMethodCall, lowerExtraNumberMethodCall, lowerExtraStringMethodCall, } from "./containers/string-and-regexp.js";
61
68
  import { createRequireSpecOf } from "./builtins/module-bindings.js";
62
69
  import { lowerChildStreamMethodCall, lowerChildWriterMethodCall, } from "./builtins/child-process-methods.js";
63
70
  import { lowerCreateRequireCall, lowerImportMetaResolveCall, lowerRequireResolveCall, } from "./builtins/module-resolution.js";
@@ -69,10 +76,12 @@ import { lowerDirentMethodCall, lowerFileHandleMethodCall, lowerDirMethodCall, l
69
76
  import { fencePerfEntryKeyWalk, isPerfEntryType, lowerHistogramMethodCall, lowerPerfHooksCall, perfEntryTag, } from "./builtins/performance.js";
70
77
  import { fenceX509KeyWalk } from "./builtins/x509.js";
71
78
  import { lowerProcStreamMethodCall, lowerProcessBuiltinModuleNamespace, } from "./builtins/process.js";
72
- import { recordMayKeepSource, throughRecordSource } from "./record-sources.js";
79
+ import { recordMayKeepSource, recordSourceTest, throughRecordSource } from "./record-sources.js";
80
+ import { answerLinkedCopies, linkedCopyBranches, recordStringCall, registerLinkedHelper, } from "./record-links.js";
73
81
  import { lowerReflectCall } from "./builtins/reflection.js";
74
82
  import { lowerAbsenceProbe, v8CalleeText, lowerPromiseAllTupleCall, lowerPromiseRejectCall, lowerToNumberArgument, stringWrapperToString, symbolFieldInfo, templateRawTextOf, primitiveCtorClosure, } from "./lower-exprs.js";
75
83
  import { isSafeToDiscard } from "./expressions/evaluation-safety.js";
84
+ import { nullishLiteral, nullishReadTypeError, throwAfterEach } from "./primitive-throws.js";
76
85
  import { tryLowerExpression } from "./expressions/try-lower-expression.js";
77
86
  import { lowerChildMethodValue, lowerChildPropertyCall } from "./handle-properties.js";
78
87
  import { classObjectTag, classToNumberConversion } from "./class-to-primitive.js";
@@ -81,14 +90,16 @@ import { structuralReadType } from "./class-unions.js";
81
90
  import { httpClientFnBindingOf, lowerCompatReqStreamOptionalCall, lowerHttpClientFnCall, } from "./lower-server.js";
82
91
  import { EMITTER_API_MEMBERS, exactClassOfReceiver, exactInstanceClassOf, findGenericMethodOn, lowerClassGenericMethodCall, lowerStaticMethodCall, lowerStaticFieldRead, returnsOnlyThis, storedClassValueType, } from "./lower-classes.js";
83
92
  import { classCallbackCall, isClassCallback } from "./class-callbacks.js";
84
- import { emitterRooted, lowerEmitterMethodCall } from "./lower-event-emitter.js";
93
+ import { emitOverrideAtOrAbove, emitterRooted, lowerEmitterMethodCall, } from "./lower-event-emitter.js";
85
94
  import { eventTargetApiMethod, lowerEventTargetMethodCall } from "./lower-event-target.js";
86
95
  import { dateRootOf, isDatePrototypeMethod, lowerInheritedDateMethodCall, } from "./builtins/date-classes.js";
87
96
  import { lowerConsoleInstanceCall, lowerConsoleMethodCall, lowerConsoleOutput, } from "./lower-console.js";
88
97
  import { STREAM_API_MEMBERS, STREAM_OPERATORS, lowerStreamMethodCall, lowerStreamStaticCall, streamSidesOf, } from "./lower-stream.js";
89
98
  import { ambientNsRootOf, ambientUndefReadType, ambientUndefVarRootOf, ambientUndefinedFnSymbolOf, contextualUndefReadType, fenceEarlyAliasUse, fenceEarlyNsMemberRef, nsMemberIdentOf, nsUndefRead, } from "./lower-namespaces.js";
99
+ import { hostGlobalNameOfRead, hostGlobalPrototypeMemberOf } from "./host-globals.js";
90
100
  import { expandoMemberRead } from "./lower-expando.js";
91
- import { fenceNodeModuleMutationCall, lowerRequireCacheKeys } from "./lower-node-module.js";
101
+ import { fenceNodeModuleMutationCall, isCjsRequireGlobal, lowerRequireCacheKeys, } from "./lower-node-module.js";
102
+ import { pathModuleValue } from "./lower-builtin-values.js";
92
103
  import { defaultAfterUndefined, lowerOptionalArgument, lowerStaticallyUndefinedArgument, positionNumber, } from "./optional-arguments.js";
93
104
  import { fenceSymbolFieldCopy } from "./symbol-fields.js";
94
105
  import { lowerClassDataDescriptor, lowerClassDescriptorRead } from "./class-descriptors.js";
@@ -97,15 +108,17 @@ import { freezableRecordType, lowerNativeFreeze, noteUntypedIntegrity } from "./
97
108
  import { classStaticDataFor } from "./class-static-data.js";
98
109
  import { lowerUrlFactory } from "./lower-url.js";
99
110
  import { nullishValueUnitOf } from "./binding-analysis.js";
100
- import { spreadNeedsRuntimeArity, completeFuncValueArgs, lowerSpreadArgsCall, completeArgs, } from "./call-arguments.js";
111
+ import { spreadNeedsRuntimeArity, completeFuncValueArgs, checkedRestCallArgs, lowerSpreadArgsCall, completeArgs, } from "./call-arguments.js";
101
112
  import { isThisParameter } from "./call-signatures.js";
102
113
  import { dynamicOverloadChoice } from "./overload-choice.js";
103
114
  import { lowerStringIteratorValue } from "./iterator-adapters.js";
115
+ import { iterableGenerator, iterableUnionOf } from "./iterable-values.js";
104
116
  import { checkedArmExtraction } from "./coercions/unions.js";
105
117
  import { maybePromiseReturnStmt, promiseArmedUnionOf, promiseOrUnitUnionOf, } from "./maybe-promise.js";
106
118
  import { requireObjLitGenericReceiver, objLitGenericFnNodeOf, objLitGenericFnInfoOf, genericCallInstance, } from "./generic-functions.js";
107
119
  import { codeGenerationCalleeOf, lowerCodeGenerationCall } from "./code-generation.js";
108
120
  import { lowerRecordInheritedCall } from "./record-inherited.js";
121
+ import { fenceDatePrototypeWriteCall } from "./expressions/property-access.js";
109
122
  const ZLIB_STREAM_METHODS = new Set(["flush", "params", "close", "reset"]);
110
123
  /** The node:util member a `(0, member)` callee names, or null. */
111
124
  function indirectUtilCalleeOf(lowerer, callee) {
@@ -175,8 +188,60 @@ function receiverlessCalleeOf(callee) {
175
188
  }
176
189
  export function lowerCall(lowerer, expr) {
177
190
  const loc = locOf(expr);
191
+ // A JavaScript source calling a member that resizes, grows or detaches a
192
+ // buffer is the mutableBuffers fact (buffers.ts, t262-dc §2.4). The
193
+ // receiver may be a checked-dynamic value, so the callee's name decides;
194
+ // the member read never reaches lowerPropertyAccessExpr when the call
195
+ // lowers straight through its receiver.
196
+ if (isJsSourceFile(ts.getSourceFileOfNode(expr))) {
197
+ const callee = expr.expression;
198
+ const name = ts.isPropertyAccessExpression(callee)
199
+ ? callee.name.text
200
+ : ts.isElementAccessExpression(callee)
201
+ ? lowerer.foldedStringKeyOf(callee.argumentExpression)
202
+ : null;
203
+ if (name !== null && MUTABLE_BUFFER_MEMBERS.has(name))
204
+ lowerer.buffersMutable = true;
205
+ }
206
+ // `(null).foo()` / `(undefined)["foo"]()`: the MEMBER READ throws Node's
207
+ // TypeError before the arguments evaluate, exactly as a plain read does.
208
+ // Only a nullish LITERAL qualifies — every other receiver, a binding or a
209
+ // property included, has a value the runtime reads and refuses itself,
210
+ // with the same message and the same order.
211
+ {
212
+ const callee = expr.expression;
213
+ const member = ts.isPropertyAccessExpression(callee) && !callee.questionDotToken
214
+ ? { base: callee.expression, name: callee.name.text }
215
+ : ts.isElementAccessExpression(callee) && !callee.questionDotToken
216
+ ? { base: callee.expression, name: lowerer.foldedStringKeyOf(callee.argumentExpression) }
217
+ : null;
218
+ const unit = !expr.questionDotToken && member !== null ? nullishLiteral(lowerer, member.base) : null;
219
+ if (member !== null && member.name !== null && unit !== null) {
220
+ const recv = lowerer.lowerExpr(member.base);
221
+ const t = lowerer.mapTypeOf(lowerer.typeOf(expr)) ?? F64;
222
+ return throwAfterEach([recv], nullishReadTypeError(unit, member.name, t, loc), loc);
223
+ }
224
+ }
178
225
  if (lowerer.errorAccessorReflection === null)
179
226
  noteErrorAccessorReflection(lowerer, expr);
227
+ // Calling a Node 24 global the native runtime does not provide (WebSocket,
228
+ // FormData, …): the value a read answers refuses the call
229
+ // (host-global-values.ts), so the call is that refusal — SC2020, which a
230
+ // JavaScript source defers to the throw at this statement.
231
+ {
232
+ const hostGlobal = hostGlobalNameOfRead(lowerer, expr.expression);
233
+ if (hostGlobal !== null)
234
+ lowerer.hostGlobalFence(hostGlobal, expr.expression);
235
+ }
236
+ // A method on the value's prototype (`FormData.prototype.append(...)`):
237
+ // the prototype carries the constructor link only, so the method is
238
+ // surface native code does not have (SC2020, host-global). A call reads
239
+ // its callee without going through the member-read hook.
240
+ {
241
+ const prototypeOf = hostGlobalPrototypeMemberOf(lowerer, expr.expression);
242
+ if (prototypeOf !== null)
243
+ lowerer.hostGlobalFence(prototypeOf, expr.expression);
244
+ }
180
245
  // Object's checker return type is `any`. Claim known object inputs
181
246
  // before generic checked-dynamic dispatch tries to load the constructor.
182
247
  if (ts.isIdentifier(expr.expression) &&
@@ -191,6 +256,14 @@ export function lowerCall(lowerer, expr) {
191
256
  const builtinClassCall = lowerBuiltinClassCall(lowerer, expr);
192
257
  if (builtinClassCall)
193
258
  return builtinClassCall;
259
+ // `R.<method>.call(thisArg, ...)` over EventEmitter.prototype's methods.
260
+ if (ts.isPropertyAccessExpression(expr.expression) &&
261
+ !expr.expression.questionDotToken &&
262
+ expr.expression.name.text === "call") {
263
+ const emitterMethod = lowerEmitterMethodValueCall(lowerer, expr, expr.expression);
264
+ if (emitterMethod)
265
+ return emitterMethod;
266
+ }
194
267
  // require() of a JSON document: the shared parsed object.
195
268
  const json = lowerJsonRequireCall(lowerer, expr);
196
269
  if (json)
@@ -269,6 +342,20 @@ export function lowerCall(lowerer, expr) {
269
342
  if (inlineValue)
270
343
  return inlineValue;
271
344
  }
345
+ // `require("path/posix")` of a builtin as a value: the module's
346
+ // namespace, as a `const posix = require("path/posix")` binding is.
347
+ if (ts.isIdentifier(expr.expression) &&
348
+ expr.expression.text === "require" &&
349
+ isCjsRequireGlobal(lowerer, expr.expression)) {
350
+ const module = lowerer.builtinNamespaceModuleOf(expr);
351
+ // The platform namespaces are the path module objects.
352
+ if (module === "path/posix" || module === "path/win32")
353
+ return pathModuleValue(lowerer, module, loc);
354
+ if (module !== null && module !== "constants") {
355
+ const moduleId = `builtin:${module}`;
356
+ return { kind: "moduleNsRef", moduleId, type: { kind: "moduleNs", moduleId }, loc };
357
+ }
358
+ }
272
359
  // A call whose chain ROOTS at an ambient-undefined name (`declare
273
360
  // const value: Y | undefined; value?.foo("a")`, `declare function
274
361
  // chain...; chain(o).mapValues(f).value()`, a trap binding's read):
@@ -441,6 +528,9 @@ export function lowerCall(lowerer, expr) {
441
528
  if (ts.isPropertyAccessExpression(expr.expression) &&
442
529
  ts.isPrivateIdentifier(expr.expression.name) &&
443
530
  !expr.expression.questionDotToken) {
531
+ const staticPrivate = lowerStaticPrivateCall(lowerer, expr, expr.expression);
532
+ if (staticPrivate)
533
+ return staticPrivate;
444
534
  const privateCall = lowerCheckedPrivateMethodCall(lowerer, expr, expr.expression);
445
535
  if (privateCall)
446
536
  return privateCall;
@@ -688,7 +778,12 @@ export function lowerCall(lowerer, expr) {
688
778
  const converted = lowerBigIntConstructorValue(lowerer, arg, loc);
689
779
  if (converted)
690
780
  return converted;
691
- lowerer.noLowering(`BigInt of ${lowerer.fmt(arg.type)} values`, argNode, "string, number, boolean, and bigint arguments are supported");
781
+ // Report the type the program wrote, which is the type the checker has
782
+ // narrowed to here. The stored union only shows up when it is what
783
+ // actually blocks the conversion.
784
+ const narrowed = lowerer.mapTypeOf(lowerer.typeOf(argNode));
785
+ const shown = narrowed && !typeEquals(narrowed, arg.type) ? narrowed : arg.type;
786
+ lowerer.noLowering(`BigInt of ${lowerer.fmt(shown)} values`, argNode, bigintRefusalHint(lowerer, arg, narrowed));
692
787
  }
693
788
  if (lowerer.isStdlibGlobal(expr.expression, "String") ||
694
789
  lowerer.isStdlibGlobal(expr.expression, "Boolean") ||
@@ -968,32 +1063,7 @@ export function lowerCall(lowerer, expr) {
968
1063
  // different, non-stdlib symbol.
969
1064
  if ((expr.expression.text === "atob" || expr.expression.text === "btoa") &&
970
1065
  lowerer.isStdlibSymbol(lowerer.resolveValueSymbol(expr.expression) ?? undefined)) {
971
- const name = expr.expression.text;
972
- if (expr.arguments.nodes.length === 0) {
973
- return { kind: "libCall", fn: "str.b64Missing", args: [], type: STRING, loc };
974
- }
975
- if (expr.arguments.nodes.length > 1) {
976
- lowerer.noLowering(`${name} with ${expr.arguments.nodes.length} arguments`, expr);
977
- }
978
- const argNode = expr.arguments.nodes[0];
979
- const v = lowerer.lowerExpr(argNode);
980
- let data;
981
- if (v.type.kind === "dyn") {
982
- data = v;
983
- }
984
- else if (v.kind === "unitLit" || lowerer.dynConvertible(v.type)) {
985
- data = { kind: "dynFrom", value: v, type: DYN, loc };
986
- }
987
- else {
988
- lowerer.noLowering(`${name} with a '${lowerer.fmt(v.type)}' argument`, argNode, "string-convertible arguments lower (Node ToStrings the value — convert it explicitly)");
989
- }
990
- return {
991
- kind: "libCall",
992
- fn: name === "atob" ? "str.atob" : "str.btoa",
993
- args: [data],
994
- type: STRING,
995
- loc,
996
- };
1066
+ return lowerBase64Call(lowerer, expr, expr.expression.text, loc);
997
1067
  }
998
1068
  // global function executes — callFn(globalGet(name)) — and the
999
1069
  // result exits to the declared static type. A user function
@@ -1415,6 +1485,11 @@ export function lowerCall(lowerer, expr) {
1415
1485
  // (untyped in fallback builds, so before the dyn receiver path) or
1416
1486
  // webcrypto.
1417
1487
  lowerWebCryptoMethodCall(lowerer, expr, expr.expression) ??
1488
+ // A helper call on a JavaScript binding reassigned with a helper
1489
+ // stage (`let it = g(); it = it.filter(...)`): the binding holds the
1490
+ // checked value, and the dyn receiver path would read `filter` as
1491
+ // Array.prototype's. Before it, so the runtime's helper answers.
1492
+ lowerWidenedIteratorHelperCall(lowerer, expr) ??
1418
1493
  // Dyn receivers (JSON.parse-derived `unknown`/`any` values) —
1419
1494
  lowerDynReceiverMethodCall(lowerer, expr, expr.expression) ??
1420
1495
  // Narrowing filters (inferred predicates, filter(Boolean)) claim
@@ -1561,6 +1636,11 @@ export function lowerCall(lowerer, expr) {
1561
1636
  lowerer.unsupported("SC1090", expr, `calls of the generic method '${expr.expression.name.text}' through this receiver (no compiled declaration with a body resolves statically here — ambient 'declare class' and interface-only methods are signature-only, and only class, static, and object-literal generic methods with bodies monomorphize)`);
1562
1637
  }
1563
1638
  }
1639
+ {
1640
+ const unionCall = lowerUnionReceiverMethodCall(lowerer, expr, expr.expression);
1641
+ if (unionCall)
1642
+ return unionCall;
1643
+ }
1564
1644
  lowerer.unsupported("SC1090", expr, `method calls like '${ts.getTextOfNode(expr.expression)}'`);
1565
1645
  }
1566
1646
  // `s[Symbol.iterator]()` on a string: the string iterator as a value.
@@ -1751,9 +1831,156 @@ function callableInstanceStringCall(lowerer, expr, callee, loc) {
1751
1831
  loc,
1752
1832
  };
1753
1833
  }
1834
+ /** Refuses a copying conversion at a call through a value whose checker
1835
+ * signature keeps its own type parameters — the erased instance
1836
+ * lowerGenericFnValue / erasedGenericInstance produce. The call itself
1837
+ * needs no new rule: such a value's IR type is already the erased func
1838
+ * type, so the ordinary func-value lane completes its arguments into the
1839
+ * erased signature's `unknown` slots (records, arrays and collections box
1840
+ * as live capsules, primitives as themselves) and leaves the result dyn
1841
+ * for each use to convert, where a lie throws (dynCheck) instead of
1842
+ * answering a value the program never had. Keeping the lane unchanged is
1843
+ * what keeps every program that compiles today byte-identical. */
1844
+ function refuseCopyingErasureInstanceCall(lowerer, call, callee) {
1845
+ if (callee.type.kind !== "func")
1846
+ return;
1847
+ const sigs = lowerer.checker.getCallSignatures(lowerer.typeOf(call.expression));
1848
+ if (!sigs.some((sig) => sig.getTypeParameters().length > 0))
1849
+ return;
1850
+ refuseCopyingErasureBoundary(lowerer, call, callee.type);
1851
+ }
1852
+ /** Refuse an erased instantiation whose boundary conversion would COPY the
1853
+ * value instead of carrying it by reference.
1854
+ *
1855
+ * Most conversions across the erased boundary are exact: records and arrays
1856
+ * box into `unknown` as live capsules of themselves, and the checked unbox
1857
+ * back answers the same object (object-model S1). Two conversions are not,
1858
+ * and compiling them would silently hand the program a different object
1859
+ * than Node's:
1860
+ *
1861
+ * - a promise payload crossing the boundary. The dynamic promise conversion
1862
+ * re-materializes the settled record rather than boxing it live, so a
1863
+ * `Promise<{ id: number }>` that crosses into `unknown` (or into a wider
1864
+ * promise) settles to a copy. This is a pre-existing dynamic-tier
1865
+ * behaviour — it is what `const u: unknown = await p` does today for a
1866
+ * `Promise<Record>` with no generics in sight — so the erased form must
1867
+ * not promise otherwise. A closure counts by its RESULT: calling a boxed
1868
+ * closure converts its result into `unknown`, so a callback returning a
1869
+ * promise of a record loses that record's identity (the createLimiter
1870
+ * shape: `async () => shared` over the boundary).
1871
+ * - a record (or array) converting to a different record (or array) type: a
1872
+ * width conversion copies.
1873
+ *
1874
+ * Everything the rule names is a shape the compiler refuses today, so no
1875
+ * program that compiles changes: these fences only replace a silent
1876
+ * divergence with a diagnostic. */
1877
+ function refuseCopyingErasureBoundary(lowerer, call, funcType) {
1878
+ const argNodes = call.arguments.nodes;
1879
+ for (let i = 0; i < argNodes.length && i < funcType.params.length; i++) {
1880
+ const arg = argNodes[i];
1881
+ if (ts.isSpreadElement(arg))
1882
+ continue;
1883
+ const reason = erasureCopyReason(lowerer, lowerer.irTypeOf(arg), funcType.params[i]);
1884
+ if (reason !== null) {
1885
+ lowerer.unsupported("SC1090", arg, `passing this argument across the erased generic boundary (${reason}; JavaScript hands the same object over)`);
1886
+ }
1887
+ }
1888
+ const reason = erasureCopyReason(lowerer, funcType.ret, lowerer.irTypeOf(call));
1889
+ if (reason !== null) {
1890
+ lowerer.unsupported("SC1090", call, `returning this call's result across the erased generic boundary (${reason}; JavaScript hands the same object back)`);
1891
+ }
1892
+ }
1893
+ /** Why converting a value of type `src` at the erased boundary (`dst`)
1894
+ * copies it, or null when the conversion is exact. */
1895
+ function erasureCopyReason(lowerer, src, dst) {
1896
+ if (typeEquals(src, dst))
1897
+ return null;
1898
+ // An unboxed capsule answers the same object, and a promise payload
1899
+ // boxes by reference as well (object-model S1), so no dynamic-side
1900
+ // crossing copies.
1901
+ if (src.kind === "dyn")
1902
+ return null;
1903
+ if (dst.kind === "dyn")
1904
+ return dynCrossingCopyReason(lowerer, src);
1905
+ if (src.kind === "record" && dst.kind === "record")
1906
+ return `a '${lowerer.fmt(src)}' becomes the narrower '${lowerer.fmt(dst)}' by copying it`;
1907
+ if (src.kind === "array" && dst.kind === "array")
1908
+ return `a '${lowerer.fmt(src)}' becomes '${lowerer.fmt(dst)}' by copying it`;
1909
+ if (src.kind === "promise" && dst.kind === "promise")
1910
+ return erasureCopyReason(lowerer, src.inner, dst.inner);
1911
+ if (src.kind === "func" && dst.kind === "func")
1912
+ return erasureCopyReason(lowerer, src.ret, dst.ret);
1913
+ return null;
1914
+ }
1915
+ /** Why a value of type `t` crossing INTO `unknown` copies, or null. A
1916
+ * record, array or promise boxes as a live capsule of itself (a promise's
1917
+ * payload boxes by reference too, object-model S1); a function boxes as a
1918
+ * callable whose RESULT converts through the dynamic call, so a record or
1919
+ * array result comes back as a fresh value. */
1920
+ function dynCrossingCopyReason(lowerer, t) {
1921
+ if (t.kind === "func") {
1922
+ const inner = dynCrossingCopyReason(lowerer, t.ret);
1923
+ if (inner !== null)
1924
+ return inner;
1925
+ if (structuredResultHoldsCopy(lowerer, t.ret))
1926
+ return `a '${lowerer.fmt(t.ret)}' result is re-materialized when the boxed function returns it`;
1927
+ return null;
1928
+ }
1929
+ if (t.kind === "union") {
1930
+ const def = lowerer.unions.get(t.unionId);
1931
+ for (const arm of def?.arms ?? []) {
1932
+ const reason = dynCrossingCopyReason(lowerer, arm);
1933
+ if (reason !== null)
1934
+ return reason;
1935
+ }
1936
+ return null;
1937
+ }
1938
+ return null;
1939
+ }
1940
+ /** True when a boxed function's RESULT is a record or array, or a union with
1941
+ * such an arm. The boxed callable converts that result through the dynamic
1942
+ * call, which answers a fresh value, so the caller does not get the object
1943
+ * the function returned. */
1944
+ function structuredResultHoldsCopy(lowerer, t) {
1945
+ if (t.kind === "record" || t.kind === "array")
1946
+ return true;
1947
+ if (t.kind !== "union")
1948
+ return false;
1949
+ const def = lowerer.unions.get(t.unionId);
1950
+ return def !== undefined && def.arms.some((arm) => structuredResultHoldsCopy(lowerer, arm));
1951
+ }
1754
1952
  /** A call through an evaluated callee value: checked-dynamic callees,
1755
1953
  * function unions, typed-rest and runtime-arity closures. */
1756
- function lowerCallThroughValue(lowerer, expr, callee, loc) {
1954
+ export function lowerCallThroughValue(lowerer, expr, callee, loc) {
1955
+ return overloadValueResult(lowerer, expr, callee, lowerCallThroughValueRaw(lowerer, expr, callee, loc));
1956
+ }
1957
+ /** A call through a VALUE of an OVERLOADED type: the value holds the set's
1958
+ * erased function (mapType's overload-value rule), so its result converts to
1959
+ * the resolved overload's type, as a call through an overloaded record
1960
+ * member does. Only a callee whose IR type IS that erased function converts,
1961
+ * so a class method or a declared function called through its own
1962
+ * implementation is unchanged. Shared with the optional chain's own call
1963
+ * step (`f?.(x)`, `a.m?.(x)`), which builds its callValue directly. */
1964
+ export function overloadValueResult(lowerer, expr, callee, result) {
1965
+ if (result.kind !== "callValue" || callee.type.kind !== "func")
1966
+ return result;
1967
+ const calleeTs = lowerer.checker.getNonNullableType(lowerer.typeOf(expr.expression));
1968
+ if (!isOverloadedCallableMemberType(calleeTs, lowerer.checker))
1969
+ return result;
1970
+ const erased = erasedOverloadMemberType(calleeTs, lowerer.typeCtx);
1971
+ if (erased === undefined || !typeEquals(erased, callee.type))
1972
+ return result;
1973
+ return lowerer.coerceInto(expr, result, resolvedOverloadResultType(lowerer, expr));
1974
+ }
1975
+ function lowerCallThroughValueRaw(lowerer, expr, callee, loc) {
1976
+ // A callee value that keeps its call signature's OWN type parameters
1977
+ // (`f(3)` where `f: <T>(x: T) => T`, a generic method's record slot, a
1978
+ // generic result read back) is the ERASED instance — one function whose
1979
+ // parameters and result are `unknown`, exactly the function JavaScript
1980
+ // runs for every type argument. Its IR type is that erased func type, so
1981
+ // the ordinary lanes below serve the call; only a boundary conversion
1982
+ // that would COPY is refused instead of compiled.
1983
+ refuseCopyingErasureInstanceCall(lowerer, expr, callee);
1757
1984
  // A CHECKED-DYNAMIC callee — `fn(a, b)` where fn is an implicit-any
1758
1985
  // JS binding (the mustCall body's `fn(...args)`), a dyn capture, or a
1759
1986
  // keyed read off a dyn value: the dynCall boundary. Arguments convert
@@ -2138,6 +2365,32 @@ function lowerNumberConstructorValue(lowerer, argNode, loc) {
2138
2365
  ? "unions of numbers, booleans, strings, null, and undefined lower — narrow other arms first"
2139
2366
  : undefined);
2140
2367
  }
2368
+ /** Whether a stored union arm converts on its own. A whole dynamic
2369
+ * argument takes dyn.bigintConstructor instead, so dyn is never a
2370
+ * dispatched arm. */
2371
+ function bigintArmLowers(arm) {
2372
+ return (arm.kind === "bigint" ||
2373
+ arm.kind === "string" ||
2374
+ arm.kind === "f64" ||
2375
+ arm.kind === "bool" ||
2376
+ arm.kind === "bytes" ||
2377
+ arm.kind === "array" ||
2378
+ isUnitType(arm));
2379
+ }
2380
+ /** The hint for a BigInt argument no conversion covers. Lowering dispatches
2381
+ * on the STORED union, which a call-site guard need not narrow; when the
2382
+ * checker sees a different type, name both and point at the arms that stand
2383
+ * in the way, rather than pasting the whole tagged storage at the reader. */
2384
+ function bigintRefusalHint(lowerer, arg, narrowed) {
2385
+ const supported = "string, number, boolean, bigint, byte views, and array arguments are supported";
2386
+ if (!narrowed || arg.type.kind !== "union" || typeEquals(narrowed, arg.type))
2387
+ return supported;
2388
+ const arms = lowerer.unions.get(arg.type.unionId)?.arms ?? [];
2389
+ const blocking = arms.filter((arm) => !bigintArmLowers(arm)).map((arm) => lowerer.fmt(arm));
2390
+ if (blocking.length === 0)
2391
+ return supported;
2392
+ return `the checker narrows the argument to ${lowerer.fmt(narrowed)}, but the stored value can also hold ${blocking.join(" | ")} at run time; ${supported}`;
2393
+ }
2141
2394
  /** A runtime-optional local retains its full tagged storage even after a
2142
2395
  * checker guard. Dispatch BigInt by the actual value, including nullish
2143
2396
  * TypeErrors, rather than interpreting that storage as the narrowed arm. */
@@ -2155,7 +2408,10 @@ function lowerBigIntConstructorValue(lowerer, arg, loc) {
2155
2408
  // as that element, none as 0n, several throw the SyntaxError for the
2156
2409
  // joined text), a Buffer's is its UTF-8 decoding and a DataView's is
2157
2410
  // "[object DataView]". The runtime value tells them apart, as for String.
2158
- if (arg.type.kind === "bytes") {
2411
+ // An array reaches the same ToPrimitive: its text is the elements joined
2412
+ // with "," (`[5]` reads "5", `[]` reads ""), whichever element types it
2413
+ // holds, and BigInt parses that.
2414
+ if (arg.type.kind === "bytes" || arg.type.kind === "array") {
2159
2415
  const text = {
2160
2416
  kind: "toString",
2161
2417
  operand: { kind: "dynFrom", value: arg, type: DYN, loc },
@@ -2194,13 +2450,7 @@ function lowerBigIntConstructorValue(lowerer, arg, loc) {
2194
2450
  return null;
2195
2451
  const unionId = arg.type.unionId;
2196
2452
  const arms = lowerer.unions.get(unionId)?.arms;
2197
- if (!arms ||
2198
- !arms.every((arm) => arm.kind === "bigint" ||
2199
- arm.kind === "string" ||
2200
- arm.kind === "f64" ||
2201
- arm.kind === "bool" ||
2202
- arm.kind === "bytes" ||
2203
- isUnitType(arm)))
2453
+ if (!arms || !arms.every(bigintArmLowers))
2204
2454
  return null;
2205
2455
  const key = `bigint.scalar:${unionId}`;
2206
2456
  let helper = lowerer.valueHelpers.get(key);
@@ -2283,8 +2533,12 @@ function objectToStringTag(lowerer, type) {
2283
2533
  return "Symbol";
2284
2534
  case "array":
2285
2535
  return "Array";
2286
- case "record":
2287
- return "Object";
2536
+ case "record": {
2537
+ // TextEncoder and TextDecoder define Symbol.toStringTag on their
2538
+ // prototypes.
2539
+ const shape = lowerer.shapes.get(type.shapeId);
2540
+ return (shape && recordTextCodecClass(shape)) ?? "Object";
2541
+ }
2288
2542
  case "func":
2289
2543
  case "classval":
2290
2544
  return "Function";
@@ -2393,6 +2647,29 @@ function immediateObjectTagReceiver(lowerer, node) {
2393
2647
  }
2394
2648
  return null;
2395
2649
  }
2650
+ /** Array.prototype methods whose `.<name>.call(receiver, ...)` form the
2651
+ * array-like unit runs generically when `receiver` is not a native array:
2652
+ * the rest of the prototype's methods besides the invoke unit's own set
2653
+ * (at, slice, indexOf, lastIndexOf, includes and the higher-order
2654
+ * callbacks). */
2655
+ const ARRAY_LIKE_BORROW_METHODS = new Set([
2656
+ "concat",
2657
+ "copyWithin",
2658
+ "fill",
2659
+ "flat",
2660
+ "flatMap",
2661
+ "join",
2662
+ "pop",
2663
+ "push",
2664
+ "reverse",
2665
+ "shift",
2666
+ "splice",
2667
+ "toReversed",
2668
+ "toSorted",
2669
+ "toSpliced",
2670
+ "unshift",
2671
+ "with",
2672
+ ]);
2396
2673
  const ARRAY_BORROW_METHODS = new Set([
2397
2674
  "at",
2398
2675
  "every",
@@ -2421,7 +2698,7 @@ function lowerArrayPrototypeBorrowCall(lowerer, call, access) {
2421
2698
  return null;
2422
2699
  const method = access.expression;
2423
2700
  if (method.questionDotToken ||
2424
- !ARRAY_BORROW_METHODS.has(method.name.text) ||
2701
+ !(ARRAY_BORROW_METHODS.has(method.name.text) || ARRAY_LIKE_BORROW_METHODS.has(method.name.text)) ||
2425
2702
  !ts.isPropertyAccessExpression(method.expression) ||
2426
2703
  method.expression.questionDotToken ||
2427
2704
  method.expression.name.text !== "prototype" ||
@@ -2435,7 +2712,12 @@ function lowerArrayPrototypeBorrowCall(lowerer, call, access) {
2435
2712
  const args = call.arguments.nodes.slice(1).map((arg) => lowerer.lowerExprExpecting(arg, DYN));
2436
2713
  return {
2437
2714
  kind: "libCall",
2438
- fn: "dyn.arrayProtoCall",
2715
+ // The array-like unit runs an extended method's algorithm over a
2716
+ // receiver that is not a native array and delegates the rest to the
2717
+ // invoke unit's dispatch.
2718
+ fn: ARRAY_LIKE_BORROW_METHODS.has(method.name.text)
2719
+ ? "dyn.arrayLikeProtoCall"
2720
+ : "dyn.arrayProtoCall",
2439
2721
  args: [
2440
2722
  receiver,
2441
2723
  { kind: "strLit", value: method.name.text, type: STRING, loc },
@@ -2800,11 +3082,16 @@ function lowerStringPrototypeCall(lowerer, call, access) {
2800
3082
  return null;
2801
3083
  const methodAccess = access.expression;
2802
3084
  const prototypeAccess = methodAccess.expression;
3085
+ // The Annex B CreateHTML methods, substr, concat and the locale-cased pair
3086
+ // lower only as EXTRA_STRING_METHODS; a `.call` reaches the same lowering
3087
+ // with the receiver as its first argument.
3088
+ const extraMethod = EXTRA_STRING_METHODS.has(methodAccess.name.text);
2803
3089
  if (!ts.isPropertyAccessExpression(prototypeAccess) ||
2804
3090
  prototypeAccess.name.text !== "prototype" ||
2805
3091
  !ts.isIdentifier(prototypeAccess.expression) ||
2806
3092
  prototypeAccess.expression.text !== "String" ||
2807
- (!Object.hasOwn(STR_METHODS, methodAccess.name.text) &&
3093
+ (!extraMethod &&
3094
+ !Object.hasOwn(STR_METHODS, methodAccess.name.text) &&
2808
3095
  !STRING_INDEX_METHODS.has(methodAccess.name.text)) ||
2809
3096
  !lowerer.isStdlibMember(methodAccess))
2810
3097
  return null;
@@ -2814,9 +3101,11 @@ function lowerStringPrototypeCall(lowerer, call, access) {
2814
3101
  const indexMethod = STRING_INDEX_METHODS.has(methodAccess.name.text)
2815
3102
  ? methodAccess.name.text
2816
3103
  : null;
2817
- const resultType = indexMethod
2818
- ? lowerer.withUndefinedArmOf(indexMethod === "at" ? STRING : F64)
2819
- : entry?.result;
3104
+ const resultType = extraMethod
3105
+ ? STRING
3106
+ : indexMethod
3107
+ ? lowerer.withUndefinedArmOf(indexMethod === "at" ? STRING : F64)
3108
+ : entry?.result;
2820
3109
  if (!resultType)
2821
3110
  return null;
2822
3111
  const method = methodAccess.name.text === "trimStart"
@@ -2876,6 +3165,17 @@ function lowerStringPrototypeCall(lowerer, call, access) {
2876
3165
  false));
2877
3166
  // Other methods convert object receivers before lowering their arguments;
2878
3167
  // padding uses a helper that delays conversion until every argument is ready.
3168
+ if (extraMethod) {
3169
+ // Only the receivers the typed extra-method lowering already accepts: a
3170
+ // scalar converts without running code, and the checked-dynamic receiver
3171
+ // took the branch above. An object receiver's ToString can run user code,
3172
+ // which `Function.call` orders after every argument, so it keeps its fence.
3173
+ if (!scalar) {
3174
+ lowerer.noLowering(`String.prototype.${methodAccess.name.text}.call with ${lowerer.fmt(receiverType)} receivers`, call);
3175
+ }
3176
+ const receiver = lowerer.ensureString(receiverValue, receiverNode);
3177
+ return lowerExtraStringMethodCall(lowerer, call, methodAccess.name.text, receiver, receiverNode, call.arguments.nodes.slice(1));
3178
+ }
2879
3179
  const objectWithoutMethodArgs = entry?.maxArgs === 0 &&
2880
3180
  call.arguments.nodes.length === 1 &&
2881
3181
  (receiverType.kind === "record" ||
@@ -3020,7 +3320,11 @@ function lowerOptionalStringNumber(lowerer, arg, loc, fn = "num.fromString", lab
3020
3320
  return { kind: "call", callee: helper, args: [arg], type: F64, loc };
3021
3321
  }
3022
3322
  /** `s[Symbol.iterator]()` on a string-typed receiver: the generator over
3023
- * its code points. Null for other element calls. */
3323
+ * its code points. On an `Iterable<T>` value (`Iterable<SegmentData>` in a
3324
+ * union with another iterable, an option's segment function): GetIterator
3325
+ * over the current arm, the same interned helper for-of and spread open —
3326
+ * the answer is the canonical iterator, so `.next()` reads like any other.
3327
+ * Null for other element calls. */
3024
3328
  function lowerStringIteratorCall(lowerer, call, access) {
3025
3329
  let key = access.argumentExpression;
3026
3330
  while (ts.isParenthesizedExpression(key))
@@ -3028,7 +3332,11 @@ function lowerStringIteratorCall(lowerer, call, access) {
3028
3332
  if (!ts.isPropertyAccessExpression(key) ||
3029
3333
  lowerer.stdlibGlobalMember(key, "Symbol") !== "iterator")
3030
3334
  return null;
3031
- if (lowerer.mapTypeOf(lowerer.typeOf(access.expression))?.kind !== "string")
3335
+ const receiverT = lowerer.mapTypeOf(lowerer.typeOf(access.expression));
3336
+ const iterable = receiverT ? iterableUnionOf(lowerer, receiverT) : null;
3337
+ if (iterable)
3338
+ return iterableGenerator(lowerer, lowerer.lowerExpr(access.expression), iterable);
3339
+ if (receiverT?.kind !== "string")
3032
3340
  return null;
3033
3341
  const type = lowerer.mapTypeOf(lowerer.typeOf(call));
3034
3342
  if (type?.kind !== "generator")
@@ -3062,6 +3370,57 @@ function isFreshCallResult(node) {
3062
3370
  e = e.expression;
3063
3371
  return ts.isCallExpression(e);
3064
3372
  }
3373
+ /** A METHOD call on a union receiver whose arms declare the member with
3374
+ * DIFFERENT signatures (`OAuthAuth | ApiKeyAuth` both declare `login`, one
3375
+ * with an options parameter): no single static signature picks an arm, and
3376
+ * JavaScript does not pick one either — it reads the property off the value
3377
+ * and calls it. Box the receiver into the checked-dynamic value and lower
3378
+ * the read and the call dynamically, so the member lookup and the call stay
3379
+ * checked (a missing member throws V8's own TypeError) and the result
3380
+ * crosses back through the expected type's checked conversion. Null when
3381
+ * the receiver is not a union of object/record arms with a dyn-safe layout,
3382
+ * leaving the method-call fence in place. */
3383
+ function lowerUnionReceiverMethodCall(lowerer, call, access) {
3384
+ if (access.questionDotToken || call.questionDotToken)
3385
+ return null;
3386
+ if (call.arguments.nodes.some(ts.isSpreadElement))
3387
+ return null;
3388
+ const value = tryLowerExpression(lowerer, access.expression);
3389
+ if (value?.type.kind !== "union")
3390
+ return null;
3391
+ const union = lowerer.unions.get(value.type.unionId);
3392
+ if (!union || !union.arms.every((arm) => arm.kind === "object" || arm.kind === "record")) {
3393
+ return null;
3394
+ }
3395
+ if (!lowerer.dynConvertible(value.type))
3396
+ return null;
3397
+ const loc = locOf(call);
3398
+ const boxed = lowerer.coerceToExpected(value, DYN);
3399
+ const local = lowerer.declareHiddenLocal("%unionReceiver", DYN);
3400
+ const receiver = { kind: "varRef", localId: local.id, type: DYN, loc };
3401
+ const member = {
3402
+ kind: "dynKeyGet",
3403
+ value: receiver,
3404
+ key: { kind: "strLit", value: access.name.text, type: STRING, loc },
3405
+ type: DYN,
3406
+ loc,
3407
+ };
3408
+ return {
3409
+ kind: "seqExpr",
3410
+ stmts: [{ kind: "varDecl", localId: local.id, init: boxed, loc }],
3411
+ result: {
3412
+ kind: "dynCall",
3413
+ callee: member,
3414
+ receiver,
3415
+ calleeName: ts.getTextOfNode(access),
3416
+ args: call.arguments.nodes.map((arg) => lowerer.lowerExprExpecting(arg, DYN)),
3417
+ type: DYN,
3418
+ loc,
3419
+ },
3420
+ type: DYN,
3421
+ loc,
3422
+ };
3423
+ }
3065
3424
  /** METHOD calls on dyn receivers (`pkg.name.replace(...)`, `rawName.split`,
3066
3425
  * `ws.packages.filter(...)` — JSON.parse-derived values): validate the
3067
3426
  * receiver's dyn kind, extract, and ride the STATIC method machinery — the
@@ -3277,6 +3636,12 @@ function lowerDynReceiverMethodCall(lowerer, call, access, boxTypedTemporary = f
3277
3636
  recv = lowerer.coerceToExpected(recv, DYN);
3278
3637
  if (recv.type.kind !== "dyn")
3279
3638
  return null;
3639
+ // `Number.prototype.m(...)` reads the prototype OBJECT, whose `m` is its
3640
+ // own member, so every primitive specialization below — which assumes a
3641
+ // primitive receiver and coerces the value it is given — would be wrong.
3642
+ // The shared dispatch reads the member and calls it with the prototype as
3643
+ // `this`, which is Node's answer for the wrapper around +0 / false.
3644
+ const prototypeReceiver = isPrimitivePrototypeRead(lowerer, access.expression);
3280
3645
  if (access.name.text === "normalize" &&
3281
3646
  call.arguments.nodes.length <= 1 &&
3282
3647
  !call.arguments.nodes.some(ts.isSpreadElement)) {
@@ -3383,7 +3748,7 @@ function lowerDynReceiverMethodCall(lowerer, call, access, boxTypedTemporary = f
3383
3748
  // prototype declares (Array carries includes/indexOf/slice too), so no
3384
3749
  // other kind inherits them. Shared names would need a receiver-kind
3385
3750
  // dispatch — they keep the fence.
3386
- if (DYN_STRING_ONLY_METHODS.has(access.name.text) && !ownCallable) {
3751
+ if (DYN_STRING_ONLY_METHODS.has(access.name.text) && !ownCallable && !prototypeReceiver) {
3387
3752
  // A checked-dynamic object can still carry its OWN member of that
3388
3753
  // name: zod's schemas assign `trim`, `toLowerCase` and `startsWith`
3389
3754
  // in their constructors (`z.string().trim().min(1)`), an object's
@@ -3394,9 +3759,10 @@ function lowerDynReceiverMethodCall(lowerer, call, access, boxTypedTemporary = f
3394
3759
  // receiver's runtime kind: a string runs the string lowering, anything
3395
3760
  // else calls its member as Node does.
3396
3761
  if ((checkerUntyped ||
3397
- (lowerer.typeOf(access).flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) !== 0) &&
3398
- !call.questionDotToken &&
3399
- !access.questionDotToken &&
3762
+ (lowerer.typeOf(access).flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) !== 0 ||
3763
+ // A receiver of the boxed String type may be a wrapper object.
3764
+ (lowerer.createsWrappers ??= programCreatesWrappers(lowerer))) &&
3765
+ !lowerer.chainBlocked(call, access) &&
3400
3766
  !call.arguments.nodes.some(ts.isSpreadElement))
3401
3767
  return lowerStringOrMemberCall(lowerer, call, access, recv);
3402
3768
  const checked = () => dynStringReceiver(lowerer, recv, access);
@@ -3408,8 +3774,7 @@ function lowerDynReceiverMethodCall(lowerer, call, access, boxTypedTemporary = f
3408
3774
  // or number receiver runs the typed lowering, every other kind keeps the
3409
3775
  // runtime dispatch.
3410
3776
  if (!ownCallable &&
3411
- !call.questionDotToken &&
3412
- !access.questionDotToken &&
3777
+ !prototypeReceiver &&
3413
3778
  isDynPrimitiveKindMethod(access.name.text) &&
3414
3779
  !lowerer.chainBlocked(access, call)) {
3415
3780
  const primitive = lowerDynPrimitiveMethodCall(lowerer, call, access.name.text, ts.getTextOfNode(access), recv);
@@ -3423,6 +3788,7 @@ function lowerDynReceiverMethodCall(lowerer, call, access, boxTypedTemporary = f
3423
3788
  if (access.name.text === "toString" &&
3424
3789
  call.arguments.nodes.length <= 1 &&
3425
3790
  !ownCallable &&
3791
+ !prototypeReceiver &&
3426
3792
  !(checkerUntyped && jsAssignsOwnToString(lowerer, access.expression))) {
3427
3793
  const argument = call.arguments.nodes[0];
3428
3794
  return {
@@ -3440,7 +3806,7 @@ function lowerDynReceiverMethodCall(lowerer, call, access, boxTypedTemporary = f
3440
3806
  // Every dyn kind's prototype chain declares valueOf, and the runtime
3441
3807
  // answers each kind's own: primitives and plain objects themselves, a
3442
3808
  // Date its time value, an own or inherited valueOf member its result.
3443
- if (access.name.text === "valueOf" && call.arguments.nodes.length === 0) {
3809
+ if (access.name.text === "valueOf" && call.arguments.nodes.length === 0 && !prototypeReceiver) {
3444
3810
  const webAssembly = lowerWebAssemblyValueOf(lowerer, access.expression, recv, locOf(call));
3445
3811
  if (webAssembly !== null)
3446
3812
  return webAssembly;
@@ -3537,9 +3903,13 @@ function lowerDynReceiverMethodCall(lowerer, call, access, boxTypedTemporary = f
3537
3903
  !ownToString &&
3538
3904
  !stringOnlyName)
3539
3905
  return null;
3540
- // Optional forms (`obj.cb?.()`, `obj?.cb()`) belong to the chain
3541
- // machinery's short-circuit semantics — not modeled here yet.
3542
- if (call.questionDotToken || access.questionDotToken)
3906
+ // An UNHANDLED `?.` step (`obj.cb?.()`, `obj?.cb()`) belongs to the chain
3907
+ // machinery's short-circuit semantics. Inside the guarded body of a chain
3908
+ // the active lowering has ALREADY proven the receiver present, so the
3909
+ // step is a plain read-and-call there — the same "read the member, call
3910
+ // it" shape below, with `dynCall` throwing Node's catchable
3911
+ // "obj.cb is not a function" for a present but non-callable member.
3912
+ if (lowerer.chainBlocked(call, access))
3543
3913
  return null;
3544
3914
  const loc = locOf(call);
3545
3915
  const receiverLocal = lowerer.declareHiddenLocal("%dynCallReceiver", DYN);
@@ -3604,7 +3974,24 @@ function lowerStringOrMemberCall(lowerer, call, access, recv) {
3604
3974
  const loc = locOf(call);
3605
3975
  const receiverLocal = lowerer.declareHiddenLocal("%dynCallReceiver", DYN);
3606
3976
  const receiver = varRef(receiverLocal.id, DYN, loc);
3607
- const isString = { kind: "dynTest", test: "string", value: receiver, type: BOOL, loc };
3977
+ const nameLit = { kind: "strLit", value: access.name.text, type: STRING, loc };
3978
+ const receiverIsString = {
3979
+ kind: "dynTest",
3980
+ test: "string",
3981
+ value: receiver,
3982
+ type: BOOL,
3983
+ loc,
3984
+ };
3985
+ // In a program that creates wrapper objects, a receiver whose member is
3986
+ // the builtin String.prototype method runs the string lowering on
3987
+ // ToString of the receiver, after the arguments, as the builtin does.
3988
+ // The member is read once: the check inspects the value the call read.
3989
+ const wrappers = (lowerer.createsWrappers ??= programCreatesWrappers(lowerer));
3990
+ const builtinLocal = wrappers ? lowerer.declareHiddenLocal("%dynCallStringMethod", BOOL) : null;
3991
+ const isString = builtinLocal
3992
+ ? { kind: "varRef", localId: builtinLocal.id, type: BOOL, loc }
3993
+ : receiverIsString;
3994
+ const stringLocal = wrappers ? lowerer.declareHiddenLocal("%dynCallString", DYN) : null;
3608
3995
  const calleeLocal = lowerer.declareHiddenLocal("%dynCallCallee", DYN);
3609
3996
  const callee = varRef(calleeLocal.id, DYN, loc);
3610
3997
  const stmts = [
@@ -3614,7 +4001,7 @@ function lowerStringOrMemberCall(lowerer, call, access, recv) {
3614
4001
  localId: calleeLocal.id,
3615
4002
  init: {
3616
4003
  kind: "ternary",
3617
- cond: isString,
4004
+ cond: receiverIsString,
3618
4005
  then: dynUndefinedExpr(loc),
3619
4006
  else_: {
3620
4007
  kind: "dynKeyGet",
@@ -3628,16 +4015,52 @@ function lowerStringOrMemberCall(lowerer, call, access, recv) {
3628
4015
  },
3629
4016
  loc,
3630
4017
  },
4018
+ ...(builtinLocal
4019
+ ? [
4020
+ {
4021
+ kind: "varDecl",
4022
+ localId: builtinLocal.id,
4023
+ init: {
4024
+ kind: "logical",
4025
+ op: "||",
4026
+ left: receiverIsString,
4027
+ right: {
4028
+ kind: "libCall",
4029
+ fn: "wrapper.isStringMethod",
4030
+ args: [callee, nameLit],
4031
+ type: BOOL,
4032
+ loc,
4033
+ },
4034
+ type: BOOL,
4035
+ loc,
4036
+ },
4037
+ loc,
4038
+ },
4039
+ ]
4040
+ : []),
3631
4041
  ];
3632
4042
  const args = call.arguments.nodes.map((node) => {
3633
- const value = lowerer.lowerExpr(node);
4043
+ const lowered = lowerer.lowerExpr(node);
4044
+ // A unit-typed argument (`f()` of a void function, a literal undefined
4045
+ // or null) has no local storage of its own: hold it as the dynamic
4046
+ // value both branches receive.
4047
+ const value = lowered.type.kind === "void" ||
4048
+ lowered.type.kind === "undefinedT" ||
4049
+ lowered.type.kind === "nullT"
4050
+ ? lowerer.coerceToExpected(lowered, DYN)
4051
+ : lowered;
3634
4052
  const local = lowerer.declareHiddenLocal("%dynCallArg", value.type);
3635
4053
  stmts.push({ kind: "varDecl", localId: local.id, init: value, loc: value.loc });
3636
4054
  return { node, value: varRef(local.id, value.type, value.loc) };
3637
4055
  });
3638
4056
  // String.prototype methods ignore arguments past the ones they read.
3639
4057
  const arity = DYN_STRING_ONLY_ARITY[access.name.text] ?? call.arguments.nodes.length;
3640
- const stringReceiver = () => ({ kind: "dynCheck", value: receiver, type: STRING, loc });
4058
+ const stringReceiver = () => ({
4059
+ kind: "dynCheck",
4060
+ value: stringLocal ? varRef(stringLocal.id, DYN, loc) : receiver,
4061
+ type: STRING,
4062
+ loc,
4063
+ });
3641
4064
  const lowerString = () => (call.arguments.nodes.length <= arity
3642
4065
  ? lowerRegexMethodCall(lowerer, call, access, stringReceiver)
3643
4066
  : null) ??
@@ -3659,7 +4082,35 @@ function lowerStringOrMemberCall(lowerer, call, access, recv) {
3659
4082
  kind: "ternary",
3660
4083
  cond: isString,
3661
4084
  then: stringCall
3662
- ? lowerer.coerceToExpected(stringCall, DYN)
4085
+ ? stringLocal
4086
+ ? {
4087
+ kind: "seqExpr",
4088
+ stmts: [
4089
+ {
4090
+ kind: "varDecl",
4091
+ localId: stringLocal.id,
4092
+ init: {
4093
+ kind: "ternary",
4094
+ cond: receiverIsString,
4095
+ then: receiver,
4096
+ else_: {
4097
+ kind: "libCall",
4098
+ fn: "wrapper.thisString",
4099
+ args: [receiver, nameLit],
4100
+ type: DYN,
4101
+ loc,
4102
+ },
4103
+ type: DYN,
4104
+ loc,
4105
+ },
4106
+ loc,
4107
+ },
4108
+ ],
4109
+ result: lowerer.coerceToExpected(stringCall, DYN),
4110
+ type: DYN,
4111
+ loc,
4112
+ }
4113
+ : lowerer.coerceToExpected(stringCall, DYN)
3663
4114
  : nodeThrowExpr(0, "SC1090", `method calls like '${ts.getTextOfNode(access)}' on a string are not supported yet [SC1090 at ${ts.getSourceFileOfNode(call).fileName}:${ts.getLineAndCharacterOfPosition(ts.getSourceFileOfNode(call), ts.tokenStartOfNode(call)).line + 1}]`, DYN, loc),
3664
4115
  else_: memberCall,
3665
4116
  type: DYN,
@@ -4243,7 +4694,10 @@ function lowerArrayIsArrayCall(lowerer, call, access) {
4243
4694
  return folded;
4244
4695
  // A computed argument (`Array.isArray(make())`, `Array.isArray([1, 2])`)
4245
4696
  // still answers from its static type, so evaluate the argument for its
4246
- // effects and discard the value.
4697
+ // effects and discard the value. `undefined`/`null` lower to a bare unitLit,
4698
+ // which carries no effect and is not a valid IR expression statement.
4699
+ if (arg.kind === "unitLit")
4700
+ return folded;
4247
4701
  return {
4248
4702
  kind: "seqExpr",
4249
4703
  stmts: [{ kind: "exprStmt", expr: arg, loc }],
@@ -4476,8 +4930,13 @@ function lowerDefaultToStringCall(lowerer, call, access) {
4476
4930
  // throws "<callee> is not a function".
4477
4931
  const nullProtoT = nullProtoRecordShape(lowerer, recvT);
4478
4932
  const missing = nullProtoT ? `${ts.getTextOfNode(access)} is not a function` : null;
4933
+ // A linked copy or a record with a kept source answers as its source
4934
+ // does (record-links.ts).
4935
+ const linked = !missing && recvT.kind === "record" && recordMayKeepSource(lowerer, recvT);
4479
4936
  if (!missing && pureObjectToStringReceiver(access.expression))
4480
- return constant;
4937
+ return linked
4938
+ ? recordStringCall(lowerer, lowerer.lowerExpr(access.expression), "string", loc, "constant")
4939
+ : constant;
4481
4940
  const recv = lowerer.lowerExpr(access.expression);
4482
4941
  const key = `objToStr:${typeKey(recv.type)}${missing ? `:${missing}` : ""}`;
4483
4942
  let helper = lowerer.valueHelpers.get(key);
@@ -4485,7 +4944,7 @@ function lowerDefaultToStringCall(lowerer, call, access) {
4485
4944
  helper = keyedHelperName(lowerer, "%obj.tostr", key);
4486
4945
  lowerer.valueHelpers.set(key, helper);
4487
4946
  const o = varRef("o.0", recv.type, loc);
4488
- lowerer.liftedFns.push({
4947
+ const fn = {
4489
4948
  name: helper,
4490
4949
  params: [{ localId: "o.0", name: "o", type: recv.type }],
4491
4950
  returnType: STRING,
@@ -4500,7 +4959,10 @@ function lowerDefaultToStringCall(lowerer, call, access) {
4500
4959
  },
4501
4960
  ],
4502
4961
  loc,
4503
- });
4962
+ };
4963
+ lowerer.liftedFns.push(fn);
4964
+ if (linked)
4965
+ registerLinkedHelper(lowerer, fn, recvT.shapeId, "string");
4504
4966
  }
4505
4967
  return { kind: "call", callee: helper, args: [recv], type: STRING, loc };
4506
4968
  }
@@ -4713,17 +5175,57 @@ function lowerPrimitiveProtoCall(lowerer, call, recv, name, memberSym) {
4713
5175
  }
4714
5176
  // Number.prototype.toLocaleString("en-US") — the spec makes it
4715
5177
  // NumberFormat(locale).format(this), so the en-US embedded formatter
4716
- // answers exactly. The unlowered forms fence by NAME: no locale (the
4717
- // host environment's default, which a compiled binary cannot carry),
4718
- // other locales (ICU data the binary does not embed), options bags.
5178
+ // answers exactly. Without a locale (or with `undefined`) the DEFAULT
5179
+ // locale answers, over the ICU data scr_intl.c loads; other locales and
5180
+ // options bags stay fenced.
4719
5181
  if (name === "toLocaleString" && recvKind === "f64") {
4720
- if (call.arguments.nodes.length === 0) {
4721
- lowerer.noLowering("Number.prototype.toLocaleString without a locale", call, "the default locale is the host environment's, which a compiled binary cannot carry — " +
4722
- 'pass it explicitly: x.toLocaleString("en-US")');
5182
+ // Exactly undefined (or void): what the absent form means. A union that
5183
+ // merely includes undefined may hold a locale at run time and falls
5184
+ // through to the refusal below.
5185
+ const isUndefined = (node) => {
5186
+ const flags = lowerer.typeOf(node).flags;
5187
+ return flags === ts.TypeFlags.Undefined || flags === ts.TypeFlags.Void;
5188
+ };
5189
+ const defaultLocale = call.arguments.nodes.length === 0 ||
5190
+ (call.arguments.nodes.length === 1 &&
5191
+ !ts.isSpreadElement(call.arguments.nodes[0]) &&
5192
+ isUndefined(call.arguments.nodes[0]));
5193
+ if (defaultLocale) {
5194
+ const operand = lowerer.lowerExpr(recv);
5195
+ if (operand.type.kind !== "f64")
5196
+ return null;
5197
+ const stmts = [];
5198
+ let formatted = operand;
5199
+ if (call.arguments.nodes.length === 1) {
5200
+ // An explicit undefined may be any expression that evaluates to it
5201
+ // (a call, a variable), so it still runs, after the receiver and
5202
+ // before the formatting: the receiver's value is read first, so an
5203
+ // argument that writes it does not change the number formatted. Its
5204
+ // unit value has no standalone representation, so it is coerced
5205
+ // into the dynamic slot every argument occupies.
5206
+ const receiver = lowerer.declareHiddenLocal("%localeReceiver", F64);
5207
+ stmts.push({ kind: "varDecl", localId: receiver.id, init: operand, loc });
5208
+ formatted = varRef(receiver.id, F64, loc);
5209
+ const arg = call.arguments.nodes[0];
5210
+ const value = lowerer.lowerExpr(arg);
5211
+ stmts.push({
5212
+ kind: "exprStmt",
5213
+ expr: value.type.kind === "void" ? value : lowerer.coerceInto(arg, value, DYN),
5214
+ loc,
5215
+ });
5216
+ }
5217
+ const call_ = {
5218
+ kind: "libCall",
5219
+ fn: "icu.numFormatDefault",
5220
+ args: [formatted],
5221
+ type: STRING,
5222
+ loc,
5223
+ };
5224
+ return stmts.length ? { kind: "seqExpr", stmts, result: call_, type: STRING, loc } : call_;
4723
5225
  }
4724
5226
  if (call.arguments.nodes.length > 1) {
4725
- lowerer.noLowering("Number.prototype.toLocaleString with an options bag", call, "the embedded data covers DEFAULT options only (decimal notation, up to 3 fraction " +
4726
- 'digits, grouping) — x.toLocaleString("en-US")');
5227
+ lowerer.noLowering("Number.prototype.toLocaleString with an options bag", call, "what lowers is the DEFAULT options shape (decimal notation, up to 3 fraction digits, " +
5228
+ "grouping) at the default locale or at en-US — omit the options bag");
4727
5229
  }
4728
5230
  const locNode = call.arguments.nodes[0];
4729
5231
  if (ts.isSpreadElement(locNode) ||
@@ -4731,8 +5233,8 @@ function lowerPrimitiveProtoCall(lowerer, call, recv, name, memberSym) {
4731
5233
  locNode.text !== "en-US") {
4732
5234
  lowerer.noLowering(!ts.isSpreadElement(locNode) && ts.isStringLiteralLike(locNode)
4733
5235
  ? `Number.prototype.toLocaleString at locale "${locNode.text}"`
4734
- : "Number.prototype.toLocaleString with a non-literal locale", locNode, '"en-US" (Node\'s default-build locale) is the one locale whose data the runtime embeds — ' +
4735
- "everything else is ICU data the binary does not carry");
5236
+ : "Number.prototype.toLocaleString with a non-literal locale", locNode, "what lowers is the default locale (no argument) and the composed en-US form — " +
5237
+ "other locales are ICU data the binary does not negotiate yet");
4736
5238
  }
4737
5239
  const operand = lowerer.lowerExpr(recv);
4738
5240
  if (operand.type.kind !== "f64")
@@ -6506,11 +7008,39 @@ export function recordKeysArrayCall(lowerer, receiver, argIr, shape, loc) {
6506
7008
  }
6507
7009
  body.push(...perKeyOrder(current, ref, walks, loc));
6508
7010
  body.push({ kind: "return", value: outRef, loc });
7011
+ // A record that kept undeclared keys answers for-in through its live
7012
+ // kept view, exactly as Object.keys does at its call site. Gated on
7013
+ // the shape being one a kept width spread builds (a shape that keeps
7014
+ // no source stays byte-identical to main) and on the shape holding a
7015
+ // source at all.
7016
+ if (lowerer.keyOrder.keptSourceShapes.has(argIr.shapeId) &&
7017
+ recordMayKeepSource(lowerer, argIr)) {
7018
+ body.unshift({
7019
+ kind: "if",
7020
+ cond: recordSourceTest(ref, loc),
7021
+ then: [
7022
+ {
7023
+ kind: "return",
7024
+ value: {
7025
+ kind: "libCall",
7026
+ fn: "dyn.objKeyStrings",
7027
+ args: [{ kind: "dynFrom", value: ref, liveRef: true, type: DYN, loc }],
7028
+ type: resultT,
7029
+ loc,
7030
+ },
7031
+ loc,
7032
+ },
7033
+ ],
7034
+ else_: null,
7035
+ loc,
7036
+ });
7037
+ }
6509
7038
  fn.body = body;
6510
7039
  };
6511
7040
  finalize();
6512
7041
  lowerer.shapeOrderHelperFinalizers.push(finalize);
6513
7042
  lowerer.liftedFns.push(fn);
7043
+ registerLinkedHelper(lowerer, fn, argIr.shapeId, "keys");
6514
7044
  }
6515
7045
  return { kind: "call", callee: helper, args: [receiver], type: resultT, loc };
6516
7046
  }
@@ -6553,7 +7083,7 @@ export function recordHasOwnHelper(lowerer, shapeId, loc) {
6553
7083
  ? { kind: "recordOvfHas", obj: rRef, shapeId, key: kRef, type: BOOL, loc }
6554
7084
  : { kind: "boolLit", value: false, type: BOOL, loc };
6555
7085
  body.push({ kind: "return", value: fallback, loc });
6556
- lowerer.liftedFns.push({
7086
+ const fn = {
6557
7087
  name: helper,
6558
7088
  params: [
6559
7089
  { localId: "r.0", name: "r", type: recT },
@@ -6566,7 +7096,37 @@ export function recordHasOwnHelper(lowerer, shapeId, loc) {
6566
7096
  ],
6567
7097
  body,
6568
7098
  loc,
6569
- });
7099
+ };
7100
+ lowerer.liftedFns.push(fn);
7101
+ registerLinkedHelper(lowerer, fn, shapeId, "hasOwn");
7102
+ // A record that kept undeclared keys answers an undeclared key through
7103
+ // its kept view: the declared branches above stay exact (the table's
7104
+ // placeholders only fill declared names the record owns), and the
7105
+ // closed-shape `false` fallback becomes the view's own-key test when a
7106
+ // kept width spread builds this shape.
7107
+ if (!shape.indexValue && recordMayKeepSource(lowerer, recT)) {
7108
+ lowerer.shapeOrderHelperFinalizers.push(() => {
7109
+ if (!lowerer.keyOrder.keptSourceShapes.has(shapeId))
7110
+ return;
7111
+ const last = fn.body[fn.body.length - 1];
7112
+ if (last.kind !== "return")
7113
+ return;
7114
+ last.value = {
7115
+ kind: "logical",
7116
+ op: "&&",
7117
+ left: recordSourceTest(rRef, loc),
7118
+ right: {
7119
+ kind: "libCall",
7120
+ fn: "dyn.hasOwn",
7121
+ args: [{ kind: "dynFrom", value: rRef, liveRef: true, type: DYN, loc }, kRef],
7122
+ type: BOOL,
7123
+ loc,
7124
+ },
7125
+ type: BOOL,
7126
+ loc,
7127
+ };
7128
+ });
7129
+ }
6570
7130
  return helper;
6571
7131
  }
6572
7132
  /** Whether `Object.assign(instance, record)` can copy every field of the
@@ -6725,6 +7285,12 @@ function lowerIteratorStaticFence(lowerer, call, access) {
6725
7285
  const from = lowerIteratorFromCall(lowerer, call, access);
6726
7286
  if (from)
6727
7287
  return from;
7288
+ // Any other argument in JavaScript: the runtime's Iterator.from.
7289
+ if (access.name.text === "from" && !call.questionDotToken && !access.questionDotToken) {
7290
+ const dynamic = lowerIteratorFromDyn(lowerer, call);
7291
+ if (dynamic)
7292
+ return dynamic;
7293
+ }
6728
7294
  lowerer.noLowering(`Iterator.${access.name.text}`, call, access.name.text === "from"
6729
7295
  ? "Iterator.from accepts arrays, strings, typed arrays, Sets, Maps and iterator objects such as generators"
6730
7296
  : "iterator helpers apply directly to generators and to array, Map and Set iterators: " +
@@ -6839,6 +7405,67 @@ function isDynEntryPairsType(lowerer, t) {
6839
7405
  const field = (name) => shape.fields.find((f) => f.name === name)?.type;
6840
7406
  return field("0")?.kind === "string" && field("1")?.kind === "dyn";
6841
7407
  }
7408
+ /** Object.seal, Object.freeze, Object.preventExtensions and their queries
7409
+ * over a byte view (a typed array or a DataView) in JavaScript code. A view
7410
+ * boxes BY REFERENCE and carries its integrity state on itself
7411
+ * (ScrBytes.properties), so the checked-dynamic operations model it exactly:
7412
+ * seal and freeze of a view with elements throw after making it
7413
+ * non-extensible, as in V8. seal, freeze and preventExtensions answer the
7414
+ * view itself, so the result converts back to the same view (a checked cast,
7415
+ * which preserves its identity) wherever the element type admits the
7416
+ * conversion — bytes<u8>, the DataView and Uint8Array case. A view of wider
7417
+ * elements stays checked-dynamic, which the discarded statement form and a
7418
+ * later comparison against the view both handle exactly. The queries answer
7419
+ * a boolean. */
7420
+ export function lowerBytesIntegrity(lowerer, fn, view, loc) {
7421
+ const query = fn.startsWith("dyn.is");
7422
+ const result = {
7423
+ kind: "libCall",
7424
+ fn,
7425
+ args: [lowerer.coerceToExpected(view, DYN)],
7426
+ type: query ? BOOL : DYN,
7427
+ loc,
7428
+ };
7429
+ return query ? result : lowerer.coerceToExpected(result, view.type);
7430
+ }
7431
+ /** True when the expression is statically a PLAIN OBJECT at runtime: a dyn
7432
+ * object literal, or a record (a literal, a clone, or any expression of a
7433
+ * record type, which dynFrom boxes field by field). Both build an ordinary
7434
+ * object whose fields are own data properties, which the plain-object
7435
+ * descriptor reader answers exactly. Every other expression (a variable of
7436
+ * any other type, a call, an array, a function) may be an object of any
7437
+ * kind with inherited fields, so it takes the entry points whose
7438
+ * ToPropertyDescriptor reads every object kind (dyn.definePropertyShapes
7439
+ * and its siblings). */
7440
+ export function isPlainObjectLiteral(expr) {
7441
+ if (expr.kind === "dynObjLit")
7442
+ return true;
7443
+ if (expr.kind !== "dynFrom")
7444
+ return false;
7445
+ const value = expr.value;
7446
+ return value.kind === "dynObjLit" || value.type.kind === "record";
7447
+ }
7448
+ /** True when the expression is a plain property-descriptor map for
7449
+ * Object.defineProperties or Object.create: a plain object
7450
+ * (isPlainObjectLiteral) whose every field is a plain object too. A dyn
7451
+ * literal's field values are checked with isPlainObjectLiteral and a
7452
+ * record's fields by their types, since dynFrom boxes a record-typed field
7453
+ * into an ordinary object. A map with any other field (`{ a: view }`, where
7454
+ * `view` is a DataView or an array) takes the any-object entry points. */
7455
+ export function isPlainDescriptorMap(expr, getRecord) {
7456
+ if (!isPlainObjectLiteral(expr))
7457
+ return false;
7458
+ const literal = expr.kind === "dynFrom" ? expr.value : expr;
7459
+ if (literal.kind === "dynObjLit")
7460
+ return (literal.fields ?? []).every((field) => isPlainObjectLiteral(field.value));
7461
+ if (literal.type.kind !== "record")
7462
+ return false;
7463
+ const shape = getRecord(literal.type.shapeId);
7464
+ return (shape !== undefined &&
7465
+ !shape.tuple &&
7466
+ shape.indexValue === undefined &&
7467
+ shape.fields.every((field) => field.type.kind === "record"));
7468
+ }
6842
7469
  function lowerObjectStaticCall(lowerer, call, access) {
6843
7470
  if (call.questionDotToken || access.questionDotToken)
6844
7471
  return null;
@@ -6883,6 +7510,16 @@ function lowerObjectStaticCall(lowerer, call, access) {
6883
7510
  object.type.kind === "bool" ||
6884
7511
  isUnitType(object.type))
6885
7512
  object = { kind: "dynFrom", value: object, type: DYN, loc: locOf(call) };
7513
+ // An array or class instance reflects through its own checked-dynamic
7514
+ // view (own fields and elements, in property order). A record keeps its
7515
+ // static key walk below when it has one — `getOwnPropertyNames` over a
7516
+ // fixed record is exactly Object.keys' construction, and boxing a typed
7517
+ // record would link the dynamic tier into a program that needs none of
7518
+ // it. The descriptor and symbol forms have no static walk, so a record
7519
+ // takes the view there.
7520
+ const staticWalk = member === "getOwnPropertyNames" && object.type.kind === "record";
7521
+ if (!staticWalk && object.type.kind !== "dyn" && lowerer.dynConvertible(object.type))
7522
+ object = lowerer.coerceToExpected(object, DYN);
6886
7523
  if (object.type.kind === "dyn")
6887
7524
  return {
6888
7525
  kind: "libCall",
@@ -7133,7 +7770,12 @@ function lowerObjectStaticCall(lowerer, call, access) {
7133
7770
  if (descriptors.type.kind === "dyn")
7134
7771
  return {
7135
7772
  kind: "libCall",
7136
- fn: "dyn.objCreateWithProperties",
7773
+ // A descriptor map built by an expression, or a literal map with a
7774
+ // descriptor built by one, may hold an array, a function or an
7775
+ // object with inherited fields.
7776
+ fn: isPlainDescriptorMap(descriptors, (id) => lowerer.shapes.get(id))
7777
+ ? "dyn.objCreateWithProperties"
7778
+ : "dyn.objCreateWithPropertiesShapes",
7137
7779
  args: [proto, descriptors],
7138
7780
  type: DYN,
7139
7781
  loc,
@@ -7147,6 +7789,9 @@ function lowerObjectStaticCall(lowerer, call, access) {
7147
7789
  const prototype = lowerClassPrototypeAssign(lowerer, call);
7148
7790
  if (prototype)
7149
7791
  return prototype;
7792
+ // A standard-library prototype value as the target is a write through it.
7793
+ if (call.arguments.nodes.length > 0)
7794
+ fenceDatePrototypeWriteCall(lowerer, call.arguments.nodes[0]);
7150
7795
  if (isJsSourceFile(ts.getSourceFileOfNode(call)) &&
7151
7796
  call.arguments.nodes.length > 0 &&
7152
7797
  !call.arguments.nodes.some(ts.isSpreadElement)) {
@@ -7220,8 +7865,14 @@ function lowerObjectStaticCall(lowerer, call, access) {
7220
7865
  const sProbe = tryLowerExpression(lowerer, call.arguments.nodes[1]);
7221
7866
  // CHECKED-DYNAMIC target and source (the JS file-scope
7222
7867
  // object-literal identity story): the runtime dyn copy — own
7223
- // members of the source land on the target, which returns.
7224
- if (tProbe?.type.kind === "dyn") {
7868
+ // members of the source land on the target, which returns. A
7869
+ // CLASS-INSTANCE target joins them when the call's own RESULT type
7870
+ // is checked-dynamic: that is the `C & { extra }` intersection
7871
+ // (mapClassExpandoIntersection), whose value IS the instance, so
7872
+ // the same dyn copy writes the expando members onto its view and
7873
+ // answers the instance — identity and prototype intact.
7874
+ if (tProbe?.type.kind === "dyn" ||
7875
+ (tProbe?.type.kind === "object" && lowerer.mapTypeOf(lowerer.typeOf(call))?.kind === "dyn")) {
7225
7876
  const loc = locOf(call);
7226
7877
  const target = lowerer.lowerExpr(call.arguments.nodes[0]);
7227
7878
  const rawSource = lowerer.lowerExpr(call.arguments.nodes[1]);
@@ -7232,8 +7883,9 @@ function lowerObjectStaticCall(lowerer, call, access) {
7232
7883
  if (ts.isObjectLiteralExpression(targetNode))
7233
7884
  fenceClassCopyIntoFreshObject(lowerer, call, call.arguments.nodes[1], rawSource);
7234
7885
  const source = lowerer.coerceToExpected(rawSource, DYN);
7235
- if (target.type.kind === "dyn" && source.type.kind === "dyn") {
7236
- return { kind: "libCall", fn: "dyn.assign", args: [target, source], type: DYN, loc };
7886
+ const dynTarget = target.type.kind === "dyn" ? target : lowerer.coerceToExpected(target, DYN);
7887
+ if (dynTarget.type.kind === "dyn" && source.type.kind === "dyn") {
7888
+ return { kind: "libCall", fn: "dyn.assign", args: [dynTarget, source], type: DYN, loc };
7237
7889
  }
7238
7890
  }
7239
7891
  // A CLASS-INSTANCE target and a plain record source whose fields are
@@ -7253,9 +7905,30 @@ function lowerObjectStaticCall(lowerer, call, access) {
7253
7905
  }
7254
7906
  }
7255
7907
  }
7256
- if (tProbe?.type.kind === "record" && sProbe?.type.kind === "record") {
7257
- const tShape = lowerer.shapes.get(tProbe.type.shapeId);
7258
- const sShape = lowerer.shapes.get(sProbe.type.shapeId);
7908
+ // An operand the CHECKER narrowed to one record ARM of its declared
7909
+ // union (`content?.type === "toolCall"` narrows the array element to
7910
+ // ToolCall, whose lowered value still carries the element's
7911
+ // `ToolCall | ToolResult`): the plan runs over the arm, and the
7912
+ // operand lowers through the CHECKED extraction — the same
7913
+ // `%union.narrow` every other arm-typed site uses, so a value that
7914
+ // is not that arm throws the catchable TypeError instead of being
7915
+ // copied through the wrong layout. The extraction yields the arm's
7916
+ // own record, so the write still mutates the value the program holds.
7917
+ const assignOperand = (node, probe) => {
7918
+ if (probe?.type.kind === "record")
7919
+ return probe.type;
7920
+ if (probe?.type.kind !== "union")
7921
+ return null;
7922
+ const site = lowerer.mapTypeOf(lowerer.typeOf(node));
7923
+ return site?.kind === "record" && lowerer.armTag(probe.type.unionId, site) >= 0
7924
+ ? site
7925
+ : null;
7926
+ };
7927
+ const tOperand = assignOperand(call.arguments.nodes[0], tProbe);
7928
+ const sOperand = assignOperand(call.arguments.nodes[1], sProbe);
7929
+ if (tOperand?.kind === "record" && sOperand?.kind === "record") {
7930
+ const tShape = lowerer.shapes.get(tOperand.shapeId);
7931
+ const sShape = lowerer.shapes.get(sOperand.shapeId);
7259
7932
  const ok = tShape &&
7260
7933
  sShape &&
7261
7934
  !tShape.tuple &&
@@ -7273,8 +7946,12 @@ function lowerObjectStaticCall(lowerer, call, access) {
7273
7946
  });
7274
7947
  if (ok) {
7275
7948
  const loc = locOf(call);
7276
- const target = lowerer.lowerExpr(call.arguments.nodes[0]);
7277
- const source = lowerer.lowerExpr(call.arguments.nodes[1]);
7949
+ const operand = (node, arm) => {
7950
+ const value = lowerer.lowerExpr(node);
7951
+ return value.type.kind === "record" ? value : lowerer.coerceToExpected(value, arm);
7952
+ };
7953
+ const target = operand(call.arguments.nodes[0], tOperand);
7954
+ const source = operand(call.arguments.nodes[1], sOperand);
7278
7955
  if (target.type.kind === "record" && source.type.kind === "record") {
7279
7956
  const helper = recordAssignHelper(lowerer, target.type.shapeId, source.type.shapeId, loc);
7280
7957
  return { kind: "call", callee: helper, args: [target, source], type: target.type, loc };
@@ -7439,8 +8116,14 @@ function lowerObjectStaticCall(lowerer, call, access) {
7439
8116
  (member === "getOwnPropertyDescriptor" && call.arguments.nodes.length === 2)) {
7440
8117
  if (call.arguments.nodes.some((a) => ts.isSpreadElement(a)))
7441
8118
  return null;
7442
- let target = tryLowerExpression(lowerer, call.arguments.nodes[0]);
7443
8119
  const targetNode = call.arguments.nodes[0];
8120
+ // Object.defineProperty/defineProperties over a standard-library prototype
8121
+ // value: a typed Date never observes a dynamic definition there, so the
8122
+ // write keeps the fence it reached before the value existed. The
8123
+ // descriptor READ below is not a write and stays open.
8124
+ if (member === "defineProperty")
8125
+ fenceDatePrototypeWriteCall(lowerer, targetNode);
8126
+ let target = tryLowerExpression(lowerer, targetNode);
7444
8127
  // The checker gives C.prototype the instance type, but its lowered
7445
8128
  // value is the shared prototype table, not an instance to unbox.
7446
8129
  const prototypeTarget = ts.isPropertyAccessExpression(targetNode) &&
@@ -7517,7 +8200,10 @@ function lowerObjectStaticCall(lowerer, call, access) {
7517
8200
  return null;
7518
8201
  return {
7519
8202
  kind: "libCall",
7520
- fn: "dyn.defineProperty",
8203
+ // A descriptor built by an expression may be an array, a function or an
8204
+ // object with inherited fields, which only the any-object entry point
8205
+ // reads; a plain object literal keeps the plain-object reader.
8206
+ fn: isPlainObjectLiteral(descriptor) ? "dyn.defineProperty" : "dyn.definePropertyShapes",
7521
8207
  args: [target, key, descriptor],
7522
8208
  type: DYN,
7523
8209
  loc: locOf(call),
@@ -7533,6 +8219,10 @@ function lowerObjectStaticCall(lowerer, call, access) {
7533
8219
  if (member === "defineProperties" &&
7534
8220
  call.arguments.nodes.length === 2 &&
7535
8221
  !call.arguments.nodes.some((a) => ts.isSpreadElement(a))) {
8222
+ // A standard-library prototype value as the target is a write through it,
8223
+ // exactly like the defineProperty form above: a typed Date never observes
8224
+ // a definition made on the dynamic prototype object.
8225
+ fenceDatePrototypeWriteCall(lowerer, call.arguments.nodes[0]);
7536
8226
  const prototype = lowerClassPrototypeDescriptors(lowerer, call, member);
7537
8227
  if (prototype)
7538
8228
  return prototype;
@@ -7573,7 +8263,12 @@ function lowerObjectStaticCall(lowerer, call, access) {
7573
8263
  if (descs.type.kind === "dyn") {
7574
8264
  return {
7575
8265
  kind: "libCall",
7576
- fn: "dyn.defineProps",
8266
+ // As for Object.create above: a descriptor map built by an
8267
+ // expression, or a literal map with a descriptor built by one, takes
8268
+ // the any-object entry point.
8269
+ fn: isPlainDescriptorMap(descs, (id) => lowerer.shapes.get(id))
8270
+ ? "dyn.defineProps"
8271
+ : "dyn.definePropsShapes",
7577
8272
  args: [target, descs],
7578
8273
  type: DYN,
7579
8274
  loc: locOf(call),
@@ -7624,6 +8319,17 @@ function lowerObjectStaticCall(lowerer, call, access) {
7624
8319
  ? extensible
7625
8320
  : { kind: "unary", op: "!", operand: extensible, type: BOOL, loc: locOf(call) };
7626
8321
  }
8322
+ // A byte view carries its integrity state on itself and boxes by
8323
+ // reference, so the checked-dynamic operations model these exactly.
8324
+ if (value.type.kind === "bytes" && isJsSourceFile(ts.getSourceFileOfNode(call))) {
8325
+ const operation = {
8326
+ preventExtensions: "dyn.preventExtensions",
8327
+ isExtensible: "dyn.isExtensible",
8328
+ seal: "dyn.seal",
8329
+ isSealed: "dyn.isSealed",
8330
+ };
8331
+ return lowerBytesIntegrity(lowerer, operation[member], value, locOf(call));
8332
+ }
7627
8333
  if (member === "preventExtensions" || member === "seal") {
7628
8334
  const integrity = lowerClassIntegrity(lowerer, call, member, value);
7629
8335
  if (integrity)
@@ -7640,11 +8346,16 @@ function lowerObjectStaticCall(lowerer, call, access) {
7640
8346
  };
7641
8347
  }
7642
8348
  if (value.type.kind === "dyn") {
8349
+ // The kind is only known at runtime: the queries refuse a native
8350
+ // handle or a promise, whose integrity state scriptc does not track
8351
+ // (Object.preventExtensions and Object.seal do not change it, so any
8352
+ // answer would be invented). The static arms above keep the plain
8353
+ // queries for the kinds whose state is modeled.
7643
8354
  const operation = {
7644
8355
  preventExtensions: "dyn.preventExtensions",
7645
- isExtensible: "dyn.isExtensible",
8356
+ isExtensible: "dyn.isExtensibleQuery",
7646
8357
  seal: "dyn.seal",
7647
- isSealed: "dyn.isSealed",
8358
+ isSealed: "dyn.isSealedQuery",
7648
8359
  };
7649
8360
  const fn = operation[member];
7650
8361
  if (!member.startsWith("is"))
@@ -7697,6 +8408,8 @@ function lowerObjectStaticCall(lowerer, call, access) {
7697
8408
  loc,
7698
8409
  };
7699
8410
  }
8411
+ if (probedKind === "bytes" && isJsSourceFile(ts.getSourceFileOfNode(call)))
8412
+ return lowerBytesIntegrity(lowerer, "dyn.isFrozen", lowerer.lowerExpr(argNode), locOf(call));
7700
8413
  const value = lowerer.lowerExprExpecting(argNode, DYN);
7701
8414
  return { kind: "libCall", fn: "dyn.isFrozen", args: [value], type: BOOL, loc: locOf(call) };
7702
8415
  }
@@ -7755,6 +8468,8 @@ function lowerObjectStaticCall(lowerer, call, access) {
7755
8468
  return lowerNativeFreeze(lowerer, "array.freeze", value, locOf(call));
7756
8469
  if (value.type.kind === "map" || value.type.kind === "set")
7757
8470
  return lowerNativeFreeze(lowerer, "collection.preventExtensions", value, locOf(call));
8471
+ if (value.type.kind === "bytes" && isJsSourceFile(ts.getSourceFileOfNode(call)))
8472
+ return lowerBytesIntegrity(lowerer, "dyn.freeze", value, locOf(call));
7758
8473
  lowerer.noLowering("Object.freeze of a possibly-aliased value", call, "freeze of a FRESH object/array literal (and of primitives) compiles — frozen-ness is unobservable there; an aliased target's later writes would need the runtime frozen bit");
7759
8474
  }
7760
8475
  // `Object.hasOwn(r, k)` over a RECORD receiver: a record's own-key set
@@ -8140,7 +8855,6 @@ function lowerObjectStaticCall(lowerer, call, access) {
8140
8855
  helper = keyedHelperName(lowerer, `%obj.${member}`, key);
8141
8856
  const recT = argIr;
8142
8857
  const ref = { kind: "varRef", localId: "r.0", type: recT, loc };
8143
- const outRef = { kind: "varRef", localId: "out.0", type: resultT, loc };
8144
8858
  const fn = {
8145
8859
  name: helper,
8146
8860
  params: [{ localId: "r.0", name: "r", type: recT }],
@@ -8152,189 +8866,290 @@ function lowerObjectStaticCall(lowerer, call, access) {
8152
8866
  body: [],
8153
8867
  loc,
8154
8868
  };
8155
- const finalize = () => {
8156
- const latest = lowerer.shapes.get(argIr.shapeId);
8157
- const current = latest !== undefined ? latest : shape;
8158
- const body = [
8159
- {
8160
- kind: "varDecl",
8161
- localId: "out.0",
8162
- init: { kind: "arrayLit", elems: [], type: resultT, loc },
8163
- loc,
8164
- },
8165
- ];
8166
- // One walk per key order (see perKeyOrder).
8167
- const orders = shapeKeyOrders(current);
8168
- const walks = orders.map(() => []);
8169
- for (const [k, name] of orders.flatMap((order, k) => order.map((name) => [k, name]))) {
8170
- const f = current.fields.find((x) => x.name === name);
8171
- const raw = {
8172
- kind: "recordGet",
8173
- obj: ref,
8174
- shapeId: argIr.shapeId,
8175
- field: f.name,
8176
- type: f.type,
8177
- loc,
8178
- };
8179
- // The pushed element per member; null when the field's value
8180
- // cannot flow into the result element type.
8181
- const elemOf = (value, vt) => {
8182
- if (!valueT)
8183
- return null;
8184
- if (typeEquals(vt, valueT))
8185
- return value;
8186
- if (valueT.kind === "dyn" && lowerer.dynConvertible(vt))
8187
- return lowerer.coerceToExpected(value, DYN);
8188
- if (valueT.kind === "union" && vt.kind !== "union") {
8189
- const tag = lowerer.armTag(valueT.unionId, vt);
8190
- if (tag >= 0) {
8191
- return { kind: "unionWrap", unionId: valueT.unionId, tag, value, type: valueT, loc };
8192
- }
8193
- }
8869
+ // The statement that pushes field `f` of the record `obj` (of shape
8870
+ // `shapeId`), or the reason its value cannot flow into the result.
8871
+ const fieldPush = (obj, shapeId, f, out) => {
8872
+ const raw = {
8873
+ kind: "recordGet",
8874
+ obj,
8875
+ shapeId,
8876
+ field: f.name,
8877
+ type: f.type,
8878
+ loc,
8879
+ };
8880
+ // The pushed element per member; null when the field's value
8881
+ // cannot flow into the result element type.
8882
+ const elemOf = (value, vt) => {
8883
+ if (!valueT)
8194
8884
  return null;
8195
- };
8196
- // Undefined-armed fields: the push is guarded by the field's
8197
- // presence; a narrowed push re-tags the non-undefined arm.
8198
- let guardUndefTag = null;
8199
- let value = raw;
8200
- let vt = f.type;
8201
- if (f.type.kind === "union") {
8202
- const undefTag = lowerer.armTag(f.type.unionId, UNDEFINED_T);
8203
- if (undefTag >= 0) {
8204
- guardUndefTag = undefTag;
8205
- const arms = lowerer.unions.get(f.type.unionId)?.arms ?? [];
8206
- const others = arms.filter((a) => a.kind !== "undefinedT");
8207
- if (valueT?.kind === "dyn" || typeEquals(f.type, valueT ?? f.type)) {
8208
- // The field union IS the result union (single-field shapes):
8209
- // push the raw box — but then the undefined skip must NOT
8210
- // narrow. Handled below via vt === valueT.
8211
- value = raw;
8212
- vt = f.type;
8213
- }
8214
- else if (others.length === 1) {
8215
- vt = others[0];
8216
- // A UNIT other arm (`null | undefined` fields — the mixed-
8217
- // defaults spread idiom; undefined was filtered above, so
8218
- // the unit is null): units carry no payload, so the guarded
8219
- // push writes the unit LITERAL — unionNarrow to a unit arm
8220
- // (and unionWrap of a narrowed unit) is malformed IR; the
8221
- // literal is the one legal unit spelling.
8222
- value = isUnitType(vt)
8223
- ? { kind: "unitLit", unit: "null", type: vt, loc }
8224
- : {
8225
- kind: "unionNarrow",
8226
- unionId: f.type.unionId,
8227
- tag: lowerer.armTag(f.type.unionId, vt),
8228
- value: raw,
8229
- type: vt,
8230
- loc,
8231
- };
8232
- }
8233
- else {
8234
- lowerer.unsupported("SC1090", call, `Object.${member} over '${lowerer.fmt(argIr)}' (field '${f.name}' is a multi-arm union that ` +
8235
- "cannot re-tag into the result element type — read the fields directly)");
8236
- }
8885
+ if (typeEquals(vt, valueT))
8886
+ return value;
8887
+ if (valueT.kind === "dyn" && lowerer.dynConvertible(vt))
8888
+ return lowerer.coerceToExpected(value, DYN);
8889
+ if (valueT.kind === "union" && vt.kind === "union") {
8890
+ // A field union that is a PROPER SUBSET of the element union
8891
+ // (`{ accent: number | string; scrollbarThumb: number | string
8892
+ // | undefined }` enumerates as `[string, number | string |
8893
+ // undefined][]`): every arm the field can hold is an arm of the
8894
+ // element union, so the box re-tags onto it — the same runtime
8895
+ // value under the element union's tag numbering.
8896
+ return lowerer.unionRetagMappable(vt.unionId, valueT.unionId)
8897
+ ? lowerer.coerceToExpected(value, valueT)
8898
+ : null;
8899
+ }
8900
+ if (valueT.kind === "union" && vt.kind !== "union") {
8901
+ const tag = lowerer.armTag(valueT.unionId, vt);
8902
+ if (tag >= 0) {
8903
+ return { kind: "unionWrap", unionId: valueT.unionId, tag, value, type: valueT, loc };
8904
+ }
8905
+ }
8906
+ return null;
8907
+ };
8908
+ // Undefined-armed fields: the push is guarded by the field's
8909
+ // presence; a narrowed push re-tags the non-undefined arm.
8910
+ let guardUndefTag = null;
8911
+ let value = raw;
8912
+ let vt = f.type;
8913
+ if (f.type.kind === "union") {
8914
+ const undefTag = lowerer.armTag(f.type.unionId, UNDEFINED_T);
8915
+ if (undefTag >= 0) {
8916
+ guardUndefTag = undefTag;
8917
+ const arms = lowerer.unions.get(f.type.unionId)?.arms ?? [];
8918
+ const others = arms.filter((a) => a.kind !== "undefinedT");
8919
+ if (valueT?.kind === "dyn" || typeEquals(f.type, valueT ?? f.type)) {
8920
+ // The field union IS the result union (single-field shapes):
8921
+ // push the raw box — but then the undefined skip must NOT
8922
+ // narrow. Handled below via vt === valueT.
8923
+ value = raw;
8924
+ vt = f.type;
8237
8925
  }
8238
- else if (valueT?.kind !== "dyn" && !typeEquals(f.type, valueT ?? f.type)) {
8239
- lowerer.unsupported("SC1090", call, `Object.${member} over '${lowerer.fmt(argIr)}' (field '${f.name}' is a union that cannot ` +
8240
- "re-tag into the result element type — read the fields directly)");
8926
+ else if (others.length === 1) {
8927
+ vt = others[0];
8928
+ // A UNIT other arm (`null | undefined` fields — the mixed-
8929
+ // defaults spread idiom; undefined was filtered above, so
8930
+ // the unit is null): units carry no payload, so the guarded
8931
+ // push writes the unit LITERAL — unionNarrow to a unit arm
8932
+ // (and unionWrap of a narrowed unit) is malformed IR; the
8933
+ // literal is the one legal unit spelling.
8934
+ value = isUnitType(vt)
8935
+ ? { kind: "unitLit", unit: "null", type: vt, loc }
8936
+ : {
8937
+ kind: "unionNarrow",
8938
+ unionId: f.type.unionId,
8939
+ tag: lowerer.armTag(f.type.unionId, vt),
8940
+ value: raw,
8941
+ type: vt,
8942
+ loc,
8943
+ };
8944
+ }
8945
+ else {
8946
+ return `field '${f.name}' is a multi-arm union that cannot re-tag into the result element type`;
8241
8947
  }
8242
8948
  }
8243
- const coerced = elemOf(value, vt);
8244
- if (!coerced) {
8245
- lowerer.unsupported("SC1090", call, `Object.${member} over '${lowerer.fmt(argIr)}' (field '${f.name}' of type '${lowerer.fmt(f.type)}' ` +
8246
- `cannot flow into the '${lowerer.fmt(valueT)}' result element — read the fields directly)`);
8949
+ else if (valueT?.kind !== "dyn" &&
8950
+ !typeEquals(f.type, valueT ?? f.type) &&
8951
+ !(valueT?.kind === "union" && lowerer.unionRetagMappable(f.type.unionId, valueT.unionId))) {
8952
+ return `field '${f.name}' is a union that cannot re-tag into the result element type`;
8247
8953
  }
8248
- const pushOf = (element) => ({
8249
- kind: "exprStmt",
8250
- expr: {
8251
- kind: "arrIntrinsic",
8252
- method: "push",
8253
- receiver: outRef,
8254
- args: [
8255
- member === "values"
8256
- ? element
8257
- : {
8258
- kind: "recordLit",
8259
- fields: [
8260
- { name: "0", value: { kind: "strLit", value: f.name, type: STRING, loc } },
8261
- { name: "1", value: element },
8262
- ],
8263
- type: tupleT,
8264
- loc,
8265
- },
8266
- ],
8267
- type: F64,
8268
- loc,
8269
- },
8954
+ }
8955
+ const coerced = elemOf(value, vt);
8956
+ if (!coerced) {
8957
+ return (`field '${f.name}' of type '${lowerer.fmt(f.type)}' ` +
8958
+ `cannot flow into the '${lowerer.fmt(valueT)}' result element`);
8959
+ }
8960
+ const pushOf = (element) => ({
8961
+ kind: "exprStmt",
8962
+ expr: {
8963
+ kind: "arrIntrinsic",
8964
+ method: "push",
8965
+ receiver: out,
8966
+ args: [
8967
+ member === "values"
8968
+ ? element
8969
+ : {
8970
+ kind: "recordLit",
8971
+ fields: [
8972
+ { name: "0", value: { kind: "strLit", value: f.name, type: STRING, loc } },
8973
+ { name: "1", value: element },
8974
+ ],
8975
+ type: tupleT,
8976
+ loc,
8977
+ },
8978
+ ],
8979
+ type: F64,
8270
8980
  loc,
8271
- });
8272
- let stmt = pushOf(coerced);
8273
- if (guardUndefTag !== null && f.type.kind === "union") {
8274
- if (value !== raw) {
8275
- // A narrowed push: a present field holding undefined pushes
8276
- // the result element's own undefined when it has one; a values
8277
- // array without one stores a present undefined element (a
8278
- // runtime-optional field the checker typed as required). An
8279
- // entries tuple slot has no spelling for it.
8280
- const undefinedElement = valueT ? lowerer.wrappedUndefined(valueT, loc) : null;
8281
- const undefinedPush = undefinedElement
8282
- ? pushOf(undefinedElement)
8283
- : member === "values"
8284
- ? {
8285
- kind: "arraySetUndefined",
8286
- arr: outRef,
8287
- index: {
8288
- kind: "arrIntrinsic",
8289
- method: "length",
8290
- receiver: outRef,
8291
- args: [],
8292
- type: F64,
8293
- loc,
8294
- },
8981
+ },
8982
+ loc,
8983
+ });
8984
+ let stmt = pushOf(coerced);
8985
+ if (guardUndefTag !== null && f.type.kind === "union") {
8986
+ if (value !== raw) {
8987
+ // A narrowed push: a present field holding undefined pushes
8988
+ // the result element's own undefined when it has one; a values
8989
+ // array without one stores a present undefined element (a
8990
+ // runtime-optional field the checker typed as required). An
8991
+ // entries tuple slot has no spelling for it.
8992
+ const undefinedElement = valueT ? lowerer.wrappedUndefined(valueT, loc) : null;
8993
+ const undefinedPush = undefinedElement
8994
+ ? pushOf(undefinedElement)
8995
+ : member === "values"
8996
+ ? {
8997
+ kind: "arraySetUndefined",
8998
+ arr: out,
8999
+ index: {
9000
+ kind: "arrIntrinsic",
9001
+ method: "length",
9002
+ receiver: out,
9003
+ args: [],
9004
+ type: F64,
8295
9005
  loc,
8296
- }
8297
- : null;
8298
- stmt = {
8299
- kind: "if",
8300
- cond: {
8301
- kind: "unionIsTag",
8302
- unionId: f.type.unionId,
8303
- tag: guardUndefTag,
8304
- negated: true,
8305
- value: raw,
8306
- type: BOOL,
9006
+ },
8307
9007
  loc,
8308
- },
8309
- then: [stmt],
8310
- else_: undefinedPush ? [undefinedPush] : null,
8311
- loc,
8312
- };
8313
- }
8314
- // Absent fields contribute nothing; present ones push their
8315
- // value, undefined included.
9008
+ }
9009
+ : null;
8316
9010
  stmt = {
8317
9011
  kind: "if",
8318
- cond: lowerer.recordFieldPresent(ref, argIr.shapeId, f.name, loc),
9012
+ cond: {
9013
+ kind: "unionIsTag",
9014
+ unionId: f.type.unionId,
9015
+ tag: guardUndefTag,
9016
+ negated: true,
9017
+ value: raw,
9018
+ type: BOOL,
9019
+ loc,
9020
+ },
8319
9021
  then: [stmt],
8320
- else_: null,
9022
+ else_: undefinedPush ? [undefinedPush] : null,
8321
9023
  loc,
8322
9024
  };
8323
9025
  }
8324
- walks[k].push(stmt);
9026
+ // Absent fields contribute nothing; present ones push their
9027
+ // value, undefined included.
9028
+ stmt = {
9029
+ kind: "if",
9030
+ cond: lowerer.recordFieldPresent(obj, shapeId, f.name, loc),
9031
+ then: [stmt],
9032
+ else_: null,
9033
+ loc,
9034
+ };
8325
9035
  }
8326
- body.push(...perKeyOrder(current, ref, walks, loc));
8327
- body.push({ kind: "return", value: outRef, loc });
8328
- fn.body = body;
9036
+ return stmt;
9037
+ };
9038
+ // The walk that pushes the fields of `obj` (of `current`) into out.0,
9039
+ // one walk per key order (see perKeyOrder). `refused` answers a field
9040
+ // whose value cannot flow into the result.
9041
+ // The walk that pushes the fields of `obj` (of `current`) into the
9042
+ // local `outId` and returns it, one walk per key order (see
9043
+ // perKeyOrder). `refused` answers a field whose value cannot flow into
9044
+ // the result.
9045
+ const fieldWalk = (obj, current, outId, refused) => {
9046
+ const out = { kind: "varRef", localId: outId, type: resultT, loc };
9047
+ const orders = shapeKeyOrders(current);
9048
+ const walks = orders.map(() => []);
9049
+ for (const [k, name] of orders.flatMap((order, k) => order.map((name) => [k, name]))) {
9050
+ const f = current.fields.find((x) => x.name === name);
9051
+ const stmt = fieldPush(obj, current.id, f, out);
9052
+ walks[k].push(typeof stmt === "string" ? refused(stmt) : stmt);
9053
+ }
9054
+ return [
9055
+ {
9056
+ kind: "varDecl",
9057
+ localId: outId,
9058
+ init: { kind: "arrayLit", elems: [], type: resultT, loc },
9059
+ loc,
9060
+ },
9061
+ ...perKeyOrder(current, obj, walks, loc),
9062
+ { kind: "return", value: out, loc },
9063
+ ];
9064
+ };
9065
+ const finalize = () => {
9066
+ const latest = lowerer.shapes.get(argIr.shapeId);
9067
+ const current = latest !== undefined ? latest : shape;
9068
+ fn.body = fieldWalk(ref, current, "out.0", (reason) => lowerer.unsupported("SC1090", call, `Object.${member} over '${lowerer.fmt(argIr)}' (${reason} — read the fields directly)`));
8329
9069
  };
8330
9070
  finalize();
8331
9071
  lowerer.arrHofHelpers.set(key, helper);
8332
9072
  lowerer.shapeOrderHelperFinalizers.push(finalize);
8333
9073
  lowerer.liftedFns.push(fn);
9074
+ // A linked copy lists its source's fields. When one of them cannot
9075
+ // flow into the result, the copy answers as a kept source does: its
9076
+ // checked view's values, checked into the result (which throws).
9077
+ registerLinkedHelper(lowerer, fn, argIr.shapeId, "custom");
9078
+ lowerer.linkedHelperFinalizers.push(() => {
9079
+ // The answer for the composed record of a link, which can itself be
9080
+ // a linked copy or keep a checked source: their properties come first.
9081
+ // `path` holds the record types the links followed so far. Two types
9082
+ // can link both ways (each lacks an optional field of the other): a
9083
+ // composed record of this helper's own type calls the helper, and one
9084
+ // of another type on the path answers from its checked view.
9085
+ const answerAt = (path) => (composed) => {
9086
+ const composedT = composed.type;
9087
+ const sourceShape = lowerer.shapes.get(composedT.shapeId);
9088
+ const view = { kind: "dynFrom", value: composed, liveRef: true, type: DYN, loc };
9089
+ const viewAnswer = {
9090
+ kind: "return",
9091
+ value: {
9092
+ kind: "dynCheck",
9093
+ value: {
9094
+ kind: "libCall",
9095
+ fn: member === "values" ? "dyn.objValues" : "dyn.objEntries",
9096
+ args: [view],
9097
+ type: DYN,
9098
+ loc,
9099
+ },
9100
+ type: resultT,
9101
+ loc,
9102
+ },
9103
+ loc,
9104
+ };
9105
+ if (composedT.shapeId === argIr.shapeId)
9106
+ return [
9107
+ {
9108
+ kind: "return",
9109
+ value: { kind: "call", callee: fn.name, args: [composed], type: resultT, loc },
9110
+ loc,
9111
+ },
9112
+ ];
9113
+ if (path.has(composedT.shapeId))
9114
+ return [viewAnswer];
9115
+ let fits = true;
9116
+ const walk = fieldWalk(composed, sourceShape, linkedOut(fn, resultT), () => {
9117
+ fits = false;
9118
+ return {
9119
+ kind: "exprStmt",
9120
+ expr: { kind: "unitLit", unit: "undefined", type: UNDEFINED_T, loc },
9121
+ loc,
9122
+ };
9123
+ });
9124
+ const further = linkedCopyBranches(lowerer, fn, composed, composedT.shapeId, answerAt(new Set([...path, composedT.shapeId])));
9125
+ if (!fits)
9126
+ return [...further, viewAnswer];
9127
+ if (!recordMayKeepSource(lowerer, composedT))
9128
+ return [...further, ...walk];
9129
+ return [
9130
+ ...further,
9131
+ {
9132
+ kind: "if",
9133
+ cond: recordSourceTest(composed, loc),
9134
+ then: [viewAnswer],
9135
+ else_: null,
9136
+ loc,
9137
+ },
9138
+ ...walk,
9139
+ ];
9140
+ };
9141
+ answerLinkedCopies(lowerer, fn, argIr.shapeId, answerAt(new Set([argIr.shapeId])));
9142
+ });
8334
9143
  }
8335
9144
  const callee = helper;
8336
9145
  return sourced((receiver) => ({ kind: "call", callee, args: [receiver], type: resultT, loc }));
8337
9146
  }
9147
+ /** A fresh hidden local of `fn` for a linked copy's values or entries. */
9148
+ function linkedOut(fn, type) {
9149
+ const id = `linkedOut.${fn.locals.length}`;
9150
+ fn.locals.push({ id, name: "linkedOut", type, mutable: false });
9151
+ return id;
9152
+ }
8338
9153
  /** An entries array consumed pair by pair right where it is built: a
8339
9154
  * for-of loop or an array callback method. These consumers bind each pair
8340
9155
  * from the array's own layout, so the pair's value slot can keep a
@@ -8616,6 +9431,60 @@ export function lowerRecordFieldCall(lowerer, call, access) {
8616
9431
  lowerer.unsupported("SC1090", call, `calling a function field of a '${lowerer.fmt(target.obj.type)}' record (the record has no dynamic form to pass as 'this')`);
8617
9432
  }
8618
9433
  }
9434
+ // A generic member's field holds its erased instance, and the call
9435
+ // through the field crosses the same boundary as one through the
9436
+ // instance value itself: the conversions that would copy are refused
9437
+ // here too.
9438
+ refuseCopyingErasureInstanceCall(lowerer, call, callee);
9439
+ // A rest-marked field value hides one synthetic trailing dyn array in
9440
+ // its lifted signature — the checked variadic ABI a JS rest closure
9441
+ // has, and the one a generic member's erased instance keeps when its
9442
+ // erased signature cannot pin the tail (`...args: EventArguments<…>`, a
9443
+ // conditional tuple over the member's own type parameters). The call
9444
+ // passes that slot natively, so a record or array the callee returns
9445
+ // comes back as the object it returned, exactly as JavaScript hands it
9446
+ // back; the boxed thunk would copy it and break identity and mutation
9447
+ // sharing. A call that leaves an omitted parameter without an absent
9448
+ // spelling still rides the thunk (JavaScript's own arity).
9449
+ if (init === null &&
9450
+ receiver === undefined &&
9451
+ callee.type.rest === true &&
9452
+ callee.type.restAbi === undefined &&
9453
+ !call.arguments.nodes.some(ts.isSpreadElement) &&
9454
+ canBoxFuncIntoDyn(callee.type, (id) => lowerer.shapes.get(id), (id) => lowerer.unions.get(id))) {
9455
+ const nativeArgs = checkedRestCallArgs(lowerer, call, callee.type, loc);
9456
+ if (nativeArgs) {
9457
+ // The resolved result converts exactly like the fixed-arity lane
9458
+ // below; a void result needs no conversion (the call's own value is
9459
+ // discarded, as an `unknown` has no void spelling).
9460
+ let nativeResult = {
9461
+ kind: "callValue",
9462
+ callee,
9463
+ args: nativeArgs,
9464
+ type: callee.type.ret,
9465
+ loc,
9466
+ };
9467
+ const resolved = lowerer.irTypeOf(call);
9468
+ if (resolved.kind !== "void" &&
9469
+ isGenericCallableMemberType(lowerer.typeOf(access), lowerer.checker))
9470
+ nativeResult = lowerer.coerceInto(call, nativeResult, resolved);
9471
+ return nativeResult;
9472
+ }
9473
+ const boxed = { kind: "dynFrom", value: callee, type: DYN, loc };
9474
+ let boxedResult = {
9475
+ kind: "dynCall",
9476
+ callee: boxed,
9477
+ calleeName: v8CalleeText(call.expression),
9478
+ args: call.arguments.nodes.map((arg) => lowerer.lowerExprExpecting(arg, DYN)),
9479
+ type: DYN,
9480
+ loc,
9481
+ };
9482
+ const resolved = lowerer.irTypeOf(call);
9483
+ if (resolved.kind !== "void" &&
9484
+ isGenericCallableMemberType(lowerer.typeOf(access), lowerer.checker))
9485
+ boxedResult = lowerer.coerceInto(call, boxedResult, resolved);
9486
+ return boxedResult;
9487
+ }
8619
9488
  const args = completeFuncValueArgs(lowerer, call, callee.type, locOf(call));
8620
9489
  let result = {
8621
9490
  kind: "callValue",
@@ -8649,9 +9518,11 @@ export function lowerRecordFieldCall(lowerer, call, access) {
8649
9518
  /** The URL factories use the constructor's conversion order and parser.
8650
9519
  * URL.revokeObjectURL() with NO argument: Node's ERR_MISSING_ARGS
8651
9520
  * throws before the registry lookup, so the zero-argument contract is
8652
- * exact without any blob machinery. The one-argument form (Node's
8653
- * no-op for unregistered ids) and createObjectURL keep their
8654
- * fences — a compiled program has no blob registry to consult. */
9521
+ * exact without any blob machinery. The one-argument form coerces the
9522
+ * id to a string (a Symbol throws) and finds nothing registered — a
9523
+ * compiled program cannot create a blob URL, so the lookup always
9524
+ * misses and the call is its own coercion. createObjectURL keeps its
9525
+ * fence: there is no blob registry to register into. */
8655
9526
  function lowerUrlStaticCall(lowerer, call, callee) {
8656
9527
  if (!ts.isPropertyAccessExpression(callee) || callee.questionDotToken !== undefined)
8657
9528
  return null;
@@ -8663,9 +9534,20 @@ function lowerUrlStaticCall(lowerer, call, callee) {
8663
9534
  if (callee.name.text === "canParse" || callee.name.text === "parse") {
8664
9535
  return lowerUrlFactory(lowerer, call, callee.name.text);
8665
9536
  }
8666
- if (callee.name.text !== "revokeObjectURL" || call.arguments.nodes.length !== 0)
9537
+ if (callee.name.text !== "revokeObjectURL")
9538
+ return null;
9539
+ const args = call.arguments.nodes;
9540
+ if (args.length === 0) {
9541
+ return nodeThrowExpr(1, "ERR_MISSING_ARGS", 'The "url" argument must be specified', VOID, locOf(call));
9542
+ }
9543
+ if (args.length !== 1)
8667
9544
  return null;
8668
- return nodeThrowExpr(1, "ERR_MISSING_ARGS", 'The "url" argument must be specified', VOID, locOf(call));
9545
+ const arg = args[0];
9546
+ const id = lowerer.lowerExpr(arg);
9547
+ const text = id.type.kind === "url"
9548
+ ? { kind: "libCall", fn: "url.href", args: [id], type: STRING, loc: locOf(arg) }
9549
+ : lowerer.ensureString(id, arg);
9550
+ return { kind: "libCall", fn: "url.revokeObjectURL", args: [text], type: VOID, loc: locOf(call) };
8669
9551
  }
8670
9552
  const SP_BRAND_METHODS = new Set([
8671
9553
  "append",
@@ -8870,10 +9752,84 @@ function lowerArrowFunctionApply(lowerer, call, access) {
8870
9752
  }
8871
9753
  return { kind: "seqExpr", stmts, result, type: DYN, loc };
8872
9754
  }
9755
+ /** The Promise statics whose generic algorithms depend only on the `this`
9756
+ * constructor: NewPromiseCapability(C), GetPromiseResolve(C) and the
9757
+ * iterator protocol. scr_js_promise_generic.c runs them for a `this` that
9758
+ * is not %Promise%. `withResolvers` and `try` take no iterable and stay
9759
+ * refused (their capability shapes have no dynamic representation yet). */
9760
+ const PROMISE_GENERIC_STATICS = new Set([
9761
+ "all",
9762
+ "allSettled",
9763
+ "any",
9764
+ "race",
9765
+ "resolve",
9766
+ "reject",
9767
+ ]);
8873
9768
  function lowerObjLitGenericMethodCall(lowerer, call, access) {
8874
9769
  if (lowerer.chainBlocked(access, call))
8875
9770
  return null;
8876
9771
  const name = access.name.text;
9772
+ // The Promise statics through Function.prototype.call with ANY `this`
9773
+ // (`Promise.all.call(NotPromise, iterable)`): the specification's
9774
+ // algorithms over NewPromiseCapability(C), where %Promise% answers the
9775
+ // ordinary implementation. A `.js` source only — the arm replaces the
9776
+ // checked-value fence below, so no typed program changes shape. The
9777
+ // runtime unit scr_js_promise_generic.c runs the generic steps; the
9778
+ // builtin function's own thunk (dyn_builtin_fn_call) does not grow.
9779
+ if (name === "call" && !call.questionDotToken && isJsSourceFile(ts.getSourceFileOfNode(call))) {
9780
+ const stat = ts.isPropertyAccessExpression(access.expression)
9781
+ ? lowerer.stdlibGlobalMember(access.expression, "Promise")
9782
+ : null;
9783
+ if (stat !== null &&
9784
+ PROMISE_GENERIC_STATICS.has(stat) &&
9785
+ !call.arguments.nodes.some(ts.isSpreadElement)) {
9786
+ const loc = locOf(call);
9787
+ const thisArg = call.arguments.nodes[0];
9788
+ const value = call.arguments.nodes[1];
9789
+ // `Promise.all.call(Promise, …)` is the ordinary call: the runtime
9790
+ // recognizes %Promise% by identity and forwards to the native
9791
+ // implementation. The global read yields the interned constructor
9792
+ // value (`dyn.globalConstructor`) — exactly the identity compared —
9793
+ // rather than the reflected-value fence a stdlib global read as a
9794
+ // `.call` receiver otherwise reports.
9795
+ let thisIr = !thisArg
9796
+ ? dynUndefinedExpr(loc)
9797
+ : stdlibGlobalNameOf(lowerer, thisArg) === "Promise"
9798
+ ? (builtinGlobalValue("Promise", loc, true) ?? lowerer.lowerExprExpecting(thisArg, DYN))
9799
+ : lowerer.lowerExprExpecting(thisArg, DYN);
9800
+ let valueIr = value ? lowerer.lowerExprExpecting(value, DYN) : dynUndefinedExpr(loc);
9801
+ const callOf = (receiver, iterable) => ({
9802
+ kind: "libCall",
9803
+ fn: "promise.genericStatic",
9804
+ args: [{ kind: "strLit", value: stat, type: STRING, loc }, receiver, iterable],
9805
+ type: DYN,
9806
+ loc,
9807
+ });
9808
+ // The algorithm reads only the first two arguments, but Node evaluates
9809
+ // every argument of the call before it runs: the receiver and the
9810
+ // iterable first, then each surplus argument, in source order. Hold the
9811
+ // two the unit reads in hidden locals so the surplus arguments'
9812
+ // effects and exceptions happen after them, and drop their values.
9813
+ const surplus = call.arguments.nodes.slice(2);
9814
+ if (surplus.length === 0)
9815
+ return callOf(thisIr, valueIr);
9816
+ const holds = [];
9817
+ // Both are lowered into the checked-dynamic slot, so each is a dyn value
9818
+ // a hidden local can hold.
9819
+ const hold = (expr, name) => {
9820
+ const local = lowerer.declareHiddenLocal(name, expr.type);
9821
+ holds.push({ kind: "varDecl", localId: local.id, init: expr, loc });
9822
+ return varRef(local.id, expr.type, loc);
9823
+ };
9824
+ thisIr = hold(thisIr, "%promiseStaticThis");
9825
+ valueIr = hold(valueIr, "%promiseStaticIterable");
9826
+ for (const arg of surplus) {
9827
+ const argIr = lowerer.lowerExprExpecting(arg, DYN);
9828
+ holds.push({ kind: "exprStmt", expr: argIr, loc: locOf(arg) });
9829
+ }
9830
+ return { kind: "seqExpr", stmts: holds, result: callOf(thisIr, valueIr), type: DYN, loc };
9831
+ }
9832
+ }
8877
9833
  // URLSearchParams method values through Function.prototype.call/apply
8878
9834
  // with a receiver that is provably NOT a URLSearchParams (the suite's
8879
9835
  // `params.append.call(undefined)` probes): the WHATWG brand check
@@ -9959,7 +10915,8 @@ function maybePromiseHandlerResult(lowerer, call, value, R) {
9959
10915
  }
9960
10916
  return stmt;
9961
10917
  }
9962
- /** `view.m(args)` where `view` is a `Pick<C, K>` / `Omit<C, K>` view of a
10918
+ /** `view.m(args)` where `view` is a `Pick<C, K>` / `Omit<C, K>` view (inline
10919
+ * or through type aliases, classViewOf) of a
9963
10920
  * program class C and `m` is one of C's GENERIC methods (its overloads
9964
10921
  * included): generic methods have no dispatchable method value, so the
9965
10922
  * view's live receiver is extracted as the C instance it holds (a checked
@@ -9967,12 +10924,10 @@ function maybePromiseHandlerResult(lowerer, call, value, R) {
9967
10924
  * text naming C) and the call monomorphizes statically against C, the
9968
10925
  * same lowering a C-typed receiver gets. Null for other receivers. */
9969
10926
  function pickViewGenericMethodCall(lowerer, call, access, recvTs) {
9970
- const alias = recvTs.getAliasSymbol();
9971
- if (alias === undefined || (ts.symbolName(alias) !== "Pick" && ts.symbolName(alias) !== "Omit"))
10927
+ const view = classViewOf(lowerer.checker, recvTs);
10928
+ if (view === null)
9972
10929
  return null;
9973
- if (!alias.declarations.every((d) => ts.getSourceFileOfNode(d).isDeclarationFile))
9974
- return null;
9975
- const source = recvTs.getAliasTypeArguments()[0];
10930
+ const source = view.source;
9976
10931
  const symbol = source?.getSymbol();
9977
10932
  const info = symbol ? lowerer.classBySymbol.get(symbol) : undefined;
9978
10933
  if (!info || call.questionDotToken || access.questionDotToken)
@@ -9989,7 +10944,7 @@ function pickViewGenericMethodCall(lowerer, call, access, recvTs) {
9989
10944
  if (lowered.type.kind === "object" &&
9990
10945
  lowered.type.className !== info.def.name &&
9991
10946
  !lowerer.isSubclassOf(lowered.type.className, info.def.name)) {
9992
- lowerer.unsupported("SC1090", access, `calling the generic method '${access.name.text}' through a '${ts.symbolName(alias)}' view of '${info.def.name}' that holds a '${lowerer.fmt(lowered.type)}'`);
10947
+ lowerer.unsupported("SC1090", access, `calling the generic method '${access.name.text}' through a '${view.name}' view of '${info.def.name}' that holds a '${lowerer.fmt(lowered.type)}'`);
9993
10948
  }
9994
10949
  const receiver = lowered.type.kind === "object"
9995
10950
  ? lowered
@@ -10247,4 +11202,130 @@ function checkedDynamicOperand(expr) {
10247
11202
  return expr;
10248
11203
  return expr.kind === "dynCheck" && expr.value.type.kind === "dyn" ? expr.value : null;
10249
11204
  }
11205
+ /** The class of the object `node` is statically, or null. */
11206
+ function objectClassOf(lowerer, node) {
11207
+ let t;
11208
+ try {
11209
+ t = lowerer.mapTypeOf(lowerer.typeOf(node));
11210
+ }
11211
+ catch {
11212
+ return null;
11213
+ }
11214
+ if (t?.kind !== "object")
11215
+ return null;
11216
+ return lowerer.classes.get(t.className) ?? null;
11217
+ }
11218
+ /** The class of an EventEmitter instance (not a stream) that `node` is
11219
+ * statically, or null. */
11220
+ function plainEmitterInfoOf(lowerer, node) {
11221
+ const info = objectClassOf(lowerer, node);
11222
+ return info && emitterRooted(lowerer, info) && streamSidesOf(lowerer, info) === null
11223
+ ? info
11224
+ : null;
11225
+ }
11226
+ /** `R.<method>.call(thisArg, ...args)` where `R.<method>` is
11227
+ * EventEmitter.prototype's method: R is `EventEmitter.prototype` or an
11228
+ * EventEmitter instance (not a stream) whose class does not override
11229
+ * `emit`, read without effects. Node runs the method with thisArg as
11230
+ * `this`. A thisArg that is statically such an emitter takes the method's
11231
+ * typed lowering with thisArg as the receiver and static dispatch (the
11232
+ * super spelling); any other thisArg calls the untyped
11233
+ * EventEmitter.prototype method, which works on the object's `_events`.
11234
+ * Null for every other shape. */
11235
+ function lowerEmitterMethodValueCall(lowerer, call, access) {
11236
+ const target = access.expression;
11237
+ if (!ts.isPropertyAccessExpression(target) || target.questionDotToken)
11238
+ return null;
11239
+ const member = target.name.text;
11240
+ if (!EMITTER_API_MEMBERS.has(member))
11241
+ return null;
11242
+ const holderNode = target.expression;
11243
+ const emitterKind = builtinClassKind(RUNTIME_EMITTER_CLASS);
11244
+ const isPrototype = ts.isPropertyAccessExpression(holderNode) &&
11245
+ holderNode.name.text === "prototype" &&
11246
+ builtinClassKindOf(lowerer, holderNode.expression) === emitterKind;
11247
+ // `EventEmitter.prototype` is a builtin read; any other holder must be
11248
+ // effect-free, or its getter (and its exceptions) would be skipped.
11249
+ if (!isPrototype && !isPureReference(lowerer, holderNode))
11250
+ return null;
11251
+ const holder = isPrototype ? null : plainEmitterInfoOf(lowerer, holderNode);
11252
+ if (!isPrototype && (!holder || (member === "emit" && emitOverrideAtOrAbove(holder))))
11253
+ return null;
11254
+ const args = call.arguments.nodes;
11255
+ if (args.length === 0 || args.some(ts.isSpreadElement))
11256
+ return null;
11257
+ const thisArg = args[0];
11258
+ const thisInfo = plainEmitterInfoOf(lowerer, thisArg);
11259
+ const thisClass = objectClassOf(lowerer, thisArg);
11260
+ if (!thisInfo &&
11261
+ thisClass !== null &&
11262
+ emitterRooted(lowerer, thisClass) &&
11263
+ streamSidesOf(lowerer, thisClass) !== null) {
11264
+ // A stream keeps its own event table: the untyped method would read
11265
+ // fields the compiled stream does not have.
11266
+ lowerer.noLowering(`EventEmitter.prototype.${member}.call on a stream`, call, "call the method on the stream directly");
11267
+ }
11268
+ if (thisInfo && member === "emit" && emitOverrideAtOrAbove(thisInfo)) {
11269
+ lowerer.noLowering("EventEmitter.prototype.emit called on an instance whose class overrides emit", call, "call the override, or emit from a class that does not override emit");
11270
+ }
11271
+ if (thisInfo) {
11272
+ const thisRef = lowerer.lowerExpr(thisArg);
11273
+ if (thisRef.type.kind !== "object")
11274
+ return null;
11275
+ return lowerEmitterMethodCall(lowerer, call, target, thisInfo, { thisRef, cls: thisInfo }, args.slice(1));
11276
+ }
11277
+ const loc = locOf(call);
11278
+ const prototype = {
11279
+ kind: "dynKeyGet",
11280
+ value: builtinClassValue(emitterKind, loc),
11281
+ key: { kind: "strLit", value: "prototype", type: STRING, loc },
11282
+ type: DYN,
11283
+ loc,
11284
+ };
11285
+ return {
11286
+ kind: "dynInvoke",
11287
+ recv: {
11288
+ kind: "dynKeyGet",
11289
+ value: prototype,
11290
+ key: { kind: "strLit", value: member, type: STRING, loc },
11291
+ type: DYN,
11292
+ loc,
11293
+ },
11294
+ method: "call",
11295
+ calleeName: ts.getTextOfNode(access),
11296
+ args: args.map((arg) => lowerer.lowerExprExpecting(arg, DYN)),
11297
+ type: DYN,
11298
+ loc,
11299
+ };
11300
+ }
11301
+ /** atob(data) / btoa(data), the globals and node:buffer's members (the same
11302
+ * functions in Node): str.atob / str.btoa over the argument as a dyn value,
11303
+ * str.b64Missing for the zero-argument call. */
11304
+ export function lowerBase64Call(lowerer, expr, name, loc) {
11305
+ if (expr.arguments.nodes.length === 0) {
11306
+ return { kind: "libCall", fn: "str.b64Missing", args: [], type: STRING, loc };
11307
+ }
11308
+ if (expr.arguments.nodes.length > 1) {
11309
+ lowerer.noLowering(`${name} with ${expr.arguments.nodes.length} arguments`, expr);
11310
+ }
11311
+ const argNode = expr.arguments.nodes[0];
11312
+ const v = lowerer.lowerExpr(argNode);
11313
+ let data;
11314
+ if (v.type.kind === "dyn") {
11315
+ data = v;
11316
+ }
11317
+ else if (v.kind === "unitLit" || lowerer.dynConvertible(v.type)) {
11318
+ data = { kind: "dynFrom", value: v, type: DYN, loc };
11319
+ }
11320
+ else {
11321
+ lowerer.noLowering(`${name} with a '${lowerer.fmt(v.type)}' argument`, argNode, "string-convertible arguments lower (Node ToStrings the value — convert it explicitly)");
11322
+ }
11323
+ return {
11324
+ kind: "libCall",
11325
+ fn: name === "atob" ? "str.atob" : "str.btoa",
11326
+ args: [data],
11327
+ type: STRING,
11328
+ loc,
11329
+ };
11330
+ }
10250
11331
  //# sourceMappingURL=lower-calls.js.map