xbintsc 0.6.22 → 0.6.24

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 (191) hide show
  1. package/AGENTS.md +5 -0
  2. package/dist/src/cli/help.d.ts +1 -1
  3. package/dist/src/driver/build-key.js +2 -1
  4. package/dist/src/driver/build-key.js.map +1 -1
  5. package/dist/src/driver/bundler/concatenate.d.ts +23 -0
  6. package/dist/src/driver/bundler/concatenate.js +210 -0
  7. package/dist/src/driver/bundler/concatenate.js.map +1 -0
  8. package/dist/src/driver/bundler/merge.d.ts +4 -4
  9. package/dist/src/driver/bundler/merge.js +24 -207
  10. package/dist/src/driver/bundler/merge.js.map +1 -1
  11. package/dist/src/driver/bundler/{namespace-import.d.ts → namespace-object.d.ts} +5 -1
  12. package/dist/src/driver/bundler/{namespace-import.js → namespace-object.js} +6 -2
  13. package/dist/src/driver/bundler/namespace-object.js.map +1 -0
  14. package/dist/src/driver/bundler/{reexport-fixup.d.ts → reexport-resolution.d.ts} +9 -3
  15. package/dist/src/driver/bundler/{reexport-fixup.js → reexport-resolution.js} +16 -6
  16. package/dist/src/driver/bundler/reexport-resolution.js.map +1 -0
  17. package/dist/src/driver/fingerprint.d.ts +11 -0
  18. package/dist/src/driver/fingerprint.js +25 -0
  19. package/dist/src/driver/fingerprint.js.map +1 -1
  20. package/dist/src/driver/link-features.js +36 -11
  21. package/dist/src/driver/link-features.js.map +1 -1
  22. package/dist/src/driver/modules.d.ts +12 -5
  23. package/dist/src/driver/modules.js +12 -5
  24. package/dist/src/driver/modules.js.map +1 -1
  25. package/dist/src/driver/paths.d.ts +10 -0
  26. package/dist/src/driver/paths.js +18 -0
  27. package/dist/src/driver/paths.js.map +1 -1
  28. package/dist/src/driver/runtime-objects.d.ts +1 -1
  29. package/dist/src/driver/runtime-objects.js +22 -6
  30. package/dist/src/driver/runtime-objects.js.map +1 -1
  31. package/dist/src/driver/toolchain.d.ts +1 -1
  32. package/dist/src/driver/toolchain.js +10 -1
  33. package/dist/src/driver/toolchain.js.map +1 -1
  34. package/dist/src/driver/version.d.ts +1 -1
  35. package/dist/src/driver/version.js +1 -1
  36. package/dist/src/extensions/node/http2/feature.d.ts +14 -0
  37. package/dist/src/extensions/node/http2/feature.js +28 -0
  38. package/dist/src/extensions/node/http2/feature.js.map +1 -0
  39. package/dist/src/extensions/node/http2/index.d.ts +5 -1
  40. package/dist/src/extensions/node/http2/index.js +6 -1
  41. package/dist/src/extensions/node/http2/index.js.map +1 -1
  42. package/dist/src/extensions/node/index.js +3 -1
  43. package/dist/src/extensions/node/index.js.map +1 -1
  44. package/dist/src/extensions/node/tls/feature.d.ts +12 -0
  45. package/dist/src/extensions/node/tls/feature.js +24 -0
  46. package/dist/src/extensions/node/tls/feature.js.map +1 -0
  47. package/dist/src/extensions/node/tls/index.d.ts +5 -1
  48. package/dist/src/extensions/node/tls/index.js +5 -1
  49. package/dist/src/extensions/node/tls/index.js.map +1 -1
  50. package/dist/src/extensions/node/zlib/compression.js +11 -6
  51. package/dist/src/extensions/node/zlib/compression.js.map +1 -1
  52. package/dist/src/extensions/registry.js +2 -1
  53. package/dist/src/extensions/registry.js.map +1 -1
  54. package/dist/src/extensions/storage.js +4 -3
  55. package/dist/src/extensions/storage.js.map +1 -1
  56. package/dist/src/extensions/tls.d.ts +26 -0
  57. package/dist/src/extensions/tls.js +46 -0
  58. package/dist/src/extensions/tls.js.map +1 -0
  59. package/dist/tests/driver/deferred-reexport.test.js +25 -0
  60. package/dist/tests/driver/deferred-reexport.test.js.map +1 -1
  61. package/dist/tests/driver/link-features.test.js +9 -0
  62. package/dist/tests/driver/link-features.test.js.map +1 -1
  63. package/dist/tests/e2e/fetch.test.js +3 -1
  64. package/dist/tests/e2e/fetch.test.js.map +1 -1
  65. package/dist/tests/e2e/http2.test.d.ts +7 -0
  66. package/dist/tests/e2e/http2.test.js +201 -0
  67. package/dist/tests/e2e/http2.test.js.map +1 -0
  68. package/dist/tests/e2e/net-helpers.d.ts +28 -0
  69. package/dist/tests/e2e/net-helpers.js +59 -0
  70. package/dist/tests/e2e/net-helpers.js.map +1 -0
  71. package/dist/tests/e2e/node-modules.test.js +3 -5
  72. package/dist/tests/e2e/node-modules.test.js.map +1 -1
  73. package/dist/tests/e2e/tls.test.d.ts +10 -0
  74. package/dist/tests/e2e/tls.test.js +197 -0
  75. package/dist/tests/e2e/tls.test.js.map +1 -0
  76. package/dist/tests/extensions/storage.test.js +3 -2
  77. package/dist/tests/extensions/storage.test.js.map +1 -1
  78. package/doc/ai/contributing.md +14 -0
  79. package/doc/ai/extensions.md +5 -3
  80. package/doc/ai/language-support.md +1 -1
  81. package/doc/ai/zh-CN/contributing.md +12 -0
  82. package/doc/ai/zh-CN/extensions.md +4 -2
  83. package/doc/ai/zh-CN/language-support.md +1 -1
  84. package/doc/gui/api.md +1 -1
  85. package/doc/gui/build.md +5 -3
  86. package/doc/gui/rendering.md +1 -1
  87. package/doc/gui.md +1 -1
  88. package/doc/implemented/async.md +1 -1
  89. package/doc/implemented/extensions.md +1 -0
  90. package/doc/implemented/fetch.md +19 -4
  91. package/doc/implemented/node/http2.md +51 -0
  92. package/doc/implemented/node/tls.md +56 -0
  93. package/doc/implemented/node.md +8 -0
  94. package/doc/implemented/storage.md +2 -1
  95. package/doc/implemented.md +2 -2
  96. package/doc/unimplemented/node/modules.md +6 -6
  97. package/doc/unimplemented/toolchain.md +1 -1
  98. package/doc/zh-CN/gui/api.md +1 -1
  99. package/doc/zh-CN/gui/build.md +4 -2
  100. package/doc/zh-CN/gui/rendering.md +1 -1
  101. package/doc/zh-CN/gui.md +1 -1
  102. package/doc/zh-CN/implemented/async.md +1 -1
  103. package/doc/zh-CN/implemented/extensions.md +1 -0
  104. package/doc/zh-CN/implemented/fetch.md +15 -3
  105. package/doc/zh-CN/implemented/node/http2.md +44 -0
  106. package/doc/zh-CN/implemented/node/tls.md +47 -0
  107. package/doc/zh-CN/implemented/node.md +7 -0
  108. package/doc/zh-CN/implemented/storage.md +2 -1
  109. package/doc/zh-CN/implemented.md +2 -2
  110. package/doc/zh-CN/unimplemented/node/modules.md +3 -3
  111. package/doc/zh-CN/unimplemented/toolchain.md +1 -1
  112. package/package.json +16 -8
  113. package/runtime/ext_node/http2/http2.c +25 -11
  114. package/runtime/ext_node/http2/http2_backend.c +48 -0
  115. package/runtime/ext_node/http2/http2_bridge.c +25 -0
  116. package/runtime/ext_node/http2/parts/api.inc +40 -0
  117. package/runtime/ext_node/http2/parts/client.inc +215 -0
  118. package/runtime/ext_node/http2/parts/common.inc +330 -0
  119. package/runtime/ext_node/http2/parts/events.inc +139 -0
  120. package/runtime/ext_node/http2/parts/server.inc +301 -0
  121. package/runtime/ext_node/http2/parts/streams.inc +254 -0
  122. package/runtime/ext_node/tls/parts/api.inc +38 -0
  123. package/runtime/ext_node/tls/parts/connect.inc +107 -0
  124. package/runtime/ext_node/tls/parts/helpers.inc +121 -0
  125. package/runtime/ext_node/tls/parts/server.inc +101 -0
  126. package/runtime/ext_node/tls/parts/socket.inc +171 -0
  127. package/runtime/ext_node/tls/tls.c +21 -13
  128. package/runtime/ext_node/tls/tls_backend.c +50 -0
  129. package/runtime/ext_node/zlib/{miniz/compression_bridge.c → compression_bridge.c} +1 -1
  130. package/runtime/xt_fetch/async.inc +19 -12
  131. package/runtime/xt_fetch/socket.inc +55 -0
  132. package/runtime/xt_fetch.c +3 -0
  133. package/runtime/xt_http2/nghttp2_compat.h +19 -0
  134. package/runtime/xt_http2/nghttp2_static.h +18 -0
  135. package/runtime/xt_http2_api.h +38 -0
  136. package/runtime/xt_node_tls_api.h +37 -0
  137. package/runtime/xt_protocol_registry.c +22 -0
  138. package/runtime/xt_storage/storage_internal.h +3 -3
  139. package/runtime/xt_tls/parts/api.inc +21 -0
  140. package/runtime/xt_tls/parts/client.inc +112 -0
  141. package/runtime/xt_tls/parts/io.inc +157 -0
  142. package/runtime/xt_tls/parts/server.inc +102 -0
  143. package/runtime/xt_tls/parts/setup.inc +146 -0
  144. package/runtime/xt_tls/tls_bridge.c +27 -0
  145. package/runtime/xt_tls/tls_core.c +39 -0
  146. package/runtime/xt_tls/tls_internal.h +73 -0
  147. package/runtime/xt_tls_api.h +73 -0
  148. package/scripts/build-gui.ts +8 -7
  149. package/scripts/build-tls.ts +248 -0
  150. package/scripts/check-file-length.ts +4 -25
  151. package/scripts/fetch-vendored.ts +244 -0
  152. package/scripts/package-release.ts +13 -3
  153. package/src/driver/build-key.ts +7 -1
  154. package/src/driver/bundler/README.md +55 -0
  155. package/src/driver/bundler/concatenate.ts +244 -0
  156. package/src/driver/bundler/merge.ts +24 -215
  157. package/src/driver/bundler/{namespace-import.ts → namespace-object.ts} +5 -1
  158. package/src/driver/bundler/{reexport-fixup.ts → reexport-resolution.ts} +15 -5
  159. package/src/driver/fingerprint.ts +24 -0
  160. package/src/driver/link-features.ts +33 -11
  161. package/src/driver/modules.ts +12 -5
  162. package/src/driver/paths.ts +20 -0
  163. package/src/driver/runtime-objects.ts +25 -6
  164. package/src/driver/toolchain.ts +11 -2
  165. package/src/driver/version.ts +1 -1
  166. package/src/extensions/node/http2/feature.ts +33 -0
  167. package/src/extensions/node/http2/index.ts +6 -1
  168. package/src/extensions/node/index.ts +3 -1
  169. package/src/extensions/node/tls/feature.ts +29 -0
  170. package/src/extensions/node/tls/index.ts +5 -1
  171. package/src/extensions/node/zlib/compression.ts +11 -6
  172. package/src/extensions/registry.ts +2 -1
  173. package/src/extensions/storage.ts +4 -3
  174. package/src/extensions/tls.ts +52 -0
  175. package/{runtime/ext_gui → vendor/stb}/stb_image.h +17 -1
  176. package/dist/src/driver/bundler/namespace-import.js.map +0 -1
  177. package/dist/src/driver/bundler/reexport-fixup.js.map +0 -1
  178. /package/{runtime/ext_node/zlib → vendor}/miniz/miniz.c +0 -0
  179. /package/{runtime/ext_node/zlib → vendor}/miniz/miniz.h +0 -0
  180. /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_common.h +0 -0
  181. /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_export.h +0 -0
  182. /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_tdef.c +0 -0
  183. /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_tdef.h +0 -0
  184. /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_tinfl.c +0 -0
  185. /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_tinfl.h +0 -0
  186. /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_zip.h +0 -0
  187. /package/{runtime/ext_gui → vendor/nanosvg}/nanosvg.h +0 -0
  188. /package/{runtime/ext_gui → vendor/nanosvg}/nanosvgrast.h +0 -0
  189. /package/{runtime/xt_storage → vendor}/sqlite3/sqlite3.c +0 -0
  190. /package/{runtime/xt_storage → vendor}/sqlite3/sqlite3.h +0 -0
  191. /package/{runtime/ext_gui → vendor/stb}/stb_truetype.h +0 -0
