@despia-native/kernel 0.0.0-coming-soon.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (661) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +1414 -0
  3. package/README.md +16 -1
  4. package/dist/.dsx-build-stamp.json +7 -0
  5. package/dist/api-cohort.d.ts +27 -0
  6. package/dist/api-cohort.d.ts.map +1 -0
  7. package/dist/api-cohort.js +94 -0
  8. package/dist/api-cohort.js.map +1 -0
  9. package/dist/api.d.ts +454 -0
  10. package/dist/api.d.ts.map +1 -0
  11. package/dist/api.js +2442 -0
  12. package/dist/api.js.map +1 -0
  13. package/dist/app-consts.d.ts +10 -0
  14. package/dist/app-consts.d.ts.map +1 -0
  15. package/dist/app-consts.js +39 -0
  16. package/dist/app-consts.js.map +1 -0
  17. package/dist/app-update.d.ts +12 -0
  18. package/dist/app-update.d.ts.map +1 -0
  19. package/dist/app-update.js +32 -0
  20. package/dist/app-update.js.map +1 -0
  21. package/dist/aria.d.ts +152 -0
  22. package/dist/aria.d.ts.map +1 -0
  23. package/dist/aria.js +524 -0
  24. package/dist/aria.js.map +1 -0
  25. package/dist/audio-core.d.ts +260 -0
  26. package/dist/audio-core.d.ts.map +1 -0
  27. package/dist/audio-core.js +1440 -0
  28. package/dist/audio-core.js.map +1 -0
  29. package/dist/audio-edit.d.ts +100 -0
  30. package/dist/audio-edit.d.ts.map +1 -0
  31. package/dist/audio-edit.js +489 -0
  32. package/dist/audio-edit.js.map +1 -0
  33. package/dist/audio-mix.d.ts +84 -0
  34. package/dist/audio-mix.d.ts.map +1 -0
  35. package/dist/audio-mix.js +393 -0
  36. package/dist/audio-mix.js.map +1 -0
  37. package/dist/auth-proof.d.ts +145 -0
  38. package/dist/auth-proof.d.ts.map +1 -0
  39. package/dist/auth-proof.js +644 -0
  40. package/dist/auth-proof.js.map +1 -0
  41. package/dist/availability-explain.d.ts +3 -0
  42. package/dist/availability-explain.d.ts.map +1 -0
  43. package/dist/availability-explain.js +322 -0
  44. package/dist/availability-explain.js.map +1 -0
  45. package/dist/availability.d.ts +246 -0
  46. package/dist/availability.d.ts.map +1 -0
  47. package/dist/availability.js +615 -0
  48. package/dist/availability.js.map +1 -0
  49. package/dist/background.d.ts +116 -0
  50. package/dist/background.d.ts.map +1 -0
  51. package/dist/background.js +235 -0
  52. package/dist/background.js.map +1 -0
  53. package/dist/boot-tables-flag.d.ts +2 -0
  54. package/dist/boot-tables-flag.d.ts.map +1 -0
  55. package/dist/boot-tables-flag.js +16 -0
  56. package/dist/boot-tables-flag.js.map +1 -0
  57. package/dist/boot-tables.d.ts +40 -0
  58. package/dist/boot-tables.d.ts.map +1 -0
  59. package/dist/boot-tables.js +102 -0
  60. package/dist/boot-tables.js.map +1 -0
  61. package/dist/border-edges.d.ts +5 -0
  62. package/dist/border-edges.d.ts.map +1 -0
  63. package/dist/border-edges.js +47 -0
  64. package/dist/border-edges.js.map +1 -0
  65. package/dist/bus.d.ts +1203 -0
  66. package/dist/bus.d.ts.map +1 -0
  67. package/dist/bus.js +2647 -0
  68. package/dist/bus.js.map +1 -0
  69. package/dist/calendar-core.d.ts +143 -0
  70. package/dist/calendar-core.d.ts.map +1 -0
  71. package/dist/calendar-core.js +372 -0
  72. package/dist/calendar-core.js.map +1 -0
  73. package/dist/call-value.d.ts +16 -0
  74. package/dist/call-value.d.ts.map +1 -0
  75. package/dist/call-value.js +54 -0
  76. package/dist/call-value.js.map +1 -0
  77. package/dist/camera-core.d.ts +222 -0
  78. package/dist/camera-core.d.ts.map +1 -0
  79. package/dist/camera-core.js +980 -0
  80. package/dist/camera-core.js.map +1 -0
  81. package/dist/canvas-core.d.ts +404 -0
  82. package/dist/canvas-core.d.ts.map +1 -0
  83. package/dist/canvas-core.js +2186 -0
  84. package/dist/canvas-core.js.map +1 -0
  85. package/dist/capture-core.d.ts +74 -0
  86. package/dist/capture-core.d.ts.map +1 -0
  87. package/dist/capture-core.js +158 -0
  88. package/dist/capture-core.js.map +1 -0
  89. package/dist/compile/codegen.d.ts +146 -0
  90. package/dist/compile/codegen.d.ts.map +1 -0
  91. package/dist/compile/codegen.js +1949 -0
  92. package/dist/compile/codegen.js.map +1 -0
  93. package/dist/compile/jstier.d.ts +44 -0
  94. package/dist/compile/jstier.d.ts.map +1 -0
  95. package/dist/compile/jstier.js +181 -0
  96. package/dist/compile/jstier.js.map +1 -0
  97. package/dist/compile/tier-door.d.ts +41 -0
  98. package/dist/compile/tier-door.d.ts.map +1 -0
  99. package/dist/compile/tier-door.js +167 -0
  100. package/dist/compile/tier-door.js.map +1 -0
  101. package/dist/compile/tier-realm.d.ts +49 -0
  102. package/dist/compile/tier-realm.d.ts.map +1 -0
  103. package/dist/compile/tier-realm.js +368 -0
  104. package/dist/compile/tier-realm.js.map +1 -0
  105. package/dist/compile/tier.d.ts +23 -0
  106. package/dist/compile/tier.d.ts.map +1 -0
  107. package/dist/compile/tier.js +157 -0
  108. package/dist/compile/tier.js.map +1 -0
  109. package/dist/compose-core.d.ts +86 -0
  110. package/dist/compose-core.d.ts.map +1 -0
  111. package/dist/compose-core.js +112 -0
  112. package/dist/compose-core.js.map +1 -0
  113. package/dist/config-validate.d.ts +31 -0
  114. package/dist/config-validate.d.ts.map +1 -0
  115. package/dist/config-validate.js +147 -0
  116. package/dist/config-validate.js.map +1 -0
  117. package/dist/config-values.d.ts +106 -0
  118. package/dist/config-values.d.ts.map +1 -0
  119. package/dist/config-values.js +340 -0
  120. package/dist/config-values.js.map +1 -0
  121. package/dist/contacts-core.d.ts +127 -0
  122. package/dist/contacts-core.d.ts.map +1 -0
  123. package/dist/contacts-core.js +211 -0
  124. package/dist/contacts-core.js.map +1 -0
  125. package/dist/content-transition.d.ts +58 -0
  126. package/dist/content-transition.d.ts.map +1 -0
  127. package/dist/content-transition.js +94 -0
  128. package/dist/content-transition.js.map +1 -0
  129. package/dist/controls-core.d.ts +227 -0
  130. package/dist/controls-core.d.ts.map +1 -0
  131. package/dist/controls-core.js +652 -0
  132. package/dist/controls-core.js.map +1 -0
  133. package/dist/cookies.d.ts +78 -0
  134. package/dist/cookies.d.ts.map +1 -0
  135. package/dist/cookies.js +265 -0
  136. package/dist/cookies.js.map +1 -0
  137. package/dist/corner-shape-core.d.ts +69 -0
  138. package/dist/corner-shape-core.d.ts.map +1 -0
  139. package/dist/corner-shape-core.js +261 -0
  140. package/dist/corner-shape-core.js.map +1 -0
  141. package/dist/crypto-core.d.ts +57 -0
  142. package/dist/crypto-core.d.ts.map +1 -0
  143. package/dist/crypto-core.js +128 -0
  144. package/dist/crypto-core.js.map +1 -0
  145. package/dist/dataviz.d.ts +436 -0
  146. package/dist/dataviz.d.ts.map +1 -0
  147. package/dist/dataviz.js +956 -0
  148. package/dist/dataviz.js.map +1 -0
  149. package/dist/debug.d.ts +293 -0
  150. package/dist/debug.d.ts.map +1 -0
  151. package/dist/debug.js +767 -0
  152. package/dist/debug.js.map +1 -0
  153. package/dist/device-ownership.d.ts +50 -0
  154. package/dist/device-ownership.d.ts.map +1 -0
  155. package/dist/device-ownership.js +105 -0
  156. package/dist/device-ownership.js.map +1 -0
  157. package/dist/effects.d.ts +86 -0
  158. package/dist/effects.d.ts.map +1 -0
  159. package/dist/effects.js +98 -0
  160. package/dist/effects.js.map +1 -0
  161. package/dist/element.d.ts +108 -0
  162. package/dist/element.d.ts.map +1 -0
  163. package/dist/element.js +63 -0
  164. package/dist/element.js.map +1 -0
  165. package/dist/file-watch.d.ts +16 -0
  166. package/dist/file-watch.d.ts.map +1 -0
  167. package/dist/file-watch.js +49 -0
  168. package/dist/file-watch.js.map +1 -0
  169. package/dist/filepaths.d.ts +72 -0
  170. package/dist/filepaths.d.ts.map +1 -0
  171. package/dist/filepaths.js +271 -0
  172. package/dist/filepaths.js.map +1 -0
  173. package/dist/film.d.ts +264 -0
  174. package/dist/film.d.ts.map +1 -0
  175. package/dist/film.js +313 -0
  176. package/dist/film.js.map +1 -0
  177. package/dist/fonts.d.ts +66 -0
  178. package/dist/fonts.d.ts.map +1 -0
  179. package/dist/fonts.js +135 -0
  180. package/dist/fonts.js.map +1 -0
  181. package/dist/forms.d.ts +191 -0
  182. package/dist/forms.d.ts.map +1 -0
  183. package/dist/forms.js +663 -0
  184. package/dist/forms.js.map +1 -0
  185. package/dist/geo.d.ts +289 -0
  186. package/dist/geo.d.ts.map +1 -0
  187. package/dist/geo.js +460 -0
  188. package/dist/geo.js.map +1 -0
  189. package/dist/handler-announce.d.ts +46 -0
  190. package/dist/handler-announce.d.ts.map +1 -0
  191. package/dist/handler-announce.js +96 -0
  192. package/dist/handler-announce.js.map +1 -0
  193. package/dist/handoff.d.ts +71 -0
  194. package/dist/handoff.d.ts.map +1 -0
  195. package/dist/handoff.js +250 -0
  196. package/dist/handoff.js.map +1 -0
  197. package/dist/identity-durability.d.ts +76 -0
  198. package/dist/identity-durability.d.ts.map +1 -0
  199. package/dist/identity-durability.js +150 -0
  200. package/dist/identity-durability.js.map +1 -0
  201. package/dist/image-core.d.ts +240 -0
  202. package/dist/image-core.d.ts.map +1 -0
  203. package/dist/image-core.js +618 -0
  204. package/dist/image-core.js.map +1 -0
  205. package/dist/image-schemes.d.ts +10 -0
  206. package/dist/image-schemes.d.ts.map +1 -0
  207. package/dist/image-schemes.js +28 -0
  208. package/dist/image-schemes.js.map +1 -0
  209. package/dist/index.d.ts +143 -0
  210. package/dist/index.d.ts.map +1 -0
  211. package/dist/index.js +299 -0
  212. package/dist/index.js.map +1 -0
  213. package/dist/ink-core.d.ts +53 -0
  214. package/dist/ink-core.d.ts.map +1 -0
  215. package/dist/ink-core.js +119 -0
  216. package/dist/ink-core.js.map +1 -0
  217. package/dist/input.d.ts +148 -0
  218. package/dist/input.d.ts.map +1 -0
  219. package/dist/input.js +358 -0
  220. package/dist/input.js.map +1 -0
  221. package/dist/integrity.d.ts +63 -0
  222. package/dist/integrity.d.ts.map +1 -0
  223. package/dist/integrity.js +150 -0
  224. package/dist/integrity.js.map +1 -0
  225. package/dist/intents.d.ts +95 -0
  226. package/dist/intents.d.ts.map +1 -0
  227. package/dist/intents.js +282 -0
  228. package/dist/intents.js.map +1 -0
  229. package/dist/interpolate-core.d.ts +37 -0
  230. package/dist/interpolate-core.d.ts.map +1 -0
  231. package/dist/interpolate-core.js +443 -0
  232. package/dist/interpolate-core.js.map +1 -0
  233. package/dist/jse/color.d.ts +12 -0
  234. package/dist/jse/color.d.ts.map +1 -0
  235. package/dist/jse/color.js +196 -0
  236. package/dist/jse/color.js.map +1 -0
  237. package/dist/jse/core.d.ts +54 -0
  238. package/dist/jse/core.d.ts.map +1 -0
  239. package/dist/jse/core.js +1519 -0
  240. package/dist/jse/core.js.map +1 -0
  241. package/dist/jse/dispatch.d.ts +28 -0
  242. package/dist/jse/dispatch.d.ts.map +1 -0
  243. package/dist/jse/dispatch.js +116 -0
  244. package/dist/jse/dispatch.js.map +1 -0
  245. package/dist/jse/highlight-grammar.d.ts +15 -0
  246. package/dist/jse/highlight-grammar.d.ts.map +1 -0
  247. package/dist/jse/highlight-grammar.js +161 -0
  248. package/dist/jse/highlight-grammar.js.map +1 -0
  249. package/dist/jse/highlight-grammars.generated.d.ts +2 -0
  250. package/dist/jse/highlight-grammars.generated.d.ts.map +1 -0
  251. package/dist/jse/highlight-grammars.generated.js +4 -0
  252. package/dist/jse/highlight-grammars.generated.js.map +1 -0
  253. package/dist/jse/highlight.d.ts +37 -0
  254. package/dist/jse/highlight.d.ts.map +1 -0
  255. package/dist/jse/highlight.js +323 -0
  256. package/dist/jse/highlight.js.map +1 -0
  257. package/dist/jse/jse.d.ts +674 -0
  258. package/dist/jse/jse.d.ts.map +1 -0
  259. package/dist/jse/jse.js +5841 -0
  260. package/dist/jse/jse.js.map +1 -0
  261. package/dist/jse/pathmatch.d.ts +10 -0
  262. package/dist/jse/pathmatch.d.ts.map +1 -0
  263. package/dist/jse/pathmatch.js +73 -0
  264. package/dist/jse/pathmatch.js.map +1 -0
  265. package/dist/jse/regex.d.ts +33 -0
  266. package/dist/jse/regex.d.ts.map +1 -0
  267. package/dist/jse/regex.js +375 -0
  268. package/dist/jse/regex.js.map +1 -0
  269. package/dist/jse/stdlib.d.ts +8 -0
  270. package/dist/jse/stdlib.d.ts.map +1 -0
  271. package/dist/jse/stdlib.js +765 -0
  272. package/dist/jse/stdlib.js.map +1 -0
  273. package/dist/jse/tokens.d.ts +102 -0
  274. package/dist/jse/tokens.d.ts.map +1 -0
  275. package/dist/jse/tokens.js +982 -0
  276. package/dist/jse/tokens.js.map +1 -0
  277. package/dist/jse/values.d.ts +206 -0
  278. package/dist/jse/values.d.ts.map +1 -0
  279. package/dist/jse/values.js +846 -0
  280. package/dist/jse/values.js.map +1 -0
  281. package/dist/keyboard.d.ts +196 -0
  282. package/dist/keyboard.d.ts.map +1 -0
  283. package/dist/keyboard.js +186 -0
  284. package/dist/keyboard.js.map +1 -0
  285. package/dist/label-choices.d.ts +3 -0
  286. package/dist/label-choices.d.ts.map +1 -0
  287. package/dist/label-choices.js +168 -0
  288. package/dist/label-choices.js.map +1 -0
  289. package/dist/language.d.ts +33 -0
  290. package/dist/language.d.ts.map +1 -0
  291. package/dist/language.js +50 -0
  292. package/dist/language.js.map +1 -0
  293. package/dist/length-units.d.ts +30 -0
  294. package/dist/length-units.d.ts.map +1 -0
  295. package/dist/length-units.js +83 -0
  296. package/dist/length-units.js.map +1 -0
  297. package/dist/lightsensor.d.ts +48 -0
  298. package/dist/lightsensor.d.ts.map +1 -0
  299. package/dist/lightsensor.js +97 -0
  300. package/dist/lightsensor.js.map +1 -0
  301. package/dist/link-refresh.d.ts +27 -0
  302. package/dist/link-refresh.d.ts.map +1 -0
  303. package/dist/link-refresh.js +166 -0
  304. package/dist/link-refresh.js.map +1 -0
  305. package/dist/link.d.ts +57 -0
  306. package/dist/link.d.ts.map +1 -0
  307. package/dist/link.js +333 -0
  308. package/dist/link.js.map +1 -0
  309. package/dist/linkpreview.d.ts +114 -0
  310. package/dist/linkpreview.d.ts.map +1 -0
  311. package/dist/linkpreview.js +439 -0
  312. package/dist/linkpreview.js.map +1 -0
  313. package/dist/list-presence.d.ts +32 -0
  314. package/dist/list-presence.d.ts.map +1 -0
  315. package/dist/list-presence.js +48 -0
  316. package/dist/list-presence.js.map +1 -0
  317. package/dist/live-stream.d.ts +27 -0
  318. package/dist/live-stream.d.ts.map +1 -0
  319. package/dist/live-stream.js +274 -0
  320. package/dist/live-stream.js.map +1 -0
  321. package/dist/livelogs.d.ts +134 -0
  322. package/dist/livelogs.d.ts.map +1 -0
  323. package/dist/livelogs.js +409 -0
  324. package/dist/livelogs.js.map +1 -0
  325. package/dist/logs.d.ts +80 -0
  326. package/dist/logs.d.ts.map +1 -0
  327. package/dist/logs.js +206 -0
  328. package/dist/logs.js.map +1 -0
  329. package/dist/mcp/apps.d.ts +82 -0
  330. package/dist/mcp/apps.d.ts.map +1 -0
  331. package/dist/mcp/apps.js +219 -0
  332. package/dist/mcp/apps.js.map +1 -0
  333. package/dist/mcp/entities.d.ts +25 -0
  334. package/dist/mcp/entities.d.ts.map +1 -0
  335. package/dist/mcp/entities.js +71 -0
  336. package/dist/mcp/entities.js.map +1 -0
  337. package/dist/mcp/result.d.ts +73 -0
  338. package/dist/mcp/result.d.ts.map +1 -0
  339. package/dist/mcp/result.js +119 -0
  340. package/dist/mcp/result.js.map +1 -0
  341. package/dist/mcp/webmcp.d.ts +162 -0
  342. package/dist/mcp/webmcp.d.ts.map +1 -0
  343. package/dist/mcp/webmcp.js +214 -0
  344. package/dist/mcp/webmcp.js.map +1 -0
  345. package/dist/mcp.d.ts +5 -0
  346. package/dist/mcp.d.ts.map +1 -0
  347. package/dist/mcp.js +14 -0
  348. package/dist/mcp.js.map +1 -0
  349. package/dist/media-core.d.ts +191 -0
  350. package/dist/media-core.d.ts.map +1 -0
  351. package/dist/media-core.js +446 -0
  352. package/dist/media-core.js.map +1 -0
  353. package/dist/media-timeline-core.d.ts +94 -0
  354. package/dist/media-timeline-core.d.ts.map +1 -0
  355. package/dist/media-timeline-core.js +620 -0
  356. package/dist/media-timeline-core.js.map +1 -0
  357. package/dist/message.d.ts +42 -0
  358. package/dist/message.d.ts.map +1 -0
  359. package/dist/message.js +582 -0
  360. package/dist/message.js.map +1 -0
  361. package/dist/missing-element.d.ts +29 -0
  362. package/dist/missing-element.d.ts.map +1 -0
  363. package/dist/missing-element.js +76 -0
  364. package/dist/missing-element.js.map +1 -0
  365. package/dist/motion-core.d.ts +160 -0
  366. package/dist/motion-core.d.ts.map +1 -0
  367. package/dist/motion-core.js +752 -0
  368. package/dist/motion-core.js.map +1 -0
  369. package/dist/motion-pose.d.ts +65 -0
  370. package/dist/motion-pose.d.ts.map +1 -0
  371. package/dist/motion-pose.js +143 -0
  372. package/dist/motion-pose.js.map +1 -0
  373. package/dist/motion.d.ts +132 -0
  374. package/dist/motion.d.ts.map +1 -0
  375. package/dist/motion.js +260 -0
  376. package/dist/motion.js.map +1 -0
  377. package/dist/mount-core.d.ts +203 -0
  378. package/dist/mount-core.d.ts.map +1 -0
  379. package/dist/mount-core.js +437 -0
  380. package/dist/mount-core.js.map +1 -0
  381. package/dist/net-core.d.ts +110 -0
  382. package/dist/net-core.d.ts.map +1 -0
  383. package/dist/net-core.js +225 -0
  384. package/dist/net-core.js.map +1 -0
  385. package/dist/notify.d.ts +399 -0
  386. package/dist/notify.d.ts.map +1 -0
  387. package/dist/notify.js +964 -0
  388. package/dist/notify.js.map +1 -0
  389. package/dist/orientation-binding.d.ts +39 -0
  390. package/dist/orientation-binding.d.ts.map +1 -0
  391. package/dist/orientation-binding.js +64 -0
  392. package/dist/orientation-binding.js.map +1 -0
  393. package/dist/orientation.d.ts +55 -0
  394. package/dist/orientation.d.ts.map +1 -0
  395. package/dist/orientation.js +89 -0
  396. package/dist/orientation.js.map +1 -0
  397. package/dist/ota.d.ts +52 -0
  398. package/dist/ota.d.ts.map +1 -0
  399. package/dist/ota.js +122 -0
  400. package/dist/ota.js.map +1 -0
  401. package/dist/passkeys.d.ts +91 -0
  402. package/dist/passkeys.d.ts.map +1 -0
  403. package/dist/passkeys.js +307 -0
  404. package/dist/passkeys.js.map +1 -0
  405. package/dist/payment.d.ts +85 -0
  406. package/dist/payment.d.ts.map +1 -0
  407. package/dist/payment.js +270 -0
  408. package/dist/payment.js.map +1 -0
  409. package/dist/pending-presenter.d.ts +31 -0
  410. package/dist/pending-presenter.d.ts.map +1 -0
  411. package/dist/pending-presenter.js +119 -0
  412. package/dist/pending-presenter.js.map +1 -0
  413. package/dist/permission-core.d.ts +59 -0
  414. package/dist/permission-core.d.ts.map +1 -0
  415. package/dist/permission-core.js +102 -0
  416. package/dist/permission-core.js.map +1 -0
  417. package/dist/persist.d.ts +169 -0
  418. package/dist/persist.d.ts.map +1 -0
  419. package/dist/persist.js +361 -0
  420. package/dist/persist.js.map +1 -0
  421. package/dist/phase-plan.d.ts +114 -0
  422. package/dist/phase-plan.d.ts.map +1 -0
  423. package/dist/phase-plan.js +837 -0
  424. package/dist/phase-plan.js.map +1 -0
  425. package/dist/playback-core.d.ts +64 -0
  426. package/dist/playback-core.d.ts.map +1 -0
  427. package/dist/playback-core.js +176 -0
  428. package/dist/playback-core.js.map +1 -0
  429. package/dist/player-sources.d.ts +12 -0
  430. package/dist/player-sources.d.ts.map +1 -0
  431. package/dist/player-sources.js +44 -0
  432. package/dist/player-sources.js.map +1 -0
  433. package/dist/proxy-denylist.d.ts +11 -0
  434. package/dist/proxy-denylist.d.ts.map +1 -0
  435. package/dist/proxy-denylist.js +44 -0
  436. package/dist/proxy-denylist.js.map +1 -0
  437. package/dist/public-config.d.ts +20 -0
  438. package/dist/public-config.d.ts.map +1 -0
  439. package/dist/public-config.js +109 -0
  440. package/dist/public-config.js.map +1 -0
  441. package/dist/qoe-core.d.ts +72 -0
  442. package/dist/qoe-core.d.ts.map +1 -0
  443. package/dist/qoe-core.js +113 -0
  444. package/dist/qoe-core.js.map +1 -0
  445. package/dist/reactive-request.d.ts +80 -0
  446. package/dist/reactive-request.d.ts.map +1 -0
  447. package/dist/reactive-request.js +192 -0
  448. package/dist/reactive-request.js.map +1 -0
  449. package/dist/read-cache.d.ts +129 -0
  450. package/dist/read-cache.d.ts.map +1 -0
  451. package/dist/read-cache.js +566 -0
  452. package/dist/read-cache.js.map +1 -0
  453. package/dist/recorder-core.d.ts +57 -0
  454. package/dist/recorder-core.d.ts.map +1 -0
  455. package/dist/recorder-core.js +136 -0
  456. package/dist/recorder-core.js.map +1 -0
  457. package/dist/ref.d.ts +41 -0
  458. package/dist/ref.d.ts.map +1 -0
  459. package/dist/ref.js +98 -0
  460. package/dist/ref.js.map +1 -0
  461. package/dist/refusal.d.ts +82 -0
  462. package/dist/refusal.d.ts.map +1 -0
  463. package/dist/refusal.js +218 -0
  464. package/dist/refusal.js.map +1 -0
  465. package/dist/region-insets.d.ts +61 -0
  466. package/dist/region-insets.d.ts.map +1 -0
  467. package/dist/region-insets.js +67 -0
  468. package/dist/region-insets.js.map +1 -0
  469. package/dist/rive-core.d.ts +323 -0
  470. package/dist/rive-core.d.ts.map +1 -0
  471. package/dist/rive-core.js +677 -0
  472. package/dist/rive-core.js.map +1 -0
  473. package/dist/runner.d.ts +595 -0
  474. package/dist/runner.d.ts.map +1 -0
  475. package/dist/runner.js +4094 -0
  476. package/dist/runner.js.map +1 -0
  477. package/dist/scene/a11y.d.ts +11 -0
  478. package/dist/scene/a11y.d.ts.map +1 -0
  479. package/dist/scene/a11y.js +67 -0
  480. package/dist/scene/a11y.js.map +1 -0
  481. package/dist/scene/anim.d.ts +149 -0
  482. package/dist/scene/anim.d.ts.map +1 -0
  483. package/dist/scene/anim.js +396 -0
  484. package/dist/scene/anim.js.map +1 -0
  485. package/dist/scene/bind.d.ts +33 -0
  486. package/dist/scene/bind.d.ts.map +1 -0
  487. package/dist/scene/bind.js +66 -0
  488. package/dist/scene/bind.js.map +1 -0
  489. package/dist/scene/collide.d.ts +56 -0
  490. package/dist/scene/collide.d.ts.map +1 -0
  491. package/dist/scene/collide.js +146 -0
  492. package/dist/scene/collide.js.map +1 -0
  493. package/dist/scene/frame.d.ts +22 -0
  494. package/dist/scene/frame.d.ts.map +1 -0
  495. package/dist/scene/frame.js +57 -0
  496. package/dist/scene/frame.js.map +1 -0
  497. package/dist/scene/gltf.d.ts +79 -0
  498. package/dist/scene/gltf.d.ts.map +1 -0
  499. package/dist/scene/gltf.js +409 -0
  500. package/dist/scene/gltf.js.map +1 -0
  501. package/dist/scene/ir.d.ts +293 -0
  502. package/dist/scene/ir.d.ts.map +1 -0
  503. package/dist/scene/ir.js +692 -0
  504. package/dist/scene/ir.js.map +1 -0
  505. package/dist/scene/math.d.ts +50 -0
  506. package/dist/scene/math.d.ts.map +1 -0
  507. package/dist/scene/math.js +180 -0
  508. package/dist/scene/math.js.map +1 -0
  509. package/dist/scene/orbit.d.ts +19 -0
  510. package/dist/scene/orbit.d.ts.map +1 -0
  511. package/dist/scene/orbit.js +60 -0
  512. package/dist/scene/orbit.js.map +1 -0
  513. package/dist/scene/physics.d.ts +228 -0
  514. package/dist/scene/physics.d.ts.map +1 -0
  515. package/dist/scene/physics.js +1500 -0
  516. package/dist/scene/physics.js.map +1 -0
  517. package/dist/scene/registry.d.ts +85 -0
  518. package/dist/scene/registry.d.ts.map +1 -0
  519. package/dist/scene/registry.js +75 -0
  520. package/dist/scene/registry.js.map +1 -0
  521. package/dist/scene/skin.d.ts +82 -0
  522. package/dist/scene/skin.d.ts.map +1 -0
  523. package/dist/scene/skin.js +351 -0
  524. package/dist/scene/skin.js.map +1 -0
  525. package/dist/scene/sprite.d.ts +36 -0
  526. package/dist/scene/sprite.d.ts.map +1 -0
  527. package/dist/scene/sprite.js +107 -0
  528. package/dist/scene/sprite.js.map +1 -0
  529. package/dist/scene/viewer.d.ts +96 -0
  530. package/dist/scene/viewer.d.ts.map +1 -0
  531. package/dist/scene/viewer.js +235 -0
  532. package/dist/scene/viewer.js.map +1 -0
  533. package/dist/scoped-slots.d.ts +9 -0
  534. package/dist/scoped-slots.d.ts.map +1 -0
  535. package/dist/scoped-slots.js +42 -0
  536. package/dist/scoped-slots.js.map +1 -0
  537. package/dist/screen.d.ts +109 -0
  538. package/dist/screen.d.ts.map +1 -0
  539. package/dist/screen.js +309 -0
  540. package/dist/screen.js.map +1 -0
  541. package/dist/scroll.d.ts +525 -0
  542. package/dist/scroll.d.ts.map +1 -0
  543. package/dist/scroll.js +1226 -0
  544. package/dist/scroll.js.map +1 -0
  545. package/dist/settings-plane.d.ts +58 -0
  546. package/dist/settings-plane.d.ts.map +1 -0
  547. package/dist/settings-plane.js +86 -0
  548. package/dist/settings-plane.js.map +1 -0
  549. package/dist/share-inbox.d.ts +56 -0
  550. package/dist/share-inbox.d.ts.map +1 -0
  551. package/dist/share-inbox.js +114 -0
  552. package/dist/share-inbox.js.map +1 -0
  553. package/dist/shared-transition.d.ts +152 -0
  554. package/dist/shared-transition.d.ts.map +1 -0
  555. package/dist/shared-transition.js +257 -0
  556. package/dist/shared-transition.js.map +1 -0
  557. package/dist/sheet-content-padding.d.ts +24 -0
  558. package/dist/sheet-content-padding.d.ts.map +1 -0
  559. package/dist/sheet-content-padding.js +32 -0
  560. package/dist/sheet-content-padding.js.map +1 -0
  561. package/dist/shot-devices.d.ts +36 -0
  562. package/dist/shot-devices.d.ts.map +1 -0
  563. package/dist/shot-devices.js +90 -0
  564. package/dist/shot-devices.js.map +1 -0
  565. package/dist/shot-guards.d.ts +100 -0
  566. package/dist/shot-guards.d.ts.map +1 -0
  567. package/dist/shot-guards.js +260 -0
  568. package/dist/shot-guards.js.map +1 -0
  569. package/dist/shot-scope.d.ts +140 -0
  570. package/dist/shot-scope.d.ts.map +1 -0
  571. package/dist/shot-scope.js +302 -0
  572. package/dist/shot-scope.js.map +1 -0
  573. package/dist/slot-partition.d.ts +9 -0
  574. package/dist/slot-partition.d.ts.map +1 -0
  575. package/dist/slot-partition.js +38 -0
  576. package/dist/slot-partition.js.map +1 -0
  577. package/dist/snackbar.d.ts +165 -0
  578. package/dist/snackbar.d.ts.map +1 -0
  579. package/dist/snackbar.js +220 -0
  580. package/dist/snackbar.js.map +1 -0
  581. package/dist/socket.d.ts +96 -0
  582. package/dist/socket.d.ts.map +1 -0
  583. package/dist/socket.js +370 -0
  584. package/dist/socket.js.map +1 -0
  585. package/dist/spotlight.d.ts +77 -0
  586. package/dist/spotlight.d.ts.map +1 -0
  587. package/dist/spotlight.js +174 -0
  588. package/dist/spotlight.js.map +1 -0
  589. package/dist/state-primitive.d.ts +37 -0
  590. package/dist/state-primitive.d.ts.map +1 -0
  591. package/dist/state-primitive.js +91 -0
  592. package/dist/state-primitive.js.map +1 -0
  593. package/dist/store-query.d.ts +25 -0
  594. package/dist/store-query.d.ts.map +1 -0
  595. package/dist/store-query.js +88 -0
  596. package/dist/store-query.js.map +1 -0
  597. package/dist/store-value.d.ts +48 -0
  598. package/dist/store-value.d.ts.map +1 -0
  599. package/dist/store-value.js +264 -0
  600. package/dist/store-value.js.map +1 -0
  601. package/dist/store-versioning.d.ts +70 -0
  602. package/dist/store-versioning.d.ts.map +1 -0
  603. package/dist/store-versioning.js +188 -0
  604. package/dist/store-versioning.js.map +1 -0
  605. package/dist/store.d.ts +282 -0
  606. package/dist/store.d.ts.map +1 -0
  607. package/dist/store.js +1144 -0
  608. package/dist/store.js.map +1 -0
  609. package/dist/strings.d.ts +141 -0
  610. package/dist/strings.d.ts.map +1 -0
  611. package/dist/strings.js +581 -0
  612. package/dist/strings.js.map +1 -0
  613. package/dist/telemetry.d.ts +95 -0
  614. package/dist/telemetry.d.ts.map +1 -0
  615. package/dist/telemetry.js +255 -0
  616. package/dist/telemetry.js.map +1 -0
  617. package/dist/transform-core.d.ts +228 -0
  618. package/dist/transform-core.d.ts.map +1 -0
  619. package/dist/transform-core.js +921 -0
  620. package/dist/transform-core.js.map +1 -0
  621. package/dist/transition-core.d.ts +58 -0
  622. package/dist/transition-core.d.ts.map +1 -0
  623. package/dist/transition-core.js +352 -0
  624. package/dist/transition-core.js.map +1 -0
  625. package/dist/trim-trailing.d.ts +3 -0
  626. package/dist/trim-trailing.d.ts.map +1 -0
  627. package/dist/trim-trailing.js +14 -0
  628. package/dist/trim-trailing.js.map +1 -0
  629. package/dist/upload.d.ts +51 -0
  630. package/dist/upload.d.ts.map +1 -0
  631. package/dist/upload.js +68 -0
  632. package/dist/upload.js.map +1 -0
  633. package/dist/vendor-face.d.ts +44 -0
  634. package/dist/vendor-face.d.ts.map +1 -0
  635. package/dist/vendor-face.js +80 -0
  636. package/dist/vendor-face.js.map +1 -0
  637. package/dist/vendor-session.d.ts +166 -0
  638. package/dist/vendor-session.d.ts.map +1 -0
  639. package/dist/vendor-session.js +423 -0
  640. package/dist/vendor-session.js.map +1 -0
  641. package/dist/vendor-surface.d.ts +290 -0
  642. package/dist/vendor-surface.d.ts.map +1 -0
  643. package/dist/vendor-surface.js +439 -0
  644. package/dist/vendor-surface.js.map +1 -0
  645. package/dist/version-rules.generated.d.ts +17 -0
  646. package/dist/version-rules.generated.d.ts.map +1 -0
  647. package/dist/version-rules.generated.js +99 -0
  648. package/dist/version-rules.generated.js.map +1 -0
  649. package/dist/view-transition-core.d.ts +99 -0
  650. package/dist/view-transition-core.d.ts.map +1 -0
  651. package/dist/view-transition-core.js +127 -0
  652. package/dist/view-transition-core.js.map +1 -0
  653. package/dist/view-transition-door.d.ts +26 -0
  654. package/dist/view-transition-door.d.ts.map +1 -0
  655. package/dist/view-transition-door.js +88 -0
  656. package/dist/view-transition-door.js.map +1 -0
  657. package/dist/window-identity.d.ts +3 -0
  658. package/dist/window-identity.d.ts.map +1 -0
  659. package/dist/window-identity.js +27 -0
  660. package/dist/window-identity.js.map +1 -0
  661. package/package.json +141 -2
