xbintsc 0.6.18 → 0.6.22

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 (464) hide show
  1. package/dist/src/ast/common.d.ts +2 -2
  2. package/dist/src/ast/declarations.d.ts +2 -0
  3. package/dist/src/ast/expressions.d.ts +5 -0
  4. package/dist/src/ast/kinds.d.ts +2 -0
  5. package/dist/src/ast/kinds.js +2 -0
  6. package/dist/src/ast/kinds.js.map +1 -1
  7. package/dist/src/ast/types.d.ts +2 -0
  8. package/dist/src/binder/binder.d.ts +6 -0
  9. package/dist/src/binder/binder.js +13 -0
  10. package/dist/src/binder/binder.js.map +1 -1
  11. package/dist/src/binder/references.js +9 -2
  12. package/dist/src/binder/references.js.map +1 -1
  13. package/dist/src/checker/assignability.js +11 -3
  14. package/dist/src/checker/assignability.js.map +1 -1
  15. package/dist/src/checker/calls.js +4 -0
  16. package/dist/src/checker/calls.js.map +1 -1
  17. package/dist/src/checker/flow.js +16 -12
  18. package/dist/src/checker/flow.js.map +1 -1
  19. package/dist/src/checker/globals.js +3 -1
  20. package/dist/src/checker/globals.js.map +1 -1
  21. package/dist/src/checker/type-system.js +1 -0
  22. package/dist/src/checker/type-system.js.map +1 -1
  23. package/dist/src/checker/typecheck.js +8 -1
  24. package/dist/src/checker/typecheck.js.map +1 -1
  25. package/dist/src/cli/help.d.ts +1 -1
  26. package/dist/src/cli/main.js +4 -0
  27. package/dist/src/cli/main.js.map +1 -1
  28. package/dist/src/codegen/generator/calls/access.js +3 -1
  29. package/dist/src/codegen/generator/calls/access.js.map +1 -1
  30. package/dist/src/codegen/generator/calls/invocation.js +8 -4
  31. package/dist/src/codegen/generator/calls/invocation.js.map +1 -1
  32. package/dist/src/codegen/generator/context.js +3 -3
  33. package/dist/src/codegen/generator/context.js.map +1 -1
  34. package/dist/src/codegen/generator/expressions/assignment.js +1 -0
  35. package/dist/src/codegen/generator/expressions/assignment.js.map +1 -1
  36. package/dist/src/codegen/generator/expressions/module-values.d.ts +21 -0
  37. package/dist/src/codegen/generator/expressions/module-values.js +84 -0
  38. package/dist/src/codegen/generator/expressions/module-values.js.map +1 -0
  39. package/dist/src/codegen/generator/expressions/primary.js +38 -6
  40. package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
  41. package/dist/src/codegen/generator/expressions.d.ts +2 -1
  42. package/dist/src/codegen/generator/expressions.js +2 -1
  43. package/dist/src/codegen/generator/expressions.js.map +1 -1
  44. package/dist/src/codegen/generator/module.js +16 -6
  45. package/dist/src/codegen/generator/module.js.map +1 -1
  46. package/dist/src/codegen/generator/state.js +6 -0
  47. package/dist/src/codegen/generator/state.js.map +1 -1
  48. package/dist/src/codegen/generator/statements/dispatch.js +10 -0
  49. package/dist/src/codegen/generator/statements/dispatch.js.map +1 -1
  50. package/dist/src/codegen/generator/tables.d.ts +7 -0
  51. package/dist/src/codegen/generator/tables.js +26 -0
  52. package/dist/src/codegen/generator/tables.js.map +1 -1
  53. package/dist/src/driver/build-key.d.ts +3 -0
  54. package/dist/src/driver/build-key.js +3 -1
  55. package/dist/src/driver/build-key.js.map +1 -1
  56. package/dist/src/driver/bundler/commonjs.js +9 -5
  57. package/dist/src/driver/bundler/commonjs.js.map +1 -1
  58. package/dist/src/driver/bundler/deferred.d.ts +1 -1
  59. package/dist/src/driver/bundler/deferred.js +2 -2
  60. package/dist/src/driver/bundler/deferred.js.map +1 -1
  61. package/dist/src/driver/bundler/dynamic-import.d.ts +30 -0
  62. package/dist/src/driver/bundler/dynamic-import.js +123 -0
  63. package/dist/src/driver/bundler/dynamic-import.js.map +1 -0
  64. package/dist/src/driver/bundler/graph.d.ts +1 -1
  65. package/dist/src/driver/bundler/graph.js +30 -12
  66. package/dist/src/driver/bundler/graph.js.map +1 -1
  67. package/dist/src/driver/bundler/merge.d.ts +1 -1
  68. package/dist/src/driver/bundler/merge.js +37 -55
  69. package/dist/src/driver/bundler/merge.js.map +1 -1
  70. package/dist/src/driver/bundler/namespace-import.d.ts +7 -0
  71. package/dist/src/driver/bundler/namespace-import.js +46 -0
  72. package/dist/src/driver/bundler/namespace-import.js.map +1 -0
  73. package/dist/src/driver/bundler/reexport-fixup.d.ts +14 -0
  74. package/dist/src/driver/bundler/reexport-fixup.js +92 -0
  75. package/dist/src/driver/bundler/reexport-fixup.js.map +1 -0
  76. package/dist/src/driver/bundler/resolve.d.ts +6 -5
  77. package/dist/src/driver/bundler/resolve.js +52 -6
  78. package/dist/src/driver/bundler/resolve.js.map +1 -1
  79. package/dist/src/driver/bundler/symbols.d.ts +4 -0
  80. package/dist/src/driver/bundler/symbols.js +12 -0
  81. package/dist/src/driver/bundler/symbols.js.map +1 -1
  82. package/dist/src/driver/bundler/types.d.ts +1 -0
  83. package/dist/src/driver/compiler.js +12 -1
  84. package/dist/src/driver/compiler.js.map +1 -1
  85. package/dist/src/driver/config.d.ts +14 -0
  86. package/dist/src/driver/config.js +40 -0
  87. package/dist/src/driver/config.js.map +1 -1
  88. package/dist/src/driver/frontend.d.ts +3 -1
  89. package/dist/src/driver/frontend.js +5 -4
  90. package/dist/src/driver/frontend.js.map +1 -1
  91. package/dist/src/driver/index.d.ts +2 -1
  92. package/dist/src/driver/index.js +1 -0
  93. package/dist/src/driver/index.js.map +1 -1
  94. package/dist/src/driver/options.d.ts +13 -1
  95. package/dist/src/driver/runtime-objects.d.ts +1 -1
  96. package/dist/src/driver/runtime-objects.js +2 -0
  97. package/dist/src/driver/runtime-objects.js.map +1 -1
  98. package/dist/src/driver/storage.d.ts +34 -0
  99. package/dist/src/driver/storage.js +67 -0
  100. package/dist/src/driver/storage.js.map +1 -0
  101. package/dist/src/driver/version.d.ts +1 -1
  102. package/dist/src/driver/version.js +1 -1
  103. package/dist/src/extensions/gui/features.d.ts +1 -1
  104. package/dist/src/extensions/gui/features.js +2 -2
  105. package/dist/src/extensions/gui/features.js.map +1 -1
  106. package/dist/src/extensions/gui/index.js +3 -1
  107. package/dist/src/extensions/gui/index.js.map +1 -1
  108. package/dist/src/extensions/node/async-hooks/index.d.ts +6 -0
  109. package/dist/src/extensions/node/async-hooks/index.js +19 -0
  110. package/dist/src/extensions/node/async-hooks/index.js.map +1 -0
  111. package/dist/src/extensions/node/buffer/index.js +2 -0
  112. package/dist/src/extensions/node/buffer/index.js.map +1 -1
  113. package/dist/src/extensions/node/child_process/index.js +10 -1
  114. package/dist/src/extensions/node/child_process/index.js.map +1 -1
  115. package/dist/src/extensions/node/console/index.d.ts +6 -0
  116. package/dist/src/extensions/node/console/index.js +34 -0
  117. package/dist/src/extensions/node/console/index.js.map +1 -0
  118. package/dist/src/extensions/node/constants/index.d.ts +6 -0
  119. package/dist/src/extensions/node/constants/index.js +27 -0
  120. package/dist/src/extensions/node/constants/index.js.map +1 -0
  121. package/dist/src/extensions/node/diagnostics-channel/index.d.ts +5 -0
  122. package/dist/src/extensions/node/diagnostics-channel/index.js +16 -0
  123. package/dist/src/extensions/node/diagnostics-channel/index.js.map +1 -0
  124. package/dist/src/extensions/node/dns/index.d.ts +5 -0
  125. package/dist/src/extensions/node/dns/index.js +14 -0
  126. package/dist/src/extensions/node/dns/index.js.map +1 -0
  127. package/dist/src/extensions/node/events/index.js +1 -0
  128. package/dist/src/extensions/node/events/index.js.map +1 -1
  129. package/dist/src/extensions/node/http/index.js +5 -1
  130. package/dist/src/extensions/node/http/index.js.map +1 -1
  131. package/dist/src/extensions/node/http2/index.d.ts +5 -0
  132. package/dist/src/extensions/node/http2/index.js +16 -0
  133. package/dist/src/extensions/node/http2/index.js.map +1 -0
  134. package/dist/src/extensions/node/index.js +36 -0
  135. package/dist/src/extensions/node/index.js.map +1 -1
  136. package/dist/src/extensions/node/module/index.d.ts +5 -0
  137. package/dist/src/extensions/node/module/index.js +15 -0
  138. package/dist/src/extensions/node/module/index.js.map +1 -0
  139. package/dist/src/extensions/node/os/index.js +4 -1
  140. package/dist/src/extensions/node/os/index.js.map +1 -1
  141. package/dist/src/extensions/node/path/index.js +9 -1
  142. package/dist/src/extensions/node/path/index.js.map +1 -1
  143. package/dist/src/extensions/node/perf_hooks/index.d.ts +6 -0
  144. package/dist/src/extensions/node/perf_hooks/index.js +15 -0
  145. package/dist/src/extensions/node/perf_hooks/index.js.map +1 -0
  146. package/dist/src/extensions/node/readline-promises/index.d.ts +5 -0
  147. package/dist/src/extensions/node/readline-promises/index.js +14 -0
  148. package/dist/src/extensions/node/readline-promises/index.js.map +1 -0
  149. package/dist/src/extensions/node/sqlite/index.d.ts +6 -0
  150. package/dist/src/extensions/node/sqlite/index.js +16 -0
  151. package/dist/src/extensions/node/sqlite/index.js.map +1 -0
  152. package/dist/src/extensions/node/stream/index.js +2 -0
  153. package/dist/src/extensions/node/stream/index.js.map +1 -1
  154. package/dist/src/extensions/node/stream-web/index.d.ts +5 -0
  155. package/dist/src/extensions/node/stream-web/index.js +17 -0
  156. package/dist/src/extensions/node/stream-web/index.js.map +1 -0
  157. package/dist/src/extensions/node/string-decoder/index.d.ts +5 -0
  158. package/dist/src/extensions/node/string-decoder/index.js +14 -0
  159. package/dist/src/extensions/node/string-decoder/index.js.map +1 -0
  160. package/dist/src/extensions/node/timers/index.d.ts +6 -0
  161. package/dist/src/extensions/node/timers/index.js +20 -0
  162. package/dist/src/extensions/node/timers/index.js.map +1 -0
  163. package/dist/src/extensions/node/timers-promises/index.d.ts +5 -0
  164. package/dist/src/extensions/node/timers-promises/index.js +15 -0
  165. package/dist/src/extensions/node/timers-promises/index.js.map +1 -0
  166. package/dist/src/extensions/node/tls/index.d.ts +5 -0
  167. package/dist/src/extensions/node/tls/index.js +16 -0
  168. package/dist/src/extensions/node/tls/index.js.map +1 -0
  169. package/dist/src/extensions/node/tty/index.d.ts +5 -0
  170. package/dist/src/extensions/node/tty/index.js +14 -0
  171. package/dist/src/extensions/node/tty/index.js.map +1 -0
  172. package/dist/src/extensions/node/url/index.js +1 -0
  173. package/dist/src/extensions/node/url/index.js.map +1 -1
  174. package/dist/src/extensions/node/util/index.js +15 -1
  175. package/dist/src/extensions/node/util/index.js.map +1 -1
  176. package/dist/src/extensions/node/util-types/index.d.ts +6 -0
  177. package/dist/src/extensions/node/util-types/index.js +26 -0
  178. package/dist/src/extensions/node/util-types/index.js.map +1 -0
  179. package/dist/src/extensions/node/worker_threads/index.js +1 -0
  180. package/dist/src/extensions/node/worker_threads/index.js.map +1 -1
  181. package/dist/src/extensions/node/zlib/compression.d.ts +10 -0
  182. package/dist/src/extensions/node/zlib/compression.js +44 -0
  183. package/dist/src/extensions/node/zlib/compression.js.map +1 -0
  184. package/dist/src/extensions/node/zlib/index.d.ts +5 -2
  185. package/dist/src/extensions/node/zlib/index.js +21 -2
  186. package/dist/src/extensions/node/zlib/index.js.map +1 -1
  187. package/dist/src/extensions/registry.d.ts +4 -1
  188. package/dist/src/extensions/registry.js +8 -2
  189. package/dist/src/extensions/registry.js.map +1 -1
  190. package/dist/src/extensions/storage.d.ts +22 -0
  191. package/dist/src/extensions/storage.js +50 -0
  192. package/dist/src/extensions/storage.js.map +1 -0
  193. package/dist/src/lexer/scanner/punctuation.js +8 -2
  194. package/dist/src/lexer/scanner/punctuation.js.map +1 -1
  195. package/dist/src/lexer/scanner/regex.d.ts +3 -1
  196. package/dist/src/lexer/scanner/regex.js +32 -22
  197. package/dist/src/lexer/scanner/regex.js.map +1 -1
  198. package/dist/src/lexer/scanner.d.ts +2 -0
  199. package/dist/src/lexer/scanner.js +8 -0
  200. package/dist/src/lexer/scanner.js.map +1 -1
  201. package/dist/src/lexer/token.d.ts +1 -0
  202. package/dist/src/lexer/token.js +2 -0
  203. package/dist/src/lexer/token.js.map +1 -1
  204. package/dist/src/parser/declarations/classes.js +7 -0
  205. package/dist/src/parser/declarations/classes.js.map +1 -1
  206. package/dist/src/parser/declarations/functions.js +8 -2
  207. package/dist/src/parser/declarations/functions.js.map +1 -1
  208. package/dist/src/parser/expressions.d.ts +2 -2
  209. package/dist/src/parser/expressions.js +32 -17
  210. package/dist/src/parser/expressions.js.map +1 -1
  211. package/dist/src/parser/helpers.js +1 -0
  212. package/dist/src/parser/helpers.js.map +1 -1
  213. package/dist/src/parser/literals.js +27 -0
  214. package/dist/src/parser/literals.js.map +1 -1
  215. package/dist/src/parser/statements.js +3 -0
  216. package/dist/src/parser/statements.js.map +1 -1
  217. package/dist/src/parser/types.js +106 -45
  218. package/dist/src/parser/types.js.map +1 -1
  219. package/dist/tests/binder/binder.test.js +8 -1
  220. package/dist/tests/binder/binder.test.js.map +1 -1
  221. package/dist/tests/checker/checker.test.js +63 -0
  222. package/dist/tests/checker/checker.test.js.map +1 -1
  223. package/dist/tests/codegen/expressions.test.js +8 -0
  224. package/dist/tests/codegen/expressions.test.js.map +1 -1
  225. package/dist/tests/conformance/test262/manifest.js +9 -10
  226. package/dist/tests/conformance/test262/manifest.js.map +1 -1
  227. package/dist/tests/driver/bundler-resolve.test.js +22 -0
  228. package/dist/tests/driver/bundler-resolve.test.js.map +1 -1
  229. package/dist/tests/driver/config.test.js +46 -0
  230. package/dist/tests/driver/config.test.js.map +1 -1
  231. package/dist/tests/driver/deferred-reexport.test.d.ts +9 -0
  232. package/dist/tests/driver/deferred-reexport.test.js +62 -0
  233. package/dist/tests/driver/deferred-reexport.test.js.map +1 -0
  234. package/dist/tests/driver/link-features.test.js +4 -2
  235. package/dist/tests/driver/link-features.test.js.map +1 -1
  236. package/dist/tests/driver/modules.test.js +110 -11
  237. package/dist/tests/driver/modules.test.js.map +1 -1
  238. package/dist/tests/driver/storage.test.d.ts +1 -0
  239. package/dist/tests/driver/storage.test.js +29 -0
  240. package/dist/tests/driver/storage.test.js.map +1 -0
  241. package/dist/tests/e2e/compile-basics.test.js +11 -0
  242. package/dist/tests/e2e/compile-basics.test.js.map +1 -1
  243. package/dist/tests/e2e/compile-modules.test.js +40 -0
  244. package/dist/tests/e2e/compile-modules.test.js.map +1 -1
  245. package/dist/tests/e2e/compile-node.test.js +49 -0
  246. package/dist/tests/e2e/compile-node.test.js.map +1 -1
  247. package/dist/tests/e2e/compile-objects-classes.test.js +32 -0
  248. package/dist/tests/e2e/compile-objects-classes.test.js.map +1 -1
  249. package/dist/tests/e2e/node-modules.test.js +174 -0
  250. package/dist/tests/e2e/node-modules.test.js.map +1 -1
  251. package/dist/tests/e2e/npm-modules.test.js +8 -0
  252. package/dist/tests/e2e/npm-modules.test.js.map +1 -1
  253. package/dist/tests/e2e/storage.test.d.ts +7 -0
  254. package/dist/tests/e2e/storage.test.js +86 -0
  255. package/dist/tests/e2e/storage.test.js.map +1 -0
  256. package/dist/tests/e2e/weak-collections.test.js +12 -0
  257. package/dist/tests/e2e/weak-collections.test.js.map +1 -1
  258. package/dist/tests/extensions/gui-features.test.js +1 -1
  259. package/dist/tests/extensions/gui-features.test.js.map +1 -1
  260. package/dist/tests/extensions/storage.test.d.ts +1 -0
  261. package/dist/tests/extensions/storage.test.js +50 -0
  262. package/dist/tests/extensions/storage.test.js.map +1 -0
  263. package/dist/tests/lexer/scanner.test.js +17 -0
  264. package/dist/tests/lexer/scanner.test.js.map +1 -1
  265. package/dist/tests/parser/declarations.test.js +24 -0
  266. package/dist/tests/parser/declarations.test.js.map +1 -1
  267. package/dist/tests/parser/expressions.test.js +34 -7
  268. package/dist/tests/parser/expressions.test.js.map +1 -1
  269. package/dist/tests/parser/literals.test.js +15 -0
  270. package/dist/tests/parser/literals.test.js.map +1 -1
  271. package/dist/tests/parser/types.test.js +26 -0
  272. package/dist/tests/parser/types.test.js.map +1 -1
  273. package/doc/ai/cli.md +2 -0
  274. package/doc/ai/extensions.md +26 -0
  275. package/doc/ai/language-support.md +4 -2
  276. package/doc/ai/zh-CN/cli.md +2 -0
  277. package/doc/ai/zh-CN/extensions.md +23 -0
  278. package/doc/ai/zh-CN/language-support.md +4 -2
  279. package/doc/gui/build.md +3 -3
  280. package/doc/gui/media.md +4 -4
  281. package/doc/gui.md +2 -2
  282. package/doc/implemented/extensions.md +1 -1
  283. package/doc/implemented/node/buffer.md +2 -0
  284. package/doc/implemented/node/child-process.md +29 -6
  285. package/doc/implemented/node/http.md +2 -0
  286. package/doc/implemented/node/os.md +1 -0
  287. package/doc/implemented/node/path.md +3 -0
  288. package/doc/implemented/node/stream.md +3 -0
  289. package/doc/implemented/node/util.md +1 -0
  290. package/doc/implemented/node/zlib.md +12 -1
  291. package/doc/implemented/node.md +8 -1
  292. package/doc/implemented/storage.md +64 -0
  293. package/doc/implemented/wasm.md +22 -0
  294. package/doc/implemented.md +3 -0
  295. package/doc/support-matrix.md +3 -3
  296. package/doc/unimplemented/node/modules.md +4 -3
  297. package/doc/unimplemented/stdlib.md +1 -0
  298. package/doc/unimplemented/wasm.md +15 -0
  299. package/doc/unimplemented.md +1 -0
  300. package/doc/xbintsc.config.schema.json +16 -1
  301. package/doc/zh-CN/gui/build.md +3 -3
  302. package/doc/zh-CN/gui/media.md +3 -3
  303. package/doc/zh-CN/gui.md +2 -2
  304. package/doc/zh-CN/implemented/extensions.md +1 -1
  305. package/doc/zh-CN/implemented/node/child-process.md +27 -5
  306. package/doc/zh-CN/implemented/node.md +1 -1
  307. package/doc/zh-CN/implemented/storage.md +51 -0
  308. package/doc/zh-CN/implemented/wasm.md +20 -0
  309. package/doc/zh-CN/implemented.md +3 -0
  310. package/doc/zh-CN/support-matrix.md +3 -3
  311. package/doc/zh-CN/unimplemented/node/modules.md +3 -2
  312. package/doc/zh-CN/unimplemented/stdlib.md +1 -0
  313. package/doc/zh-CN/unimplemented/wasm.md +14 -0
  314. package/doc/zh-CN/unimplemented.md +1 -0
  315. package/package.json +7 -7
  316. package/runtime/ext_gui/dom_api_form.cpp +10 -0
  317. package/runtime/ext_gui/gui_media.cpp +1 -1
  318. package/runtime/ext_gui/media.cpp +1 -1
  319. package/runtime/ext_gui/media_api.h +2 -2
  320. package/runtime/ext_node/async_hooks/async_hooks.c +59 -0
  321. package/runtime/ext_node/buffer/parts/static-api.inc +39 -0
  322. package/runtime/ext_node/child_process/spawn.c +201 -0
  323. package/runtime/ext_node/child_process/spawn.h +56 -0
  324. package/runtime/ext_node/child_process/spawn_posix.c +206 -0
  325. package/runtime/ext_node/child_process/spawn_win.c +276 -0
  326. package/runtime/ext_node/console/console.c +67 -0
  327. package/runtime/ext_node/constants/constants.c +72 -0
  328. package/runtime/ext_node/diagnostics_channel/diagnostics_channel.c +61 -0
  329. package/runtime/ext_node/dns/dns.c +77 -0
  330. package/runtime/ext_node/events/events.c +7 -0
  331. package/runtime/ext_node/http/http.c +38 -0
  332. package/runtime/ext_node/http2/http2.c +26 -0
  333. package/runtime/ext_node/module/module.c +31 -0
  334. package/runtime/ext_node/os/os.c +42 -0
  335. package/runtime/ext_node/path/path.c +93 -0
  336. package/runtime/ext_node/perf_hooks/perf_hooks.c +22 -0
  337. package/runtime/ext_node/readline_promises/readline_promises.c +59 -0
  338. package/runtime/ext_node/sqlite/sqlite.c +24 -0
  339. package/runtime/ext_node/stream/stream.c +19 -1
  340. package/runtime/ext_node/stream_web/stream_web.c +22 -0
  341. package/runtime/ext_node/string_decoder/string_decoder.c +31 -0
  342. package/runtime/ext_node/timers_promises/timers_promises.c +58 -0
  343. package/runtime/ext_node/tls/tls.c +26 -0
  344. package/runtime/ext_node/tty/tty.c +18 -0
  345. package/runtime/ext_node/util/util.c +84 -0
  346. package/runtime/ext_node/worker_threads/worker_threads.c +8 -0
  347. package/runtime/ext_node/zlib/miniz/compression_bridge.c +43 -0
  348. package/runtime/ext_node/zlib/miniz/miniz.c +646 -0
  349. package/runtime/ext_node/zlib/miniz/miniz.h +615 -0
  350. package/runtime/ext_node/zlib/miniz/miniz_common.h +89 -0
  351. package/runtime/ext_node/zlib/miniz/miniz_export.h +4 -0
  352. package/runtime/ext_node/zlib/miniz/miniz_tdef.c +1653 -0
  353. package/runtime/ext_node/zlib/miniz/miniz_tdef.h +206 -0
  354. package/runtime/ext_node/zlib/miniz/miniz_tinfl.c +778 -0
  355. package/runtime/ext_node/zlib/miniz/miniz_tinfl.h +150 -0
  356. package/runtime/ext_node/zlib/miniz/miniz_zip.h +454 -0
  357. package/runtime/ext_node/zlib/zlib.c +194 -0
  358. package/runtime/xt_builtins.c +1 -0
  359. package/runtime/xt_constructors.c +5 -0
  360. package/runtime/xt_module_values.c +29 -0
  361. package/runtime/xt_storage/indexed_db.c +408 -0
  362. package/runtime/xt_storage/indexed_db_internal.h +26 -0
  363. package/runtime/xt_storage/indexed_db_store.c +305 -0
  364. package/runtime/xt_storage/sqlite3/sqlite3.c +271131 -0
  365. package/runtime/xt_storage/sqlite3/sqlite3.h +14447 -0
  366. package/runtime/xt_storage/storage.c +209 -0
  367. package/runtime/xt_storage/storage_internal.h +66 -0
  368. package/runtime/xt_weak.c +43 -0
  369. package/runtime/xt_webassembly.c +53 -0
  370. package/scripts/build-gui.ts +1 -1
  371. package/scripts/build-media.ts +2 -2
  372. package/scripts/check-file-length.ts +14 -0
  373. package/src/ast/common.ts +2 -0
  374. package/src/ast/declarations.ts +2 -0
  375. package/src/ast/expressions.ts +6 -0
  376. package/src/ast/kinds.ts +2 -0
  377. package/src/ast/types.ts +2 -0
  378. package/src/binder/binder.ts +13 -0
  379. package/src/binder/references.ts +9 -2
  380. package/src/checker/assignability.ts +12 -2
  381. package/src/checker/calls.ts +3 -0
  382. package/src/checker/flow.ts +13 -9
  383. package/src/checker/globals.ts +3 -0
  384. package/src/checker/type-system.ts +1 -0
  385. package/src/checker/typecheck.ts +8 -1
  386. package/src/cli/main.ts +4 -0
  387. package/src/codegen/generator/calls/access.ts +4 -1
  388. package/src/codegen/generator/calls/invocation.ts +8 -4
  389. package/src/codegen/generator/context.ts +5 -3
  390. package/src/codegen/generator/expressions/assignment.ts +1 -0
  391. package/src/codegen/generator/expressions/module-values.ts +105 -0
  392. package/src/codegen/generator/expressions/primary.ts +35 -5
  393. package/src/codegen/generator/expressions.ts +3 -0
  394. package/src/codegen/generator/module.ts +16 -5
  395. package/src/codegen/generator/state.ts +6 -0
  396. package/src/codegen/generator/statements/dispatch.ts +9 -0
  397. package/src/codegen/generator/tables.ts +27 -0
  398. package/src/driver/build-key.ts +6 -1
  399. package/src/driver/bundler/commonjs.ts +18 -5
  400. package/src/driver/bundler/deferred.ts +2 -1
  401. package/src/driver/bundler/dynamic-import.ts +135 -0
  402. package/src/driver/bundler/graph.ts +34 -19
  403. package/src/driver/bundler/merge.ts +38 -64
  404. package/src/driver/bundler/namespace-import.ts +59 -0
  405. package/src/driver/bundler/reexport-fixup.ts +102 -0
  406. package/src/driver/bundler/resolve.ts +49 -5
  407. package/src/driver/bundler/symbols.ts +13 -0
  408. package/src/driver/bundler/types.ts +1 -0
  409. package/src/driver/compiler.ts +14 -1
  410. package/src/driver/config.ts +55 -0
  411. package/src/driver/frontend.ts +13 -8
  412. package/src/driver/index.ts +8 -0
  413. package/src/driver/options.ts +13 -1
  414. package/src/driver/runtime-objects.ts +2 -0
  415. package/src/driver/storage.ts +84 -0
  416. package/src/driver/version.ts +1 -1
  417. package/src/extensions/gui/features.ts +2 -2
  418. package/src/extensions/gui/index.ts +3 -1
  419. package/src/extensions/node/async-hooks/index.ts +23 -0
  420. package/src/extensions/node/buffer/index.ts +2 -0
  421. package/src/extensions/node/child_process/index.ts +13 -1
  422. package/src/extensions/node/console/index.ts +44 -0
  423. package/src/extensions/node/constants/index.ts +34 -0
  424. package/src/extensions/node/diagnostics-channel/index.ts +20 -0
  425. package/src/extensions/node/dns/index.ts +18 -0
  426. package/src/extensions/node/events/index.ts +1 -0
  427. package/src/extensions/node/http/index.ts +5 -3
  428. package/src/extensions/node/http2/index.ts +20 -0
  429. package/src/extensions/node/index.ts +36 -0
  430. package/src/extensions/node/module/index.ts +19 -0
  431. package/src/extensions/node/os/index.ts +4 -3
  432. package/src/extensions/node/path/index.ts +9 -3
  433. package/src/extensions/node/perf_hooks/index.ts +19 -0
  434. package/src/extensions/node/readline-promises/index.ts +18 -0
  435. package/src/extensions/node/sqlite/index.ts +20 -0
  436. package/src/extensions/node/stream/index.ts +3 -0
  437. package/src/extensions/node/stream-web/index.ts +21 -0
  438. package/src/extensions/node/string-decoder/index.ts +18 -0
  439. package/src/extensions/node/timers/index.ts +27 -0
  440. package/src/extensions/node/timers-promises/index.ts +19 -0
  441. package/src/extensions/node/tls/index.ts +20 -0
  442. package/src/extensions/node/tty/index.ts +18 -0
  443. package/src/extensions/node/url/index.ts +1 -0
  444. package/src/extensions/node/util/index.ts +15 -3
  445. package/src/extensions/node/util-types/index.ts +33 -0
  446. package/src/extensions/node/worker_threads/index.ts +1 -0
  447. package/src/extensions/node/zlib/compression.ts +48 -0
  448. package/src/extensions/node/zlib/index.ts +23 -2
  449. package/src/extensions/registry.ts +8 -2
  450. package/src/extensions/storage.ts +57 -0
  451. package/src/lexer/scanner/punctuation.ts +7 -1
  452. package/src/lexer/scanner/regex.ts +31 -22
  453. package/src/lexer/scanner.ts +7 -0
  454. package/src/lexer/token.ts +2 -0
  455. package/src/parser/declarations/classes.ts +7 -0
  456. package/src/parser/declarations/functions.ts +9 -3
  457. package/src/parser/expressions.ts +29 -20
  458. package/src/parser/helpers.ts +1 -0
  459. package/src/parser/literals.ts +28 -0
  460. package/src/parser/statements.ts +3 -0
  461. package/src/parser/types.ts +106 -43
  462. /package/runtime/{ext_media → xt_media}/decode_audio.cpp +0 -0
  463. /package/runtime/{ext_media → xt_media}/media.cpp +0 -0
  464. /package/runtime/{ext_media → xt_media}/media_bridge.c +0 -0