package/AGENTS.md CHANGED
@@ -104,6 +104,11 @@ doc/ the detailed, canonical documentation
104
104
  - **Run the gate before you claim done:** `npm run typecheck && npm run lint &&
105
105
  npm test`. End-to-end tests compile and run real binaries, so they need clang;
106
106
  they skip when it is missing.
107
+ - **Third-party sources live in `vendor/`, not in git.** `npm run vendor`
108
+ fetches the pinned stb/NanoSVG/miniz/SQLite sources
109
+ (`scripts/fetch-vendored.ts`); `npm run gui` and the test scripts fetch what
110
+ they need. Never commit files under `vendor/`; change a pin deliberately and
111
+ update its SHA-256 instead.
107
112
  - **Runtime changes are C.** Compiled functions use one ABI —
108
113
  `xt_value fn(xt_value env, int32_t argc, xt_value *argv)` — and every value is
109
114
  one NaN-boxed 64-bit word (see `runtime/rt.h`, `src/codegen/values.ts`).
@@ -4,4 +4,4 @@
4
4
  * It lives apart from the command dispatch so the executable entry point stays
5
5
  * under the repository's per-file line budget; the text is data, not logic.
6
6
  */
7
- export declare const HELP = "xbintsc 0.6.22 - TypeScript binary compiler\n\nUsage:\n xbintsc build <file.ts> [options] Compile to a native binary\n xbintsc run <file.ts> [-- args] Compile and execute\n xbintsc check <file.ts> Parse, bind and check without linking\n xbintsc watch <file.ts> [options] Rebuild whenever the source tree changes\n xbintsc emit <file.ts> Print LLVM IR\n xbintsc doctor Report the resolved toolchain\n xbintsc version Print the version\n xbintsc help Show this message\n\nOptions:\n -o, --output <path> Output path\n --out <dir> Output directory (default: build/)\n --emit <kind> exe | obj | ir (default: exe)\n -O0..-O3 Optimization level (default: -O2)\n --ext <names> Comma separated extensions (e.g. node,gui)\n --feature <names> Force optional link features on (media,gpu,images,shaping,webgl,all)\n --no-feature <n> Keep optional link features out even when detected\n --ext-native <m> Register a C++/Rust extension from a JSON manifest\n (comma separated for several)\n --config <path> Use a project config (default: auto-detect\n xbintsc.config.json)\n --no-config Do not read any project config\n --icon <path> Embed an application icon (PNG/ICO/ICNS)\n --bundle macOS: also produce a .app bundle\n --app-name <name> Bundle / display name\n --app-id <id> macOS bundle identifier (e.g. com.example.demo)\n --force Ignore the incremental cache\n --verbose Print progress information\n --time Print per-phase build timings\n --debug Emit debug info (DWARF/CodeView) and keep frame pointers\n --check Run the semantic checker (default)\n --no-check Skip the semantic checker; only erase type syntax\n --lto Compile program and runtime to LTO bitcode; link with lld\n --pgo-generate [dir] Build an instrumented binary writing profiles to dir\n --pgo-use [dir] Build with the profiles collected from --pgo-generate\n --json Print diagnostics as a JSON array on stdout\n --no-hints Do not append the \"hint: \u2026 see <doc>\" line to failures\n\nxbintsc compiles a subset of TypeScript to a native binary. Types are erased;\nonly inference-free facts (names, redeclarations, call arity) are checked.\nNode built-ins need --ext node, packages in node_modules are bundled at build\ntime, and clang 16+ is required to link.\n\nInstalled as a project dependency (npm):\n npx xbintsc doctor\n npx xbintsc build <entry.ts> --out build\n npx xbintsc run <entry.ts>\nThe first build compiles the C runtime; later builds reuse the cache.\n\nDocs: doc/ai/README.md (task guide) - doc/ai/language-support.md (subset) -\ndoc/ai/troubleshooting.md (failures) - llms.txt (index of every document).\nWhen installed from npm, these live under node_modules/xbintsc/doc/ and\nnode_modules/xbintsc/doc/npm-package.md is the project guide.\n";
7
+ export declare const HELP = "xbintsc 0.6.24 - TypeScript binary compiler\n\nUsage:\n xbintsc build <file.ts> [options] Compile to a native binary\n xbintsc run <file.ts> [-- args] Compile and execute\n xbintsc check <file.ts> Parse, bind and check without linking\n xbintsc watch <file.ts> [options] Rebuild whenever the source tree changes\n xbintsc emit <file.ts> Print LLVM IR\n xbintsc doctor Report the resolved toolchain\n xbintsc version Print the version\n xbintsc help Show this message\n\nOptions:\n -o, --output <path> Output path\n --out <dir> Output directory (default: build/)\n --emit <kind> exe | obj | ir (default: exe)\n -O0..-O3 Optimization level (default: -O2)\n --ext <names> Comma separated extensions (e.g. node,gui)\n --feature <names> Force optional link features on (media,gpu,images,shaping,webgl,all)\n --no-feature <n> Keep optional link features out even when detected\n --ext-native <m> Register a C++/Rust extension from a JSON manifest\n (comma separated for several)\n --config <path> Use a project config (default: auto-detect\n xbintsc.config.json)\n --no-config Do not read any project config\n --icon <path> Embed an application icon (PNG/ICO/ICNS)\n --bundle macOS: also produce a .app bundle\n --app-name <name> Bundle / display name\n --app-id <id> macOS bundle identifier (e.g. com.example.demo)\n --force Ignore the incremental cache\n --verbose Print progress information\n --time Print per-phase build timings\n --debug Emit debug info (DWARF/CodeView) and keep frame pointers\n --check Run the semantic checker (default)\n --no-check Skip the semantic checker; only erase type syntax\n --lto Compile program and runtime to LTO bitcode; link with lld\n --pgo-generate [dir] Build an instrumented binary writing profiles to dir\n --pgo-use [dir] Build with the profiles collected from --pgo-generate\n --json Print diagnostics as a JSON array on stdout\n --no-hints Do not append the \"hint: \u2026 see <doc>\" line to failures\n\nxbintsc compiles a subset of TypeScript to a native binary. Types are erased;\nonly inference-free facts (names, redeclarations, call arity) are checked.\nNode built-ins need --ext node, packages in node_modules are bundled at build\ntime, and clang 16+ is required to link.\n\nInstalled as a project dependency (npm):\n npx xbintsc doctor\n npx xbintsc build <entry.ts> --out build\n npx xbintsc run <entry.ts>\nThe first build compiles the C runtime; later builds reuse the cache.\n\nDocs: doc/ai/README.md (task guide) - doc/ai/language-support.md (subset) -\ndoc/ai/troubleshooting.md (failures) - llms.txt (index of every document).\nWhen installed from npm, these live under node_modules/xbintsc/doc/ and\nnode_modules/xbintsc/doc/npm-package.md is the project guide.\n";
@@ -8,7 +8,7 @@
8
8
  * not the build orchestration.
