@scriptc/compiler 0.2.5 → 0.2.7

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 (520) hide show
  1. package/ambient/scriptc-node-fallback.d.ts +62 -48
  2. package/dist/backend/cycle-analysis.d.ts +21 -9
  3. package/dist/backend/cycle-analysis.js +139 -67
  4. package/dist/backend/cycle-analysis.js.map +1 -1
  5. package/dist/backend/cycle-analysis.test.js +283 -3
  6. package/dist/backend/cycle-analysis.test.js.map +1 -1
  7. package/dist/backend/cycle-mutability.d.ts +39 -0
  8. package/dist/backend/cycle-mutability.js +205 -0
  9. package/dist/backend/cycle-mutability.js.map +1 -0
  10. package/dist/backend/executable-features.js +1 -0
  11. package/dist/backend/executable-features.js.map +1 -1
  12. package/dist/backend/link-plan-core.d.ts +4 -1
  13. package/dist/backend/link-plan-core.js +16 -3
  14. package/dist/backend/link-plan-core.js.map +1 -1
  15. package/dist/backend/link-plan.d.ts +3 -1
  16. package/dist/backend/link-plan.js +3 -0
  17. package/dist/backend/link-plan.js.map +1 -1
  18. package/dist/backend/llvm/alloc.d.ts +40 -0
  19. package/dist/backend/llvm/alloc.js +205 -0
  20. package/dist/backend/llvm/alloc.js.map +1 -0
  21. package/dist/backend/llvm/alloc.test.d.ts +1 -0
  22. package/dist/backend/llvm/alloc.test.js +102 -0
  23. package/dist/backend/llvm/alloc.test.js.map +1 -0
  24. package/dist/backend/llvm/byte-numbers.js +32 -4
  25. package/dist/backend/llvm/byte-numbers.js.map +1 -1
  26. package/dist/backend/llvm/byte-windows.d.ts +31 -0
  27. package/dist/backend/llvm/byte-windows.js +334 -0
  28. package/dist/backend/llvm/byte-windows.js.map +1 -0
  29. package/dist/backend/llvm/byte-windows.test.d.ts +1 -0
  30. package/dist/backend/llvm/byte-windows.test.js +244 -0
  31. package/dist/backend/llvm/byte-windows.test.js.map +1 -0
  32. package/dist/backend/llvm/call-lifetimes.d.ts +17 -5
  33. package/dist/backend/llvm/call-lifetimes.js +58 -24
  34. package/dist/backend/llvm/call-lifetimes.js.map +1 -1
  35. package/dist/backend/llvm/call-lifetimes.test.js +170 -0
  36. package/dist/backend/llvm/call-lifetimes.test.js.map +1 -1
  37. package/dist/backend/llvm/classes.d.ts +18 -2
  38. package/dist/backend/llvm/classes.js +115 -41
  39. package/dist/backend/llvm/classes.js.map +1 -1
  40. package/dist/backend/llvm/classes.test.d.ts +1 -0
  41. package/dist/backend/llvm/classes.test.js +132 -0
  42. package/dist/backend/llvm/classes.test.js.map +1 -0
  43. package/dist/backend/llvm/common.d.ts +13 -0
  44. package/dist/backend/llvm/common.js +30 -0
  45. package/dist/backend/llvm/common.js.map +1 -1
  46. package/dist/backend/llvm/constant-callbacks.d.ts +27 -0
  47. package/dist/backend/llvm/constant-callbacks.js +450 -0
  48. package/dist/backend/llvm/constant-callbacks.js.map +1 -0
  49. package/dist/backend/llvm/constant-callbacks.test.d.ts +1 -0
  50. package/dist/backend/llvm/constant-callbacks.test.js +261 -0
  51. package/dist/backend/llvm/constant-callbacks.test.js.map +1 -0
  52. package/dist/backend/llvm/dense-array-access.d.ts +29 -0
  53. package/dist/backend/llvm/dense-array-access.js +335 -0
  54. package/dist/backend/llvm/dense-array-access.js.map +1 -0
  55. package/dist/backend/llvm/dense-array-access.test.d.ts +1 -0
  56. package/dist/backend/llvm/dense-array-access.test.js +149 -0
  57. package/dist/backend/llvm/dense-array-access.test.js.map +1 -0
  58. package/dist/backend/llvm/dyn.d.ts +35 -1
  59. package/dist/backend/llvm/dyn.js +196 -35
  60. package/dist/backend/llvm/dyn.js.map +1 -1
  61. package/dist/backend/llvm/emitter.d.ts +143 -4
  62. package/dist/backend/llvm/emitter.js +882 -136
  63. package/dist/backend/llvm/emitter.js.map +1 -1
  64. package/dist/backend/llvm/emitter.test.js +82 -14
  65. package/dist/backend/llvm/emitter.test.js.map +1 -1
  66. package/dist/backend/llvm/expr-async.js +58 -4
  67. package/dist/backend/llvm/expr-async.js.map +1 -1
  68. package/dist/backend/llvm/expr-async.test.d.ts +1 -0
  69. package/dist/backend/llvm/expr-async.test.js +62 -0
  70. package/dist/backend/llvm/expr-async.test.js.map +1 -0
  71. package/dist/backend/llvm/expr-bytes.js +11 -0
  72. package/dist/backend/llvm/expr-bytes.js.map +1 -1
  73. package/dist/backend/llvm/expr-calls.js +151 -25
  74. package/dist/backend/llvm/expr-calls.js.map +1 -1
  75. package/dist/backend/llvm/expr-containers.js +37 -14
  76. package/dist/backend/llvm/expr-containers.js.map +1 -1
  77. package/dist/backend/llvm/expr-control.js +92 -2
  78. package/dist/backend/llvm/expr-control.js.map +1 -1
  79. package/dist/backend/llvm/expr-dispatch.js +2 -0
  80. package/dist/backend/llvm/expr-dispatch.js.map +1 -1
  81. package/dist/backend/llvm/expr-dynamic.js +210 -28
  82. package/dist/backend/llvm/expr-dynamic.js.map +1 -1
  83. package/dist/backend/llvm/expr-primitives.d.ts +1 -1
  84. package/dist/backend/llvm/expr-primitives.js +58 -23
  85. package/dist/backend/llvm/expr-primitives.js.map +1 -1
  86. package/dist/backend/llvm/expr-primitives.test.js +1 -1
  87. package/dist/backend/llvm/expr-records.js +3 -3
  88. package/dist/backend/llvm/expr-records.js.map +1 -1
  89. package/dist/backend/llvm/expr-stream-bridges.js +59 -2
  90. package/dist/backend/llvm/expr-stream-bridges.js.map +1 -1
  91. package/dist/backend/llvm/expr-stream-bridges.test.js +1 -1
  92. package/dist/backend/llvm/integer-remainder.d.ts +18 -0
  93. package/dist/backend/llvm/integer-remainder.js +117 -0
  94. package/dist/backend/llvm/integer-remainder.js.map +1 -0
  95. package/dist/backend/llvm/layouts.d.ts +2 -1
  96. package/dist/backend/llvm/layouts.js +4 -3
  97. package/dist/backend/llvm/layouts.js.map +1 -1
  98. package/dist/backend/llvm/lazy-captures.d.ts +16 -0
  99. package/dist/backend/llvm/lazy-captures.js +96 -0
  100. package/dist/backend/llvm/lazy-captures.js.map +1 -0
  101. package/dist/backend/llvm/lazy-captures.test.d.ts +1 -0
  102. package/dist/backend/llvm/lazy-captures.test.js +78 -0
  103. package/dist/backend/llvm/lazy-captures.test.js.map +1 -0
  104. package/dist/backend/llvm/lib-abi.js +7 -0
  105. package/dist/backend/llvm/lib-abi.js.map +1 -1
  106. package/dist/backend/llvm/lib-dispatch.js +7 -22
  107. package/dist/backend/llvm/lib-dispatch.js.map +1 -1
  108. package/dist/backend/llvm/lib-filesystem.js +3 -4
  109. package/dist/backend/llvm/lib-filesystem.js.map +1 -1
  110. package/dist/backend/llvm/lib-shared.js +15 -0
  111. package/dist/backend/llvm/lib-shared.js.map +1 -1
  112. package/dist/backend/llvm/local-array-reads.d.ts +13 -3
  113. package/dist/backend/llvm/local-array-reads.js +159 -77
  114. package/dist/backend/llvm/local-array-reads.js.map +1 -1
  115. package/dist/backend/llvm/local-array-reads.test.js +105 -4
  116. package/dist/backend/llvm/local-array-reads.test.js.map +1 -1
  117. package/dist/backend/llvm/local-union-storage.d.ts +5 -1
  118. package/dist/backend/llvm/local-union-storage.js +48 -6
  119. package/dist/backend/llvm/local-union-storage.js.map +1 -1
  120. package/dist/backend/llvm/local-union-storage.test.js +91 -4
  121. package/dist/backend/llvm/local-union-storage.test.js.map +1 -1
  122. package/dist/backend/llvm/loop-array-borrows.d.ts +11 -0
  123. package/dist/backend/llvm/loop-array-borrows.js +70 -0
  124. package/dist/backend/llvm/loop-array-borrows.js.map +1 -0
  125. package/dist/backend/llvm/loop-array-borrows.test.d.ts +1 -0
  126. package/dist/backend/llvm/loop-array-borrows.test.js +145 -0
  127. package/dist/backend/llvm/loop-array-borrows.test.js.map +1 -0
  128. package/dist/backend/llvm/map-read-lifetimes.d.ts +5 -0
  129. package/dist/backend/llvm/map-read-lifetimes.js +20 -5
  130. package/dist/backend/llvm/map-read-lifetimes.js.map +1 -1
  131. package/dist/backend/llvm/map-read-lifetimes.test.js +1 -1
  132. package/dist/backend/llvm/nullable-fields.d.ts +28 -0
  133. package/dist/backend/llvm/nullable-fields.js +45 -0
  134. package/dist/backend/llvm/nullable-fields.js.map +1 -0
  135. package/dist/backend/llvm/nullable-fields.test.d.ts +1 -0
  136. package/dist/backend/llvm/nullable-fields.test.js +48 -0
  137. package/dist/backend/llvm/nullable-fields.test.js.map +1 -0
  138. package/dist/backend/llvm/reference-effects.d.ts +2 -1
  139. package/dist/backend/llvm/reference-effects.js +7 -0
  140. package/dist/backend/llvm/reference-effects.js.map +1 -1
  141. package/dist/backend/llvm/serialized-ir-emission.test.d.ts +1 -0
  142. package/dist/backend/llvm/serialized-ir-emission.test.js +52 -0
  143. package/dist/backend/llvm/serialized-ir-emission.test.js.map +1 -0
  144. package/dist/backend/llvm/shapes.d.ts +73 -3
  145. package/dist/backend/llvm/shapes.js +281 -34
  146. package/dist/backend/llvm/shapes.js.map +1 -1
  147. package/dist/backend/llvm/shapes.test.js +114 -5
  148. package/dist/backend/llvm/shapes.test.js.map +1 -1
  149. package/dist/backend/llvm/split-loops.d.ts +48 -0
  150. package/dist/backend/llvm/split-loops.js +183 -0
  151. package/dist/backend/llvm/split-loops.js.map +1 -0
  152. package/dist/backend/llvm/split.js +0 -7
  153. package/dist/backend/llvm/split.js.map +1 -1
  154. package/dist/backend/llvm/split.test.js +66 -2
  155. package/dist/backend/llvm/split.test.js.map +1 -1
  156. package/dist/backend/llvm/stack-callbacks.d.ts +14 -0
  157. package/dist/backend/llvm/stack-callbacks.js +72 -0
  158. package/dist/backend/llvm/stack-callbacks.js.map +1 -0
  159. package/dist/backend/llvm/stack-captures.d.ts +27 -0
  160. package/dist/backend/llvm/stack-captures.js +152 -0
  161. package/dist/backend/llvm/stack-captures.js.map +1 -0
  162. package/dist/backend/llvm/stack-unions.test.js +38 -1
  163. package/dist/backend/llvm/stack-unions.test.js.map +1 -1
  164. package/dist/backend/llvm/string-construction.test.js +1 -1
  165. package/dist/backend/llvm/string-key-hash.d.ts +8 -0
  166. package/dist/backend/llvm/string-key-hash.js +59 -0
  167. package/dist/backend/llvm/string-key-hash.js.map +1 -0
  168. package/dist/backend/llvm/string-key-hash.test.d.ts +1 -0
  169. package/dist/backend/llvm/string-key-hash.test.js +34 -0
  170. package/dist/backend/llvm/string-key-hash.test.js.map +1 -0
  171. package/dist/backend/llvm/string-lifetimes.test.js +48 -7
  172. package/dist/backend/llvm/string-lifetimes.test.js.map +1 -1
  173. package/dist/backend/llvm/string-slices.d.ts +20 -0
  174. package/dist/backend/llvm/string-slices.js +87 -0
  175. package/dist/backend/llvm/string-slices.js.map +1 -0
  176. package/dist/backend/llvm/string-slices.test.d.ts +1 -0
  177. package/dist/backend/llvm/string-slices.test.js +98 -0
  178. package/dist/backend/llvm/string-slices.test.js.map +1 -0
  179. package/dist/backend/llvm/switch-dispatch.js +1 -1
  180. package/dist/backend/llvm/switch-dispatch.js.map +1 -1
  181. package/dist/backend/llvm/switch-dispatch.test.js +2 -2
  182. package/dist/backend/llvm/switch-dispatch.test.js.map +1 -1
  183. package/dist/backend/llvm/walkers.d.ts +4 -14
  184. package/dist/backend/llvm/walkers.js +53 -311
  185. package/dist/backend/llvm/walkers.js.map +1 -1
  186. package/dist/backend/may-throw.js +4 -1
  187. package/dist/backend/may-throw.js.map +1 -1
  188. package/dist/backend/may-throw.test.js +1 -1
  189. package/dist/backend/native/cache-warm.d.ts +2 -1
  190. package/dist/backend/native/cache-warm.js.map +1 -1
  191. package/dist/backend/native/contracts.d.ts +5 -2
  192. package/dist/backend/native/contracts.js.map +1 -1
  193. package/dist/backend/native/executable.js +12 -4
  194. package/dist/backend/native/executable.js.map +1 -1
  195. package/dist/backend/native/runtime-inputs.d.ts +1 -1
  196. package/dist/backend/native/runtime-inputs.js +3 -0
  197. package/dist/backend/native/runtime-inputs.js.map +1 -1
  198. package/dist/backend/native-codegen-core.d.ts +7 -0
  199. package/dist/backend/native-codegen-core.js +21 -0
  200. package/dist/backend/native-codegen-core.js.map +1 -1
  201. package/dist/backend/native-codegen.d.ts +9 -0
  202. package/dist/backend/native-codegen.js +38 -18
  203. package/dist/backend/native-codegen.js.map +1 -1
  204. package/dist/backend/native-codegen.test.js +70 -2
  205. package/dist/backend/native-codegen.test.js.map +1 -1
  206. package/dist/backend/native-link-info-core.d.ts +4 -2
  207. package/dist/backend/native-link-info-core.js.map +1 -1
  208. package/dist/backend/native-link-info.d.ts +2 -1
  209. package/dist/backend/native-link-info.js.map +1 -1
  210. package/dist/backend/native-link-info.test.js +2 -2
  211. package/dist/backend/native-link-info.test.js.map +1 -1
  212. package/dist/backend/native-tools.d.ts +6 -2
  213. package/dist/backend/native-tools.js +6 -5
  214. package/dist/backend/native-tools.js.map +1 -1
  215. package/dist/backend/optimization.d.ts +25 -0
  216. package/dist/backend/optimization.js +21 -0
  217. package/dist/backend/optimization.js.map +1 -0
  218. package/dist/backend/optimization.test.d.ts +1 -0
  219. package/dist/backend/optimization.test.js +24 -0
  220. package/dist/backend/optimization.test.js.map +1 -0
  221. package/dist/backend/runtime-abi.d.ts +2 -2
  222. package/dist/backend/runtime-abi.js +2 -2
  223. package/dist/backend/runtime-pack-core.d.ts +16 -4
  224. package/dist/backend/runtime-pack-core.js +31 -13
  225. package/dist/backend/runtime-pack-core.js.map +1 -1
  226. package/dist/backend/runtime-pack-native.d.ts +7 -3
  227. package/dist/backend/runtime-pack-native.js +0 -3
  228. package/dist/backend/runtime-pack-native.js.map +1 -1
  229. package/dist/backend/runtime-pack-targets.test.js +41 -4
  230. package/dist/backend/runtime-pack-targets.test.js.map +1 -1
  231. package/dist/backend/runtime-pack.d.ts +20 -2
  232. package/dist/backend/runtime-pack.js +23 -0
  233. package/dist/backend/runtime-pack.js.map +1 -1
  234. package/dist/backend/runtime-pack.test.js +125 -2
  235. package/dist/backend/runtime-pack.test.js.map +1 -1
  236. package/dist/backend/target-diagnostics.test.js +1 -1
  237. package/dist/backend/targets.d.ts +2 -1
  238. package/dist/backend/targets.js +1 -1
  239. package/dist/backend/targets.js.map +1 -1
  240. package/dist/cli/command.js +5 -4
  241. package/dist/cli/command.js.map +1 -1
  242. package/dist/cli/host.d.ts +2 -1
  243. package/dist/cli/usage.d.ts +1 -1
  244. package/dist/cli/usage.js +5 -2
  245. package/dist/cli/usage.js.map +1 -1
  246. package/dist/compile-types.d.ts +5 -2
  247. package/dist/diagnostics/diagnostic.js +10 -8
  248. package/dist/diagnostics/diagnostic.js.map +1 -1
  249. package/dist/executable/executable-cache.d.ts +3 -2
  250. package/dist/executable/executable-cache.js +8 -4
  251. package/dist/executable/executable-cache.js.map +1 -1
  252. package/dist/executable/executable-cache.test.js +35 -0
  253. package/dist/executable/executable-cache.test.js.map +1 -1
  254. package/dist/frontend/fork-target.d.ts +5 -0
  255. package/dist/frontend/fork-target.js +40 -8
  256. package/dist/frontend/fork-target.js.map +1 -1
  257. package/dist/frontend/fork-target.test.d.ts +1 -0
  258. package/dist/frontend/fork-target.test.js +59 -0
  259. package/dist/frontend/fork-target.test.js.map +1 -0
  260. package/dist/frontend/lowering/abstract-equality.js +5 -49
  261. package/dist/frontend/lowering/abstract-equality.js.map +1 -1
  262. package/dist/frontend/lowering/array-values.d.ts +23 -0
  263. package/dist/frontend/lowering/array-values.js +129 -0
  264. package/dist/frontend/lowering/array-values.js.map +1 -1
  265. package/dist/frontend/lowering/binding-analysis.js +2 -2
  266. package/dist/frontend/lowering/binding-analysis.js.map +1 -1
  267. package/dist/frontend/lowering/builtins/atomics.d.ts +2 -11
  268. package/dist/frontend/lowering/builtins/atomics.js +64 -28
  269. package/dist/frontend/lowering/builtins/atomics.js.map +1 -1
  270. package/dist/frontend/lowering/builtins/errors.js +17 -2
  271. package/dist/frontend/lowering/builtins/errors.js.map +1 -1
  272. package/dist/frontend/lowering/builtins/filesystem-calls.d.ts +3 -0
  273. package/dist/frontend/lowering/builtins/filesystem-calls.js +51 -4
  274. package/dist/frontend/lowering/builtins/filesystem-calls.js.map +1 -1
  275. package/dist/frontend/lowering/builtins/module-calls.js +6 -1
  276. package/dist/frontend/lowering/builtins/module-calls.js.map +1 -1
  277. package/dist/frontend/lowering/builtins/process.d.ts +6 -17
  278. package/dist/frontend/lowering/builtins/process.js +56 -29
  279. package/dist/frontend/lowering/builtins/process.js.map +1 -1
  280. package/dist/frontend/lowering/builtins/workers.d.ts +5 -0
  281. package/dist/frontend/lowering/builtins/workers.js +65 -0
  282. package/dist/frontend/lowering/builtins/workers.js.map +1 -0
  283. package/dist/frontend/lowering/caught-value-dispatch.d.ts +11 -0
  284. package/dist/frontend/lowering/caught-value-dispatch.js +87 -0
  285. package/dist/frontend/lowering/caught-value-dispatch.js.map +1 -0
  286. package/dist/frontend/lowering/class-assertions.d.ts +11 -0
  287. package/dist/frontend/lowering/class-assertions.js +104 -0
  288. package/dist/frontend/lowering/class-assertions.js.map +1 -0
  289. package/dist/frontend/lowering/class-callbacks.d.ts +3 -3
  290. package/dist/frontend/lowering/class-callbacks.js +18 -5
  291. package/dist/frontend/lowering/class-callbacks.js.map +1 -1
  292. package/dist/frontend/lowering/class-dynamic-dispatch.d.ts +1 -0
  293. package/dist/frontend/lowering/class-dynamic-dispatch.js +4 -1
  294. package/dist/frontend/lowering/class-dynamic-dispatch.js.map +1 -1
  295. package/dist/frontend/lowering/class-method-mutations.d.ts +5 -0
  296. package/dist/frontend/lowering/class-method-mutations.js +472 -0
  297. package/dist/frontend/lowering/class-method-mutations.js.map +1 -0
  298. package/dist/frontend/lowering/class-method-values.js +25 -5
  299. package/dist/frontend/lowering/class-method-values.js.map +1 -1
  300. package/dist/frontend/lowering/class-protocols.d.ts +17 -0
  301. package/dist/frontend/lowering/class-protocols.js +126 -0
  302. package/dist/frontend/lowering/class-protocols.js.map +1 -0
  303. package/dist/frontend/lowering/class-prototypes.js +8 -2
  304. package/dist/frontend/lowering/class-prototypes.js.map +1 -1
  305. package/dist/frontend/lowering/class-unions.d.ts +16 -0
  306. package/dist/frontend/lowering/class-unions.js +127 -0
  307. package/dist/frontend/lowering/class-unions.js.map +1 -0
  308. package/dist/frontend/lowering/coercions/builders.js +8 -1
  309. package/dist/frontend/lowering/coercions/builders.js.map +1 -1
  310. package/dist/frontend/lowering/coercions/function-adapters.js +2 -0
  311. package/dist/frontend/lowering/coercions/function-adapters.js.map +1 -1
  312. package/dist/frontend/lowering/coercions/identity.d.ts +7 -0
  313. package/dist/frontend/lowering/coercions/identity.js +26 -0
  314. package/dist/frontend/lowering/coercions/identity.js.map +1 -0
  315. package/dist/frontend/lowering/coercions/structural.js +9 -6
  316. package/dist/frontend/lowering/coercions/structural.js.map +1 -1
  317. package/dist/frontend/lowering/collection-narrowing.d.ts +6 -0
  318. package/dist/frontend/lowering/collection-narrowing.js +31 -0
  319. package/dist/frontend/lowering/collection-narrowing.js.map +1 -0
  320. package/dist/frontend/lowering/containers/array-callback-call.d.ts +7 -0
  321. package/dist/frontend/lowering/containers/array-callback-call.js +52 -0
  322. package/dist/frontend/lowering/containers/array-callback-call.js.map +1 -0
  323. package/dist/frontend/lowering/containers/array-callbacks.d.ts +8 -12
  324. package/dist/frontend/lowering/containers/array-callbacks.js +415 -136
  325. package/dist/frontend/lowering/containers/array-callbacks.js.map +1 -1
  326. package/dist/frontend/lowering/containers/array-concat.d.ts +7 -0
  327. package/dist/frontend/lowering/containers/array-concat.js +130 -0
  328. package/dist/frontend/lowering/containers/array-concat.js.map +1 -0
  329. package/dist/frontend/lowering/containers/array-construction.d.ts +2 -0
  330. package/dist/frontend/lowering/containers/array-construction.js +95 -3
  331. package/dist/frontend/lowering/containers/array-construction.js.map +1 -1
  332. package/dist/frontend/lowering/containers/array-methods.d.ts +1 -11
  333. package/dist/frontend/lowering/containers/array-methods.js +43 -132
  334. package/dist/frontend/lowering/containers/array-methods.js.map +1 -1
  335. package/dist/frontend/lowering/containers/bytes.js +12 -34
  336. package/dist/frontend/lowering/containers/bytes.js.map +1 -1
  337. package/dist/frontend/lowering/containers/collection-methods.js +10 -1
  338. package/dist/frontend/lowering/containers/collection-methods.js.map +1 -1
  339. package/dist/frontend/lowering/containers/indexed-objects.js +56 -70
  340. package/dist/frontend/lowering/containers/indexed-objects.js.map +1 -1
  341. package/dist/frontend/lowering/containers/string-and-regexp.js +22 -3
  342. package/dist/frontend/lowering/containers/string-and-regexp.js.map +1 -1
  343. package/dist/frontend/lowering/cycle-initialization.d.ts +41 -0
  344. package/dist/frontend/lowering/cycle-initialization.js +277 -0
  345. package/dist/frontend/lowering/cycle-initialization.js.map +1 -0
  346. package/dist/frontend/lowering/expressions/evaluation-safety.js +4 -0
  347. package/dist/frontend/lowering/expressions/evaluation-safety.js.map +1 -1
  348. package/dist/frontend/lowering/expressions/object-literals.js +140 -38
  349. package/dist/frontend/lowering/expressions/object-literals.js.map +1 -1
  350. package/dist/frontend/lowering/expressions/union-field-write.d.ts +4 -4
  351. package/dist/frontend/lowering/expressions/union-field-write.js +54 -44
  352. package/dist/frontend/lowering/expressions/union-field-write.js.map +1 -1
  353. package/dist/frontend/lowering/generic-functions.d.ts +2 -5
  354. package/dist/frontend/lowering/generic-functions.js +13 -10
  355. package/dist/frontend/lowering/generic-functions.js.map +1 -1
  356. package/dist/frontend/lowering/instantiation-path.d.ts +8 -0
  357. package/dist/frontend/lowering/instantiation-path.js +10 -0
  358. package/dist/frontend/lowering/instantiation-path.js.map +1 -0
  359. package/dist/frontend/lowering/instantiation-path.test.d.ts +1 -0
  360. package/dist/frontend/lowering/instantiation-path.test.js +23 -0
  361. package/dist/frontend/lowering/instantiation-path.test.js.map +1 -0
  362. package/dist/frontend/lowering/iterator-adapters.d.ts +20 -0
  363. package/dist/frontend/lowering/iterator-adapters.js +605 -0
  364. package/dist/frontend/lowering/iterator-adapters.js.map +1 -0
  365. package/dist/frontend/lowering/lower-array-sort.d.ts +1 -1
  366. package/dist/frontend/lowering/lower-array-sort.js +44 -5
  367. package/dist/frontend/lowering/lower-array-sort.js.map +1 -1
  368. package/dist/frontend/lowering/lower-array-sort.test.d.ts +1 -0
  369. package/dist/frontend/lowering/lower-array-sort.test.js +31 -0
  370. package/dist/frontend/lowering/lower-array-sort.test.js.map +1 -0
  371. package/dist/frontend/lowering/lower-assert.js +7 -0
  372. package/dist/frontend/lowering/lower-assert.js.map +1 -1
  373. package/dist/frontend/lowering/lower-builtin-values.js +12 -7
  374. package/dist/frontend/lowering/lower-builtin-values.js.map +1 -1
  375. package/dist/frontend/lowering/lower-calls.d.ts +3 -3
  376. package/dist/frontend/lowering/lower-calls.js +198 -124
  377. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  378. package/dist/frontend/lowering/lower-classes.d.ts +7 -0
  379. package/dist/frontend/lowering/lower-classes.js +166 -96
  380. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  381. package/dist/frontend/lowering/lower-event-emitter.js +1 -1
  382. package/dist/frontend/lowering/lower-event-emitter.js.map +1 -1
  383. package/dist/frontend/lowering/lower-exprs.d.ts +9 -2
  384. package/dist/frontend/lowering/lower-exprs.js +421 -167
  385. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  386. package/dist/frontend/lowering/lower-functions.d.ts +1 -1
  387. package/dist/frontend/lowering/lower-functions.js +33 -20
  388. package/dist/frontend/lowering/lower-functions.js.map +1 -1
  389. package/dist/frontend/lowering/lower-inspect.js +26 -2
  390. package/dist/frontend/lowering/lower-inspect.js.map +1 -1
  391. package/dist/frontend/lowering/lower-island.js +1 -1
  392. package/dist/frontend/lowering/lower-island.js.map +1 -1
  393. package/dist/frontend/lowering/lower-modules.d.ts +1 -0
  394. package/dist/frontend/lowering/lower-modules.js +54 -11
  395. package/dist/frontend/lowering/lower-modules.js.map +1 -1
  396. package/dist/frontend/lowering/lower-stmts.js +59 -69
  397. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  398. package/dist/frontend/lowering/lower-stream.js +1 -1
  399. package/dist/frontend/lowering/lower-stream.js.map +1 -1
  400. package/dist/frontend/lowering/lowerer.d.ts +50 -1
  401. package/dist/frontend/lowering/lowerer.js +333 -26
  402. package/dist/frontend/lowering/lowerer.js.map +1 -1
  403. package/dist/frontend/lowering/native-ffi.js +3 -1
  404. package/dist/frontend/lowering/native-ffi.js.map +1 -1
  405. package/dist/frontend/lowering/runtime-optional-provenance.d.ts +15 -0
  406. package/dist/frontend/lowering/runtime-optional-provenance.js +40 -0
  407. package/dist/frontend/lowering/runtime-optional-provenance.js.map +1 -0
  408. package/dist/frontend/lowering/sanitize-class-types.test.js +2 -2
  409. package/dist/frontend/lowering/split-consumers.d.ts +7 -0
  410. package/dist/frontend/lowering/split-consumers.js +64 -0
  411. package/dist/frontend/lowering/split-consumers.js.map +1 -0
  412. package/dist/frontend/lowering/strict-equality.d.ts +9 -0
  413. package/dist/frontend/lowering/strict-equality.js +116 -0
  414. package/dist/frontend/lowering/strict-equality.js.map +1 -0
  415. package/dist/frontend/lowering/surfaces.d.ts +3 -4
  416. package/dist/frontend/lowering/surfaces.js +38 -7
  417. package/dist/frontend/lowering/surfaces.js.map +1 -1
  418. package/dist/frontend/lowering/union-comparison.d.ts +5 -0
  419. package/dist/frontend/lowering/union-comparison.js +47 -0
  420. package/dist/frontend/lowering/union-comparison.js.map +1 -0
  421. package/dist/frontend/module-source-candidates.d.ts +10 -0
  422. package/dist/frontend/module-source-candidates.js +40 -0
  423. package/dist/frontend/module-source-candidates.js.map +1 -0
  424. package/dist/frontend/module-source-candidates.test.d.ts +1 -0
  425. package/dist/frontend/module-source-candidates.test.js +53 -0
  426. package/dist/frontend/module-source-candidates.test.js.map +1 -0
  427. package/dist/frontend/pipeline.js +2 -2
  428. package/dist/frontend/pipeline.js.map +1 -1
  429. package/dist/frontend/program-analysis.d.ts +2 -0
  430. package/dist/frontend/program-analysis.js +2 -0
  431. package/dist/frontend/program-analysis.js.map +1 -1
  432. package/dist/frontend/program.d.ts +38 -2
  433. package/dist/frontend/program.js +457 -88
  434. package/dist/frontend/program.js.map +1 -1
  435. package/dist/frontend/program.test.js +59 -6
  436. package/dist/frontend/program.test.js.map +1 -1
  437. package/dist/frontend/ts7/ast-node.js +6 -8
  438. package/dist/frontend/ts7/ast-node.js.map +1 -1
  439. package/dist/frontend/ts7/ast-node.test.js +42 -1
  440. package/dist/frontend/ts7/ast-node.test.js.map +1 -1
  441. package/dist/frontend/ts7/ast-wire.d.ts +4 -0
  442. package/dist/frontend/ts7/ast-wire.js +28 -0
  443. package/dist/frontend/ts7/ast-wire.js.map +1 -1
  444. package/dist/frontend/ts7/ast.d.ts +2 -1
  445. package/dist/frontend/ts7/ast.js +8 -4
  446. package/dist/frontend/ts7/ast.js.map +1 -1
  447. package/dist/frontend/ts7/checker.d.ts +8 -2
  448. package/dist/frontend/ts7/checker.js +41 -5
  449. package/dist/frontend/ts7/checker.js.map +1 -1
  450. package/dist/frontend/ts7/checker.test.js +42 -0
  451. package/dist/frontend/ts7/checker.test.js.map +1 -1
  452. package/dist/frontend/ts7/program-host.d.ts +7 -0
  453. package/dist/frontend/ts7/program-host.js +26 -2
  454. package/dist/frontend/ts7/program-host.js.map +1 -1
  455. package/dist/frontend/ts7/program-host.test.js +29 -0
  456. package/dist/frontend/ts7/program-host.test.js.map +1 -1
  457. package/dist/frontend/type-mapper.d.ts +4 -1
  458. package/dist/frontend/type-mapper.js +133 -16
  459. package/dist/frontend/type-mapper.js.map +1 -1
  460. package/dist/frontend/type-mapper.test.js +15 -3
  461. package/dist/frontend/type-mapper.test.js.map +1 -1
  462. package/dist/frontend/worker-target.d.ts +6 -0
  463. package/dist/frontend/worker-target.js +108 -0
  464. package/dist/frontend/worker-target.js.map +1 -0
  465. package/dist/frontend/worker-target.test.d.ts +1 -0
  466. package/dist/frontend/worker-target.test.js +71 -0
  467. package/dist/frontend/worker-target.test.js.map +1 -0
  468. package/dist/index.js +47 -14
  469. package/dist/index.js.map +1 -1
  470. package/dist/ir/analysis.d.ts +3 -1
  471. package/dist/ir/analysis.js +4 -0
  472. package/dist/ir/analysis.js.map +1 -1
  473. package/dist/ir/builtin-effects.js +12 -0
  474. package/dist/ir/builtin-effects.js.map +1 -1
  475. package/dist/ir/builtin-signatures.d.ts +1 -1
  476. package/dist/ir/builtin-signatures.js +15 -15
  477. package/dist/ir/builtin-signatures.js.map +1 -1
  478. package/dist/ir/constant-tables.test.js +1 -1
  479. package/dist/ir/initializer-bindings.test.js +1 -1
  480. package/dist/ir/ir.d.ts +85 -23
  481. package/dist/ir/ir.js +20 -6
  482. package/dist/ir/ir.js.map +1 -1
  483. package/dist/ir/numeric-call-specialization.d.ts +8 -0
  484. package/dist/ir/numeric-call-specialization.js +198 -0
  485. package/dist/ir/numeric-call-specialization.js.map +1 -0
  486. package/dist/ir/runtime-features.js +4 -3
  487. package/dist/ir/runtime-features.js.map +1 -1
  488. package/dist/ir/scalar-records.test.js +1 -1
  489. package/dist/ir/serialize.d.ts +1 -1
  490. package/dist/ir/serialize.js +3 -3
  491. package/dist/ir/serialize.js.map +1 -1
  492. package/dist/ir/traverse.js +8 -0
  493. package/dist/ir/traverse.js.map +1 -1
  494. package/dist/ir/validate.js +207 -43
  495. package/dist/ir/validate.js.map +1 -1
  496. package/dist/ir/validate.test.js +356 -8
  497. package/dist/ir/validate.test.js.map +1 -1
  498. package/dist/library/fence-eval.test.js +1 -1
  499. package/dist/library/int-infer.test.js +4 -4
  500. package/dist/library/ir-policy.js +2 -0
  501. package/dist/library/ir-policy.js.map +1 -1
  502. package/dist/library/library-cache.test.js +5 -5
  503. package/dist/library/library-profile.d.ts +2 -1
  504. package/dist/library/library-profile.js +4 -3
  505. package/dist/library/library-profile.js.map +1 -1
  506. package/dist/native/compiler.js +24 -11
  507. package/dist/native/compiler.js.map +1 -1
  508. package/dist/native/compiler.test.js +7 -3
  509. package/dist/native/compiler.test.js.map +1 -1
  510. package/dist/native/library.d.ts +2 -1
  511. package/dist/native/library.js.map +1 -1
  512. package/dist/native/prepare.js +29 -3
  513. package/dist/native/prepare.js.map +1 -1
  514. package/dist/native/sanitizer.d.ts +3 -2
  515. package/dist/native/sanitizer.js +3 -13
  516. package/dist/native/sanitizer.js.map +1 -1
  517. package/dist/native/sanitizer.test.js +1 -0
  518. package/dist/native/sanitizer.test.js.map +1 -1
  519. package/package.json +20 -20
  520. package/surface-manifest.json +37 -3