@@ -346,6 +346,9 @@ export class TypeChecker {
346
346
  for (const argument of call.arguments) this.checkExpression(argument, flow, context);
347
347
  return this.resolver.inferExpression(call, (symbol) => this.lookup(symbol.id, flow));
348
348
  }
349
+ case SyntaxKind.ImportExpression:
350
+ this.checkExpression((expression as unknown as { specifier: Expression }).specifier, flow, context);
351
+ return ANY;
349
352
  case SyntaxKind.BinaryExpression:
350
353
  return this.checkBinary(expression as BinaryExpression, flow, context);
351
354
  case SyntaxKind.ConditionalExpression: {
@@ -492,7 +495,11 @@ export class TypeChecker {
492
495
  const target = unwrap(expression);
493
496
  if (target.kind === SyntaxKind.Identifier) {
494
497
  const symbol = this.binding.symbolOfIdentifier.get(target as Identifier);
495
- return symbol ? this.lookup(symbol.id, flow) : ANY;
498
+ // A write target takes the variable's *declared* type, not the
499
+ // flow-narrowed type: inside `if (mode === "interactive")` the branch
500
+ // narrows `mode` to `"interactive"`, but `mode = "print"` is still valid
501
+ // because its declared type is the full `AppMode` union.
502
+ return symbol ? (this.resolver.typeOfSymbolId(symbol.id) ?? ANY) : ANY;
496
503
  }
497
504
  if (target.kind === SyntaxKind.PropertyAccessExpression) {
498
505
  const access = target as PropertyAccessExpression;
package/src/cli/main.ts CHANGED
@@ -402,6 +402,7 @@ function dispatch(argv: readonly string[], io: CliIo): number {
402
402
  * write output. The checker is on unless `--no-check` is passed. */
403
403
  const { diagnostics } = compileEntry(entry, registry, {
404
404
  check: !args.flags.has("no-check"),
405
+ ...(resolved.config.moduleOverrides ? { moduleOverrides: resolved.config.moduleOverrides } : {}),
405
406
  });
406
407
  const failed = diagnostics.some((diagnostic) => diagnostic.category === "error");
407
408
  if (args.flags.has("json")) {
@@ -455,6 +456,7 @@ function dispatch(argv: readonly string[], io: CliIo): number {
455
456
  const { ir, diagnostics } = compileEntry(entry, registry, {
456
457
  debug: Boolean(args.flags.get("debug")),
457
458
  check: !args.flags.has("no-check"),
459
+ ...(resolved.config.moduleOverrides ? { moduleOverrides: resolved.config.moduleOverrides } : {}),
458
460
  });
459
461
  if (diagnostics.some((d) => d.category === "error")) {
460
462
  if (args.flags.has("json")) {
@@ -518,6 +520,7 @@ function dispatch(argv: readonly string[], io: CliIo): number {
518
520
  verbose: Boolean(args.flags.get("verbose")),
519
521
  extensions: registry,
520
522
  app: mergeAppConfig(args.flags, config),
523
+ storage: config.storage,
521
524
  debug: Boolean(args.flags.get("debug")),
522
525
  check: !args.flags.has("no-check"),
523
526
  lto: Boolean(args.flags.get("lto")) || config.lto === true,
@@ -525,6 +528,7 @@ function dispatch(argv: readonly string[], io: CliIo): number {
525
528
  ...(pgoDir ? { pgoDir } : {}),
526
529
  ...(features.length > 0 ? { features } : {}),
527
530
  ...(noFeatures.length > 0 ? { noFeatures } : {}),
531
+ ...(config.moduleOverrides ? { moduleOverrides: config.moduleOverrides } : {}),
528
532
  });
529
533
 
530
534
  if (result.diagnostics.some((d) => d.category === "error")) {
@@ -115,7 +115,10 @@ export const accessCallMethods: AccessCallMethods = {
115
115
  const moduleExports = this.moduleExportsOfSymbol(
116
116
  this.binding.symbolOfIdentifier.get(node.expression as Identifier),
117
117
  );
118
- const exported = moduleExports?.[node.name.text];
118
+ const exported =
119
+ moduleExports && Object.prototype.hasOwnProperty.call(moduleExports, node.name.text)
120
+ ? moduleExports[node.name.text]
121
+ : undefined;
119
122
  if (exported?.valueSymbol) {
120
123
  this.extraDeclarations.add(`declare i64 @${exported.valueSymbol}(i32, i64*)`);
121
124
  const result = this.reg();
@@ -12,7 +12,7 @@ import {
12
12
  type PropertyAccessExpression,
13
13
  type SpreadElement,
14
14
  } from "../../../ast/nodes.js";
15
- import { SymbolKind } from "../../../binder/binder.js";
15
+ import { implementationFunctionInfo, SymbolKind } from "../../../binder/binder.js";
16
16
  import type { ModuleExport } from "../../../extensions/registry.js";
17
17
  import { i64, XT_UNDEFINED } from "../../values.js";
18
18
  import {
@@ -107,8 +107,7 @@ export const invocationCallMethods: InvocationCallMethods = {
107
107
  if (defaultExport) return this.emitModuleExport(node, defaultExport);
108
108
  }
109
109
  if (symbol && symbol.kind === SymbolKind.Function) {
110
- const declaration = symbol.declarations[0];
111
- const fn = declaration ? this.binding.functionOfNode.get(declaration) : undefined;
110
+ const fn = implementationFunctionInfo(this.binding, symbol);
112
111
  /* Generator and `async` functions are not called directly: the call
113
112
  * must create a suspended generator / start a coroutine, so fall
114
113
  * through to the closure-call path. The same applies to a function that
@@ -228,7 +227,12 @@ export const invocationCallMethods: InvocationCallMethods = {
228
227
  // named exports, exactly like a named import of `readFileSync`.
229
228
  const moduleExports = this.moduleExportsOfSymbol(targetSymbol);
230
229
  if (moduleExports) {
231
- const exported = moduleExports[method];
230
+ // `hasOwn` guards against `Object.prototype` members leaking in as
231
+ // fake exports (`ns.hasOwnProperty(...)` is an object method, not an
232
+ // imported function).
233
+ const exported = Object.prototype.hasOwnProperty.call(moduleExports, method)
234
+ ? moduleExports[method]
235
+ : undefined;
232
236
  if (exported) return this.emitModuleExport(node, exported);
233
237
  }
234
238
  }
@@ -148,7 +148,8 @@ export class GeneratorContext {
148
148
  for (const specifierNode of bindings.elements) {
149
149
  if (specifierNode.isTypeOnly) continue;
150
150
  const importedName = specifierNode.propertyName?.text ?? specifierNode.name.text;
151
- const exported = module.exports?.[importedName];
151
+ const exported =
152
+ module.exports && Object.hasOwn(module.exports, importedName) ? module.exports[importedName] : undefined;
152
153
  const symbol = this.binding.symbolOfDeclaration.get(specifierNode.name);
153
154
  if (!symbol) continue;
154
155
  if (exported) {
@@ -229,7 +230,8 @@ export class GeneratorContext {
229
230
  private bindModuleAlias(symbol: SymbolInfo, module: ExtensionModule): void {
230
231
  if (module.namespace) {
231
232
  this.importNamespaces.set(symbol.id, module.namespace);
232
- } else if (module.exports) {
233
+ }
234
+ if (module.exports) {
233
235
  this.importModuleExports.set(symbol.id, module.exports);
234
236
  }
235
237
  }
@@ -409,7 +411,7 @@ export class GeneratorContext {
409
411
  if (this.unsupportedCount === 0) {
410
412
  this.diagnostics.error(
411
413
  DiagnosticCode.CodegenError,
412
- `Internal: no slot for '${symbol.name}' in ${this.current.fn.name}`,
414
+ `Internal: no slot for '${symbol.name}' in ${this.current.fn.name} (${this.fileNameOf(this.current.fn.node)})`,
413
415
  );
414
416
  }
415
417
  return i64(XT_UNDEFINED);
@@ -140,6 +140,7 @@ export const assignmentExpressionMethods: AssignmentExpressionMethods = {
140
140
  return;
141
141
  }
142
142
  case SyntaxKind.ParenthesizedExpression:
143
+ case SyntaxKind.NonNullExpression:
143
144
  this.emitAssignmentTarget((target as { expression: Expression }).expression, value);
144
145
  return;
145
146
  case SyntaxKind.ArrayLiteralExpression:
@@ -0,0 +1,105 @@
1
+ /**
2
+ * First-class values for imported extension bindings.
3
+ *
4
+ * An imported binding is normally called (`readFileSync(...)`) or namespaced
5
+ * (`path.join(...)`), both lowered before identifier handling. When it is read
6
+ * as a *value* — `const a = assert`, `arr.filter(strictEqual)` — the runtime
7
+ * symbol has no object of its own, so these helpers wrap it in a closure (or,
8
+ * for a whole-namespace import, build an object holding every export).
9
+ */
10
+
11
+ import { i64, XT_UNDEFINED } from "../../values.js";
12
+ import { NAMESPACE_STATICS } from "../tables.js";
13
+ import type { ModuleExport, ModuleExports } from "../../../extensions/registry.js";
14
+ import type { Expression } from "../../../ast/nodes.js";
15
+ import type { Generator } from "../generator.js";
16
+
17
+ export interface ModuleValueExpressionMethods {
18
+ /** Lower one module export to a first-class closure value. */
19
+ emitModuleExportValue(this: Generator, exported: ModuleExport): string;
20
+ /** Build a namespace object holding every export of an imported module. */
21
+ emitNamespaceObject(this: Generator, exports: ModuleExports): string;
22
+ /** Lower a non-literal `import(specifier)` to a rejected promise. */
23
+ emitDynamicImportReject(this: Generator, specifier: Expression): string;
24
+ }
25
+
26
+ export const moduleValueExpressionMethods: ModuleValueExpressionMethods = {
27
+ emitModuleExportValue(this: Generator, exported: ModuleExport): string {
28
+ if (exported.symbol) {
29
+ // A direct runtime function: wrap its `(argc, argv)` pointer in a closure.
30
+ this.extraDeclarations.add(`declare i64 @${exported.symbol}(i32, i64*)`);
31
+ const fnPtr = this.reg();
32
+ this.emit(` ${fnPtr} = ptrtoint i64 (i32, i64*)* @${exported.symbol} to i64`);
33
+ const env = this.alloca();
34
+ this.emit(` store i64 ${fnPtr}, i64* ${env}`);
35
+ const closure = this.reg();
36
+ this.emit(
37
+ ` ${closure} = call i64 @xt_closure_new(i8* bitcast (i64 (i64, i64, i32, i64*)* @xt_fnptr_trampoline to i8*), i32 1, i64* ${env})`,
38
+ );
39
+ return closure;
40
+ }
41
+ if (exported.valueSymbol) {
42
+ // A plain value (`constants.O_WRONLY`, `worker_threads.isMainThread`):
43
+ // the getter has the uniform `(i32, i64*)` ABI and is invoked with no
44
+ // arguments. This makes it work inside a built namespace object, not just
45
+ // as a direct named import.
46
+ this.extraDeclarations.add(`declare i64 @${exported.valueSymbol}(i32, i64*)`);
47
+ const result = this.reg();
48
+ this.emit(` ${result} = call i64 @${exported.valueSymbol}(i32 0, i64* null)`);
49
+ return result;
50
+ }
51
+ if (exported.namespace && exported.method) {
52
+ const dispatcher = NAMESPACE_STATICS[exported.namespace];
53
+ if (dispatcher) {
54
+ this.extraDeclarations.add(`declare i64 @${dispatcher}(i64, i32, i64*)`);
55
+ const name = this.stringValue(exported.method);
56
+ const fnPtr = this.reg();
57
+ this.emit(` ${fnPtr} = ptrtoint i64 (i64, i32, i64*)* @${dispatcher} to i64`);
58
+ const env = `%mval${this.current.allocas.length}`;
59
+ this.current.allocas.push(`${env} = alloca i64, i32 2`);
60
+ const slot0 = this.reg();
61
+ this.emit(` ${slot0} = getelementptr i64, i64* ${env}, i32 0`);
62
+ this.emit(` store i64 ${name}, i64* ${slot0}`);
63
+ const slot1 = this.reg();
64
+ this.emit(` ${slot1} = getelementptr i64, i64* ${env}, i32 1`);
65
+ this.emit(` store i64 ${fnPtr}, i64* ${slot1}`);
66
+ const closure = this.reg();
67
+ this.emit(
68
+ ` ${closure} = call i64 @xt_closure_new(i8* bitcast (i64 (i64, i64, i32, i64*)* @xt_method_trampoline to i8*), i32 2, i64* ${env})`,
69
+ );
70
+ return closure;
71
+ }
72
+ }
73
+ return i64(XT_UNDEFINED);
74
+ },
75
+
76
+ emitNamespaceObject(this: Generator, exports: ModuleExports): string {
77
+ const object = this.reg();
78
+ this.emit(` ${object} = call i64 @xt_object_new()`);
79
+ for (const [name, exported] of Object.entries(exports)) {
80
+ const key = this.stringValue(name);
81
+ const value = this.emitModuleExportValue(exported);
82
+ this.emit(` call i64 @xt_set(i64 ${object}, i64 ${key}, i64 ${value})`);
83
+ }
84
+ return object;
85
+ },
86
+
87
+ emitDynamicImportReject(this: Generator, specifier: Expression): string {
88
+ // Evaluate the specifier for its side effects, then reject: a compiled
89
+ // binary has no runtime module loader to resolve a computed specifier.
90
+ this.emitExpression(specifier);
91
+ const message = this.stringValue(
92
+ "dynamic import with a non-literal specifier is not supported in compiled binaries",
93
+ );
94
+ const argPtr = `%dynimp${this.current.allocas.length}`;
95
+ this.current.allocas.push(`${argPtr} = alloca i64, i32 1`);
96
+ const argSlot = this.reg();
97
+ this.emit(` ${argSlot} = getelementptr i64, i64* ${argPtr}, i32 0`);
98
+ this.emit(` store i64 ${message}, i64* ${argSlot}`);
99
+ const error = this.reg();
100
+ this.emit(` ${error} = call i64 @xt_error_ctor(i32 1, i64* ${argPtr})`);
101
+ const promise = this.reg();
102
+ this.emit(` ${promise} = call i64 @xt_promise_reject(i64 ${error})`);
103
+ return promise;
104
+ },
105
+ };
@@ -15,6 +15,7 @@ import {
15
15
  type Expression,
16
16
  type FunctionExpression,
17
17
  type Identifier,
18
+ type ImportExpression,
18
19
  type NewExpression,
19
20
  type ObjectLiteralExpression,
20
21
  type PostfixUnaryExpression,
@@ -26,7 +27,7 @@ import {
26
27
  type YieldExpression,
27
28
  type ArrayLiteralExpression,
28
29
  } from "../../../ast/nodes.js";
29
- import { SymbolKind, type SymbolInfo } from "../../../binder/binder.js";
30
+ import { implementationFunctionInfo, SymbolKind, type SymbolInfo } from "../../../binder/binder.js";
30
31
  import { DiagnosticCode } from "../../../diagnostics/diagnostic.js";
31
32
  import { i64, numberLiteral, XT_FALSE, XT_NULL, XT_TRUE, XT_UNDEFINED } from "../../values.js";
32
33
  import {
@@ -38,6 +39,7 @@ import {
38
39
  NAMESPACE_PROPERTIES,
39
40
  NAMESPACE_STATICS,
40
41
  NAMESPACE_VALUES,
42
+ WEB_GLOBALS,
41
43
  } from "../tables.js";
42
44
  import type { GlobalValue } from "../../../extensions/registry.js";
43
45
  import type { Generator } from "../generator.js";
@@ -73,6 +75,10 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
73
75
  switch (node.kind) {
74
76
  case SyntaxKind.Identifier:
75
77
  return this.emitIdentifier(node as Identifier);
78
+ case SyntaxKind.PrivateIdentifier:
79
+ // A bare `#field` (the `#field in obj` test) names the private field's
80
+ // literal storage key, which is the `#field` string.
81
+ return this.stringValue((node as { text: string }).text);
76
82
  case SyntaxKind.NumericLiteral: {
77
83
  const value = (node as { value: number }).value;
78
84
  return numberLiteral(value);
@@ -134,6 +140,12 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
134
140
  return this.emitNew(node as NewExpression);
135
141
  case SyntaxKind.AwaitExpression:
136
142
  return this.emitAwait(node as AwaitExpression);
143
+ case SyntaxKind.ImportExpression: {
144
+ const specifier = (node as ImportExpression).specifier;
145
+ if (specifier.kind !== SyntaxKind.StringLiteral) return this.emitDynamicImportReject(specifier);
146
+ this.unsupported(node, "expression");
147
+ return i64(XT_UNDEFINED);
148
+ }
137
149
  case SyntaxKind.YieldExpression:
138
150
  return this.emitYield(node as YieldExpression);
139
151
  case SyntaxKind.ClassExpression: {
@@ -250,8 +262,18 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
250
262
  this.emit(` ${result} = call i64 @${defaultExport.valueSymbol}(i32 0, i64* null)`);
251
263
  return result;
252
264
  }
253
- // Imported runtime bindings have no first-class value: they are meant
254
- // to be called (`readFileSync(...)`) or used as a namespace
265
+ // A function/method import used as a value (`const a = assert`,
266
+ // `import { strictEqual } from "assert"`) wraps the runtime symbol in a
267
+ // closure through a generic trampoline.
268
+ if (exported?.symbol || (exported?.namespace && exported?.method)) {
269
+ return this.emitModuleExportValue(exported);
270
+ }
271
+ // A whole-namespace import used as a value (`import assert from
272
+ // "node:assert"`) becomes an object holding every export.
273
+ const namespaceExports = this.moduleExportsOfSymbol(symbol);
274
+ if (namespaceExports) return this.emitNamespaceObject(namespaceExports);
275
+ // Imported namespace bindings have no first-class value yet: they are
276
+ // meant to be called (`readFileSync(...)`) or used as a namespace
255
277
  // (`path.join(...)`), both handled before identifier lowering.
256
278
  this.diagnostics.error(
257
279
  DiagnosticCode.CodegenError,
@@ -281,6 +303,13 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
281
303
  this.emit(` ${rest} = call i64 @xt_rest_args(i32 ${argc}, i64* ${argv}, i32 0)`);
282
304
  return rest;
283
305
  }
306
+ case "new.target": {
307
+ // `new.target` is the constructor inside a constructor body and
308
+ // undefined everywhere else.
309
+ const fn = this.current.fn;
310
+ if (fn.isConstructor && fn.classInfo) return this.emitClassReference(fn.classInfo);
311
+ return i64(XT_UNDEFINED);
312
+ }
284
313
  default: {
285
314
  const namespaceValue = NAMESPACE_VALUES[identifier.text];
286
315
  if (namespaceValue) {
@@ -324,6 +353,8 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
324
353
  this.reportRequireUse(identifier);
325
354
  return i64(XT_UNDEFINED);
326
355
  }
356
+ // Recognized web globals with no runtime yet lower to `undefined`.
357
+ if (WEB_GLOBALS.has(identifier.text)) return i64(XT_UNDEFINED);
327
358
  /* The parser's recovery node for a missing expression. The syntax
328
359
  * error has already been reported; "Cannot find name '<error>'" is
329
360
  * pure noise on top of it. */
@@ -369,8 +400,7 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
369
400
  },
370
401
 
371
402
  emitFunctionValue(symbol: SymbolInfo): string {
372
- const declaration = symbol.declarations[0];
373
- const fn = declaration ? this.binding.functionOfNode.get(declaration) : undefined;
403
+ const fn = implementationFunctionInfo(this.binding, symbol);
374
404
  if (!fn) return i64(XT_UNDEFINED);
375
405
  /* A declared function is a value like any closure: it captures the outer
376
406
  * bindings its body mentions, so build the environment instead of calling
@@ -9,17 +9,20 @@
9
9
  */
10
10
 
11
11
  import { primaryExpressionMethods, type PrimaryExpressionMethods } from "./expressions/primary.js";
12
+ import { moduleValueExpressionMethods, type ModuleValueExpressionMethods } from "./expressions/module-values.js";
12
13
  import { operatorExpressionMethods, type OperatorExpressionMethods } from "./expressions/operators.js";
13
14
  import { assignmentExpressionMethods, type AssignmentExpressionMethods } from "./expressions/assignment.js";
14
15
 
15
16
  export interface ExpressionMethods
16
17
  extends PrimaryExpressionMethods,
18
+ ModuleValueExpressionMethods,
17
19
  OperatorExpressionMethods,
18
20
  AssignmentExpressionMethods {}
19
21
 
20
22
  export const expressionMethods: ExpressionMethods = Object.assign(
21
23
  {},
22
24
  primaryExpressionMethods,
25
+ moduleValueExpressionMethods,
23
26
  operatorExpressionMethods,
24
27
  assignmentExpressionMethods,
25
28
  );
@@ -68,7 +68,13 @@ export const moduleMethods: ModuleMethods = {
68
68
  symbol.kind === SymbolKind.Var || symbol.kind === SymbolKind.Let || symbol.kind === SymbolKind.Const;
69
69
  const isEnum = symbol.kind === SymbolKind.Enum;
70
70
  if ((!isVariable && !isEnum) || !symbol.fn?.isModule) continue;
71
- if (isVariable && !symbol.boxed) continue;
71
+ // Every module-level binding lives in a global, not just the boxed
72
+ // (closure-captured) ones. An import cycle can reference a binding
73
+ // before its declaration statement runs (`require`ing a CommonJS module
74
+ // back through a cycle, or a re-exported `const` reached before its
75
+ // module body), and a stack slot would not exist yet; the global is
76
+ // hoisted, so the read sees the initial `undefined` instead of
77
+ // crashing with "no slot".
72
78
  const globalName = `@g.${symbol.id}`;
73
79
  this.moduleGlobals.set(symbol.id, globalName);
74
80
  this.globals.push(`${globalName} = internal global i64 ${i64(XT_UNDEFINED)}`);
@@ -228,12 +234,17 @@ export const moduleMethods: ModuleMethods = {
228
234
  // forwards every argument to the parent constructor (`super(...arguments)`).
229
235
  if (fn.isConstructor && fn.classInfo?.parentExpression) {
230
236
  const explicitBody = (fn.node as { body?: Block }).body;
231
- const parent = fn.classInfo.parentExpression;
232
- const errorName = this.errorFamilyName(parent);
237
+ const errorName = this.errorFamilyName(fn.classInfo.parentExpression);
233
238
  if (!explicitBody && !errorName) {
234
- const parentValue = this.emitExpression(parent);
239
+ // Walk the class's own prototype chain (like `emitSuperConstructor`)
240
+ // rather than re-evaluating the parent expression: the heritage clause
241
+ // is a module-scope expression, and re-evaluating it here would read a
242
+ // binding the binder never captured into the constructor.
243
+ const owner = this.emitClassReference(fn.classInfo);
244
+ const proto = this.reg();
245
+ this.emit(` ${proto} = call i64 @xt_function_get_prototype(i64 ${owner})`);
235
246
  const parentProto = this.reg();
236
- this.emit(` ${parentProto} = call i64 @xt_function_get_prototype(i64 ${parentValue})`);
247
+ this.emit(` ${parentProto} = call i64 @xt_object_get_prototype(i64 ${proto})`);
237
248
  const ctorKey = this.stringValue("__ctor");
238
249
  const parentCtor = this.reg();
239
250
  this.emit(` ${parentCtor} = call i64 @xt_get(i64 ${parentProto}, i64 ${ctorKey})`);
@@ -112,6 +112,8 @@ export const RUNTIME_DECLARATIONS: readonly string[] = [
112
112
  "declare i64 @xt_string_from_cstr(i8*)",
113
113
  "declare i64 @xt_arg(i32, i64*, i32)",
114
114
  "declare i64 @xt_closure_new(i8*, i32, i64*)",
115
+ "declare i64 @xt_fnptr_trampoline(i64, i64, i32, i64*)",
116
+ "declare i64 @xt_method_trampoline(i64, i64, i32, i64*)",
115
117
  "declare i64 @xt_function_set_metadata(i64, i64, i32)",
116
118
  "declare i64 @xt_function_set_generator(i64)",
117
119
  "declare i64 @xt_function_set_async(i64)",
@@ -154,6 +156,8 @@ export const RUNTIME_DECLARATIONS: readonly string[] = [
154
156
  "declare i64 @xt_crypto_static(i64, i32, i64*)",
155
157
  "declare i64 @xt_crypto_object(i32, i64*)",
156
158
  "declare i64 @xt_crypto_get(i64)",
159
+ "declare i64 @xt_webassembly_static(i64, i32, i64*)",
160
+ "declare i64 @xt_webassembly_object(i32, i64*)",
157
161
  "declare i64 @xt_path_static(i64, i32, i64*)",
158
162
  "declare i64 @xt_os_static(i64, i32, i64*)",
159
163
  "declare i64 @xt_buffer_static(i64, i32, i64*)",
@@ -192,6 +196,7 @@ export const RUNTIME_DECLARATIONS: readonly string[] = [
192
196
  "declare i64 @xt_util_static(i64, i32, i64*)",
193
197
  "declare i64 @xt_querystring_static(i64, i32, i64*)",
194
198
  "declare i64 @xt_assert_static(i64, i32, i64*)",
199
+ "declare i64 @xt_diagnostics_channel_static(i64, i32, i64*)",
195
200
  "declare i64 @xt_process_call(i64, i32, i64*)",
196
201
  "declare i64 @xt_process_get(i64)",
197
202
  "declare i64 @xt_map_ctor(i32, i64*)",
@@ -199,6 +204,7 @@ export const RUNTIME_DECLARATIONS: readonly string[] = [
199
204
  "declare i64 @xt_weak_map_ctor(i32, i64*)",
200
205
  "declare i64 @xt_weak_set_ctor(i32, i64*)",
201
206
  "declare i64 @xt_weak_ref_ctor(i32, i64*)",
207
+ "declare i64 @xt_finalization_registry_ctor(i32, i64*)",
202
208
  "declare i64 @xt_text_encoder_ctor(i32, i64*)",
203
209
  "declare i64 @xt_text_decoder_ctor(i32, i64*)",
204
210
  "declare i64 @xt_date_ctor(i32, i64*)",
@@ -130,6 +130,15 @@ export const statementDispatchMethods: StatementDispatchMethods = {
130
130
  case SyntaxKind.EnumDeclaration:
131
131
  this.emitEnum(statement as EnumDeclaration);
132
132
  return;
133
+ case SyntaxKind.ModuleDeclaration: {
134
+ // `declare module "..."` augments an external module's type surface; it
135
+ // introduces no runtime value, so erase it. An identifier-named
136
+ // namespace may carry runtime members and is still unsupported.
137
+ const name = (statement as { name: { kind: SyntaxKind } }).name;
138
+ if (name.kind === SyntaxKind.StringLiteral) return;
139
+ this.unsupported(statement, "statement");
140
+ return;
141
+ }
133
142
  default:
134
143
  this.unsupported(statement, "statement");
135
144
  }
@@ -244,6 +244,7 @@ export const NAMESPACE_STATICS: Record<string, string> = {
244
244
  Symbol: "xt_symbol_static",
245
245
  Date: "xt_date_static",
246
246
  crypto: "xt_crypto_static",
247
+ WebAssembly: "xt_webassembly_static",
247
248
  Promise: "xt_promise_static",
248
249
  ArrayBuffer: "xt_array_buffer_static",
249
250
  path: "xt_path_static",
@@ -264,6 +265,7 @@ export const NAMESPACE_STATICS: Record<string, string> = {
264
265
  util: "xt_util_static",
265
266
  querystring: "xt_querystring_static",
266
267
  assert: "xt_assert_static",
268
+ diagnostics_channel: "xt_diagnostics_channel_static",
267
269
  ...TYPED_ARRAY_STATICS,
268
270
  };
269
271
 
@@ -288,8 +290,31 @@ export const SYMBOL_WELL_KNOWN = new Set<string>([
288
290
  export const NAMESPACE_VALUES: Record<string, string> = {
289
291
  Math: "xt_math_object",
290
292
  crypto: "xt_crypto_object",
293
+ WebAssembly: "xt_webassembly_object",
291
294
  };
292
295
 
296
+ /**
297
+ * Standard web-platform globals recognized so code reaching for them
298
+ * type-checks, but with no runtime implementation yet: they lower to
299
+ * `undefined`. A construct such as `new AbortController()` therefore fails at
300
+ * run time rather than being reported as an unknown name.
301
+ */
302
+ export const WEB_GLOBALS: ReadonlySet<string> = new Set<string>([
303
+ "globalThis",
304
+ "AbortController",
305
+ "AbortSignal",
306
+ "Reflect",
307
+ "Proxy",
308
+ "Intl",
309
+ "FormData",
310
+ "Blob",
311
+ "Headers",
312
+ "Request",
313
+ "Response",
314
+ "ReadableStream",
315
+ "EventTarget",
316
+ ]);
317
+
293
318
  /** Namespace identifiers whose property access maps to a runtime getter. */
294
319
  export const NAMESPACE_PROPERTIES: Record<string, string> = {
295
320
  process: "xt_process_get",
@@ -307,6 +332,7 @@ export const CTOR_FUNCTIONS: Record<string, string> = {
307
332
  WeakMap: "xt_weak_map_ctor",
308
333
  WeakSet: "xt_weak_set_ctor",
309
334
  WeakRef: "xt_weak_ref_ctor",
335
+ FinalizationRegistry: "xt_finalization_registry_ctor",
310
336
  Date: "xt_date_ctor",
311
337
  RegExp: "xt_regexp_ctor",
312
338
  Promise: "xt_promise_ctor",
@@ -344,6 +370,7 @@ export const FIRST_CLASS_CONSTRUCTORS = new Set<string>([
344
370
  "WeakMap",
345
371
  "WeakSet",
346
372
  "WeakRef",
373
+ "FinalizationRegistry",
347
374
  "Date",
348
375
  "RegExp",
349
376
  "Promise",
@@ -14,6 +14,7 @@ import type { AppConfig } from "./config.js";
14
14
  import { compilerFingerprint, registryFingerprint, runtimeFingerprint } from "./fingerprint.js";
15
15
  import { COMPILER_VERSION } from "./version.js";
16
16
  import type { IconInfo } from "./icon.js";
17
+ import type { ResolvedStorage } from "./storage.js";
17
18
  import type { PgoMode } from "./toolchain.js";
18
19
 
19
20
  export interface CacheKeyInput {
@@ -25,6 +26,8 @@ export interface CacheKeyInput {
25
26
  readonly runtimeDir: string;
26
27
  readonly icon?: IconInfo;
27
28
  readonly app: AppConfig;
29
+ /** Storage backend/path embedded into the binary (storage extension). */
30
+ readonly storage: ResolvedStorage;
28
31
  readonly debug: boolean;
29
32
  readonly lto: boolean;
30
33
  /** Whether the semantic checker ran (default true). */
@@ -37,7 +40,7 @@ export interface CacheKeyInput {
37
40
 
38
41
  /** Hash every input that can change the produced binary. */
39
42
  export function buildCacheKey(input: CacheKeyInput): string {
40
- const { app, icon, pgo } = input;
43
+ const { app, icon, pgo, storage } = input;
41
44
  return hashParts([
42
45
  COMPILER_VERSION,
43
46
  compilerFingerprint(),
@@ -51,6 +54,8 @@ export function buildCacheKey(input: CacheKeyInput): string {
51
54
  app.name ?? "",
52
55
  String(app.bundle ?? false),
53
56
  app.bundleId ?? "",
57
+ storage.backend,
58
+ storage.path,
54
59
  String(input.debug),
55
60
  String(input.lto),
56
61
  String(input.check !== false),
@@ -84,7 +84,10 @@ export function collectRequireSites(sourceFile: SourceFileNode, bind: BindResult
84
84
  if (callee.kind !== SyntaxKind.Identifier) return;
85
85
  if (!isFreeRequire(callee as Identifier, bind)) return;
86
86
  const first = call.arguments[0];
87
- if (first && first.kind === SyntaxKind.StringLiteral) {
87
+ if (
88
+ first &&
89
+ (first.kind === SyntaxKind.StringLiteral || first.kind === SyntaxKind.NoSubstitutionTemplateLiteral)
90
+ ) {
88
91
  sites.push({ node: call, specifier: (first as StringLiteral).value });
89
92
  }
90
93
  });
@@ -125,7 +128,9 @@ export function prepareCommonJS(record: ModuleRecord): void {
125
128
  const prefixStatements: Statement[] = [
126
129
  variableStatement(moduleName, objectLiteral([propertyAssignment("exports", objectLiteral([]))]), anchor),
127
130
  ];
128
- prefixStatements.push(variableStatement(exportsName, member(moduleName, "exports", anchor), anchor));
131
+ // `exports` may be reassigned (`exports = module.exports = {}`), so the alias
132
+ // is a `let`, not a `const`.
133
+ prefixStatements.push(variableStatement(exportsName, member(moduleName, "exports", anchor), anchor, "let"));
129
134
 
130
135
  const suffixStatements: Statement[] = [];
131
136
  const defaultName = `${record.prefix}$cjs_default`;
@@ -167,7 +172,10 @@ export function lowerCommonJSRequires(record: ModuleRecord, context: CommonJSLow
167
172
  if (callee.kind !== SyntaxKind.Identifier) return undefined;
168
173
  if (!isFreeRequire(callee as Identifier, record.bind)) return undefined;
169
174
  const first = call.arguments[0];
170
- if (!first || first.kind !== SyntaxKind.StringLiteral) {
175
+ if (
176
+ !first ||
177
+ (first.kind !== SyntaxKind.StringLiteral && first.kind !== SyntaxKind.NoSubstitutionTemplateLiteral)
178
+ ) {
171
179
  context.diagnostics.error(
172
180
  DiagnosticCode.UnsupportedFeature,
173
181
  "CommonJS `require()` with a non-literal argument is not supported",
@@ -388,7 +396,12 @@ function undefinedLiteral(anchor: number): Expression {
388
396
  return { kind: SyntaxKind.UndefinedKeyword, start: anchor, end: anchor };
389
397
  }
390
398
 
391
- function variableStatement(name: string, initializer: Expression, anchor: number): VariableStatement {
399
+ function variableStatement(
400
+ name: string,
401
+ initializer: Expression,
402
+ anchor: number,
403
+ kind: "const" | "let" = "const",
404
+ ): VariableStatement {
392
405
  const declaration: VariableDeclaration = {
393
406
  kind: SyntaxKind.VariableDeclaration,
394
407
  name: identifier(name, anchor),
@@ -399,7 +412,7 @@ function variableStatement(name: string, initializer: Expression, anchor: number
399
412
  };
400
413
  const list: VariableDeclarationList = {
401
414
  kind: SyntaxKind.VariableDeclarationList,
402
- declarationKind: "const",
415
+ declarationKind: kind,
403
416
  declarations: [declaration],
404
417
  start: anchor,
405
418
  end: anchor,
@@ -292,10 +292,11 @@ export function eagerModuleFunctions(record: ModuleRecord): Statement[] {
292
292
  export function computeDeferredModules(
293
293
  records: readonly ModuleRecord[],
294
294
  externalSpecifiers: ReadonlySet<string>,
295
+ moduleOverrides?: Readonly<Record<string, string>>,
295
296
  ): Set<string> {
296
297
  const byPath = new Map(records.map((record) => [record.path, record]));
297
298
  const dependencyOf = (record: ModuleRecord, specifier: string): ModuleRecord | undefined => {
298
- const resolution = classifyDependency(dirname(record.path), specifier, externalSpecifiers);
299
+ const resolution = classifyDependency(dirname(record.path), specifier, externalSpecifiers, moduleOverrides);
299
300
  return resolution.kind === "file" ? byPath.get(resolution.path) : undefined;
300
301
  };
301
302
  const specifierOf = (statement: Statement): string | undefined => {