9
9
  */
10
10
  import { hashParts } from "./cache.js";
11
- import { compilerFingerprint, registryFingerprint, runtimeFingerprint } from "./fingerprint.js";
11
+ import { compilerFingerprint, registryFingerprint, runtimeFingerprint, vendoredRuntimeFingerprint, } from "./fingerprint.js";
12
12
  import { COMPILER_VERSION } from "./version.js";
13
13
  /** Hash every input that can change the produced binary. */
14
14
  export function buildCacheKey(input) {
@@ -22,6 +22,7 @@ export function buildCacheKey(input) {
22
22
  process.platform,
23
23
  registryFingerprint(input.registry),
24
24
  runtimeFingerprint(input.runtimeDir),
25
+ vendoredRuntimeFingerprint(input.runtimeDir),
25
26
  icon ? hashParts(["icon", icon.format, Buffer.from(icon.bytes).toString("base64")]) : "",
26
27
  app.name ?? "",
27
28
  String(app.bundle ?? false),
@@ -1 +1 @@
1
- {"version":3,"file":"build-key.js","sourceRoot":"","sources":["../../../src/driver/build-key.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAChG,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AA0BhD,4DAA4D;AAC5D,MAAM,UAAU,aAAa,CAAC,KAAoB;IAChD,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAC1C,OAAO,SAAS,CAAC;QACf,gBAAgB;QAChB,mBAAmB,EAAE;QACrB,KAAK,CAAC,UAAU;QAChB,KAAK,CAAC,IAAI;QACV,KAAK,CAAC,QAAQ;QACd,O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AG,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAC1C,OAAO,SAAS,CAAC;QACf,gBAAgB;QAChB,mBAAmB,EAAE;QACrB,KAAK,CAAC,UAAU;QAChB,KAAK,CAAC,IAAI;QACV,KAAK,CAAC,QAAQ;QACd,OAAO,CAAC,QAAQ;QAChB,mBAAmB,CAAC,KAAK,CAAC,QAAQ,CAAC;QACnC,kBAAkB,CAAC,KAAK,CAAC,UAAU,CAAC;QACpC,0BAA0B,CAAC,KAAK,CAAC,UAAU,CAAC;QAC5C,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;QACxF,GAAG,CAAC,IAAI,IAAI,EAAE;QACd,MAAM,CAAC,GAAG,CAAC,MAAM,IAAI,KAAK,CAAC;QAC3B,GAAG,CAAC,QAAQ,IAAI,EAAE;QAClB,OAAO,CAAC,OAAO;QACf,OAAO,CAAC,IAAI;QACZ,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC;QACnB,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC;QACjB,MAAM,CAAC,KAAK,CAAC,KAAK,KAAK,KAAK,CAAC;QAC7B,GAAG,IAAI,EAAE;QACT,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE;QACvB,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC;KAC7C,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Concatenate the merged modules into one source file (bundle phases 4-5).
3
+ *
4
+ * Phase 4 walks every module in dependency order and copies its statements into
5
+ * a single statement list: external imports stay at top level, local imports are
6
+ * dropped (their bindings were rewritten in phase 3), and a deferred module's
7
+ * body is emitted inside its `__xt_deferred_*` wrapper. Phase 5 then renames
8
+ * every top-level declaration and reference to its final unique name.
9
+ */
10
+ import { type SourceFileNode, type Statement } from "../../ast/nodes.js";
11
+ import { type DeferredAlias } from "./deferred.js";
12
+ import type { ModuleRecord } from "./types.js";
13
+ export interface ConcatenateOptions {
14
+ readonly records: readonly ModuleRecord[];
15
+ readonly deferredModules: ReadonlySet<string>;
16
+ readonly deferredAliases: ReadonlyMap<string, readonly DeferredAlias[]>;
17
+ readonly markerTargets: ReadonlySet<string>;
18
+ readonly dynamicTargets: ReadonlySet<string>;
19
+ readonly namespaceStatements: ReadonlyMap<Statement, Statement>;
20
+ readonly externalSpecifiers: ReadonlySet<string>;
21
+ readonly moduleOverrides?: Readonly<Record<string, string>>;
22
+ }
23
+ export declare function concatenateModules(options: ConcatenateOptions): SourceFileNode;
@@ -0,0 +1,210 @@
1
+ /**
2
+ * Concatenate the merged modules into one source file (bundle phases 4-5).
3
+ *
4
+ * Phase 4 walks every module in dependency order and copies its statements into
5
+ * a single statement list: external imports stay at top level, local imports are
6
+ * dropped (their bindings were rewritten in phase 3), and a deferred module's
7
+ * body is emitted inside its `__xt_deferred_*` wrapper. Phase 5 then renames
8
+ * every top-level declaration and reference to its final unique name.
9
+ */
10
+ import { dirname } from "node:path";
11
+ import { ModifierKind, SyntaxKind, } from "../../ast/nodes.js";
12
+ import { SymbolKind } from "../../binder/binder.js";
13
+ import { deferredModuleFunctions, eagerModuleFunctions } from "./deferred.js";
14
+ import { classifyDependency } from "./resolve.js";
15
+ import { renameSymbol, topLevelSymbols } from "./symbols.js";
16
+ export function concatenateModules(options) {
17
+ const { records, deferredModules, deferredAliases, markerTargets, dynamicTargets, namespaceStatements, externalSpecifiers, moduleOverrides, } = options;
18
+ const merged = [];
19
+ /* Every node keeps the module it was parsed from, so a later codegen
20
+ * diagnostic can name the right file and line instead of pointing into the
21
+ * entry module (whose text happens to start at the same offsets). */
22
+ const origins = new Map();
23
+ /* A synthesized module (an extension asset loader such as the `gui` `.html`
24
+ * transform) may contain spans copied from another file — a `<script
25
+ * src="app.js">` body, say. Nodes inside such a span keep that file, so a
26
+ * diagnostic points at real source and a plain-`.js` script stays exempt
27
+ * from the type checker. */
28
+ const originOf = (record, node) => {
29
+ const ranges = record.originRanges;
30
+ if (ranges === undefined)
31
+ return record.path;
32
+ for (const range of ranges) {
33
+ if (node.start >= range.start && node.end <= range.end)
34
+ return range.file;
35
+ }
36
+ return record.path;
37
+ };
38
+ const trackOrigin = (record, root) => {
39
+ const visit = (node) => {
40
+ origins.set(node, originOf(record, node));
41
+ const fields = node;
42
+ for (const key of Object.keys(fields)) {
43
+ if (key === "kind" || key === "start" || key === "end" || key === "text" || key === "value" || key === "raw") {
44
+ continue;
45
+ }
46
+ const value = fields[key];
47
+ if (Array.isArray(value)) {
48
+ for (const child of value)
49
+ if (isNode(child))
50
+ visit(child);
51
+ }
52
+ else if (isNode(value)) {
53
+ visit(value);
54
+ }
55
+ }
56
+ };
57
+ visit(root);
58
+ };
59
+ const push = (record, statement) => {
60
+ trackOrigin(record, statement);
61
+ merged.push(statement);
62
+ };
63
+ const first = records[records.length - 1];
64
+ for (const record of records) {
65
+ if (deferredModules.has(record.path)) {
66
+ /* A deferred module is evaluated by the wrapper when a script runs. Its
67
+ * external imports stay top-level (codegen resolves them there); eager
68
+ * namespace objects likewise. */
69
+ const topLevel = [];
70
+ const body = [];
71
+ for (const statement of record.sourceFile.statements) {
72
+ if (statement.kind === SyntaxKind.ImportDeclaration) {
73
+ const declaration = statement;
74
+ const resolution = classifyDependency(dirname(record.path), declaration.moduleSpecifier.value, externalSpecifiers, moduleOverrides);
75
+ if (resolution.kind === "external")
76
+ topLevel.push(statement);
77
+ const synthetic = namespaceStatements.get(statement);
78
+ if (synthetic)
79
+ topLevel.push(synthetic);
80
+ continue;
81
+ }
82
+ if (statement.kind === SyntaxKind.ExportDeclaration) {
83
+ const declaration = statement;
84
+ const inner = declaration.declaration;
85
+ if (inner)
86
+ body.push(inner);
87
+ continue;
88
+ }
89
+ if (statement.kind === SyntaxKind.ExportAssignment) {
90
+ body.push(exportAssignmentToStatement(record, statement));
91
+ continue;
92
+ }
93
+ stripExportModifiers(statement);
94
+ body.push(statement);
95
+ }
96
+ for (const statement of topLevel)
97
+ push(record, statement);
98
+ for (const statement of deferredModuleFunctions(record, deferredAliases.get(record.path) ?? [], body)) {
99
+ push(record, statement);
100
+ }
101
+ continue;
102
+ }
103
+ for (const statement of record.sourceFile.statements) {
104
+ if (statement.kind === SyntaxKind.ImportDeclaration) {
105
+ // External (extension / built-in) imports stay in place for codegen.
106
+ const declaration = statement;
107
+ const resolution = classifyDependency(dirname(record.path), declaration.moduleSpecifier.value, externalSpecifiers, moduleOverrides);
108
+ if (resolution.kind === "external") {
109
+ push(record, statement);
110
+ }
111
+ else {
112
+ const synthetic = namespaceStatements.get(statement);
113
+ if (synthetic)
114
+ push(record, synthetic);
115
+ }
116
+ continue;
117
+ }
118
+ if (statement.kind === SyntaxKind.ExportDeclaration) {
119
+ const declaration = statement;
120
+ const synthetic = namespaceStatements.get(statement);
121
+ if (synthetic) {
122
+ push(record, synthetic);
123
+ continue;
124
+ }
125
+ const inner = declaration.declaration;
126
+ if (inner)
127
+ push(record, inner);
128
+ continue;
129
+ }
130
+ if (statement.kind === SyntaxKind.ExportAssignment) {
131
+ const assignment = statement;
132
+ push(record, exportAssignmentToStatement(record, assignment));
133
+ continue;
134
+ }
135
+ push(record, statement);
136
+ }
137
+ }
138
+ /* A marker or dynamic-import target that stayed eager still needs a wrapper:
139
+ * its exports are already initialised. */
140
+ for (const record of records) {
141
+ if (deferredModules.has(record.path) || (!markerTargets.has(record.path) && !dynamicTargets.has(record.path)))
142
+ continue;
143
+ for (const statement of eagerModuleFunctions(record))
144
+ push(record, statement);
145
+ }
146
+ for (const record of records) {
147
+ for (const symbol of topLevelSymbols(record)) {
148
+ if (symbol.kind === SymbolKind.Import)
149
+ continue;
150
+ const finalName = record.finalNames.get(symbol.id);
151
+ if (finalName)
152
+ renameSymbol(symbol, finalName);
153
+ }
154
+ }
155
+ return {
156
+ kind: SyntaxKind.SourceFile,
157
+ statements: merged,
158
+ fileName: first.path,
159
+ origins,
160
+ moduleTexts: new Map(records.map((record) => [record.path, record.text])),
161
+ modulePrefixes: records.map((record) => record.prefix),
162
+ text: records.map((record) => record.text).join("\n"),
163
+ start: 0,
164
+ end: 0,
165
+ };
166
+ }
167
+ /** Drop `export` / `export default` from a statement moved into a wrapper. */
168
+ function stripExportModifiers(statement) {
169
+ const modifiers = statement.modifiers;
170
+ if (!modifiers)
171
+ return;
172
+ statement.modifiers = modifiers.filter((modifier) => modifier.modifierKind !== ModifierKind.Export && modifier.modifierKind !== ModifierKind.Default);
173
+ }
174
+ /** True for anything shaped like an AST node (constructed nodes carry no trivia). */
175
+ function isNode(value) {
176
+ return !!value && typeof value === "object" && "kind" in value;
177
+ }
178
+ /** Turn `export default expr` into a synthetic `const` declaration. */
179
+ function exportAssignmentToStatement(record, assignment) {
180
+ const name = {
181
+ kind: SyntaxKind.Identifier,
182
+ text: `${record.prefix}default`,
183
+ start: assignment.start,
184
+ end: assignment.start,
185
+ };
186
+ record.exports.set("default", name.text);
187
+ const declaration = {
188
+ kind: SyntaxKind.VariableDeclaration,
189
+ name,
190
+ exclamation: false,
191
+ initializer: assignment.expression,
192
+ start: assignment.start,
193
+ end: assignment.end,
194
+ };
195
+ const list = {
196
+ kind: SyntaxKind.VariableDeclarationList,
197
+ declarationKind: "const",
198
+ declarations: [declaration],
199
+ start: assignment.start,
200
+ end: assignment.end,
201
+ };
202
+ return {
203
+ kind: SyntaxKind.VariableStatement,
204
+ declarationList: list,
205
+ modifiers: [],
206
+ start: assignment.start,
207
+ end: assignment.end,
208
+ };
209
+ }
210
+ //# sourceMappingURL=concatenate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"concatenate.js","sourceRoot":"","sources":["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AAM,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACzC,MAAM,WAAW,GAAwB;QACvC,IAAI,EAAE,UAAU,CAAC,mBAAmB;QACpC,IAAI;QACJ,WAAW,EAAE,KAAK;QAClB,WAAW,EAAE,UAAU,CAAC,UAAU;QAClC,KAAK,EAAE,UAAU,CAAC,KAAK;QACvB,GAAG,EAAE,UAAU,CAAC,GAAG;KACpB,CAAC;IACF,MAAM,IAAI,GAA4B;QACpC,IAAI,EAAE,UAAU,CAAC,uBAAuB;QACxC,eAAe,EAAE,OAAgB;QACjC,YAAY,EAAE,CAAC,WAAW,CAAC;QAC3B,KAAK,EAAE,UAAU,CAAC,KAAK;QACvB,GAAG,EAAE,UAAU,CAAC,GAAG;KACpB,CAAC;IACF,OAAO;QACL,IAAI,EAAE,UAAU,CAAC,iBAAiB;QAClC,eAAe,EAAE,IAAI;QACrB,SAAS,EAAE,EAAE;QACb,KAAK,EAAE,UAAU,CAAC,KAAK;QACvB,GAAG,EAAE,UAAU,CAAC,GAAG;KACpB,CAAC;AACJ,CAAC"}
@@ -1,10 +1,10 @@
1
1
  /**
2
- * Merge every reachable module's statements into a single source file.
2
+ * Bundling pass orchestrator (phases 1-3).
3
3
  *
4
4
  * Dependencies come first (post-order over the import graph), the entry module
5
- * last. Top-level bindings are renamed to globally unique names and imports are
6
- * rewritten to the (renamed) exported binding; namespace imports are lowered
7
- * to a synthetic object literal.
5
+ * last. These passes record each module's exports, pick globally unique final
6
+ * names, rewrite imported names and lower deferred imports. `concatenate.ts`
7
+ * then emits the statement list and applies the final renames (phases 4-5).
8
8
  */
9
9
  import type { DiagnosticBag } from "../../diagnostics/diagnostic.js";
10
10
  import type { AssetLoader } from "../../extensions/registry.js";
@@ -1,22 +1,23 @@
1
1
  /**
2
- * Merge every reachable module's statements into a single source file.
2
+ * Bundling pass orchestrator (phases 1-3).
3
3
  *
4
4
  * Dependencies come first (post-order over the import graph), the entry module
5
- * last. Top-level bindings are renamed to globally unique names and imports are
6
- * rewritten to the (renamed) exported binding; namespace imports are lowered
7
- * to a synthetic object literal.
5
+ * last. These passes record each module's exports, pick globally unique final
6
+ * names, rewrite imported names and lower deferred imports. `concatenate.ts`
7
+ * then emits the statement list and applies the final renames (phases 4-5).
8
8
  */
9
9
  import { dirname } from "node:path";
10
10
  import { ModifierKind, SyntaxKind, } from "../../ast/nodes.js";
11
- import { namespaceImportToStatement } from "./namespace-import.js";
12
- import { resolveReexports } from "./reexport-fixup.js";
13
11
  import { SymbolKind } from "../../binder/binder.js";
14
- import { loadGraph } from "./graph.js";
12
+ import { concatenateModules } from "./concatenate.js";
15
13
  import { lowerCommonJSRequires, prepareCommonJS } from "./commonjs.js";
14
+ import { computeDeferredModules, deferredAliasName, deferredWrapperName, isDeferredMarkerImport, } from "./deferred.js";
16
15
  import { prepareDynamicImports } from "./dynamic-import.js";
16
+ import { loadGraph } from "./graph.js";
17
+ import { namespaceImportToStatement } from "./namespace-object.js";
18
+ import { resolveReexports } from "./reexport-resolution.js";
17
19
  import { classifyDependency } from "./resolve.js";
18
- import { computeDeferredModules, deferredAliasName, deferredModuleFunctions, deferredWrapperName, eagerModuleFunctions, isDeferredMarkerImport, } from "./deferred.js";
19
- import { declarationName, hasModifier, moduleScope, renameImport, renameReferences, renameSymbol, topLevelSymbols, } from "./symbols.js";
20
+ import { declarationName, hasModifier, moduleScope, renameImport, renameReferences, topLevelSymbols, } from "./symbols.js";
20
21
  export function bundleModules(entryPath, diagnostics, externalSpecifiers = new Set(), assetLoaders = {}, moduleOverrides) {
21
22
  const records = loadGraph(entryPath, diagnostics, externalSpecifiers, assetLoaders, moduleOverrides);
22
23
  if (!records)
@@ -281,7 +282,7 @@ export function bundleModules(entryPath, diagnostics, externalSpecifiers = new S
281
282
  continue;
282
283
  }
283
284
  if (clause.name) {
284
- const target = dependency.exports.get("default") ?? dependency.exports.get("default");
285
+ const target = dependency.exports.get("default");
285
286
  const local = scope.symbols.get(clause.name.text);
286
287
  if (target && local)
287
288
  renameImport(record, local, target);
@@ -328,157 +329,18 @@ export function bundleModules(entryPath, diagnostics, externalSpecifiers = new S
328
329
  // Phase 3b: re-resolve module re-exports and rebuild namespace objects with
329
330
  // the final renamed names (multi-level re-export chains and cycle back-edges).
330
331
  resolveReexports(records, dependencyOf, namespaceStatements, deferredModules);
331
- // Phase 4: concatenate statements, dropping imports and pure export wrappers.
332
- const merged = [];
333
- /* Every node keeps the module it was parsed from, so a later codegen
334
- * diagnostic can name the right file and line instead of pointing into the
335
- * entry module (whose text happens to start at the same offsets). */
336
- const origins = new Map();
337
- /* A synthesized module (an extension asset loader such as the `gui` `.html`
338
- * transform) may contain spans copied from another file — a `<script
339
- * src="app.js">` body, say. Nodes inside such a span keep that file, so a
340
- * diagnostic points at real source and a plain-`.js` script stays exempt
341
- * from the type checker. */
342
- const originOf = (record, node) => {
343
- const ranges = record.originRanges;
344
- if (ranges === undefined)
345
- return record.path;
346
- for (const range of ranges) {
347
- if (node.start >= range.start && node.end <= range.end)
348
- return range.file;
349
- }
350
- return record.path;
351
- };
352
- const trackOrigin = (record, root) => {
353
- const visit = (node) => {
354
- origins.set(node, originOf(record, node));
355
- const fields = node;
356
- for (const key of Object.keys(fields)) {
357
- if (key === "kind" || key === "start" || key === "end" || key === "text" || key === "value" || key === "raw") {
358
- continue;
359
- }
360
- const value = fields[key];
361
- if (Array.isArray(value)) {
362
- for (const child of value)
363
- if (isNode(child))
364
- visit(child);
365
- }
366
- else if (isNode(value)) {
367
- visit(value);
368
- }
369
- }
370
- };
371
- visit(root);
372
- };
373
- const push = (record, statement) => {
374
- trackOrigin(record, statement);
375
- merged.push(statement);
376
- };
377
- const first = records[records.length - 1];
378
- for (const record of records) {
379
- if (deferredModules.has(record.path)) {
380
- /* A deferred module is evaluated by the wrapper when a script runs. Its
381
- * external imports stay top-level (codegen resolves them there); eager
382
- * namespace objects likewise. */
383
- const topLevel = [];
384
- const body = [];
385
- for (const statement of record.sourceFile.statements) {
386
- if (statement.kind === SyntaxKind.ImportDeclaration) {
387
- const declaration = statement;
388
- const resolution = classifyDependency(dirname(record.path), declaration.moduleSpecifier.value, externalSpecifiers, moduleOverrides);
389
- if (resolution.kind === "external")
390
- topLevel.push(statement);
391
- const synthetic = namespaceStatements.get(statement);
392
- if (synthetic)
393
- topLevel.push(synthetic);
394
- continue;
395
- }
396
- if (statement.kind === SyntaxKind.ExportDeclaration) {
397
- const declaration = statement;
398
- const inner = declaration.declaration;
399
- if (inner)
400
- body.push(inner);
401
- continue;
402
- }
403
- if (statement.kind === SyntaxKind.ExportAssignment) {
404
- body.push(exportAssignmentToStatement(record, statement));
405
- continue;
406
- }
407
- stripExportModifiers(statement);
408
- body.push(statement);
409
- }
410
- for (const statement of topLevel)
411
- push(record, statement);
412
- for (const statement of deferredModuleFunctions(record, deferredAliases.get(record.path) ?? [], body)) {
413
- push(record, statement);
414
- }
415
- continue;
416
- }
417
- for (const statement of record.sourceFile.statements) {
418
- if (statement.kind === SyntaxKind.ImportDeclaration) {
419
- // External (extension / built-in) imports stay in place for codegen.
420
- const declaration = statement;
421
- const resolution = classifyDependency(dirname(record.path), declaration.moduleSpecifier.value, externalSpecifiers, moduleOverrides);
422
- if (resolution.kind === "external") {
423
- push(record, statement);
424
- }
425
- else {
426
- const synthetic = namespaceStatements.get(statement);
427
- if (synthetic)
428
- push(record, synthetic);
429
- }
430
- continue;
431
- }
432
- if (statement.kind === SyntaxKind.ExportDeclaration) {
433
- const declaration = statement;
434
- const synthetic = namespaceStatements.get(statement);
435
- if (synthetic) {
436
- push(record, synthetic);
437
- continue;
438
- }
439
- const inner = declaration.declaration;
440
- if (inner)
441
- push(record, inner);
442
- continue;
443
- }
444
- if (statement.kind === SyntaxKind.ExportAssignment) {
445
- const assignment = statement;
446
- push(record, exportAssignmentToStatement(record, assignment));
447
- continue;
448
- }
449
- push(record, statement);
450
- }
451
- }
452
- /* A marker or dynamic-import target that stayed eager still needs a wrapper:
453
- * its exports are already initialised. */
454
- for (const record of records) {
455
- if (deferredModules.has(record.path) || (!markerTargets.has(record.path) && !dynamicTargets.has(record.path)))
456
- continue;
457
- for (const statement of eagerModuleFunctions(record))
458
- push(record, statement);
459
- }
460
- // Phase 5: rename every top-level binding (declaration + references) to its
461
- // unique final name, now that import references have been rewritten.
462
- for (const record of records) {
463
- for (const symbol of topLevelSymbols(record)) {
464
- if (symbol.kind === SymbolKind.Import)
465
- continue;
466
- const finalName = record.finalNames.get(symbol.id);
467
- if (finalName)
468
- renameSymbol(symbol, finalName);
469
- }
470
- }
471
- const sourceFile = {
472
- kind: SyntaxKind.SourceFile,
473
- statements: merged,
474
- fileName: first.path,
475
- origins,
476
- moduleTexts: new Map(records.map((record) => [record.path, record.text])),
477
- modulePrefixes: records.map((record) => record.prefix),
478
- text: records.map((record) => record.text).join("\n"),
479
- start: 0,
480
- end: 0,
481
- };
332
+ // Phases 4-5: concatenate the modules into one file and give every top-level
333
+ // binding its final name.
334
+ const sourceFile = concatenateModules({
335
+ records,
336
+ deferredModules,
337
+ deferredAliases,
338
+ markerTargets,
339
+ dynamicTargets,
340
+ namespaceStatements,
341
+ externalSpecifiers,
342
+ moduleOverrides,
343
+ });
482
344
  return { sourceFile, text: sourceFile.text, moduleCount: records.length };
483
345
  }
484
346
  function exportedNames(statement) {
@@ -500,54 +362,9 @@ function collectBindingIdentifiers(name, out) {
500
362
  out.push(name.text);
501
363
  return;
502
364
  }
503
- const elements = name.kind === SyntaxKind.ArrayBindingPattern ? name.elements : name.elements;
504
- for (const element of elements) {
365
+ for (const element of name.elements) {
505
366
  if (element)
506
367
  collectBindingIdentifiers(element.name, out);
507
368
  }
508
369
  }
509
- /** Drop `export` / `export default` from a statement moved into a wrapper. */
510
- function stripExportModifiers(statement) {
511
- const modifiers = statement.modifiers;
512
- if (!modifiers)
513
- return;
514
- statement.modifiers = modifiers.filter((modifier) => modifier.modifierKind !== ModifierKind.Export && modifier.modifierKind !== ModifierKind.Default);
515
- }
516
- /** True for anything shaped like an AST node (constructed nodes carry no trivia). */
517
- function isNode(value) {
518
- return !!value && typeof value === "object" && "kind" in value;
519
- }
520
- /** Turn `export default expr` into a synthetic `const` declaration. */
521
- function exportAssignmentToStatement(record, assignment) {
522
- const name = {
523
- kind: SyntaxKind.Identifier,
524
- text: `${record.prefix}default`,
525
- start: assignment.start,
526
- end: assignment.start,
527
- };
528
- record.exports.set("default", name.text);
529
- const declaration = {
530
- kind: SyntaxKind.VariableDeclaration,
531
- name,
532
- exclamation: false,
533
- initializer: assignment.expression,
534
- start: assignment.start,
535
- end: assignment.end,
536
- };
537
- const list = {
538
- kind: SyntaxKind.VariableDeclarationList,
539
- declarationKind: "const",
540
- declarations: [declaration],
541
- start: assignment.start,
542
- end: assignment.end,
543
- };
544
- const statement = {
545
- kind: SyntaxKind.VariableStatement,
546
- declarationList: list,
547
- modifiers: [],
548
- start: assignment.start,
549
- end: assignment.end,
550
- };
551
- return statement;
552
- }
553
370
  //# sourceMappingURL=merge.js.map