@@ -56,6 +56,8 @@ import { clearWorkspacePackages, isRelativeSpecifier, isWorkspacePackageName, np
56
56
  import { ADOPTED_OPTIONS, isJsSourceFileName, JS_ANY_OPERATOR_CODES, JS_RELAXED_TSC_CODES, } from "./tsc-codes.js";
57
57
  import { trackedFileExists, trackedReadFile, trackedRealpath } from "./input-tracker.js";
58
58
  import { forkTargetPaths } from "./fork-target.js";
59
+ import { workerTargetPaths } from "./worker-target.js";
60
+ import { moduleSourceCandidates } from "./module-source-candidates.js";
59
61
  import { inferredJsDiagnosticSuppressed } from "./inferred-js-diagnostics.js";
60
62
  const BASE_OPTIONS = {
61
63
  strict: true,
@@ -383,22 +385,21 @@ function externalTypeFileClosure7(program, externalTypes) {
383
385
  * an explicit root, to a fixpoint, so the same TS 7 AST/checker world owns
384
386
  * their exports and transitive graph. */
385
387
  function createRequireProgramRoots7(program) {
386
- const known = new Set(program.getSourceFiles().map((sf) => tsgoPath(resolve(sf.fileName))));
388
+ const known = new Set(program.getSourceFileNames().map((name) => tsgoPath(resolve(name))));
387
389
  const roots = new Set();
388
- for (const sf of program.getSourceFiles()) {
390
+ for (const sf of program.getImplementationSourceFiles()) {
389
391
  if (sf.isDeclarationFile || sf.fileName.endsWith(".json"))
390
392
  continue;
391
393
  const calls = [];
392
- ts.walkPreorder(sf, (node) => {
393
- if (!ts.isCallExpression(node) ||
394
- node.questionDotToken !== undefined ||
394
+ for (const node of moduleSourceCandidates(program, sf).calls) {
395
+ if (node.questionDotToken !== undefined ||
395
396
  node.arguments.length !== 1 ||
396
397
  !ts.isStringLiteralLike(node.arguments[0]) ||
397
398
  !ts.isIdentifier(node.expression)) {
398
- return undefined;
399
+ continue;
399
400
  }
400
401
  calls.push({ callee: node.expression, spec: node.arguments[0].text });
401
- });
402
+ }
402
403
  // Root discovery only needs the callee's binding. A first-miss lookup
403
404
  // otherwise fetches symbols and types for every identifier in the file,
404
405
  // including all unreachable bodies in large published packages.
@@ -450,7 +451,7 @@ export function entryPackageFilePredicate(entryPath) {
450
451
  function entryPackageProgramRoots7(program, entryPath) {
451
452
  const belongsToEntry = entryPackageFilePredicate(entryPath);
452
453
  const roots = new Set();
453
- for (const sf of program.getSourceFiles()) {
454
+ for (const sf of program.getImplementationSourceFiles()) {
454
455
  if (sf.isDeclarationFile ||
455
456
  (!belongsToEntry(sf.fileName) && npmStaticPackageOfPath(sf.fileName) === null))
456
457
  continue;
@@ -515,7 +516,8 @@ function loadProgram7(host, entryPath, externalTypes = new Map()) {
515
516
  const candidates = [
516
517
  ...entryPackageProgramRoots7(program, entryPath),
517
518
  ...createRequireProgramRoots7(program),
518
- ...forkTargetPaths(program, program.getSourceFiles()),
519
+ ...forkTargetPaths(program, program.getImplementationSourceFiles()),
520
+ ...workerTargetPaths(program, program.getImplementationSourceFiles()),
519
521
  ];
520
522
  const extraRoots = candidates.filter((root, index) => !programRoots.includes(root) && candidates.indexOf(root) === index);
521
523
  if (extraRoots.length === 0)
@@ -1609,6 +1611,18 @@ function inTypePosition7(node) {
1609
1611
  * callback-invoking builtin, a getter, an iterator, or an implicit
1610
1612
  * coercion of a user object) disqualifies the module's cycles. */
1611
1613
  function nonInertTopLevel7(program, sf) {
1614
+ const nonInert = topLevelInertness7(program);
1615
+ for (const stmt of sf.statements) {
1616
+ const offence = nonInert(stmt);
1617
+ if (offence !== null)
1618
+ return offence;
1619
+ }
1620
+ return null;
1621
+ }
1622
+ /** The per-statement form of nonInertTopLevel7: answers, for one
1623
+ * top-level statement, the first construct that could execute user code
1624
+ * while the statement runs, or null when the statement is inert. */
1625
+ function topLevelInertness7(program) {
1612
1626
  const checker = program.getTypeChecker();
1613
1627
  const PRIM = ts.TypeFlags.StringLike |
1614
1628
  ts.TypeFlags.NumberLike |
@@ -1777,7 +1791,7 @@ function nonInertTopLevel7(program, sf) {
1777
1791
  }
1778
1792
  return false;
1779
1793
  };
1780
- for (const stmt of sf.statements) {
1794
+ return (stmt) => {
1781
1795
  if (ts.isImportDeclaration(stmt) ||
1782
1796
  ts.isExportDeclaration(stmt) ||
1783
1797
  ts.isImportEqualsDeclaration(stmt) ||
@@ -1788,20 +1802,13 @@ function nonInertTopLevel7(program, sf) {
1788
1802
  (ts.getCombinedModifierFlags(stmt) &
1789
1803
  ts.ModifierFlags.Ambient) !==
1790
1804
  0) {
1791
- continue;
1805
+ return null;
1792
1806
  }
1793
1807
  if (ts.isEnumDeclaration(stmt)) {
1794
- const bad = stmt.members.find((m) => m.initializer !== undefined && !inert(m.initializer));
1795
- if (bad !== undefined)
1796
- return bad;
1797
- continue;
1798
- }
1799
- if (ts.isClassDeclaration(stmt)) {
1800
- const bad = inertClass(stmt);
1801
- if (bad !== null)
1802
- return bad;
1803
- continue;
1808
+ return stmt.members.find((m) => m.initializer !== undefined && !inert(m.initializer)) ?? null;
1804
1809
  }
1810
+ if (ts.isClassDeclaration(stmt))
1811
+ return inertClass(stmt);
1805
1812
  if (ts.isVariableStatement(stmt)) {
1806
1813
  for (const d of stmt.declarationList.declarations) {
1807
1814
  if (!ts.isIdentifier(d.name))
@@ -1809,21 +1816,15 @@ function nonInertTopLevel7(program, sf) {
1809
1816
  if (d.initializer !== undefined && !inert(d.initializer))
1810
1817
  return d.initializer;
1811
1818
  }
1812
- continue;
1813
- }
1814
- if (ts.isExpressionStatement(stmt)) {
1815
- if (!inert(stmt.expression))
1816
- return stmt;
1817
- continue;
1819
+ return null;
1818
1820
  }
1821
+ if (ts.isExpressionStatement(stmt))
1822
+ return inert(stmt.expression) ? null : stmt;
1819
1823
  if (ts.isExportAssignment(stmt) && !stmt.isExportEquals) {
1820
- if (!inert(stmt.expression))
1821
- return stmt;
1822
- continue;
1824
+ return inert(stmt.expression) ? null : stmt;
1823
1825
  }
1824
1826
  return stmt;
1825
- }
1826
- return null;
1827
+ };
1827
1828
  }
1828
1829
  /** The head of a property/element-access chain. */
1829
1830
  function chainRoot7(e) {
@@ -1889,13 +1890,16 @@ function backEdgeUseOffence7(program, stmt, occurrences) {
1889
1890
  * e.dep already mid-initialization in a depth-first walk), answers null
1890
1891
  * to ADMIT the cycle — the guarded %init calls reproduce Node's cache-hit
1891
1892
  * order and nothing can observe the partial initialization — or the
1892
- * human-readable reason it keeps the SC1016 fence. Two admission chances:
1893
+ * human-readable reason it keeps the SC1016 fence. Three admission chances:
1893
1894
  * - the CHEAP PER-EDGE rule: the closing statement binds nothing (a
1894
1895
  * side-effect import) or binds only namespace objects whose every use
1895
1896
  * is a bare expression statement — no read crosses the edge at all;
1896
1897
  * - the DECLARATION-ONLY INIT WINDOW rule (the admission block above):
1897
1898
  * every cluster member is an ES module with an inert top level, and
1898
- * the closing edge's bindings are used only in deferred positions.
1899
+ * the closing edge's bindings are used only in deferred positions;
1900
+ * - the EXACT INITIALIZATION rule (exactCycleRefusal7): partial
1901
+ * initialization is observable, but every observation is modeled —
1902
+ * the lowering checks each binding cycleEarlyBindings reports.
1899
1903
  * Tarjan SCCs (lazy, rooted at each queried importer) and cluster
1900
1904
  * verdicts are memoized across calls, so `edgesOf` must answer the same
1901
1905
  * edges for the same file every time. */
@@ -1946,10 +1950,11 @@ export function makeCycleAdmission(program, edgesOf) {
1946
1950
  const nsf = node.getSourceFile();
1947
1951
  return `${nsf.fileName}:${ts.getLineAndCharacterOfPosition(nsf, node.getStart(nsf)).line + 1}`;
1948
1952
  };
1949
- // Cluster verdict memo (keyed by the component array identity): the
1950
- // reason the cluster's cycles stay fenced, or null when its every
1951
- // member passes the inert-top-level bar.
1953
+ // Cluster verdict memo (keyed by the component array identity): true
1954
+ // when every member is an ES module passing the inert-top-level bar.
1952
1955
  const sccVerdict = new Map();
1956
+ // The exact-initialization verdict, same keying (exactCycleRefusal7).
1957
+ const exactVerdict = new Map();
1953
1958
  // A module can close many cycle edges, each importing many bindings.
1954
1959
  // Index its identifiers once for this admission pass. ASTs are immutable;
1955
1960
  // the pass owns the index so it cannot retain a disposed program.
@@ -1995,31 +2000,405 @@ export function makeCycleAdmission(program, edgesOf) {
1995
2000
  return "the cycle's module cluster could not be analyzed";
1996
2001
  }
1997
2002
  if (!sccVerdict.has(comp)) {
1998
- let reason = null;
1999
- for (const m of comp) {
2000
- if (isCjsJsFile7(m, program)) {
2001
- reason = `${m.fileName} is a CommonJS module — admission covers ES-module cycles only`;
2002
- break;
2003
- }
2004
- const off = nonInertTopLevel7(program, m);
2005
- if (off !== null) {
2006
- reason = `top-level code at ${lineOf(off)} can run user code during the cycle's init window — only declaration-only module bodies are admitted`;
2007
- break;
2003
+ sccVerdict.set(comp, comp.every((m) => !isCjsJsFile7(m, program) && nonInertTopLevel7(program, m) === null));
2004
+ }
2005
+ if (sccVerdict.get(comp) === true &&
2006
+ backEdgeUseOffence7(program, e.stmt, usesOf(importer)) === null) {
2007
+ return null;
2008
+ }
2009
+ // The EXACT INITIALIZATION rule: the cycle runs in Node's evaluation
2010
+ // order and every binding that can be observed before its declaration
2011
+ // runs carries an initialization check (cycleEarlyBindings).
2012
+ if (!exactVerdict.has(comp)) {
2013
+ const reason = exactCycleRefusal7(program, comp, lineOf);
2014
+ exactVerdict.set(comp, reason);
2015
+ if (reason === null) {
2016
+ let members = exactCycleMembers7.get(program);
2017
+ if (members === undefined) {
2018
+ members = new Set();
2019
+ exactCycleMembers7.set(program, members);
2008
2020
  }
2021
+ for (const m of comp)
2022
+ members.add(m);
2009
2023
  }
2010
- sccVerdict.set(comp, reason);
2011
2024
  }
2012
- const clusterReason = sccVerdict.get(comp);
2013
- if (clusterReason === undefined)
2014
- throw new Error("missing module-cycle verdict");
2015
- if (clusterReason !== null)
2016
- return clusterReason;
2017
- const use = backEdgeUseOffence7(program, e.stmt, usesOf(importer));
2018
- if (use !== null) {
2019
- return `the cycle-crossing binding '${use.name}' is read at ${lineOf(use.node)}, outside any function body — a read during the init window observes the partially-initialized module (Node's TDZ ReferenceError / stale var), which is not modeled`;
2025
+ return exactVerdict.get(comp) ?? null;
2026
+ };
2027
+ }
2028
+ /* ── exact cyclic initialization ─────────────────────────────────────────
2029
+ * Cycles that fail the declaration-only rule still evaluate exactly like
2030
+ * Node when their shape is representable: the guarded %init calls already
2031
+ * run every module body in ES evaluation order (depth-first postorder,
2032
+ * a module mid-evaluation answered from the cache), function declarations
2033
+ * are callable from the start, and live bindings are shared globals. What
2034
+ * remains is the temporal dead zone: a let/const binding read before its
2035
+ * declaration ran throws ReferenceError. cycleEarlyBindings finds every
2036
+ * such binding whose read CAN run early; the lowering gives each one an
2037
+ * initialization flag and checks it at every read or write that can run
2038
+ * before the declaration. The shapes below have no such representation
2039
+ * and keep the SC1016 fence. */
2040
+ /** Program → the modules of every cycle the exact rule admitted. */
2041
+ const exactCycleMembers7 = new WeakMap();
2042
+ /** The modules of `program` whose import cycles were admitted by the
2043
+ * exact initialization rule (not the declaration-only rule). */
2044
+ export function exactCycleMembers(program) {
2045
+ return exactCycleMembers7.get(program) ?? new Set();
2046
+ }
2047
+ /** True when the module's top level (outside every function-like body)
2048
+ * contains `await` or `for await`. */
2049
+ function hasTopLevelAwait7(sf) {
2050
+ let found = false;
2051
+ ts.walkPreorder(sf, (node) => {
2052
+ if (found)
2053
+ return "stop";
2054
+ if (node !== sf && ts.isFunctionLike(node))
2055
+ return "skip";
2056
+ if (ts.isAwaitExpression(node) ||
2057
+ (ts.isForOfStatement(node) && node.awaitModifier !== undefined)) {
2058
+ found = true;
2059
+ return "stop";
2020
2060
  }
2021
- return null;
2061
+ return undefined;
2062
+ });
2063
+ return found;
2064
+ }
2065
+ /** The reason a strongly-connected module cluster cannot be initialized
2066
+ * exactly, or null when it can. */
2067
+ function exactCycleRefusal7(program, comp, lineOf) {
2068
+ const members = new Set(comp);
2069
+ const targetOf = (stmt) => {
2070
+ const spec = stmt.moduleSpecifier;
2071
+ if (spec === undefined || !ts.isStringLiteral(spec))
2072
+ return null;
2073
+ const sf = stmt.getSourceFile();
2074
+ return resolveImport7(program, sf, spec.text) ?? npmStaticDepSf7(program, sf, spec.text);
2022
2075
  };
2076
+ for (const m of comp) {
2077
+ if (isCjsJsFile7(m, program) || /\.c[jt]s$/.test(m.fileName)) {
2078
+ return `${m.fileName} is a CommonJS module — cyclic initialization covers ES modules only`;
2079
+ }
2080
+ if (hasTopLevelAwait7(m)) {
2081
+ return `${m.fileName} uses top-level await inside the cycle`;
2082
+ }
2083
+ for (const stmt of m.statements) {
2084
+ if (ts.isExportAssignment(stmt) && !stmt.isExportEquals) {
2085
+ return `the default export expression at ${lineOf(stmt)} has no initialization state inside the cycle`;
2086
+ }
2087
+ if (ts.isExportDeclaration(stmt) &&
2088
+ !stmt.isTypeOnly &&
2089
+ (stmt.exportClause === undefined || ts.isNamespaceExport(stmt.exportClause))) {
2090
+ const dep = targetOf(stmt);
2091
+ if (dep !== null && members.has(dep)) {
2092
+ return `the namespace re-export at ${lineOf(stmt)} names a module of the cycle`;
2093
+ }
2094
+ }
2095
+ if (ts.isImportDeclaration(stmt) &&
2096
+ stmt.importClause !== undefined &&
2097
+ !stmt.importClause.isTypeOnly &&
2098
+ stmt.importClause.namedBindings !== undefined &&
2099
+ ts.isNamespaceImport(stmt.importClause.namedBindings)) {
2100
+ const dep = targetOf(stmt);
2101
+ const nsName = stmt.importClause.namedBindings.name;
2102
+ if (dep !== null &&
2103
+ members.has(dep) &&
2104
+ !nsBindingUsesAreBareStatements7(program, m, nsName)) {
2105
+ return `the namespace import '${nsName.text}' at ${lineOf(stmt)} names a module of the cycle`;
2106
+ }
2107
+ }
2108
+ if (ts.isClassDeclaration(stmt) && stmt.name === undefined) {
2109
+ return `the anonymous default class at ${lineOf(stmt)} has no initialization state inside the cycle`;
2110
+ }
2111
+ const ambient = (ts.getCombinedModifierFlags(stmt) &
2112
+ ts.ModifierFlags.Ambient) !==
2113
+ 0;
2114
+ if (ambient)
2115
+ continue;
2116
+ if (ts.isEnumDeclaration(stmt) &&
2117
+ (ts.getCombinedModifierFlags(stmt) & ts.ModifierFlags.Const) === 0) {
2118
+ return `the enum '${stmt.name.text}' at ${lineOf(stmt)} has no initialization state inside the cycle`;
2119
+ }
2120
+ if (ts.isModuleDeclaration(stmt) && !typeOnlyNamespace7(stmt)) {
2121
+ return `the namespace at ${lineOf(stmt)} has no initialization state inside the cycle`;
2122
+ }
2123
+ }
2124
+ }
2125
+ return null;
2126
+ }
2127
+ /** Every binding of the program's exactly-initialized cycles that can be
2128
+ * observed before its declaration executes. `order` is the compiled module
2129
+ * order; `singleRoot` is false when more than one module graph root runs
2130
+ * (fork or worker entries), so a cycle can be entered at different
2131
+ * members. With one root and a purely ES-module graph the evaluation order
2132
+ * is static and the analysis is precise up to "user code may run": a
2133
+ * binding needs its check when its declaration completes after some
2134
+ * top-level code that can call user functions and a deferred position
2135
+ * (function body, parameter default, instance field) references it, or
2136
+ * when the top level of a cycle member evaluated before it reads it.
2137
+ * Otherwise every deferred reference and every top-level reference from
2138
+ * another member counts. */
2139
+ export function cycleEarlyBindings(program, entry, order, singleRoot) {
2140
+ const exact = exactCycleMembers7.get(program);
2141
+ if (exact === undefined || exact.size === 0)
2142
+ return [];
2143
+ // Every lowering pass of one compile asks with the same inputs.
2144
+ const key = `${entry.fileName}\0${order.map((sf) => sf.fileName).join("\0")}\0${singleRoot}`;
2145
+ const memo = earlyBindingsMemo7.get(program);
2146
+ if (memo !== undefined && memo.key === key)
2147
+ return memo.bindings;
2148
+ const bindings = computeCycleEarlyBindings7(program, entry, order, singleRoot, exact);
2149
+ earlyBindingsMemo7.set(program, { key, bindings });
2150
+ return bindings;
2151
+ }
2152
+ const earlyBindingsMemo7 = new WeakMap();
2153
+ function computeCycleEarlyBindings7(program, entry, order, singleRoot, exact) {
2154
+ const inOrder = new Set(order);
2155
+ const members = [...exact].filter((m) => inOrder.has(m));
2156
+ if (members.length === 0)
2157
+ return [];
2158
+ const memberSet = new Set(members);
2159
+ const depsOf = (sf) => orderedImportsOf(program, sf).flatMap(({ dep }) => dep !== null && dep !== sf && inOrder.has(dep) ? [dep] : []);
2160
+ // Strongly-connected components among the exactly-initialized members.
2161
+ const comps = [];
2162
+ {
2163
+ const index = new Map();
2164
+ const low = new Map();
2165
+ const onStack = new Set();
2166
+ const stack = [];
2167
+ let next = 0;
2168
+ const connect = (v) => {
2169
+ index.set(v, next);
2170
+ low.set(v, next);
2171
+ next++;
2172
+ stack.push(v);
2173
+ onStack.add(v);
2174
+ for (const w of depsOf(v)) {
2175
+ if (!memberSet.has(w))
2176
+ continue;
2177
+ if (!index.has(w)) {
2178
+ connect(w);
2179
+ low.set(v, Math.min(low.get(v), low.get(w)));
2180
+ }
2181
+ else if (onStack.has(w)) {
2182
+ low.set(v, Math.min(low.get(v), index.get(w)));
2183
+ }
2184
+ }
2185
+ if (low.get(v) === index.get(v)) {
2186
+ const comp = [];
2187
+ for (;;) {
2188
+ const w = stack.pop();
2189
+ onStack.delete(w);
2190
+ comp.push(w);
2191
+ if (w === v)
2192
+ break;
2193
+ }
2194
+ if (comp.length > 1)
2195
+ comps.push(comp);
2196
+ }
2197
+ };
2198
+ for (const m of members)
2199
+ if (!index.has(m))
2200
+ connect(m);
2201
+ }
2202
+ if (comps.length === 0)
2203
+ return [];
2204
+ // The static evaluation order: Node's depth-first postorder from the
2205
+ // entry over ES import edges. Known only for one root and a graph with
2206
+ // no CommonJS module (a require() evaluates its target mid-body).
2207
+ const position = new Map();
2208
+ if (singleRoot &&
2209
+ !order.some((sf) => isCjsJsFile7(sf, program) || /\.c[jt]s$/.test(sf.fileName))) {
2210
+ const seen = new Set();
2211
+ const visit = (sf) => {
2212
+ seen.add(sf);
2213
+ for (const dep of depsOf(sf))
2214
+ if (!seen.has(dep))
2215
+ visit(dep);
2216
+ position.set(sf, position.size);
2217
+ };
2218
+ visit(entry);
2219
+ }
2220
+ const checker = program.getTypeChecker();
2221
+ const nonInert = topLevelInertness7(program);
2222
+ const out = [];
2223
+ for (const comp of comps) {
2224
+ const known = comp.every((m) => position.has(m));
2225
+ const evaluation = known
2226
+ ? comp.slice().sort((a, b) => position.get(a) - position.get(b))
2227
+ : comp.slice();
2228
+ const candidates = new Map();
2229
+ const names = new Set();
2230
+ let dirty = !known;
2231
+ evaluation.forEach((m, rank) => {
2232
+ for (const stmt of m.statements) {
2233
+ const offence = nonInert(stmt);
2234
+ const exposed = dirty || offence !== null;
2235
+ const declared = [];
2236
+ if (ts.isVariableStatement(stmt) &&
2237
+ (ts.getCombinedModifierFlags(stmt) &
2238
+ ts.ModifierFlags.Ambient) ===
2239
+ 0) {
2240
+ const lexical = (stmt.declarationList.flags & (ts.NodeFlags.Let | ts.NodeFlags.Const)) !== 0;
2241
+ for (const d of stmt.declarationList.declarations) {
2242
+ for (const name of boundNames7(d.name)) {
2243
+ declared.push({ name, kind: lexical ? "lexical" : "var" });
2244
+ }
2245
+ }
2246
+ }
2247
+ else if (ts.isClassDeclaration(stmt) && stmt.name !== undefined) {
2248
+ declared.push({ name: stmt.name, kind: "class" });
2249
+ }
2250
+ for (const { name, kind } of declared) {
2251
+ const symbol = checker.getSymbolAtLocation(name);
2252
+ if (symbol === undefined)
2253
+ continue;
2254
+ candidates.set(symbol, {
2255
+ symbol,
2256
+ name,
2257
+ kind,
2258
+ module: m,
2259
+ exposed,
2260
+ rank,
2261
+ start: stmt.getStart(m),
2262
+ end: stmt.getEnd(),
2263
+ reference: null,
2264
+ folded: null,
2265
+ });
2266
+ names.add(name.text);
2267
+ }
2268
+ if (offence !== null)
2269
+ dirty = true;
2270
+ }
2271
+ });
2272
+ if (candidates.size === 0)
2273
+ continue;
2274
+ const rankOf = new Map(evaluation.map((m, i) => [m, i]));
2275
+ // References: every identifier spelled like a candidate, resolved
2276
+ // through import aliases to the declaration's symbol.
2277
+ for (const sf of order) {
2278
+ const refs = [];
2279
+ ts.walkPreorder(sf, (node) => {
2280
+ if (ts.isImportDeclaration(node))
2281
+ return "skip";
2282
+ if (ts.isIdentifier(node) && names.has(node.text))
2283
+ refs.push(node);
2284
+ return undefined;
2285
+ });
2286
+ if (refs.length === 0)
2287
+ continue;
2288
+ checker.prefetchSymbolNodesExact(refs);
2289
+ for (const ref of refs) {
2290
+ const parent = ref.parent;
2291
+ if (parent !== undefined && ts.isExportSpecifier(parent))
2292
+ continue;
2293
+ if (inTypePosition7(ref))
2294
+ continue;
2295
+ let symbol = checker.getSymbolAtLocation(ref);
2296
+ if (parent !== undefined &&
2297
+ ts.isShorthandPropertyAssignment(parent) &&
2298
+ parent.name === ref) {
2299
+ symbol = checker.getShorthandAssignmentValueSymbol(parent) ?? symbol;
2300
+ }
2301
+ if (symbol !== undefined && symbol.flags & ts.SymbolFlags.Alias) {
2302
+ symbol = checker.getAliasedSymbol(symbol);
2303
+ }
2304
+ const c = symbol === undefined ? undefined : candidates.get(symbol);
2305
+ if (c === undefined || ref === c.name)
2306
+ continue;
2307
+ if (c.folded === null && foldablePosition7(ref))
2308
+ c.folded = ref;
2309
+ if (c.reference !== null)
2310
+ continue;
2311
+ // A class body names its own inner binding, initialized throughout.
2312
+ if (c.kind === "class" &&
2313
+ sf === c.module &&
2314
+ ref.getStart(sf) >= c.start &&
2315
+ ref.getEnd() <= c.end)
2316
+ continue;
2317
+ let early;
2318
+ if (inDeferredPosition7(ref))
2319
+ early = c.exposed;
2320
+ else if (sf === c.module)
2321
+ early = ref.getStart(sf) < c.start;
2322
+ else if (!memberSet.has(sf) || !rankOf.has(sf))
2323
+ early = false;
2324
+ else
2325
+ early = !known || rankOf.get(sf) < c.rank;
2326
+ if (early)
2327
+ c.reference = ref;
2328
+ }
2329
+ }
2330
+ for (const c of candidates.values()) {
2331
+ if (c.reference === null)
2332
+ continue;
2333
+ const settled = new Set(order.filter((sf) => !rankOf.has(sf)));
2334
+ if (known)
2335
+ for (const m of evaluation.slice(c.rank + 1))
2336
+ settled.add(m);
2337
+ out.push({
2338
+ symbol: c.symbol,
2339
+ name: c.name,
2340
+ kind: c.kind,
2341
+ module: c.module,
2342
+ reference: c.reference,
2343
+ ...(c.folded !== null ? { folded: c.folded } : {}),
2344
+ settled,
2345
+ });
2346
+ }
2347
+ }
2348
+ return out;
2349
+ }
2350
+ /** True for a reference whose value the lowering can take from the
2351
+ * binding's checker type instead of its storage: a property key (element
2352
+ * access argument, computed name, `in` operand, through parentheses,
2353
+ * casts and template spans) or a `typeof` operand. */
2354
+ function foldablePosition7(ref) {
2355
+ let child = ref;
2356
+ for (let p = ref.parent; p !== undefined; p = p.parent) {
2357
+ if (ts.isParenthesizedExpression(p) ||
2358
+ ts.isAsExpression(p) ||
2359
+ ts.isSatisfiesExpression(p) ||
2360
+ ts.isNonNullExpression(p) ||
2361
+ ts.isTemplateSpan(p) ||
2362
+ ts.isTemplateExpression(p)) {
2363
+ child = p;
2364
+ continue;
2365
+ }
2366
+ if (ts.isTypeOfExpression(p))
2367
+ return true;
2368
+ if (ts.isElementAccessExpression(p))
2369
+ return p.argumentExpression === child;
2370
+ if (ts.isComputedPropertyName(p))
2371
+ return true;
2372
+ if (ts.isBinaryExpression(p))
2373
+ return p.operatorToken.kind === ts.SyntaxKind.InKeyword && p.left === child;
2374
+ return false;
2375
+ }
2376
+ return false;
2377
+ }
2378
+ /** The identifiers a binding name (identifier or destructuring pattern)
2379
+ * declares. */
2380
+ function boundNames7(name) {
2381
+ if (ts.isIdentifier(name))
2382
+ return [name];
2383
+ const out = [];
2384
+ for (const el of name.elements) {
2385
+ if (ts.isOmittedExpression(el) || el.name === undefined)
2386
+ continue;
2387
+ out.push(...boundNames7(el.name));
2388
+ }
2389
+ return out;
2390
+ }
2391
+ /** A namespace declaration whose body holds only types (interfaces, type
2392
+ * aliases, nested type-only namespaces) — no runtime object exists. */
2393
+ function typeOnlyNamespace7(decl) {
2394
+ let body = decl.body;
2395
+ while (body !== undefined && ts.isModuleDeclaration(body))
2396
+ body = body.body;
2397
+ if (body === undefined || !ts.isModuleBlock(body))
2398
+ return true;
2399
+ return body.statements.every((s) => ts.isInterfaceDeclaration(s) ||
2400
+ ts.isTypeAliasDeclaration(s) ||
2401
+ (ts.isModuleDeclaration(s) && typeOnlyNamespace7(s)));
2023
2402
  }
2024
2403
  /** Resolves an import specifier from `from` to a source file of the
2025
2404
  * program, or null (unresolvable / outside the program). Exported (as
@@ -2175,26 +2554,11 @@ function preflight7(load) {
2175
2554
  if (r !== null && r.workspaceDir !== undefined)
2176
2555
  registerWorkspacePackage(r.packageName, r.workspaceDir);
2177
2556
  };
2178
- for (const sf of program.getSourceFiles()) {
2557
+ for (const sf of program.getImplementationSourceFiles()) {
2179
2558
  if (sf.isDeclarationFile || sf.fileName.endsWith(".json"))
2180
2559
  continue;
2181
- ts.walkPreorder(sf, (n) => {
2182
- if ((ts.isImportDeclaration(n) || ts.isExportDeclaration(n)) &&
2183
- n.moduleSpecifier !== undefined &&
2184
- ts.isStringLiteral(n.moduleSpecifier)) {
2185
- probe(sf.fileName, n.moduleSpecifier.text);
2186
- return "skip";
2187
- }
2188
- if (ts.isCallExpression(n)) {
2189
- const arg = n.arguments[0];
2190
- const isImportCall = n.expression.kind === ts.SyntaxKind.ImportKeyword;
2191
- const isRequireCall = ts.isIdentifier(n.expression) && n.expression.text === "require";
2192
- if ((isImportCall || isRequireCall) && arg !== undefined && ts.isStringLiteralLike(arg)) {
2193
- probe(sf.fileName, arg.text);
2194
- }
2195
- }
2196
- return undefined;
2197
- });
2560
+ for (const specifier of moduleSourceCandidates(program, sf).specifiers)
2561
+ probe(sf.fileName, specifier);
2198
2562
  }
2199
2563
  }
2200
2564
  const toPassthrough = (d) => {
@@ -2378,7 +2742,7 @@ function preflight7(load) {
2378
2742
  // reachable bodies are added by lowering's worklists.
2379
2743
  const ambient = ambientDtsPath();
2380
2744
  const programFiles = program
2381
- .getSourceFiles()
2745
+ .getImplementationSourceFiles()
2382
2746
  .filter((sf) => sf.fileName !== ambient &&
2383
2747
  !sf.isDeclarationFile &&
2384
2748
  !sf.fileName.endsWith(".json") &&
@@ -2389,7 +2753,8 @@ function preflight7(load) {
2389
2753
  const userFiles = npmStaticActive()
2390
2754
  ? planNpmStaticReexports(program, entry, programFiles, [
2391
2755
  ...createRequireProgramRoots7(program),
2392
- ...forkTargetPaths(program, program.getSourceFiles()),
2756
+ ...forkTargetPaths(program, program.getImplementationSourceFiles()),
2757
+ ...workerTargetPaths(program, program.getImplementationSourceFiles()),
2393
2758
  ], (sf, spec, resolutionKind) => resolveImport7(program, sf, spec, resolutionKind) ??
2394
2759
  npmStaticDepSf7(program, sf, spec, resolutionKind))
2395
2760
  : programFiles;
@@ -2462,10 +2827,9 @@ function preflight7(load) {
2462
2827
  // benign-cycle admission block above). Node evaluates such cycles
2463
2828
  // benignly (the revisited module is a cache hit, and no binding read
2464
2829
  // can hit TDZ or a stale slot), so the guarded %init calls reproduce
2465
- // its order exactly. Cycles that fail both keep the SC1016 fence,
2466
- // because a read through them mid-cycle observes TDZ (let/const) or
2467
- // undefined (var) in Node — runtime evaluation-order semantics the
2468
- // static story does not model.
2830
+ // its order exactly. Cycles that fail both are judged by the exact
2831
+ // initialization rule: admitted when every early read is modeled by an
2832
+ // initialization check, fenced with SC1016 otherwise.
2469
2833
  const edges = new Map();
2470
2834
  const refusals = new Map();
2471
2835
  const depPositions = new Map();
@@ -2939,9 +3303,10 @@ function preflight7(load) {
2939
3303
  // Node's evaluation order: depth-first postorder from the entry, each
2940
3304
  // module once, back-edges answered from the cache (a module already
2941
3305
  // evaluating is skipped) — which the guarded %init calls reproduce
2942
- // exactly. Cycles are admitted only where Node's partially-initialized
2943
- // semantics are UNOBSERVABLE (JS's partial-initialization is otherwise a
2944
- // silent-misbehavior trap, so SC1016 stays for the rest):
3306
+ // exactly. Cycles are admitted where Node's partially-initialized
3307
+ // semantics are UNOBSERVABLE or exactly modeled (JS's partial
3308
+ // initialization is otherwise a silent-misbehavior trap, so SC1016
3309
+ // stays for the rest):
2945
3310
  // - a DIRECT SELF-IMPORT (the package self-name reference resolving to
2946
3311
  // the importing module itself — Node's self-reference rule): the
2947
3312
  // imported bindings alias the module's OWN top-level bindings with
@@ -2953,7 +3318,11 @@ function preflight7(load) {
2953
3318
  // benign-cycle admission block: every module of the cycle's
2954
3319
  // strongly-connected component has an inert top level and the
2955
3320
  // closing edge's bindings are used only in deferred positions, so no
2956
- // read can execute before every member initialized).
3321
+ // read can execute before every member initialized);
3322
+ // - the EXACT INITIALIZATION rule: an ES-module cluster whose early
3323
+ // reads are all let/const bindings with module storage — the
3324
+ // lowering checks each one (cycleEarlyBindings) and throws Node's
3325
+ // ReferenceError on a read before the declaration ran.
2957
3326
  const cycleAdmissionReason = makeCycleAdmission(program, (sf) => edges.get(sf) ?? []);
2958
3327
  const order = [];
2959
3328
  const state = new Map();
@@ -2969,9 +3338,9 @@ function preflight7(load) {
2969
3338
  continue;
2970
3339
  if (s === "visiting") {
2971
3340
  // A back-edge: Node answers it from the cache (the module is
2972
- // already evaluating) — benign exactly when nothing can observe
2973
- // the partial initialization through this edge's bindings, by the
2974
- // cheap per-edge rule or the declaration-only init window rule.
3341
+ // already evaluating) — admitted by the cheap per-edge rule, the
3342
+ // declaration-only init window rule, or the exact initialization
3343
+ // rule.
2975
3344
  const reason = cycleAdmissionReason(sf, e);
2976
3345
  if (reason !== null) {
2977
3346
  const cycleStart = stack.indexOf(e.dep.fileName);