@@ -0,0 +1,1949 @@
1
+ //
2
+ // codegen.ts - JSE → real JS. The production executor (/web/07): each extracted JSE
3
+ // program compiles to a JS closure over an explicit scope object `$`. Operators compile
4
+ // to SEMANTIC HELPER calls (the SWIFT semantics, not raw JS operators); identifier
5
+ // reads go through `$.l(path)` (signal reads — dependency tracking is automatic).
6
+ //
7
+ // The same helper library is the native escalation executor's runtime (/web/15, /web/16)
8
+ // — one semantic table, every executor, corpus-gated. The grammar walked here is the
9
+ // token stream of the reference tokenizer, so interpreter and compiled paths cannot
10
+ // drift structurally: same tokens in, one dispatch shape.
11
+ //
12
+ // Sandbox contract (/web/07): emitted code references ONLY `$` — no window, no
13
+ // document, no globalThis. Unknown identifiers resolve through the scope object at
14
+ // runtime, exactly like the interpreter.
15
+ //
16
+ // Subset strictness (the W9 hardening, rendering-1.0-finalization.md): a body the
17
+ // tier screen classifies "js" REJECTS at compile time — `JSESubsetError`, thrown
18
+ // before the cache is touched — never a lossy emission. The eval conveniences stay
19
+ // fail-open at RUNTIME (Article 7): catch, warn one line, run null.
20
+ //
21
+ import { cachedTokens, delimiterError } from "../jse/tokens.js";
22
+ import { classifyBody } from "./tier.js";
23
+ import { JSE, JSESeams, JSE_NOT_COMPILED, Parser, captureScope, incrementTargetEnd, bumpNumbers, reportAwaitPosition, spreadValues, forInKeys, inOp, parseDeclarators, parseArrowParams, bindPattern, setInLocal, getInLocal, beginEvaluation, endEvaluation, evaluationStep, declareLocal, localsOf } from "../jse/jse.js";
24
+ import { JSECore, mutateURLSearchParams } from "../jse/core.js";
25
+ import { NSNull, isDict, isLambda, numberJS, string, truthy, jseEquals, jseStrictEquals, compare, arith, asArray, typeofString, index as indexOp, member as memberOp, isMissing, bitOp, bitNot, powOp, unwrapBraceExpression, } from "../jse/values.js";
26
+ // ── the runtime scope object compiled code closes over ──────────────────────────────
27
+ export class CompiledScope {
28
+ store;
29
+ item;
30
+ constructor(store, item) {
31
+ this.store = store;
32
+ this.item = item;
33
+ }
34
+ /** ident read (with the bare-ident constant fallback: Math.PI / Infinity / NaN …) */
35
+ l(path) {
36
+ return JSE.lookup(path, this.store, this.item) ?? JSECore.constant(path);
37
+ }
38
+ /** dotted method-split base read (NO constant fallback — the reference shape) */
39
+ lb(path) {
40
+ return JSE.lookup(path, this.store, this.item);
41
+ }
42
+ eq(a, b) { return jseEquals(a, b); }
43
+ /** `===` / `!==`: kind then value, no coercion (proposals/strict-equality.md). */
44
+ seq(a, b) { return jseStrictEquals(a, b); }
45
+ // AN AUTHOR `throw` IS A CARRIED VALUE, NEVER A BARE JAVASCRIPT ERROR (Appendix E item
46
+ // 5). The emitted code throws a JseThrow so an author's `catch` can tell its own refusal
47
+ // from a genuine runtime fault - a budget refusal, an internal bug - and re-throw what is
48
+ // not its own. The interpreter draws the same line with its `thrown` flag.
49
+ thrw(v) { return new JseThrow(v ?? NSNull); }
50
+ caught(e) { return e instanceof JseThrow; }
51
+ thrown(e) { return e instanceof JseThrow ? e.value : null; }
52
+ tr(v) { return truthy(v); }
53
+ cmp(a, b, o) { return compare(a, b, o); }
54
+ ar(a, b, o) { return arith(a, b, o); }
55
+ neg(v) { return -(numberJS(v) ?? NaN); }
56
+ ty(v) { return typeofString(v); }
57
+ ix(base, idx) { return indexOp(base, idx); }
58
+ mb(base, m) { return memberOp(base, m); }
59
+ /** destructuring default — applied only when the position is MISSING (JSE's one absent value) */
60
+ dflt(v, fallback) { return isMissing(v) ? fallback() : v; }
61
+ /** `const { a, ...rest }` — every own key the pattern did not name */
62
+ orest(base, taken) {
63
+ const out = {};
64
+ if (isDict(base))
65
+ for (const [k, v] of Object.entries(base))
66
+ if (!taken.includes(k))
67
+ out[k] = v;
68
+ return out;
69
+ }
70
+ /** `const [a, ...rest]` — the tail past the named positions */
71
+ arest(base, from) { return Array.isArray(base) ? base.slice(from) : []; }
72
+ /** dotted postfix member RUN (`arr[0].x.y` — "x.y" is one ident token): walk each segment */
73
+ mbp(base, path) {
74
+ let cur = base;
75
+ for (const seg of path.split("."))
76
+ cur = memberOp(cur, seg);
77
+ return cur;
78
+ }
79
+ /** expression-position `await`, which this compiler refuses, naming the position. `await` is a
80
+ * statement prefix and not an operator; the runner strips a statement leading one and routes
81
+ * the call to its asynchronous door, so an `await` the compiler meets is an interior one and
82
+ * this compiled closure is as synchronous as the interpreter it mirrors. The operand is not
83
+ * emitted at all, so a refused call cannot half happen, and an await in a ternary arm JS
84
+ * never takes never runs this, exactly as the interpreter's `skipping` parse files nothing. */
85
+ aw(word) { reportAwaitPosition(this.store, word); return null; }
86
+ /** A method call carries THIS CLOSURE'S store, because one method takes a lambda:
87
+ * `replace(pattern, fn)` (Appendix E item 9) calls it once per match, and a lambda with
88
+ * no store to run against is only its own source text. Every other arm ignores it. */
89
+ mc(m, base, args) { return JSE.applyMethod(m, base, args, this.store); }
90
+ ho(id, coll, fn, init, hasInit) {
91
+ return JSE.higherOrder(id, coll, isLambda(fn) ? fn : null, this.store, init, hasInit);
92
+ }
93
+ /** LAZY `a || b` / `a && b` / `a ?? b` / ternary: the right hand operand and the two
94
+ * ternary arms arrive as THUNKS and only the one JavaScript demands is called, which
95
+ * is the reference semantics the interpreter's lazy operand carries. */
96
+ or2(a, b) { return truthy(a) ? a : b(); }
97
+ and2(a, b) { return truthy(a) ? b() : a; }
98
+ nsh(a, b) { return isMissing(a) ? b() : a; }
99
+ tern(c, a, b) { return truthy(c) ? a() : b(); }
100
+ /** OPTIONAL CHAINING STOPS AT NULLISH: everything past a `?.` over a missing base is a
101
+ * thunk that never runs, so no argument or index past it evaluates. */
102
+ ochain(v, rest) { return isMissing(v) ? null : rest(v); }
103
+ bit(a, b, o) { return bitOp(a, b, o); }
104
+ bnot(v) { return bitNot(v); }
105
+ pw(a, b) { return powOp(a, b); }
106
+ pl(v) { return numberJS(v) ?? NaN; }
107
+ /** the JSE string coercion (template-literal parts concatenate through this) */
108
+ str(v) { return string(v); }
109
+ /** spread/for…of iterable coercion (array / string / Set / Map) */
110
+ spr(v) { return spreadValues(v); }
111
+ /** object-literal spread source — a dict merges, anything else contributes nothing */
112
+ spro(v) { return isDict(v) ? v : {}; }
113
+ /** JS `in` — dict key / array index membership */
114
+ ino(l, r) { return inOp(l, r); }
115
+ /** call dispatch: a scope value that IS a lambda first (JS shadowing), then the user
116
+ * function table, then the GLOBAL function library (a surface-local name shadows the
117
+ * global; all depth-capped), then the pure builtins. A scope lambda gets the caller's
118
+ * live scope as `base` (under its snapshot) so self-recursion resolves — the
119
+ * interpreter's named-call route exactly. */
120
+ call(name, args) {
121
+ const scopeFn = JSE.lookup(name, this.store, this.item);
122
+ const fromScope = isLambda(scopeFn);
123
+ const any = fromScope ? scopeFn : (this.store.functions.get(name) ?? JSE.globalFunction(name));
124
+ if (isLambda(any)) {
125
+ if (this.store.fnDepth >= 32)
126
+ return null;
127
+ this.store.fnDepth += 1;
128
+ const v = JSE.callLambda(any, args, this.store, fromScope ? this.item : null);
129
+ this.store.fnDepth -= 1;
130
+ return v;
131
+ }
132
+ return JSE.apply(name, args, this.store);
133
+ }
134
+ /** object-literal shorthand `{ id }` — the reference does a scope lookup */
135
+ sh(key) { return JSE.lookup(key, this.store, this.item) ?? NSNull; }
136
+ nul() { return NSNull; }
137
+ /** call-on-value (IIFE / indexed callee): a lambda base invokes under the shared
138
+ * 32-frame guard; anything else rides through UNCHANGED — the interpreter leaves the
139
+ * `( )` unconsumed on a non-lambda base, so the base IS the value there. */
140
+ /** optional call `o.f?.(…)` — a nullish or non-lambda callee answers null with the args
141
+ * UNEVALUATED (they arrive as a thunk); a lambda callee runs exactly as inv(). */
142
+ oinv(base, args) {
143
+ if (!isLambda(base))
144
+ return null;
145
+ return this.inv(base, args());
146
+ }
147
+ inv(base, args) {
148
+ if (!isLambda(base))
149
+ return base;
150
+ if (this.store.fnDepth >= 32)
151
+ return null;
152
+ this.store.fnDepth += 1;
153
+ const v = JSE.callLambda(base, args, this.store);
154
+ this.store.fnDepth -= 1;
155
+ return v;
156
+ }
157
+ /** create a lambda VALUE backed by a real JS closure (captures this scope's item).
158
+ * `defs` carries COMPILED param defaults by index — evaluated at CALL time in the
159
+ * callee scope when the arg is missing/null, exactly the interpreter contract. */
160
+ lam(params, body, defs = null) {
161
+ const captured = captureScope(this.item);
162
+ const store = this.store;
163
+ const lambda = {
164
+ __lambda: true,
165
+ params,
166
+ body: [],
167
+ block: false,
168
+ captured,
169
+ native: (args, base) => {
170
+ // base fills UNDER the captured snapshot (the callLambda contract) — capture
171
+ // semantics hold, and a stored lambda's own name resolves for self-recursion
172
+ const scope = base ? { ...base } : {};
173
+ Object.assign(scope, captured);
174
+ // THE LEDGER IS REBUILT, EXACTLY AS THE INTERPRETER'S `callLambda` REBUILDS IT
175
+ // (S3 cut). A parameter, a captured name and the enclosing block's declarations are
176
+ // all block locals, and after the cut a bare identifier reads the ledger and nothing
177
+ // else - so a compiled lambda whose params were merely PRESENT in the scope dict read
178
+ // null for every one of them, and `xs.map(x => x * 2)` answered 0,0,0 with the
179
+ // interpreter answering 2,4,6. The two lanes agree because they declare the same
180
+ // names; the spread and the Object.assign above do not carry a non-enumerable ledger.
181
+ if (base !== null)
182
+ for (const n of scopeLocalNamesOf(base))
183
+ declareLocal(scope, n);
184
+ for (const n of Object.keys(captured))
185
+ declareLocal(scope, n);
186
+ params.forEach((p, k) => {
187
+ if (p.rest === true && p.name !== null) {
188
+ // rest binds the REMAINING args as an array (empty when none)
189
+ scope[p.name] = k < args.length ? args.slice(k).map((x) => x ?? NSNull) : [];
190
+ declareLocal(scope, p.name);
191
+ return;
192
+ }
193
+ const a = k < args.length ? args[k] : null;
194
+ if (p.name !== null) {
195
+ const dv = defs !== null && k < defs.length ? defs[k] : null;
196
+ declareLocal(scope, p.name);
197
+ if (isMissing(a) && dv !== null && dv !== undefined) {
198
+ scope[p.name] = dv(new CompiledScope(store, scope)) ?? NSNull;
199
+ }
200
+ else {
201
+ scope[p.name] = a ?? NSNull;
202
+ }
203
+ }
204
+ else if (p.pattern !== undefined) {
205
+ bindPattern(p.pattern, a, (n, v) => { scope[n] = v ?? NSNull; declareLocal(scope, n); }, (toks) => new Parser(toks, store, scope).expression());
206
+ }
207
+ else {
208
+ const d = isDict(a) ? a : {};
209
+ for (const key of p.keys) {
210
+ scope[key] = d[key] ?? NSNull;
211
+ declareLocal(scope, key);
212
+ }
213
+ }
214
+ });
215
+ return body(new CompiledScope(store, scope));
216
+ },
217
+ };
218
+ return lambda;
219
+ }
220
+ /** One loop iteration on the EVALUATION ledger, the interpreter's loopStep exactly:
221
+ * false stops the loop, and the door answers null for the whole evaluation. */
222
+ step() { return evaluationStep(this.store); }
223
+ /** EXPRESSION-POSITION INCREMENT in a pure expression (JSE-VS-JS item 11): the value, no
224
+ * write (an expression never mutates; the interpreter's Parser with no `bump` hook). */
225
+ inc(_name, _parts, op, prefix, read) {
226
+ const n = bumpNumbers(read(), op);
227
+ return prefix ? n.next : n.old;
228
+ }
229
+ /** a child scope for compiled blocks (locals dict layered over this item). */
230
+ // A CHILD BLOCK KEEPS THE ENCLOSING BLOCK'S LEDGER (S3 cut). The copy is a copy of the
231
+ // dict, never of the names it declared: a `{ }` body that lost them would read every one of
232
+ // its own enclosing locals as a bare reach, which is null.
233
+ block() {
234
+ const child = { ...(this.item ?? {}) };
235
+ if (this.item !== null)
236
+ for (const n of scopeLocalNamesOf(this.item))
237
+ declareLocal(child, n);
238
+ return new BlockScope(this.store, child);
239
+ }
240
+ arrayFrom(args) {
241
+ return JSE.apply("Array.from", args, this.store);
242
+ }
243
+ }
244
+ /** compiled-block scope: locals live in the item dict (the interpreter's JSEval shape). */
245
+ export class BlockScope extends CompiledScope {
246
+ locals;
247
+ constructor(store, locals) {
248
+ super(store, locals);
249
+ this.locals = locals;
250
+ }
251
+ // A BLOCK'S `const`/`let`/binder DECLARES (S3 cut). `set` is the one door a compiled block
252
+ // writes a local through, so it is the one place that has to mark it: after the cut a bare
253
+ // identifier reads the authored ledger and nothing else, and a name only PRESENT in the
254
+ // dict is a row field or a payload key, not a local. The interpreter's JSEval declares at
255
+ // the same three binders.
256
+ set(name, v) { this.locals[name] = v ?? NSNull; declareLocal(this.locals, name); }
257
+ /** `name(parts) ??= / ||= / &&= rhs` as a statement: written only when the value asks. */
258
+ plog(name, parts, op, rhs) {
259
+ const base = Object.prototype.hasOwnProperty.call(this.locals, name) ? this.locals[name] : this.l(name);
260
+ const now = getInLocal(base, parts);
261
+ if (!(op === "??" ? isMissing(now) : op === "||" ? !truthy(now) : truthy(now)))
262
+ return;
263
+ const v = rhs() ?? NSNull;
264
+ declareLocal(this.locals, name);
265
+ this.locals[name] = parts.length === 0 ? v : setInLocal(base, parts, v);
266
+ }
267
+ /** `u.searchParams.<verb>(args)` as a statement: the url rebuilt with its query, written back. */
268
+ pparams(name, parts, verb, args) {
269
+ const base = Object.prototype.hasOwnProperty.call(this.locals, name) ? this.locals[name] : this.l(name);
270
+ const next = mutateURLSearchParams(getInLocal(base, parts), verb, args);
271
+ if (next === null)
272
+ return;
273
+ declareLocal(this.locals, name);
274
+ this.locals[name] = parts.length === 0 ? next : setInLocal(base, parts, next);
275
+ }
276
+ /** The block's expression-position increment: the interpreter's `exprBump` exactly, the
277
+ * statement form's path law and its namespace refusal (a namespace is read, not written). */
278
+ inc(name, parts, op, prefix, read) {
279
+ if (name.length === 0 || name === "dsx" || name === "global" || name === "route"
280
+ || name === "nav" || name === "cookie" || name === "module")
281
+ return super.inc(name, parts, op, prefix, read);
282
+ const base = Object.prototype.hasOwnProperty.call(this.locals, name) ? this.locals[name] : this.l(name);
283
+ const n = bumpNumbers(getInLocal(base, parts), op);
284
+ declareLocal(this.locals, name);
285
+ this.locals[name] = parts.length === 0 ? n.next : setInLocal(base, parts, n.next);
286
+ return prefix ? n.next : n.old;
287
+ }
288
+ }
289
+ // ── the compiling parser (mirror of the interpreter's Parser, emitting JS source) ────
290
+ const higherOrderFns = JSE.higherOrderFns;
291
+ const methodFns = JSE.methodFns;
292
+ const dsxLibCall = JSE.dsxLibCall;
293
+ // Every author string reaches the emitted source as a JSON literal, and the characters that
294
+ // could end a host <script> or a line in a pre-ES2019 parser are \u escaped as well. Inside a
295
+ // string literal the escape is the same value, so the compiled closure is unchanged.
296
+ function jsLiteral(v) {
297
+ return JSON.stringify(v).replace(/[<>/\u2028\u2029]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
298
+ }
299
+ function q(s) { return jsLiteral(s); }
300
+ class Codegen {
301
+ pos = 0;
302
+ depth = 0; // expression-nesting budget — mirrors the interpreter Parser
303
+ // THE POSITION THIS COMPILE IS IN, mirroring the interpreter Parser's `awaitPos`: the five
304
+ // constructs that hold a sub expression name themselves around it, so the refusal the
305
+ // emitted `$.aw` files names the INNERMOST one.
306
+ awaitPos = "an expression";
307
+ chainId = 0; // unique parameter names for the optional-chaining guard thunks
308
+ tokens;
309
+ constructor(tokens) {
310
+ this.tokens = tokens;
311
+ }
312
+ peek() { return this.pos < this.tokens.length ? this.tokens[this.pos] : null; }
313
+ advance() { this.pos += 1; }
314
+ op(s) { const t = this.peek(); return t !== null && t.kind === "op" && t.v === s; }
315
+ anyOp(list) {
316
+ const t = this.peek();
317
+ return t !== null && t.kind === "op" && list.includes(t.v) ? t.v : null;
318
+ }
319
+ expression() {
320
+ // a leading `;` is statement residue (a stripped comment's newline) — skip it
321
+ while (this.op(";"))
322
+ this.advance();
323
+ // recursion budget — same 200 cap as the interpreter; past it emit null (total)
324
+ if (this.depth >= 200)
325
+ return "null";
326
+ this.depth += 1;
327
+ const v = this.ternary();
328
+ this.depth -= 1;
329
+ return v;
330
+ }
331
+ /** Compile one sub expression UNDER A POSITION NAME, restoring the enclosing name after. */
332
+ positioned(word, compile) {
333
+ const prev = this.awaitPos;
334
+ this.awaitPos = word;
335
+ try {
336
+ return compile();
337
+ }
338
+ finally {
339
+ this.awaitPos = prev;
340
+ }
341
+ }
342
+ ternary() {
343
+ const cond = this.nullish();
344
+ if (!this.op("?"))
345
+ return cond;
346
+ this.advance();
347
+ return this.positioned("a ternary branch", () => {
348
+ const a = this.expression();
349
+ if (this.op(":"))
350
+ this.advance();
351
+ const b = this.expression();
352
+ return `$.tern(${cond}, () => ${a}, () => ${b})`;
353
+ });
354
+ }
355
+ nullish() {
356
+ let l = this.logicalOr();
357
+ while (this.op("??")) {
358
+ this.advance();
359
+ const r = this.logicalOr();
360
+ l = `$.nsh(${l}, () => ${r})`;
361
+ }
362
+ return l;
363
+ }
364
+ logicalOr() {
365
+ let l = this.logicalAnd();
366
+ while (this.op("||")) {
367
+ this.advance();
368
+ const r = this.logicalAnd();
369
+ l = `$.or2(${l}, () => ${r})`;
370
+ }
371
+ return l;
372
+ }
373
+ logicalAnd() {
374
+ let l = this.bitOr();
375
+ while (this.op("&&")) {
376
+ this.advance();
377
+ const r = this.bitOr();
378
+ l = `$.and2(${l}, () => ${r})`;
379
+ }
380
+ return l;
381
+ }
382
+ bitOr() {
383
+ let l = this.bitXor();
384
+ while (this.op("|")) {
385
+ this.advance();
386
+ l = `$.bit(${l}, ${this.bitXor()}, "|")`;
387
+ }
388
+ return l;
389
+ }
390
+ bitXor() {
391
+ let l = this.bitAnd();
392
+ while (this.op("^")) {
393
+ this.advance();
394
+ l = `$.bit(${l}, ${this.bitAnd()}, "^")`;
395
+ }
396
+ return l;
397
+ }
398
+ bitAnd() {
399
+ let l = this.equality();
400
+ while (this.op("&")) {
401
+ this.advance();
402
+ l = `$.bit(${l}, ${this.equality()}, "&")`;
403
+ }
404
+ return l;
405
+ }
406
+ equality() {
407
+ let l = this.comparison();
408
+ for (;;) {
409
+ const o = this.anyOp(["===", "!==", "==", "!="]);
410
+ if (o === null)
411
+ break;
412
+ this.advance();
413
+ const r = this.comparison();
414
+ const fn = o.length === 3 ? "seq" : "eq";
415
+ l = o.startsWith("!") ? `!$.${fn}(${l}, ${r})` : `$.${fn}(${l}, ${r})`;
416
+ }
417
+ return l;
418
+ }
419
+ comparison() {
420
+ let l = this.shift();
421
+ for (;;) {
422
+ const o = this.anyOp(["<", "<=", ">", ">="]);
423
+ if (o !== null) {
424
+ this.advance();
425
+ l = `$.cmp(${l}, ${this.shift()}, ${q(o)})`;
426
+ continue;
427
+ }
428
+ const t = this.peek();
429
+ if (t !== null && t.kind === "ident" && t.v === "in") { // JS `in` — relational level
430
+ this.advance();
431
+ l = `$.ino(${l}, ${this.shift()})`;
432
+ continue;
433
+ }
434
+ break;
435
+ }
436
+ return l;
437
+ }
438
+ shift() {
439
+ let l = this.additive();
440
+ for (;;) {
441
+ const o = this.anyOp(["<<", ">>", ">>>"]);
442
+ if (o === null)
443
+ break;
444
+ this.advance();
445
+ l = `$.bit(${l}, ${this.additive()}, ${q(o)})`;
446
+ }
447
+ return l;
448
+ }
449
+ additive() {
450
+ let l = this.multiplicative();
451
+ for (;;) {
452
+ const o = this.anyOp(["+", "-"]);
453
+ if (o === null)
454
+ break;
455
+ this.advance();
456
+ l = `$.ar(${l}, ${this.multiplicative()}, ${q(o)})`;
457
+ }
458
+ return l;
459
+ }
460
+ multiplicative() {
461
+ let l = this.power();
462
+ for (;;) {
463
+ const o = this.anyOp(["*", "/", "%"]);
464
+ if (o === null)
465
+ break;
466
+ this.advance();
467
+ l = `$.ar(${l}, ${this.power()}, ${q(o)})`;
468
+ }
469
+ return l;
470
+ }
471
+ power() {
472
+ const l = this.unary();
473
+ if (!this.op("**"))
474
+ return l;
475
+ this.advance();
476
+ return `$.pw(${l}, ${this.power()})`; // right-associative
477
+ }
478
+ unary() {
479
+ if (this.op("!")) {
480
+ this.advance();
481
+ return `!$.tr(${this.unary()})`;
482
+ }
483
+ if (this.op("-")) {
484
+ this.advance();
485
+ return `$.neg(${this.unary()})`;
486
+ }
487
+ if (this.op("+")) {
488
+ this.advance();
489
+ return `$.pl(${this.unary()})`;
490
+ }
491
+ if (this.op("~")) {
492
+ this.advance();
493
+ return `$.bnot(${this.unary()})`;
494
+ }
495
+ const t = this.peek();
496
+ if (t !== null && t.kind === "ident" && t.v === "typeof") {
497
+ this.advance();
498
+ return `$.ty(${this.unary()})`;
499
+ }
500
+ // EXPRESSION-POSITION INCREMENT (JSE-VS-JS item 11), the interpreter Parser's twin.
501
+ const pre = this.anyOp(["++", "--"]);
502
+ if (pre !== null) {
503
+ const end = incrementTargetEnd(this.tokens, this.pos + 1);
504
+ if (end > 0) {
505
+ const target = this.tokens.slice(this.pos + 1, end);
506
+ this.pos = end;
507
+ return this.increment(target, pre, true);
508
+ }
509
+ }
510
+ if (t !== null && t.kind === "ident") {
511
+ const end = incrementTargetEnd(this.tokens, this.pos);
512
+ const after = end > 0 ? this.tokens[end] : undefined;
513
+ if (after !== undefined && after.kind === "op" && (after.v === "++" || after.v === "--")) {
514
+ const target = this.tokens.slice(this.pos, end);
515
+ this.pos = end + 1;
516
+ return this.increment(target, after.v, false);
517
+ }
518
+ }
519
+ return this.primary();
520
+ }
521
+ /** `$.inc(name, parts, op, prefix, read)`: the path the statement form's `mutationCg` walks. */
522
+ increment(target, op, prefix) {
523
+ const head = target[0].v.split(".");
524
+ const segs = head.slice(1).map((p) => q(p));
525
+ let j = 1;
526
+ while (j < target.length) {
527
+ const a = target[j];
528
+ if (a.kind === "op" && a.v === ".") {
529
+ for (const part of target[j + 1].v.split("."))
530
+ segs.push(q(part));
531
+ j += 2;
532
+ continue;
533
+ }
534
+ let d = 1;
535
+ let k = j + 1;
536
+ const inner = [];
537
+ while (k < target.length) {
538
+ const tk = target[k];
539
+ if (tk.kind === "op" && (tk.v === "[" || tk.v === "(" || tk.v === "{"))
540
+ d += 1;
541
+ if (tk.kind === "op" && (tk.v === "]" || tk.v === ")" || tk.v === "}")) {
542
+ d -= 1;
543
+ if (d === 0)
544
+ break;
545
+ }
546
+ inner.push(tk);
547
+ k += 1;
548
+ }
549
+ segs.push(`(${compileExprTokens(inner)})`);
550
+ j = k + 1;
551
+ }
552
+ return `$.inc(${q(head[0])}, [${segs.join(", ")}], ${q(op)}, ${prefix}, () => ${compileExprTokens(target)})`;
553
+ }
554
+ primary() {
555
+ let base = this.primaryBase();
556
+ // OPTIONAL CHAINING STOPS AT NULLISH (JS). Each `?.` guards the REST of the chain,
557
+ // which compiles into a thunk over the tested value, so nothing past a missing base
558
+ // evaluates. Folded outermost-first once the chain ends.
559
+ const guards = [];
560
+ for (;;) {
561
+ if (this.op("[")) {
562
+ this.advance();
563
+ const idx = this.expression();
564
+ if (this.op("]"))
565
+ this.advance();
566
+ base = `$.ix(${base}, ${idx})`;
567
+ }
568
+ else if (this.op(".") || this.op("?.")) {
569
+ const optional = this.op("?.");
570
+ this.advance();
571
+ if (optional) {
572
+ const param = `$o${this.chainId}`;
573
+ this.chainId += 1;
574
+ guards.push({ guard: base, param });
575
+ base = param;
576
+ }
577
+ if (optional && this.op("(")) {
578
+ // optional call — args compile into a THUNK so a nullish callee never
579
+ // evaluates them (the JS rule the interpreter's skipBalanced enforces)
580
+ this.advance();
581
+ const args = this.argList();
582
+ base = `$.oinv(${base}, () => [${args.join(", ")}])`;
583
+ continue;
584
+ }
585
+ if (optional && this.op("[")) {
586
+ this.advance();
587
+ const idx = this.expression();
588
+ if (this.op("]"))
589
+ this.advance();
590
+ base = `$.ix(${base}, ${idx})`;
591
+ continue;
592
+ }
593
+ const mt = this.peek();
594
+ if (mt === null || mt.kind !== "ident")
595
+ break;
596
+ let m = mt.v;
597
+ this.advance();
598
+ if (this.op("(")) {
599
+ // dotted run before the call — walk the leading segments, dispatch on the last
600
+ if (m.includes(".")) {
601
+ const dot = m.lastIndexOf(".");
602
+ base = `$.mbp(${base}, ${q(m.substring(0, dot))})`;
603
+ m = m.substring(dot + 1);
604
+ }
605
+ this.advance();
606
+ if (higherOrderFns.has(m)) {
607
+ let fn = "null", initVal = "null", hasInit = false;
608
+ if (!this.op(")")) {
609
+ fn = this.expression();
610
+ if (this.op(",")) {
611
+ this.advance();
612
+ initVal = this.expression();
613
+ hasInit = true;
614
+ }
615
+ }
616
+ if (this.op(")"))
617
+ this.advance();
618
+ base = `$.ho(${q(m)}, ${base}, ${fn}, ${initVal}, ${hasInit})`;
619
+ }
620
+ else {
621
+ const args = this.argList();
622
+ base = `$.mc(${q(m)}, ${base}, [${args.join(", ")}])`;
623
+ }
624
+ }
625
+ else if (m.includes(".")) {
626
+ base = `$.mbp(${base}, ${q(m)})`; // dotted postfix run — walk each segment
627
+ }
628
+ else {
629
+ base = `$.mb(${base}, ${q(m)})`;
630
+ }
631
+ }
632
+ else if (this.op("(")) {
633
+ // call-on-value: `((x) => x + 1)(4)` / `fs[1](5)` — $.inv does the isLambda
634
+ // check at runtime (a non-lambda base rides through unchanged, mirroring the
635
+ // interpreter's no-consume) + the guarded callLambda.
636
+ this.advance();
637
+ const args = this.argList();
638
+ base = `$.inv(${base}, [${args.join(", ")}])`;
639
+ }
640
+ else
641
+ break;
642
+ }
643
+ for (let g = guards.length - 1; g >= 0; g -= 1) {
644
+ base = `$.ochain(${guards[g].guard}, (${guards[g].param}) => ${base})`;
645
+ }
646
+ return base;
647
+ }
648
+ argList() {
649
+ const args = [];
650
+ if (!this.op(")")) {
651
+ this.pushArgCode(args);
652
+ while (this.op(",")) {
653
+ this.advance();
654
+ this.pushArgCode(args);
655
+ }
656
+ }
657
+ if (this.op(")"))
658
+ this.advance();
659
+ return args;
660
+ }
661
+ /** one call argument — `...expr` splices the coerced iterable (call-position spread) */
662
+ pushArgCode(args) {
663
+ this.positioned("a call argument", () => {
664
+ if (this.op("...")) {
665
+ this.advance();
666
+ args.push(`...$.spr(${this.expression()})`);
667
+ }
668
+ else
669
+ args.push(this.expression());
670
+ });
671
+ }
672
+ primaryBase() {
673
+ const t = this.peek();
674
+ if (t === null)
675
+ return "null";
676
+ if (t.kind === "num") {
677
+ this.advance();
678
+ if (Number.isFinite(t.v))
679
+ return String(t.v);
680
+ // non-finite literals survive as themselves (`1e999` is Infinity on BOTH executors)
681
+ return Number.isNaN(t.v) ? "(0/0)" : t.v > 0 ? "(1/0)" : "(-1/0)";
682
+ }
683
+ if (t.kind === "str") {
684
+ this.advance();
685
+ return q(t.v);
686
+ }
687
+ if (t.kind === "regex") {
688
+ this.advance();
689
+ return `({ __regex: true, source: ${q(t.pattern)}, flags: ${q(t.flags)} })`;
690
+ }
691
+ if (t.kind === "template") {
692
+ // parts string-coerce and CONCATENATE (never the numeric-first `+`)
693
+ this.advance();
694
+ const pieces = t.parts.map((part) => "s" in part ? q(part.s) : `$.str(${compileExprTokens(part.toks, "a template hole")})`);
695
+ return pieces.length === 0 ? `""` : `(${pieces.join(" + ")})`;
696
+ }
697
+ if (t.kind === "ident") {
698
+ const id = t.v;
699
+ this.advance();
700
+ if (id === "new")
701
+ return this.primaryBase();
702
+ // `await` REFUSES HERE TOO, at the position the compile is in (interpreter parity: see
703
+ // the same arm in jse.ts primaryBase). The operand is PARSED, to keep the token stream in
704
+ // step, and DISCARDED rather than emitted, so nothing it names runs.
705
+ if (id === "await") {
706
+ const word = this.awaitPos;
707
+ this.primaryBase();
708
+ return `$.aw(${q(word)})`;
709
+ }
710
+ if (this.op("=>")) {
711
+ this.advance();
712
+ return this.arrowBody([{ name: id, keys: [] }]);
713
+ }
714
+ if (this.op("(")) {
715
+ if (id === "Object.groupBy" || id === "Array.from") {
716
+ this.advance();
717
+ const args = this.argList();
718
+ if (id === "Object.groupBy") {
719
+ return `$.ho("groupBy", ${args[0] ?? "null"}, ${args[1] ?? "null"}, null, false)`;
720
+ }
721
+ return `$.arrayFrom([${args.join(", ")}])`;
722
+ }
723
+ const dot = id.lastIndexOf(".");
724
+ // A `dsx.` LIBRARY NAME IS WHOLE (dispatch.ts dsxLibCall), exactly as it is in the
725
+ // interpreter's primaryBase. `dsx.bytes.slice(b, 0, 3)` ends in a word that is also
726
+ // a method name, and without this guard the closure compiled
727
+ // `$.mc("slice", $.lb("dsx.bytes"), ...)` and sliced the typed absence: measured
728
+ // before it, the interpreter answered [2,3] and the compiled closure answered [].
729
+ // A NAMESPACE CONSTANT IS A VALUE (logic parity sweep 5, the interpreter's
730
+ // `constantBase`): `Math.PI.toFixed(4)` is `toFixed` on the constant.
731
+ const constantBase = dot >= 0 && typeof JSECore.constant(id.substring(0, dot)) === "number";
732
+ if (dot >= 0 && (constantBase || !JSECore.handles(id)) && !dsxLibCall.test(id)) { // a JSECore STATIC is never a <base>.method()
733
+ const method = id.substring(dot + 1);
734
+ if (higherOrderFns.has(method) || methodFns.has(method)) {
735
+ const baseCode = constantBase ? `$.l(${q(id.substring(0, dot))})` : `$.lb(${q(id.substring(0, dot))})`;
736
+ this.advance();
737
+ if (higherOrderFns.has(method)) {
738
+ let fn = "null", initVal = "null", hasInit = false;
739
+ if (!this.op(")")) {
740
+ fn = this.expression();
741
+ if (this.op(",")) {
742
+ this.advance();
743
+ initVal = this.expression();
744
+ hasInit = true;
745
+ }
746
+ }
747
+ if (this.op(")"))
748
+ this.advance();
749
+ return `$.ho(${q(method)}, ${baseCode}, ${fn}, ${initVal}, ${hasInit})`;
750
+ }
751
+ const args = this.argList();
752
+ return `$.mc(${q(method)}, ${baseCode}, [${args.join(", ")}])`;
753
+ }
754
+ }
755
+ if (higherOrderFns.has(id)) {
756
+ this.advance();
757
+ const coll = this.expression();
758
+ let fn = "null", initVal = "null", hasInit = false;
759
+ if (this.op(",")) {
760
+ this.advance();
761
+ fn = this.expression();
762
+ }
763
+ if (this.op(",")) {
764
+ this.advance();
765
+ initVal = this.expression();
766
+ hasInit = true;
767
+ }
768
+ if (this.op(")"))
769
+ this.advance();
770
+ return `$.ho(${q(id)}, ${coll}, ${fn}, ${initVal}, ${hasInit})`;
771
+ }
772
+ // user function OR builtin — runtime dispatch mirrors the interpreter's order
773
+ this.advance();
774
+ const args = this.argList();
775
+ return `$.call(${q(id)}, [${args.join(", ")}])`;
776
+ }
777
+ switch (id) {
778
+ case "true": return "true";
779
+ case "false": return "false";
780
+ case "null":
781
+ case "nil":
782
+ case "undefined": return "null";
783
+ default: return `$.l(${q(id)})`;
784
+ }
785
+ }
786
+ // op
787
+ if (t.v === "[") {
788
+ this.advance();
789
+ const parts = [];
790
+ while (this.peek() !== null && !this.op("]")) {
791
+ if (this.op("...")) {
792
+ this.advance();
793
+ parts.push(`...$.spr(${this.positioned("an array element", () => this.expression())})`); // spread splices the coerced iterable
794
+ }
795
+ else {
796
+ parts.push(`(${this.positioned("an array element", () => this.expression())} ?? $.nul())`);
797
+ }
798
+ if (this.op(","))
799
+ this.advance();
800
+ }
801
+ if (this.op("]"))
802
+ this.advance();
803
+ return `[${parts.join(", ")}]`;
804
+ }
805
+ if (t.v === "{") {
806
+ this.advance();
807
+ const parts = [];
808
+ while (this.peek() !== null && !this.op("}")) {
809
+ if (this.op("...")) {
810
+ this.advance();
811
+ parts.push(`...$.spro(${this.expression()})`); // dict spread merges, last-wins
812
+ if (this.op(","))
813
+ this.advance();
814
+ continue;
815
+ }
816
+ if (this.op("[")) { // computed key `{ [expr]: v }` — the interpreter's twin
817
+ this.advance();
818
+ const keyExpr = this.expression();
819
+ if (this.op("]"))
820
+ this.advance();
821
+ if (this.op(":")) {
822
+ this.advance();
823
+ parts.push(`[$.str(${keyExpr})]: (${this.positioned("an object literal value", () => this.expression())} ?? $.nul())`);
824
+ }
825
+ else
826
+ parts.push(`[$.str(${keyExpr})]: $.nul()`);
827
+ if (this.op(","))
828
+ this.advance();
829
+ continue;
830
+ }
831
+ const kt = this.peek();
832
+ let key;
833
+ if (kt !== null && (kt.kind === "ident" || kt.kind === "str" || kt.kind === "num")) {
834
+ key = String(kt.v);
835
+ this.advance();
836
+ }
837
+ else {
838
+ this.advance();
839
+ continue;
840
+ }
841
+ if (this.op(":")) {
842
+ this.advance();
843
+ parts.push(`${q(key)}: (${this.positioned("an object literal value", () => this.expression())} ?? $.nul())`);
844
+ }
845
+ else
846
+ parts.push(`${q(key)}: $.sh(${q(key)})`); // { id } shorthand
847
+ if (this.op(","))
848
+ this.advance();
849
+ }
850
+ if (this.op("}"))
851
+ this.advance();
852
+ return `({ ${parts.join(", ")} })`;
853
+ }
854
+ if (t.v === "(") {
855
+ const lam = this.tryArrow();
856
+ if (lam !== null)
857
+ return lam;
858
+ this.advance();
859
+ const v = this.expression();
860
+ if (this.op(")"))
861
+ this.advance();
862
+ return `(${v})`;
863
+ }
864
+ this.advance();
865
+ return "null";
866
+ }
867
+ tryArrow() {
868
+ let d = 0;
869
+ let j = this.pos;
870
+ while (j < this.tokens.length) {
871
+ const tk = this.tokens[j];
872
+ if (tk.kind === "op" && tk.v === "(")
873
+ d += 1;
874
+ else if (tk.kind === "op" && tk.v === ")") {
875
+ d -= 1;
876
+ if (d === 0)
877
+ break;
878
+ }
879
+ j += 1;
880
+ }
881
+ const after = j + 1 < this.tokens.length ? this.tokens[j + 1] : null;
882
+ if (!(after !== null && after.kind === "op" && after.v === "=>"))
883
+ return null;
884
+ this.advance(); // '('
885
+ // THE ONE scanner (jse.ts parseArrowParams) — the interpreter reads the same shapes from
886
+ // the same code, so this tier cannot fall behind it the way it did when destructured
887
+ // params landed.
888
+ const scan = parseArrowParams(this.tokens, this.pos);
889
+ this.pos = scan.next;
890
+ const params = scan.params;
891
+ const defCodes = scan.defaults.map((def) => (def === null ? null : `($) => ${compileExprTokens(def)}`));
892
+ if (this.op("=>"))
893
+ this.advance();
894
+ return this.arrowBody(params, defCodes);
895
+ }
896
+ arrowBody(params, defCodes = []) {
897
+ const paramsJson = jsLiteral(params);
898
+ // the defaults ride as a THIRD $.lam arg — an index-aligned array of compiled
899
+ // closures (tokens would not survive the JSON param serialization)
900
+ const defsArg = defCodes.some((c) => c !== null)
901
+ ? `, [${defCodes.map((c) => c ?? "null").join(", ")}]`
902
+ : "";
903
+ if (this.op("{")) {
904
+ this.advance();
905
+ const body = [];
906
+ let d = 1;
907
+ for (;;) {
908
+ const tk = this.peek();
909
+ if (tk === null)
910
+ break;
911
+ if (tk.kind === "op" && tk.v === "{")
912
+ d += 1;
913
+ else if (tk.kind === "op" && tk.v === "}") {
914
+ d -= 1;
915
+ if (d === 0) {
916
+ this.advance();
917
+ break;
918
+ }
919
+ }
920
+ body.push(tk);
921
+ this.advance();
922
+ }
923
+ const blockCode = compileBlockTokens(body);
924
+ return `$.lam(${paramsJson}, ($) => ${blockCode}${defsArg})`;
925
+ }
926
+ const body = [];
927
+ let d = 0;
928
+ for (;;) {
929
+ const tk = this.peek();
930
+ if (tk === null)
931
+ break;
932
+ if (tk.kind === "op") {
933
+ const o = tk.v;
934
+ if (o === "(" || o === "[" || o === "{")
935
+ d += 1;
936
+ else if (o === ")" || o === "]" || o === "}") {
937
+ if (d === 0)
938
+ break;
939
+ d -= 1;
940
+ }
941
+ else if (d === 0 && o === ",")
942
+ break;
943
+ }
944
+ body.push(tk);
945
+ this.advance();
946
+ }
947
+ const g = new Codegen(body);
948
+ return `$.lam(${paramsJson}, ($) => ${g.expression()}${defsArg})`;
949
+ }
950
+ }
951
+ /** The ledger of a scope dict, as an iterable that is empty when there is none. The compiled
952
+ * lane rebuilds it at every scope it creates, the same way the interpreter does. */
953
+ function scopeLocalNamesOf(scope) {
954
+ return localsOf(scope) ?? [];
955
+ }
956
+ // ── block compilation (the bounded-JS statement grammar → real JS) ───────────────────
957
+ /** Compile a `{ }` statement body to an IIFE-shaped JS expression evaluated against a
958
+ * child BlockScope. Locals live in the scope dict (dynamic lookup parity). */
959
+ function compileBlockTokens(tokens) {
960
+ const b = new BlockCompiler(tokens);
961
+ const stmts = b.compileAll();
962
+ return `(($b) => { const $ = $b; ${stmts} return $b.__r; })($.block())`;
963
+ }
964
+ // -- BLOCK CONTROL, compiled tier -- the same optional fold as the interpreter's -----
965
+ // (__DSX_OPTIONAL_BLOCK_CONTROL__, jse.ts): `switch`, `try`/`catch`/`finally` and
966
+ // `throw` in an expression block. This lane emits real JavaScript, so the try and the
967
+ // finally are JavaScript's own; only two things need help. A `throw` carries its value in
968
+ // a JseThrow so a `catch` can tell an author's refusal from a genuine fault. And a
969
+ // `switch` cannot be JavaScript's, because JavaScript's compares with `===` and this
970
+ // language compares with its own `==`: the emission resolves the matching clause index
971
+ // first and then runs every clause from it, which is exactly fall through.
972
+ function throwStmtCg(b) {
973
+ b.i += 1; // 'throw'
974
+ const toks = b.capture(new Set([";"]));
975
+ if (b.isOp(";"))
976
+ b.i += 1;
977
+ return `throw $.thrw(${toks.length === 0 ? "null" : compileExprTokens(toks)});`;
978
+ }
979
+ function tryStmtCg(b) {
980
+ b.i += 1; // 'try'
981
+ const body = captureBranchTokensCg(b);
982
+ let param = null;
983
+ let catchBody = null;
984
+ let finallyBody = null;
985
+ if (b.isKw("catch")) {
986
+ b.i += 1;
987
+ if (b.isOp("(")) {
988
+ const decl = b.captureParen();
989
+ const first = decl[0];
990
+ if (first !== undefined && first.kind === "ident")
991
+ param = first.v;
992
+ }
993
+ catchBody = captureBranchTokensCg(b);
994
+ }
995
+ if (b.isKw("finally")) {
996
+ b.i += 1;
997
+ finallyBody = captureBranchTokensCg(b);
998
+ }
999
+ const v = `$c${b.declCounter}`;
1000
+ b.declCounter += 1;
1001
+ let out = `try { ${compileStatementsCg(b, body, b.activeLoop)} }`;
1002
+ if (catchBody !== null) {
1003
+ const bind = param === null ? "" : `$.set(${q(param)}, $.thrown(${v}));`;
1004
+ out += ` catch (${v}) { if (!$.caught(${v})) throw ${v}; ${bind} ${compileStatementsCg(b, catchBody, b.activeLoop)} }`;
1005
+ }
1006
+ if (finallyBody !== null)
1007
+ out += ` finally { ${compileStatementsCg(b, finallyBody, b.activeLoop)} }`;
1008
+ if (catchBody === null && finallyBody === null)
1009
+ out += ` catch (${v}) { if (!$.caught(${v})) throw ${v}; }`;
1010
+ return out;
1011
+ }
1012
+ /** Split a switch body into its clauses -- the twin of jse.ts `switchClauses`, including
1013
+ * the ternary count that keeps `case x ? 1 : 2:` from ending at the ternary's colon. */
1014
+ function switchClausesCg(body) {
1015
+ const out = [];
1016
+ let cur = null;
1017
+ let d = 0;
1018
+ let i = 0;
1019
+ while (i < body.length) {
1020
+ const tk = body[i];
1021
+ if (tk.kind === "op") {
1022
+ if (tk.v === "(" || tk.v === "[" || tk.v === "{")
1023
+ d += 1;
1024
+ else if (tk.v === ")" || tk.v === "]" || tk.v === "}")
1025
+ d -= 1;
1026
+ }
1027
+ if (d === 0 && tk.kind === "ident" && (tk.v === "case" || tk.v === "default")) {
1028
+ const isDefault = tk.v === "default";
1029
+ let j = i + 1;
1030
+ const label = [];
1031
+ let ld = 0;
1032
+ let ternary = 0;
1033
+ while (j < body.length) {
1034
+ const t = body[j];
1035
+ if (t.kind === "op") {
1036
+ if (t.v === "(" || t.v === "[" || t.v === "{")
1037
+ ld += 1;
1038
+ else if (t.v === ")" || t.v === "]" || t.v === "}")
1039
+ ld -= 1;
1040
+ else if (ld === 0 && t.v === "?")
1041
+ ternary += 1;
1042
+ else if (ld === 0 && t.v === ":") {
1043
+ if (ternary === 0)
1044
+ break;
1045
+ ternary -= 1;
1046
+ }
1047
+ }
1048
+ label.push(t);
1049
+ j += 1;
1050
+ }
1051
+ if (j >= body.length)
1052
+ break;
1053
+ cur = { label: isDefault ? null : label, stmts: [] };
1054
+ out.push(cur);
1055
+ i = j + 1;
1056
+ continue;
1057
+ }
1058
+ if (cur !== null)
1059
+ cur.stmts.push(tk);
1060
+ i += 1;
1061
+ }
1062
+ return out;
1063
+ }
1064
+ function switchStmtCg(b) {
1065
+ b.i += 1; // 'switch'
1066
+ const disc = b.captureParen();
1067
+ const body = captureBranchTokensCg(b);
1068
+ const clauses = switchClausesCg(body);
1069
+ const n = b.declCounter;
1070
+ b.declCounter += 1;
1071
+ const lbl = `$sw${n}`;
1072
+ const dv = `$sd${n}`;
1073
+ const iv = `$si${n}`;
1074
+ const parts = [`const ${dv} = (${compileExprTokens(disc)}); let ${iv} = -1;`];
1075
+ clauses.forEach((c, k) => {
1076
+ if (c.label === null)
1077
+ return;
1078
+ parts.push(`if (${iv} < 0 && $.eq(${dv}, ${compileExprTokens(c.label)})) ${iv} = ${k};`);
1079
+ });
1080
+ const defIdx = clauses.findIndex((c) => c.label === null);
1081
+ parts.push(`if (${iv} < 0) ${iv} = ${defIdx};`);
1082
+ clauses.forEach((c, k) => {
1083
+ const inner = compileStatementsCg(b, c.stmts, b.activeLoop, lbl);
1084
+ if (inner.trim().length === 0)
1085
+ return;
1086
+ parts.push(`if (${iv} >= 0 && ${iv} <= ${k}) { ${inner} }`);
1087
+ });
1088
+ return `${lbl}: { ${parts.join(" ")} }`;
1089
+ }
1090
+ const BLOCK_CONTROL_CODEGEN_IMPL = { throwStmtCg, tryStmtCg, switchStmtCg };
1091
+ // ── BLOCK ITERATION, compiled tier — the same optional fold as the interpreter's ────
1092
+ // (__DSX_OPTIONAL_BLOCK_ITERATION__, jse.ts): loop emission + path-mutation emission
1093
+ // + the BlockScope runtime halves DCE out of a slice the build proved authors none.
1094
+ function compileStatementsCg(b, toks, labels = null, switchLabel = null) {
1095
+ const sub = new BlockCompiler(toks);
1096
+ sub.declCounter = b.declCounter + 100; // keep temp names disjoint across nesting
1097
+ sub.activeLoop = labels;
1098
+ // A SWITCH CLAUSE'S `break` IS THE SWITCH'S. It is passed down rather than inherited,
1099
+ // so a clause that opens a loop of its own hands its body no switch label and that
1100
+ // loop's break is the loop's, exactly as JavaScript reads it.
1101
+ sub.activeSwitch = switchLabel ?? (labels === null ? b.activeSwitch : null);
1102
+ return sub.compileAll();
1103
+ }
1104
+ /** Capture a loop body: a `{ … }` group (braces consumed) or one bare statement. */
1105
+ function captureBranchTokensCg(b) {
1106
+ if (b.isOp("{")) {
1107
+ b.i += 1;
1108
+ const out = [];
1109
+ let d = 1;
1110
+ for (;;) {
1111
+ const tk = b.cur();
1112
+ if (tk === null)
1113
+ break;
1114
+ if (tk.kind === "op" && tk.v === "{")
1115
+ d += 1;
1116
+ else if (tk.kind === "op" && tk.v === "}") {
1117
+ d -= 1;
1118
+ if (d === 0) {
1119
+ b.i += 1;
1120
+ break;
1121
+ }
1122
+ }
1123
+ out.push(tk);
1124
+ b.i += 1;
1125
+ }
1126
+ return out;
1127
+ }
1128
+ const out = b.capture(new Set([";"]));
1129
+ if (b.isOp(";"))
1130
+ b.i += 1;
1131
+ return out;
1132
+ }
1133
+ function splitOnSemisCg(toks) {
1134
+ const out = [];
1135
+ let cur = [];
1136
+ let d = 0;
1137
+ for (const tk of toks) {
1138
+ if (tk.kind === "op") {
1139
+ if (tk.v === "(" || tk.v === "[" || tk.v === "{")
1140
+ d += 1;
1141
+ else if (tk.v === ")" || tk.v === "]" || tk.v === "}")
1142
+ d -= 1;
1143
+ else if (d === 0 && tk.v === ";") {
1144
+ out.push(cur);
1145
+ cur = [];
1146
+ continue;
1147
+ }
1148
+ }
1149
+ cur.push(tk);
1150
+ }
1151
+ out.push(cur);
1152
+ return out;
1153
+ }
1154
+ /** Compile `NAME(seg…) op= rhs` / `NAME(seg…).push(args)`; null when not that shape.
1155
+ * A dotted ident is ONE token (the tokenizer's dotted-ident rule). */
1156
+ function mutationCg(b, toks) {
1157
+ const t0 = toks[0];
1158
+ if (toks.length < 2 || t0 === undefined || t0.kind !== "ident")
1159
+ return null;
1160
+ const head = t0.v.split(".");
1161
+ const name = head[0];
1162
+ // The compiled path's twin of the interpreter's reserved-write guard (jse.ts). nav joins them: it became a READABLE reserved plane in this same pass, and a plane an author can now see is a plane an author can now try to write. Without this, `nav.canPop = false` would quietly create a surface variable named `nav` that the reader deliberately ignores — a write that succeeds and changes nothing, which is the exact silent-no-op class the read bug belonged to. The router writes this plane; an author reads it.
1163
+ if (name.length === 0 || name === "dsx" || name === "global" || name === "route"
1164
+ || name === "nav" || name === "cookie" || name === "module")
1165
+ return null;
1166
+ const segs = head.slice(1).map((p) => q(p));
1167
+ let j = 1;
1168
+ for (;;) {
1169
+ const a = toks[j];
1170
+ const b = toks[j + 1];
1171
+ if (a !== undefined && a.kind === "op" && a.v === "." && b !== undefined && b.kind === "ident") {
1172
+ for (const part of b.v.split("."))
1173
+ segs.push(q(part));
1174
+ j += 2;
1175
+ continue;
1176
+ }
1177
+ if (a !== undefined && a.kind === "op" && a.v === "[") {
1178
+ const inner = [];
1179
+ let d = 1;
1180
+ let k = j + 1;
1181
+ while (k < toks.length) {
1182
+ const tk = toks[k];
1183
+ if (tk.kind === "op" && (tk.v === "[" || tk.v === "(" || tk.v === "{"))
1184
+ d += 1;
1185
+ if (tk.kind === "op" && (tk.v === "]" || tk.v === ")" || tk.v === "}")) {
1186
+ d -= 1;
1187
+ if (d === 0)
1188
+ break;
1189
+ }
1190
+ inner.push(tk);
1191
+ k += 1;
1192
+ }
1193
+ if (k >= toks.length)
1194
+ return null;
1195
+ segs.push(`(${compileExprTokens(inner)})`);
1196
+ j = k + 1;
1197
+ continue;
1198
+ }
1199
+ break;
1200
+ }
1201
+ const after = toks[j];
1202
+ // `x++` / `m.n--` — read-modify-write through the same path law.
1203
+ if (after !== undefined && after.kind === "op" && (after.v === "++" || after.v === "--") && j === toks.length - 1) {
1204
+ return `$.inc(${q(name)}, [${segs.join(", ")}], ${q(after.v)}, false, () => null);`;
1205
+ }
1206
+ // push and unshift grow the local array; unshift prepends (core-003, nested-data stress S7)
1207
+ const grow = segs.length > 0 ? segs[segs.length - 1] : undefined;
1208
+ if ((grow === q("push") || grow === q("unshift"))
1209
+ && after !== undefined && after.kind === "op" && after.v === "(") {
1210
+ let d = 1;
1211
+ let k = j + 1;
1212
+ const inner = [];
1213
+ while (k < toks.length) {
1214
+ const tk = toks[k];
1215
+ if (tk.kind === "op" && (tk.v === "(" || tk.v === "[" || tk.v === "{"))
1216
+ d += 1;
1217
+ if (tk.kind === "op" && (tk.v === ")" || tk.v === "]" || tk.v === "}")) {
1218
+ d -= 1;
1219
+ if (d === 0)
1220
+ break;
1221
+ }
1222
+ inner.push(tk);
1223
+ k += 1;
1224
+ }
1225
+ if (d !== 0 || k !== toks.length - 1)
1226
+ return null;
1227
+ segs.pop();
1228
+ const args = splitTopLevelTokens(inner).filter((run) => run.length > 0).map((run) => compileExprTokens(run));
1229
+ return `$.ppush(${q(name)}, [${segs.join(", ")}], [${args.join(", ")}]${grow === q("unshift") ? ", true" : ""});`;
1230
+ }
1231
+ // `u.searchParams.set(k, v)` as a statement writes through the owning url (logic parity B16):
1232
+ // the interpreter's `mutation` twin
1233
+ const pverb = segs.length >= 2 ? segs[segs.length - 1] : undefined;
1234
+ if ((pverb === q("set") || pverb === q("append") || pverb === q("delete")) && segs[segs.length - 2] === q("searchParams")
1235
+ && after !== undefined && after.kind === "op" && after.v === "(") {
1236
+ let d = 1;
1237
+ let k = j + 1;
1238
+ const inner = [];
1239
+ while (k < toks.length) {
1240
+ const tk = toks[k];
1241
+ if (tk.kind === "op" && (tk.v === "(" || tk.v === "[" || tk.v === "{"))
1242
+ d += 1;
1243
+ if (tk.kind === "op" && (tk.v === ")" || tk.v === "]" || tk.v === "}")) {
1244
+ d -= 1;
1245
+ if (d === 0)
1246
+ break;
1247
+ }
1248
+ inner.push(tk);
1249
+ k += 1;
1250
+ }
1251
+ if (d === 0 && k === toks.length - 1) {
1252
+ const args = splitTopLevelTokens(inner).filter((run) => run.length > 0).map((run) => compileExprTokens(run));
1253
+ return `$.pparams(${q(name)}, [${segs.slice(0, -2).join(", ")}], ${pverb}, [${args.join(", ")}]);`;
1254
+ }
1255
+ }
1256
+ const op = toks[j];
1257
+ if (op === undefined || op.kind !== "op")
1258
+ return null;
1259
+ // logical assignment (JSE-VS-JS item 17), the interpreter's `mutation` twin: the right side
1260
+ // compiles into a thunk, run only when the target's value asks
1261
+ const eq = toks[j + 1];
1262
+ if ((op.v === "??" || op.v === "||" || op.v === "&&") && eq !== undefined && eq.kind === "op" && eq.v === "=" && toks.length > j + 2) {
1263
+ return `$.plog(${q(name)}, [${segs.join(", ")}], ${q(op.v)}, () => ${compileExprTokens(toks.slice(j + 2))});`;
1264
+ }
1265
+ if (op.v !== "=" && op.v !== "+=" && op.v !== "-=" && op.v !== "*=" && op.v !== "/=" && op.v !== "%=")
1266
+ return null;
1267
+ const rhsToks = toks.slice(j + 1);
1268
+ if (rhsToks.length === 0)
1269
+ return null;
1270
+ const verb = op.v === "=" ? "" : op.v.substring(0, 1);
1271
+ return `$.pset(${q(name)}, [${segs.join(", ")}], ${compileExprTokens(rhsToks)}, ${q(verb)});`;
1272
+ }
1273
+ /** The compiled loop grammar (corpus core-004) — the interpreter's semantics emitted
1274
+ * as real JS, with the SAME budget order: cond first, then one ledger tick. */
1275
+ function forStmtCg(b) {
1276
+ b.i += 1; // 'for'
1277
+ const head = b.captureParen();
1278
+ const body = captureBranchTokensCg(b);
1279
+ const parts = splitOnSemisCg(head);
1280
+ if (parts.length === 3) {
1281
+ const init = compileStatementsCg(b, parts[0]);
1282
+ const cond = parts[1].length > 0 ? `$.tr(${compileExprTokens(parts[1])})` : "true";
1283
+ const step = compileStatementsCg(b, parts[2]);
1284
+ const n = b.declCounter;
1285
+ b.declCounter += 1;
1286
+ const L = `$L${n}`;
1287
+ const B = `$B${n}`;
1288
+ const bodyCode = compileStatementsCg(b, body, { brk: L, cont: B });
1289
+ return `{ ${init} ${L}: for (;;) { if (!(${cond})) break ${L}; if (!$.step()) break ${L}; ${B}: do { ${bodyCode} } while (false); ${step} } }`;
1290
+ }
1291
+ let p = 0;
1292
+ const first = head[p];
1293
+ if (first !== undefined && first.kind === "ident" && (first.v === "const" || first.v === "let" || first.v === "var"))
1294
+ p += 1;
1295
+ let kwAt = -1;
1296
+ let kind = null;
1297
+ let d = 0;
1298
+ for (let k = p; k < head.length; k += 1) {
1299
+ const tk = head[k];
1300
+ if (tk.kind === "op") {
1301
+ if (tk.v === "(" || tk.v === "[" || tk.v === "{")
1302
+ d += 1;
1303
+ else if (tk.v === ")" || tk.v === "]" || tk.v === "}")
1304
+ d -= 1;
1305
+ }
1306
+ if (d === 0 && tk.kind === "ident" && (tk.v === "of" || tk.v === "in")) {
1307
+ kwAt = k;
1308
+ kind = tk.v;
1309
+ break;
1310
+ }
1311
+ }
1312
+ if (kwAt < 0 || kind === null)
1313
+ return "";
1314
+ const patToks = head.slice(p, kwAt);
1315
+ const exprToks = head.slice(kwAt + 1);
1316
+ const decls = parseDeclarators([...patToks, { kind: "op", v: "=" }, { kind: "num", v: 0 }]);
1317
+ if (decls.length !== 1)
1318
+ return "";
1319
+ const v = `$d${b.declCounter}`;
1320
+ b.declCounter += 1;
1321
+ const binds = [];
1322
+ b.emitPatternBinds(decls[0].pattern, v, binds);
1323
+ const seq = kind === "of" ? `$.spread(${compileExprTokens(exprToks)})` : `$.fkeys(${compileExprTokens(exprToks)})`;
1324
+ return `for (const ${v} of ${seq}) { if (!$.step()) break; ${binds.join(" ")} ${compileStatementsCg(b, body)} }`;
1325
+ }
1326
+ function whileStmtCg(b) {
1327
+ b.i += 1; // 'while'
1328
+ const cond = b.captureParen();
1329
+ const body = captureBranchTokensCg(b);
1330
+ return `while ($.tr(${compileExprTokens(cond)})) { if (!$.step()) break; ${compileStatementsCg(b, body)} }`;
1331
+ }
1332
+ function doStmtCg(b) {
1333
+ b.i += 1; // 'do'
1334
+ const body = captureBranchTokensCg(b);
1335
+ let cond = [];
1336
+ if (b.isKw("while")) {
1337
+ b.i += 1;
1338
+ cond = b.captureParen();
1339
+ if (b.isOp(";"))
1340
+ b.i += 1;
1341
+ }
1342
+ return `do { if (!$.step()) break; ${compileStatementsCg(b, body)} } while ($.tr(${compileExprTokens(cond)}));`;
1343
+ }
1344
+ const BLOCK_ITERATION_CODEGEN_IMPL = {
1345
+ loop(b, kind) {
1346
+ if (kind === "for")
1347
+ return forStmtCg(b);
1348
+ if (kind === "while")
1349
+ return whileStmtCg(b);
1350
+ return doStmtCg(b);
1351
+ },
1352
+ mutation: mutationCg,
1353
+ pset(scope, name, parts, rhs, op) {
1354
+ const base = Object.prototype.hasOwnProperty.call(scope.locals, name) ? scope.locals[name] : scope.l(name);
1355
+ const value = op === "" ? rhs : arith(getInLocal(base, parts), rhs, op);
1356
+ if (parts.length === 0) {
1357
+ scope.locals[name] = value ?? NSNull;
1358
+ return;
1359
+ }
1360
+ scope.locals[name] = setInLocal(base, parts, value ?? NSNull);
1361
+ },
1362
+ ppush(scope, name, parts, args, front) {
1363
+ const base = Object.prototype.hasOwnProperty.call(scope.locals, name) ? scope.locals[name] : scope.l(name);
1364
+ const added = args.map((a) => a ?? NSNull);
1365
+ const arr = front === true ? [...added, ...asArray(getInLocal(base, parts))] : [...asArray(getInLocal(base, parts)), ...added];
1366
+ scope.locals[name] = setInLocal(base, parts, arr);
1367
+ },
1368
+ spread: spreadValues,
1369
+ fkeys: forInKeys,
1370
+ };
1371
+ // The BLOCK ITERATION runtime seams ($.spread / $.fkeys / $.pset / $.ppush) attach only
1372
+ // when the fold is live — a folded slice never EMITS a call to any of them, so the
1373
+ // whole extension (and everything it references) drops with the impl. Every gate reads
1374
+ // the flag INLINE (never through a const), so esbuild's define folds each branch and
1375
+ // the impl object above becomes unreferenced in a folded build.
1376
+ if (globalThis.__DSX_OPTIONAL_BLOCK_ITERATION__ !== false) {
1377
+ Object.assign(BlockScope.prototype, {
1378
+ spread(v) { return BLOCK_ITERATION_CODEGEN_IMPL.spread(v); },
1379
+ fkeys(v) { return BLOCK_ITERATION_CODEGEN_IMPL.fkeys(v); },
1380
+ pset(name, parts, rhs, op) {
1381
+ BLOCK_ITERATION_CODEGEN_IMPL.pset(this, name, parts, rhs, op);
1382
+ },
1383
+ ppush(name, parts, args, front) {
1384
+ BLOCK_ITERATION_CODEGEN_IMPL.ppush(this, name, parts, args, front);
1385
+ },
1386
+ });
1387
+ }
1388
+ /** Split a token run on top-level commas (argument lists in block statements). */
1389
+ function splitTopLevelTokens(toks) {
1390
+ const out = [];
1391
+ let cur = [];
1392
+ let d = 0;
1393
+ for (const tk of toks) {
1394
+ if (tk.kind === "op") {
1395
+ if (tk.v === "(" || tk.v === "[" || tk.v === "{")
1396
+ d += 1;
1397
+ else if (tk.v === ")" || tk.v === "]" || tk.v === "}")
1398
+ d -= 1;
1399
+ else if (d === 0 && tk.v === ",") {
1400
+ out.push(cur);
1401
+ cur = [];
1402
+ continue;
1403
+ }
1404
+ }
1405
+ cur.push(tk);
1406
+ }
1407
+ out.push(cur);
1408
+ return out;
1409
+ }
1410
+ /** The value an author's `throw` travels in through the compiled lane (Appendix E item 5).
1411
+ * A plain value would be indistinguishable from a real fault at the `catch`. */
1412
+ class JseThrow {
1413
+ value;
1414
+ constructor(value) { this.value = value; }
1415
+ }
1416
+ class BlockCompiler {
1417
+ i = 0;
1418
+ t;
1419
+ constructor(t) {
1420
+ this.t = t;
1421
+ }
1422
+ cur() { return this.i < this.t.length ? this.t[this.i] : null; }
1423
+ isOp(s) { const tk = this.cur(); return tk !== null && tk.kind === "op" && tk.v === s; }
1424
+ isKw(s) { const tk = this.cur(); return tk !== null && tk.kind === "ident" && tk.v === s; }
1425
+ compileAll() {
1426
+ const out = [];
1427
+ for (;;) {
1428
+ const tk = this.cur();
1429
+ if (tk === null)
1430
+ break;
1431
+ if (tk.kind === "op" && tk.v === "}")
1432
+ break;
1433
+ if (tk.kind === "op" && tk.v === ";") {
1434
+ this.i += 1;
1435
+ continue;
1436
+ }
1437
+ const before = this.i;
1438
+ out.push(this.statement());
1439
+ if (this.i === before)
1440
+ this.i += 1;
1441
+ }
1442
+ return out.join(" ");
1443
+ }
1444
+ statement() {
1445
+ if (this.isKw("function")) {
1446
+ this.skipFunction();
1447
+ return "";
1448
+ }
1449
+ if (this.isKw("if"))
1450
+ return this.ifStmt();
1451
+ // BLOCK CONTROL fold (__DSX_OPTIONAL_BLOCK_CONTROL__, jse.ts): folded, the three words
1452
+ // fall through to the generic statement arm exactly as they did before this landed.
1453
+ if (globalThis.__DSX_OPTIONAL_BLOCK_CONTROL__ !== false) {
1454
+ if (this.isKw("throw"))
1455
+ return BLOCK_CONTROL_CODEGEN_IMPL.throwStmtCg(this);
1456
+ if (this.isKw("try"))
1457
+ return BLOCK_CONTROL_CODEGEN_IMPL.tryStmtCg(this);
1458
+ if (this.isKw("switch"))
1459
+ return BLOCK_CONTROL_CODEGEN_IMPL.switchStmtCg(this);
1460
+ }
1461
+ // BLOCK ITERATION fold: folded, a loop keyword falls through to the generic
1462
+ // statement arm — byte-for-byte the pre-core-004 behavior (see jse.ts).
1463
+ if (globalThis.__DSX_OPTIONAL_BLOCK_ITERATION__ !== false
1464
+ && (this.isKw("for") || this.isKw("while") || this.isKw("do"))) {
1465
+ const kind = this.isKw("for") ? "for" : this.isKw("while") ? "while" : "do";
1466
+ return BLOCK_ITERATION_CODEGEN_IMPL.loop(this, kind);
1467
+ }
1468
+ // A `break` INSIDE A SWITCH IS THE SWITCH'S, and it is read here rather than in the
1469
+ // block iteration arm below, because a slice may spell a switch and no loop at all.
1470
+ if (this.activeSwitch !== null && this.isKw("break")) {
1471
+ const lbl = this.activeSwitch;
1472
+ this.i += 1;
1473
+ if (this.isOp(";"))
1474
+ this.i += 1;
1475
+ return `break ${lbl};`;
1476
+ }
1477
+ if (globalThis.__DSX_OPTIONAL_BLOCK_ITERATION__ !== false
1478
+ && (this.isKw("break") || this.isKw("continue"))) {
1479
+ const isBreak = this.isKw("break");
1480
+ this.i += 1;
1481
+ if (this.isOp(";"))
1482
+ this.i += 1;
1483
+ if (this.activeLoop === null)
1484
+ return isBreak ? "break;" : "continue;";
1485
+ return `break ${isBreak ? this.activeLoop.brk : this.activeLoop.cont};`;
1486
+ }
1487
+ if (this.isKw("const") || this.isKw("let") || this.isKw("var"))
1488
+ return this.declStmt();
1489
+ if (this.isKw("return"))
1490
+ return this.returnStmt();
1491
+ const toks = this.capture(new Set([";"]));
1492
+ if (this.isOp(";"))
1493
+ this.i += 1;
1494
+ return this.exprStatement(toks);
1495
+ }
1496
+ ifStmt() {
1497
+ this.i += 1;
1498
+ const c = this.captureParen();
1499
+ const cond = compileExprTokens(c);
1500
+ const thenCode = this.branch();
1501
+ let elseCode = "";
1502
+ if (this.isKw("else")) {
1503
+ this.i += 1;
1504
+ if (this.isKw("if"))
1505
+ elseCode = this.ifStmt();
1506
+ else
1507
+ elseCode = this.branch();
1508
+ }
1509
+ return `if ($.tr(${cond})) { ${thenCode} }${elseCode.length > 0 ? ` else { ${elseCode} }` : ""}`;
1510
+ }
1511
+ branch() {
1512
+ if (this.isOp("{")) {
1513
+ this.i += 1;
1514
+ const inner = [];
1515
+ for (;;) {
1516
+ const tk = this.cur();
1517
+ if (tk === null)
1518
+ break;
1519
+ if (tk.kind === "op" && tk.v === "}") {
1520
+ this.i += 1;
1521
+ break;
1522
+ }
1523
+ if (tk.kind === "op" && tk.v === ";") {
1524
+ this.i += 1;
1525
+ continue;
1526
+ }
1527
+ const before = this.i;
1528
+ inner.push(this.statement());
1529
+ if (this.i === before)
1530
+ this.i += 1;
1531
+ }
1532
+ return inner.join(" ");
1533
+ }
1534
+ return this.statement();
1535
+ }
1536
+ declCounter = 0;
1537
+ declStmt() {
1538
+ this.i += 1;
1539
+ const toks = this.capture(new Set([";"]));
1540
+ if (this.isOp(";"))
1541
+ this.i += 1;
1542
+ // multi-declarators + flat destructuring — same shapes as the interpreter's JSEval
1543
+ const out = [];
1544
+ for (const d of parseDeclarators(toks)) {
1545
+ const code = d.expr.length === 0 ? "null" : compileExprTokens(d.expr);
1546
+ if (d.pattern.kind === "ident") {
1547
+ out.push(`$.set(${q(d.pattern.name)}, ${code});`);
1548
+ continue;
1549
+ }
1550
+ const v = `$d${this.declCounter}`;
1551
+ this.declCounter += 1;
1552
+ const binds = [];
1553
+ this.emitPatternBinds(d.pattern, v, binds);
1554
+ out.push(`{ const ${v} = (${code}); ${binds.join(" ")} }`);
1555
+ }
1556
+ return out.join(" ");
1557
+ }
1558
+ /** Emit the binds for one pattern against an already-evaluated source expression.
1559
+ * Mirrors the interpreter's `bindPattern` exactly — nesting, defaults and rest — because
1560
+ * a body must not mean two different things depending on which tier ran it. */
1561
+ emitPatternBinds(pattern, src, binds) {
1562
+ if (pattern.kind === "ident") {
1563
+ binds.push(`$.set(${q(pattern.name)}, ${src});`);
1564
+ return;
1565
+ }
1566
+ if (pattern.kind === "object") {
1567
+ const taken = [];
1568
+ for (const e of pattern.entries) {
1569
+ taken.push(e.key);
1570
+ const got = `$.mb(${src}, ${q(e.key)})`;
1571
+ const value = e.def === undefined ? got : `$.dflt(${got}, () => (${compileExprTokens(e.def)}))`;
1572
+ this.emitPatternBinds(e.value, value, binds);
1573
+ }
1574
+ if (pattern.rest !== undefined)
1575
+ binds.push(`$.set(${q(pattern.rest)}, $.orest(${src}, ${jsLiteral(taken)}));`);
1576
+ return;
1577
+ }
1578
+ pattern.items.forEach((item, k) => {
1579
+ if (item === null)
1580
+ return;
1581
+ const got = `$.ix(${src}, ${k})`;
1582
+ const value = item.def === undefined ? got : `$.dflt(${got}, () => (${compileExprTokens(item.def)}))`;
1583
+ this.emitPatternBinds(item.value, value, binds);
1584
+ });
1585
+ if (pattern.rest !== undefined)
1586
+ binds.push(`$.set(${q(pattern.rest)}, $.arest(${src}, ${pattern.items.length}));`);
1587
+ }
1588
+ /** A classic-for body compiles under LABELS: its `continue` must still run the step,
1589
+ * so the body sits in a `do { … } while (false)` wrapper — `continue` breaks the
1590
+ * wrapper (falling through to the step), `break` breaks the labeled for. A nested
1591
+ * loop clears the labels (its own break/continue are native again). */
1592
+ activeLoop = null;
1593
+ /** The label of the innermost `switch` this block is inside, when it is inside one and
1594
+ * no loop has been opened since (Appendix E item 5). A `break` belongs to it. */
1595
+ activeSwitch = null;
1596
+ returnStmt() {
1597
+ this.i += 1;
1598
+ const toks = this.capture(new Set([";"]));
1599
+ if (this.isOp(";"))
1600
+ this.i += 1;
1601
+ return `return ${toks.length === 0 ? "null" : compileExprTokens(toks)};`;
1602
+ }
1603
+ skipFunction() {
1604
+ for (;;) {
1605
+ const tk = this.cur();
1606
+ if (tk === null)
1607
+ return;
1608
+ if (tk.kind === "op" && tk.v === "{")
1609
+ break;
1610
+ this.i += 1;
1611
+ }
1612
+ let d = 0;
1613
+ for (;;) {
1614
+ const tk = this.cur();
1615
+ if (tk === null)
1616
+ return;
1617
+ if (tk.kind === "op" && tk.v === "{")
1618
+ d += 1;
1619
+ else if (tk.kind === "op" && tk.v === "}") {
1620
+ d -= 1;
1621
+ this.i += 1;
1622
+ if (d === 0)
1623
+ return;
1624
+ continue;
1625
+ }
1626
+ this.i += 1;
1627
+ }
1628
+ }
1629
+ exprStatement(toks) {
1630
+ // destructuring assignment `[a, b] = [b, a]` — the interpreter twin, emitted through
1631
+ // emitPatternBinds with the ASSIGNMENT writer ($.set is the one write both share).
1632
+ if (toks.length >= 4 && toks[0].kind === "op" && toks[0].v === "[") {
1633
+ const decls = parseDeclarators(toks);
1634
+ const d0 = decls.length === 1 ? decls[0] : null;
1635
+ if (d0 !== null && d0.pattern.kind === "array" && d0.expr.length > 0 &&
1636
+ (d0.pattern.items.some((it) => it !== null) || d0.pattern.rest !== undefined)) {
1637
+ const v = `$d${this.declCounter}`;
1638
+ this.declCounter += 1;
1639
+ const binds = [];
1640
+ this.emitPatternBinds(d0.pattern, v, binds);
1641
+ return `{ const ${v} = (${compileExprTokens(d0.expr)}); ${binds.join(" ")} }`;
1642
+ }
1643
+ }
1644
+ if (toks.length >= 2) {
1645
+ const t0 = toks[0];
1646
+ const t1 = toks[1];
1647
+ if (t0.kind === "ident" && (!(globalThis.__DSX_OPTIONAL_BLOCK_ITERATION__ !== false) || !t0.v.includes(".")) && t1.kind === "op" && t1.v === "=") {
1648
+ return `$.set(${q(t0.v)}, ${compileExprTokens(toks.slice(2))});`;
1649
+ }
1650
+ }
1651
+ // BLOCK-SCOPE MUTATION (corpus core-003) — the interpreter's pathMutation, emitted:
1652
+ // dotted / computed-key / indexed / compound assignment, ++/--, and statement-
1653
+ // position `.push(…)` rebuild the local through the BlockScope seam ($.pset/$.ppush).
1654
+ if (globalThis.__DSX_OPTIONAL_BLOCK_ITERATION__ !== false) {
1655
+ const lead = toks[0];
1656
+ if (lead !== undefined && lead.kind === "op" && (lead.v === "++" || lead.v === "--")) {
1657
+ const rewritten = BLOCK_ITERATION_CODEGEN_IMPL.mutation(this, [...toks.slice(1), lead]); // prefix → postfix shape
1658
+ if (rewritten !== null)
1659
+ return rewritten;
1660
+ }
1661
+ const emitted = BLOCK_ITERATION_CODEGEN_IMPL.mutation(this, toks);
1662
+ if (emitted !== null)
1663
+ return emitted;
1664
+ }
1665
+ return `$b.__r = ${compileExprTokens(toks)};`;
1666
+ }
1667
+ capture(stops) {
1668
+ const out = [];
1669
+ let d = 0;
1670
+ for (;;) {
1671
+ const tk = this.cur();
1672
+ if (tk === null)
1673
+ break;
1674
+ if (tk.kind === "op") {
1675
+ const o = tk.v;
1676
+ if (o === "(" || o === "[" || o === "{") {
1677
+ d += 1;
1678
+ out.push(tk);
1679
+ this.i += 1;
1680
+ continue;
1681
+ }
1682
+ if (o === ")" || o === "]" || o === "}") {
1683
+ if (d === 0)
1684
+ break;
1685
+ d -= 1;
1686
+ out.push(tk);
1687
+ this.i += 1;
1688
+ continue;
1689
+ }
1690
+ if (d === 0 && stops.has(o))
1691
+ break;
1692
+ }
1693
+ out.push(tk);
1694
+ this.i += 1;
1695
+ }
1696
+ return out;
1697
+ }
1698
+ captureParen() {
1699
+ const out = [];
1700
+ if (!this.isOp("("))
1701
+ return out;
1702
+ this.i += 1;
1703
+ let d = 1;
1704
+ for (;;) {
1705
+ const tk = this.cur();
1706
+ if (tk === null)
1707
+ break;
1708
+ if (tk.kind === "op" && tk.v === "(")
1709
+ d += 1;
1710
+ else if (tk.kind === "op" && tk.v === ")") {
1711
+ d -= 1;
1712
+ if (d === 0) {
1713
+ this.i += 1;
1714
+ break;
1715
+ }
1716
+ }
1717
+ out.push(tk);
1718
+ this.i += 1;
1719
+ }
1720
+ return out;
1721
+ }
1722
+ }
1723
+ function compileExprTokens(toks, awaitPos) {
1724
+ const g = new Codegen(toks);
1725
+ if (awaitPos !== undefined)
1726
+ g.awaitPos = awaitPos;
1727
+ return g.expression();
1728
+ }
1729
+ const exprCache = new Map();
1730
+ /** Every distinct source of an app is a few thousand at most (the console: about 3,000); the bound only stops an
1731
+ * unbounded producer (generated sources) from growing the map without end. */
1732
+ const EXPR_CACHE_MAX = 16384;
1733
+ /** A beyond-subset body reached the compiler. The classifier (tier.ts) is the subset
1734
+ * verdict; compiling past it would lossy-emit wrong behavior (the pinned W9 finding),
1735
+ * so `compileExpression`/`compileBlock` throw this instead — carrying the classifier's
1736
+ * reason. Runtime consumers stay fail-open (Article 7): `evalCompiled`/
1737
+ * `evalBlockCompiled` catch it, warn, run null. */
1738
+ export class JSESubsetError extends Error {
1739
+ reason;
1740
+ constructor(reason) {
1741
+ super(`beyond the JSE subset: ${reason}`);
1742
+ this.name = "JSESubsetError";
1743
+ this.reason = reason;
1744
+ }
1745
+ }
1746
+ class JSEParseError extends SyntaxError {
1747
+ }
1748
+ /** The strict gate: classify (cached in tier.ts), throw on a "js" verdict — BEFORE the
1749
+ * compile cache sees anything (a thrown outcome must never be cached). */
1750
+ function rejectBeyondSubset(body) {
1751
+ const verdict = classifyBody(body);
1752
+ if (verdict.tier === "js")
1753
+ throw new JSESubsetError(verdict.reason ?? "beyond the JSE subset");
1754
+ }
1755
+ /** Compile one JSE expression (`{{ … }}`, visible-if, computed one-liner). */
1756
+ export function compileExpression(expr) {
1757
+ const key = "e" + expr;
1758
+ const hit = exprCache.get(key);
1759
+ if (hit)
1760
+ return hit;
1761
+ rejectBeyondSubset(expr);
1762
+ const toks = cachedTokens(unwrapBraceExpression(expr.trim()));
1763
+ const error = delimiterError(toks);
1764
+ if (error !== null)
1765
+ throw new JSEParseError(`JSE parse error: ${error}`);
1766
+ const code = toks.length === 0 ? "null" : compileExprTokens(toks);
1767
+ const program = finalize(code);
1768
+ if (exprCache.size > EXPR_CACHE_MAX)
1769
+ exprCache.clear();
1770
+ exprCache.set(key, program);
1771
+ return program;
1772
+ }
1773
+ /** Compile a `<variable>`/function body (the bounded-JS block grammar). */
1774
+ export function compileBlock(body) {
1775
+ const key = "b" + body;
1776
+ const hit = exprCache.get(key);
1777
+ if (hit)
1778
+ return hit;
1779
+ rejectBeyondSubset(body);
1780
+ const trimmed = body.trim();
1781
+ // fast path mirrors JSE.evalBlock: a plain single expression compiles as one
1782
+ if (!trimmed.includes(";") && !trimmed.includes("\n") && !trimmed.includes("{") &&
1783
+ !trimmed.startsWith("return") && !trimmed.startsWith("const ") && !trimmed.startsWith("let ") &&
1784
+ !trimmed.startsWith("if ") && !trimmed.startsWith("if(") && !trimmed.startsWith("function")) {
1785
+ return compileExpression(trimmed);
1786
+ }
1787
+ const tokens = cachedTokens(body);
1788
+ const error = delimiterError(tokens);
1789
+ if (error !== null)
1790
+ throw new JSEParseError(`JSE parse error: ${error}`);
1791
+ const code = compileBlockTokens(tokens);
1792
+ const program = finalize(code);
1793
+ if (exprCache.size > EXPR_CACHE_MAX)
1794
+ exprCache.clear();
1795
+ exprCache.set(key, program);
1796
+ return program;
1797
+ }
1798
+ /** THE ONE PLACE TEXT BECOMES CODE. A target whose store policy forbids running text as code (a Manifest V3 browser
1799
+ * extension) builds with `globalThis.__DSX_NO_CODE_EVAL__` folded to true: the bundler removes the constructor call and
1800
+ * the interpreter runs every expression. Any other build leaves the name undefined and compiles. */
1801
+ function makeCompiler(src) {
1802
+ if (globalThis.__DSX_NO_CODE_EVAL__ === true)
1803
+ throw new Error("code evaluation is off for this target");
1804
+ else
1805
+ return new Function("$", src);
1806
+ }
1807
+ function finalize(code) {
1808
+ const src = `return (${code});`;
1809
+ let fn;
1810
+ try {
1811
+ const built = makeCompiler(src);
1812
+ fn = (scope) => {
1813
+ try {
1814
+ return built(scope);
1815
+ }
1816
+ catch (e) {
1817
+ // AN UNCAUGHT AUTHOR `throw` IS NULL AND ONE LINE, the interpreter's own sentence:
1818
+ // an expression is a value and has no second channel to unwind through.
1819
+ if (e instanceof JseThrow) {
1820
+ console.warn(`[JSE] uncaught throw in a block: ${string(e.value)}`);
1821
+ return null;
1822
+ }
1823
+ console.warn(`[JSE compiled] runtime error: ${String(e)} in ${code.slice(0, 120)}`);
1824
+ return null;
1825
+ }
1826
+ };
1827
+ }
1828
+ catch (e) {
1829
+ console.warn(`[JSE compiled] compile error: ${String(e)} in ${code.slice(0, 120)}`);
1830
+ return { code, fn: () => null, failed: true };
1831
+ }
1832
+ return { code, fn };
1833
+ }
1834
+ /** The runtime half of the strict gate: a rejection is LOUD but never a crash
1835
+ * (Article 7) — one warn line, then null. Anything else propagates. */
1836
+ function warnRejected(e) {
1837
+ if (e instanceof JSEParseError) {
1838
+ console.warn(`[JSE] parse error: ${e.message.replace(/^JSE parse error: /, "")}`);
1839
+ return null;
1840
+ }
1841
+ if (e instanceof JSESubsetError) {
1842
+ console.warn(`[JSE compiled] beyond-subset body rejected: ${e.reason} — runs null; full surfaces escalate via the JS tier`);
1843
+ return null;
1844
+ }
1845
+ throw e;
1846
+ }
1847
+ /** Convenience: evaluate an expression through the COMPILED path. */
1848
+ export function evalCompiled(expr, store, item) {
1849
+ let program;
1850
+ try {
1851
+ program = compileExpression(expr);
1852
+ }
1853
+ catch (e) {
1854
+ return warnRejected(e);
1855
+ }
1856
+ return runProgram(program, store, item);
1857
+ }
1858
+ /** Convenience: evaluate a block body through the COMPILED path. */
1859
+ export function evalBlockCompiled(body, store, item) {
1860
+ let program;
1861
+ try {
1862
+ program = compileBlock(body);
1863
+ }
1864
+ catch (e) {
1865
+ return warnRejected(e);
1866
+ }
1867
+ return runProgram(program, store, item);
1868
+ }
1869
+ /** THE COMPILED EVALUATION DOOR, the twin of JSE.eval's: the outermost frame owns the
1870
+ * step and wall clock ledger, and a refused evaluation answers null, never a partial
1871
+ * value. Both paths spend ONE ledger because both call JSE.callLambda and both compile
1872
+ * their loops through $.step(). */
1873
+ function runProgram(program, store, item) {
1874
+ const owned = beginEvaluation(store);
1875
+ // a pure door, the twin of JSE.eval's: no lambda it calls is in an action body
1876
+ // (reference/jse.md)
1877
+ if (!(globalThis.__DSX_OPTIONAL_ARRAY_MUTATORS__ !== false)) {
1878
+ const v = program.fn(new CompiledScope(store, item));
1879
+ return endEvaluation(store, owned) === null ? v : null;
1880
+ }
1881
+ const priorLambda = store.actionLambda;
1882
+ store.actionLambda = null;
1883
+ let v;
1884
+ try {
1885
+ v = program.fn(new CompiledScope(store, item));
1886
+ }
1887
+ finally {
1888
+ store.actionLambda = priorLambda;
1889
+ }
1890
+ return endEvaluation(store, owned) === null ? v : null;
1891
+ }
1892
+ // ── the compiled executor as the runtime path ───────────────────────────────────────
1893
+ //
1894
+ // JSE.eval parsed its source again on every call: a binding read on each render walked the whole precedence chain
1895
+ // (expression > ternary > nullish > ... > primary) before it read one variable, about a third of the main thread of a
1896
+ // tap on the console at 4x CPU. Installed, the evaluation door runs the source's cached closure; a source the compiler
1897
+ // does not take (beyond the subset, a compile failure) is remembered and goes to the interpreter, which stays the
1898
+ // reference. The door's ledger, host binding and recursion cap are JSE.eval's own, so both paths spend the same budget.
1899
+ const interpreterOnly = new Set();
1900
+ function programFor(key, src, compile) {
1901
+ if (interpreterOnly.has(key))
1902
+ return null;
1903
+ let program;
1904
+ try {
1905
+ program = compile(src);
1906
+ }
1907
+ catch {
1908
+ interpreterOnly.add(key);
1909
+ return null;
1910
+ }
1911
+ if (program.failed === true) {
1912
+ interpreterOnly.add(key);
1913
+ return null;
1914
+ }
1915
+ return program;
1916
+ }
1917
+ function probeCodeEval() {
1918
+ if (globalThis.__DSX_NO_CODE_EVAL__ === true)
1919
+ return false;
1920
+ else
1921
+ return new Function("return 1")() === 1;
1922
+ }
1923
+ /** Bind the compiled executor as JSE.eval's runtime path. Needs `new Function` (a host whose content security policy
1924
+ * refuses it keeps the interpreter): answers whether it is bound. */
1925
+ export function installCompiledEval() {
1926
+ try {
1927
+ if (probeCodeEval() !== true)
1928
+ return false;
1929
+ }
1930
+ catch {
1931
+ return false;
1932
+ }
1933
+ JSESeams.compiledEval = (expr, store, item) => {
1934
+ const program = programFor("e" + expr, expr, compileExpression);
1935
+ return program === null ? JSE_NOT_COMPILED : program.fn(new CompiledScope(store, item));
1936
+ };
1937
+ JSESeams.compiledBlock = (body, store, item) => {
1938
+ const program = programFor("b" + body, body, compileBlock);
1939
+ return program === null ? JSE_NOT_COMPILED : program.fn(new CompiledScope(store, item));
1940
+ };
1941
+ return true;
1942
+ }
1943
+ /** Back to the interpreter for every source (tests, a host that wants the reference executor). */
1944
+ export function uninstallCompiledEval() {
1945
+ JSESeams.compiledEval = null;
1946
+ JSESeams.compiledBlock = null;
1947
+ }
1948
+ export { JSESeams };
1949
+ //# sourceMappingURL=codegen.js.map