xbintsc 0.7.0 → 0.7.6

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 (323) hide show
  1. package/dist/src/ast/common.d.ts +10 -0
  2. package/dist/src/checker/source.js +4 -0
  3. package/dist/src/checker/source.js.map +1 -1
  4. package/dist/src/cli/help.d.ts +1 -1
  5. package/dist/src/cli/main.js +15 -3
  6. package/dist/src/cli/main.js.map +1 -1
  7. package/dist/src/codegen/generator/calls/access.js +4 -11
  8. package/dist/src/codegen/generator/calls/access.js.map +1 -1
  9. package/dist/src/codegen/generator/calls/element-inline.d.ts +42 -0
  10. package/dist/src/codegen/generator/calls/element-inline.js +388 -0
  11. package/dist/src/codegen/generator/calls/element-inline.js.map +1 -0
  12. package/dist/src/codegen/generator/calls/invocation.js +82 -1
  13. package/dist/src/codegen/generator/calls/invocation.js.map +1 -1
  14. package/dist/src/codegen/generator/calls.d.ts +3 -1
  15. package/dist/src/codegen/generator/calls.js +3 -1
  16. package/dist/src/codegen/generator/calls.js.map +1 -1
  17. package/dist/src/codegen/generator/debug.js +20 -3
  18. package/dist/src/codegen/generator/debug.js.map +1 -1
  19. package/dist/src/codegen/generator/expressions/assignment.js +10 -2
  20. package/dist/src/codegen/generator/expressions/assignment.js.map +1 -1
  21. package/dist/src/codegen/generator/expressions/global-values.d.ts +19 -0
  22. package/dist/src/codegen/generator/expressions/global-values.js +49 -0
  23. package/dist/src/codegen/generator/expressions/global-values.js.map +1 -0
  24. package/dist/src/codegen/generator/expressions/primary.d.ts +0 -2
  25. package/dist/src/codegen/generator/expressions/primary.js +4 -24
  26. package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
  27. package/dist/src/codegen/generator/expressions.d.ts +2 -1
  28. package/dist/src/codegen/generator/expressions.js +2 -1
  29. package/dist/src/codegen/generator/expressions.js.map +1 -1
  30. package/dist/src/codegen/generator/layout.d.ts +65 -0
  31. package/dist/src/codegen/generator/layout.js +50 -0
  32. package/dist/src/codegen/generator/layout.js.map +1 -0
  33. package/dist/src/codegen/generator/state.js +4 -0
  34. package/dist/src/codegen/generator/state.js.map +1 -1
  35. package/dist/src/diagnostics/diagnostic.js +1 -1
  36. package/dist/src/diagnostics/diagnostic.js.map +1 -1
  37. package/dist/src/diagnostics/source-text.d.ts +37 -9
  38. package/dist/src/diagnostics/source-text.js +124 -23
  39. package/dist/src/diagnostics/source-text.js.map +1 -1
  40. package/dist/src/diagnostics/source.d.ts +16 -6
  41. package/dist/src/diagnostics/source.js +25 -4
  42. package/dist/src/diagnostics/source.js.map +1 -1
  43. package/dist/src/driver/build-key.d.ts +14 -0
  44. package/dist/src/driver/build-key.js +6 -1
  45. package/dist/src/driver/build-key.js.map +1 -1
  46. package/dist/src/driver/bundler/concatenate.js +11 -4
  47. package/dist/src/driver/bundler/concatenate.js.map +1 -1
  48. package/dist/src/driver/bundler/graph.js +2 -2
  49. package/dist/src/driver/bundler/graph.js.map +1 -1
  50. package/dist/src/driver/bundler/merge.js +11 -5
  51. package/dist/src/driver/bundler/merge.js.map +1 -1
  52. package/dist/src/driver/bundler/reexport-resolution.js +3 -0
  53. package/dist/src/driver/bundler/reexport-resolution.js.map +1 -1
  54. package/dist/src/driver/compiler.js +13 -3
  55. package/dist/src/driver/compiler.js.map +1 -1
  56. package/dist/src/driver/frontend.js +3 -4
  57. package/dist/src/driver/frontend.js.map +1 -1
  58. package/dist/src/driver/runtime-objects.d.ts +1 -1
  59. package/dist/src/driver/runtime-objects.js +4 -0
  60. package/dist/src/driver/runtime-objects.js.map +1 -1
  61. package/dist/src/driver/toolchain.js +28 -5
  62. package/dist/src/driver/toolchain.js.map +1 -1
  63. package/dist/src/driver/version.d.ts +1 -1
  64. package/dist/src/driver/version.js +1 -1
  65. package/dist/src/extensions/gui/html.js +42 -10
  66. package/dist/src/extensions/gui/html.js.map +1 -1
  67. package/dist/src/extensions/gui/index.js +48 -0
  68. package/dist/src/extensions/gui/index.js.map +1 -1
  69. package/dist/src/extensions/registry.d.ts +20 -0
  70. package/dist/src/extensions/registry.js.map +1 -1
  71. package/dist/src/parser/expressions.js +2 -2
  72. package/dist/src/parser/expressions.js.map +1 -1
  73. package/dist/src/parser/helpers.d.ts +8 -0
  74. package/dist/src/parser/helpers.js +21 -0
  75. package/dist/src/parser/helpers.js.map +1 -1
  76. package/dist/tests/cli/main.test.js +9 -0
  77. package/dist/tests/cli/main.test.js.map +1 -1
  78. package/dist/tests/codegen/element-layout.test.d.ts +19 -0
  79. package/dist/tests/codegen/element-layout.test.js +80 -0
  80. package/dist/tests/codegen/element-layout.test.js.map +1 -0
  81. package/dist/tests/codegen/expressions.test.js +25 -0
  82. package/dist/tests/codegen/expressions.test.js.map +1 -1
  83. package/dist/tests/codegen/llvm.test.js +13 -0
  84. package/dist/tests/codegen/llvm.test.js.map +1 -1
  85. package/dist/tests/diagnostics/diagnostic.test.js +9 -0
  86. package/dist/tests/diagnostics/diagnostic.test.js.map +1 -1
  87. package/dist/tests/diagnostics/source-text.test.d.ts +1 -0
  88. package/dist/tests/diagnostics/source-text.test.js +50 -0
  89. package/dist/tests/diagnostics/source-text.test.js.map +1 -0
  90. package/dist/tests/diagnostics/source.test.js +17 -0
  91. package/dist/tests/diagnostics/source.test.js.map +1 -1
  92. package/dist/tests/driver/build-key.test.d.ts +1 -0
  93. package/dist/tests/driver/build-key.test.js +49 -0
  94. package/dist/tests/driver/build-key.test.js.map +1 -0
  95. package/dist/tests/driver/toolchain.test.js +8 -1
  96. package/dist/tests/driver/toolchain.test.js.map +1 -1
  97. package/dist/tests/driver/usage.test.js +2 -1
  98. package/dist/tests/driver/usage.test.js.map +1 -1
  99. package/dist/tests/e2e/async-await.test.js +16 -0
  100. package/dist/tests/e2e/async-await.test.js.map +1 -1
  101. package/dist/tests/e2e/compile-builtins.test.js +29 -0
  102. package/dist/tests/e2e/compile-builtins.test.js.map +1 -1
  103. package/dist/tests/e2e/compile-modules.test.js +13 -0
  104. package/dist/tests/e2e/compile-modules.test.js.map +1 -1
  105. package/dist/tests/e2e/compile-objects-classes.test.js.map +1 -1
  106. package/dist/tests/e2e/compile-prototype-chain.test.d.ts +8 -0
  107. package/dist/tests/e2e/compile-prototype-chain.test.js +24 -0
  108. package/dist/tests/e2e/compile-prototype-chain.test.js.map +1 -0
  109. package/dist/tests/e2e/differential-language.test.js +25 -0
  110. package/dist/tests/e2e/differential-language.test.js.map +1 -1
  111. package/dist/tests/e2e/differential-values.test.js +59 -0
  112. package/dist/tests/e2e/differential-values.test.js.map +1 -1
  113. package/dist/tests/e2e/gc.test.js +22 -0
  114. package/dist/tests/e2e/gc.test.js.map +1 -1
  115. package/dist/tests/e2e/gui-audio-extra.test.d.ts +12 -0
  116. package/dist/tests/e2e/gui-audio-extra.test.js +185 -0
  117. package/dist/tests/e2e/gui-audio-extra.test.js.map +1 -0
  118. package/dist/tests/e2e/gui-browser.test.js +35 -2
  119. package/dist/tests/e2e/gui-browser.test.js.map +1 -1
  120. package/dist/tests/e2e/gui-dom.test.js +88 -0
  121. package/dist/tests/e2e/gui-dom.test.js.map +1 -1
  122. package/dist/tests/e2e/gui-webgl-declarations.test.d.ts +13 -0
  123. package/dist/tests/e2e/gui-webgl-declarations.test.js +136 -0
  124. package/dist/tests/e2e/gui-webgl-declarations.test.js.map +1 -0
  125. package/dist/tests/e2e/gui-webgl-texture-units.test.d.ts +12 -0
  126. package/dist/tests/e2e/gui-webgl-texture-units.test.js +86 -0
  127. package/dist/tests/e2e/gui-webgl-texture-units.test.js.map +1 -0
  128. package/dist/tests/e2e/gui-webgl2-blit.test.js +6 -2
  129. package/dist/tests/e2e/gui-webgl2-blit.test.js.map +1 -1
  130. package/dist/tests/e2e/gui-webgl2-msaa-float.test.d.ts +12 -0
  131. package/dist/tests/e2e/gui-webgl2-msaa-float.test.js +157 -0
  132. package/dist/tests/e2e/gui-webgl2-msaa-float.test.js.map +1 -0
  133. package/dist/tests/e2e/gui-webgl2-msaa.test.d.ts +10 -0
  134. package/dist/tests/e2e/gui-webgl2-msaa.test.js +344 -0
  135. package/dist/tests/e2e/gui-webgl2-msaa.test.js.map +1 -0
  136. package/dist/tests/e2e/gui-webgl2-target-orientation.test.d.ts +15 -0
  137. package/dist/tests/e2e/gui-webgl2-target-orientation.test.js +287 -0
  138. package/dist/tests/e2e/gui-webgl2-target-orientation.test.js.map +1 -0
  139. package/dist/tests/e2e/gui-webgl2.test.js +59 -1
  140. package/dist/tests/e2e/gui-webgl2.test.js.map +1 -1
  141. package/dist/tests/e2e/hang-watchdog.test.d.ts +10 -0
  142. package/dist/tests/e2e/hang-watchdog.test.js +50 -0
  143. package/dist/tests/e2e/hang-watchdog.test.js.map +1 -0
  144. package/dist/tests/e2e/method-call-cache.test.d.ts +5 -0
  145. package/dist/tests/e2e/method-call-cache.test.js +65 -0
  146. package/dist/tests/e2e/method-call-cache.test.js.map +1 -0
  147. package/dist/tests/e2e/performance-now.test.d.ts +9 -0
  148. package/dist/tests/e2e/performance-now.test.js +36 -0
  149. package/dist/tests/e2e/performance-now.test.js.map +1 -0
  150. package/dist/tests/e2e/property-ic.test.js +33 -0
  151. package/dist/tests/e2e/property-ic.test.js.map +1 -1
  152. package/dist/tests/e2e/shape-interning.test.d.ts +16 -0
  153. package/dist/tests/e2e/shape-interning.test.js +55 -0
  154. package/dist/tests/e2e/shape-interning.test.js.map +1 -0
  155. package/dist/tests/e2e/string-utf16.test.js +9 -0
  156. package/dist/tests/e2e/string-utf16.test.js.map +1 -1
  157. package/dist/tests/e2e/typed-array-views.test.js +26 -0
  158. package/dist/tests/e2e/typed-array-views.test.js.map +1 -1
  159. package/dist/tests/e2e/url-search-params.test.js +19 -0
  160. package/dist/tests/e2e/url-search-params.test.js.map +1 -1
  161. package/dist/tests/extensions/gui.test.js +16 -1
  162. package/dist/tests/extensions/gui.test.js.map +1 -1
  163. package/dist/tests/helpers.js +1 -0
  164. package/dist/tests/helpers.js.map +1 -1
  165. package/dist/tests/parser/expressions.test.js +36 -0
  166. package/dist/tests/parser/expressions.test.js.map +1 -1
  167. package/doc/ai/contributing.md +8 -5
  168. package/doc/ai/extensions.md +12 -3
  169. package/doc/ai/language-support.md +2 -1
  170. package/doc/ai/troubleshooting.md +14 -0
  171. package/doc/ai/zh-CN/contributing.md +6 -3
  172. package/doc/ai/zh-CN/extensions.md +10 -2
  173. package/doc/ai/zh-CN/language-support.md +2 -1
  174. package/doc/ai/zh-CN/troubleshooting.md +12 -0
  175. package/doc/gui/api.md +26 -4
  176. package/doc/gui/dom.md +8 -0
  177. package/doc/gui/known-issues.md +35 -6
  178. package/doc/gui/runtime.md +16 -1
  179. package/doc/gui/webgl.md +97 -26
  180. package/doc/gui-scripts.md +2 -1
  181. package/doc/gui.md +8 -5
  182. package/doc/implemented/checker.md +9 -0
  183. package/doc/implemented/codegen.md +7 -0
  184. package/doc/implemented/parser.md +2 -1
  185. package/doc/implemented/runtime-core.md +9 -2
  186. package/doc/implemented/stdlib.md +10 -2
  187. package/doc/implemented/typed-arrays.md +18 -2
  188. package/doc/zh-CN/gui/api.md +19 -5
  189. package/doc/zh-CN/gui/dom.md +6 -0
  190. package/doc/zh-CN/gui/known-issues.md +24 -5
  191. package/doc/zh-CN/gui/runtime.md +13 -1
  192. package/doc/zh-CN/gui/webgl.md +20 -7
  193. package/doc/zh-CN/gui-scripts.md +2 -1
  194. package/doc/zh-CN/gui.md +4 -1
  195. package/doc/zh-CN/implemented/checker.md +7 -0
  196. package/doc/zh-CN/implemented/codegen.md +7 -0
  197. package/doc/zh-CN/implemented/parser.md +2 -1
  198. package/doc/zh-CN/implemented/runtime-core.md +9 -2
  199. package/doc/zh-CN/implemented/stdlib.md +6 -2
  200. package/doc/zh-CN/implemented/typed-arrays.md +14 -2
  201. package/package.json +7 -7
  202. package/runtime/ext_gui/audio.cpp +39 -3
  203. package/runtime/ext_gui/audio_extra.cpp +353 -0
  204. package/runtime/ext_gui/audio_extra.h +47 -0
  205. package/runtime/ext_gui/audio_fft.h +76 -0
  206. package/runtime/ext_gui/audio_internal.h +21 -0
  207. package/runtime/ext_gui/audio_mixer.cpp +46 -1
  208. package/runtime/ext_gui/audio_mixer.h +89 -1
  209. package/runtime/ext_gui/audio_mixer_extra.cpp +126 -0
  210. package/runtime/ext_gui/audio_nodes.cpp +242 -0
  211. package/runtime/ext_gui/audio_nodes_internal.h +81 -0
  212. package/runtime/ext_gui/audio_nodes_spatial.cpp +375 -0
  213. package/runtime/ext_gui/browser.cpp +9 -0
  214. package/runtime/ext_gui/browser_screen.cpp +73 -0
  215. package/runtime/ext_gui/dom_api_canvas.cpp +9 -1
  216. package/runtime/ext_gui/dom_api_internal.h +3 -0
  217. package/runtime/ext_gui/dom_api_node.cpp +21 -0
  218. package/runtime/ext_gui/dom_api_node_read.cpp +29 -0
  219. package/runtime/ext_gui/dom_api_proto.cpp +3 -0
  220. package/runtime/ext_gui/dom_api_webgl2.cpp +16 -11
  221. package/runtime/ext_gui/dom_api_webgl2_msaa.cpp +64 -0
  222. package/runtime/ext_gui/dom_api_webgl_compressed.cpp +2 -2
  223. package/runtime/ext_gui/dom_api_webgl_framebuffer.cpp +68 -11
  224. package/runtime/ext_gui/dom_api_webgl_methods.h +3 -0
  225. package/runtime/ext_gui/dom_api_webgl_state.cpp +4 -2
  226. package/runtime/ext_gui/dom_api_webgl_texture.cpp +6 -6
  227. package/runtime/ext_gui/gui.cpp +6 -1
  228. package/runtime/ext_gui/gui_engine.h +2 -0
  229. package/runtime/ext_gui/gui_events.cpp +13 -8
  230. package/runtime/ext_gui/gui_webgl.cpp +3 -2
  231. package/runtime/ext_gui/style_ua.cpp +4 -0
  232. package/runtime/ext_gui/warnings.cpp +1 -1
  233. package/runtime/ext_gui/webgl.h +102 -7
  234. package/runtime/ext_gui/webgl_api.h +3 -2
  235. package/runtime/ext_gui/webgl_blit.cpp +109 -15
  236. package/runtime/ext_gui/webgl_blit_color.cpp +264 -0
  237. package/runtime/ext_gui/webgl_blit_depth.cpp +26 -8
  238. package/runtime/ext_gui/webgl_buffer.cpp +20 -170
  239. package/runtime/ext_gui/webgl_context.cpp +117 -169
  240. package/runtime/ext_gui/webgl_draw.cpp +116 -5
  241. package/runtime/ext_gui/webgl_draw_buffers.cpp +21 -6
  242. package/runtime/ext_gui/webgl_draw_setup.cpp +1 -0
  243. package/runtime/ext_gui/webgl_draw_state.h +2 -0
  244. package/runtime/ext_gui/webgl_feature.cpp +2 -2
  245. package/runtime/ext_gui/webgl_feature.h +4 -3
  246. package/runtime/ext_gui/webgl_framebuffer.cpp +346 -0
  247. package/runtime/ext_gui/webgl_glsl_rewrite.cpp +78 -47
  248. package/runtime/ext_gui/webgl_objects.h +16 -2
  249. package/runtime/ext_gui/webgl_pipeline.cpp +1 -1
  250. package/runtime/ext_gui/webgl_state.cpp +45 -36
  251. package/runtime/ext_gui/webgl_targets.cpp +440 -0
  252. package/runtime/ext_gui/webgl_texture.cpp +81 -25
  253. package/runtime/ext_gui/window.cpp +8 -0
  254. package/runtime/rt.h +27 -27
  255. package/runtime/rt_binary.h +44 -0
  256. package/runtime/rt_internal.h +52 -60
  257. package/runtime/rt_object.h +83 -0
  258. package/runtime/rt_profile.h +45 -0
  259. package/runtime/xt_alloc.c +88 -133
  260. package/runtime/xt_array_buffer.c +99 -71
  261. package/runtime/xt_builtins.c +3 -1
  262. package/runtime/xt_constructors.c +1 -0
  263. package/runtime/xt_containers/access.inc +96 -11
  264. package/runtime/xt_containers/arrays.inc +2 -1
  265. package/runtime/xt_containers/cstr_cache.inc +56 -0
  266. package/runtime/xt_containers/method_cache.inc +121 -0
  267. package/runtime/xt_containers/object_keys.inc +58 -0
  268. package/runtime/xt_containers/objects.inc +47 -79
  269. package/runtime/xt_containers/shapes.inc +153 -8
  270. package/runtime/xt_containers.c +4 -0
  271. package/runtime/xt_gc_release.c +70 -0
  272. package/runtime/xt_gc_stack.c +83 -0
  273. package/runtime/xt_gc_verify.c +1 -0
  274. package/runtime/xt_io/console.inc +66 -0
  275. package/runtime/xt_io/exception.inc +32 -6
  276. package/runtime/xt_io/watchdog.inc +101 -0
  277. package/runtime/xt_io.c +1 -0
  278. package/runtime/xt_loop.c +23 -3
  279. package/runtime/xt_pool.c +151 -0
  280. package/runtime/xt_profile.c +126 -0
  281. package/runtime/xt_stdlib/dispatch.inc +7 -1
  282. package/runtime/xt_stdlib/math.inc +272 -57
  283. package/runtime/xt_stdlib2/json_stringify.inc +1 -2
  284. package/runtime/xt_stdlib2/regexp-match.inc +17 -0
  285. package/runtime/xt_storage/indexed_db.c +4 -1
  286. package/runtime/xt_structured_clone.c +2 -1
  287. package/runtime/xt_typed_array/construction.inc +10 -0
  288. package/runtime/xt_typed_array/elements.inc +43 -23
  289. package/runtime/xt_url.c +50 -0
  290. package/runtime/xt_values/constructors.inc +4 -1
  291. package/runtime/xt_values/strings.inc +3 -1
  292. package/src/ast/common.ts +10 -0
  293. package/src/checker/source.ts +3 -0
  294. package/src/cli/main.ts +14 -3
  295. package/src/codegen/generator/calls/access.ts +5 -10
  296. package/src/codegen/generator/calls/element-inline.ts +433 -0
  297. package/src/codegen/generator/calls/invocation.ts +87 -1
  298. package/src/codegen/generator/calls.ts +5 -0
  299. package/src/codegen/generator/debug.ts +21 -3
  300. package/src/codegen/generator/expressions/assignment.ts +11 -2
  301. package/src/codegen/generator/expressions/global-values.ts +57 -0
  302. package/src/codegen/generator/expressions/primary.ts +4 -27
  303. package/src/codegen/generator/expressions.ts +3 -0
  304. package/src/codegen/generator/layout.ts +54 -0
  305. package/src/codegen/generator/state.ts +5 -0
  306. package/src/diagnostics/diagnostic.ts +1 -1
  307. package/src/diagnostics/source-text.ts +118 -22
  308. package/src/diagnostics/source.ts +29 -7
  309. package/src/driver/build-key.ts +21 -1
  310. package/src/driver/bundler/concatenate.ts +12 -5
  311. package/src/driver/bundler/graph.ts +2 -2
  312. package/src/driver/bundler/merge.ts +11 -4
  313. package/src/driver/bundler/reexport-resolution.ts +2 -0
  314. package/src/driver/compiler.ts +14 -3
  315. package/src/driver/frontend.ts +3 -4
  316. package/src/driver/runtime-objects.ts +4 -0
  317. package/src/driver/toolchain.ts +28 -5
  318. package/src/driver/version.ts +1 -1
  319. package/src/extensions/gui/html.ts +41 -11
  320. package/src/extensions/gui/index.ts +50 -1
  321. package/src/extensions/registry.ts +20 -0
  322. package/src/parser/expressions.ts +2 -2
  323. package/src/parser/helpers.ts +22 -0
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Extension-provided global values.
3
+ *
4
+ * An extension names a global (`window`, `document`, `Image`, `location`) and
5
+ * the runtime getter that produces it; this group turns such a name into a
6
+ * value, including the two richer shapes:
7
+ *
8
+ * - a global that is a *member of a host object* (`location` off the window),
9
+ * so a browser global that only exists as a window property is still live;
10
+ * - `console`, which is both a namespace at call sites and a first-class
11
+ * object as a value (`console.error.bind(console)`).
12
+ */
13
+
14
+ import type { GlobalValue } from "../../../extensions/registry.js";
15
+ import type { Generator } from "../generator.js";
16
+
17
+ export interface GlobalValueMethods {
18
+ emitGlobalValue(this: Generator, value: GlobalValue): string;
19
+ emitConsoleObject(this: Generator): string;
20
+ }
21
+
22
+ export const globalValueMethods: GlobalValueMethods = {
23
+ /**
24
+ * Read an extension-provided global (`window`, `document`, `new Image()`).
25
+ * The getter is a normal runtime call with the uniform ABI; the optional
26
+ * argument is how one getter serves a whole family of host types.
27
+ */
28
+ emitGlobalValue(value: GlobalValue): string {
29
+ this.extraDeclarations.add(`declare i64 @${value.symbol}(i32, i64*)`);
30
+ let argc = "0";
31
+ let pointer = "i64* null";
32
+ if (value.argument !== undefined) {
33
+ const argument = this.stringValue(value.argument);
34
+ const slot = `%gval${this.current.allocas.length}`;
35
+ this.current.allocas.push(`${slot} = alloca i64, i32 1`);
36
+ const cell = this.reg();
37
+ this.emit(` ${cell} = getelementptr i64, i64* ${slot}, i32 0`);
38
+ this.emit(` store i64 ${argument}, i64* ${cell}`);
39
+ argc = "1";
40
+ pointer = `i64* ${slot}`;
41
+ }
42
+ const result = this.reg();
43
+ this.emit(` ${result} = call i64 @${value.symbol}(i32 ${argc}, ${pointer})`);
44
+ if (value.member === undefined) return result;
45
+ /* A browser global that lives on the window object (`location`): read it
46
+ * off the host object so a getter runs and answers a live value. */
47
+ const name = this.stringValue(value.member);
48
+ return this.runtimeCall("xt_get", [result, name]);
49
+ },
50
+
51
+ /** The global `console` object (see `runtime/xt_io/console.inc`). */
52
+ emitConsoleObject(): string {
53
+ const result = this.reg();
54
+ this.emit(` ${result} = call i64 @xt_console_object(i32 0, i64* null)`);
55
+ return result;
56
+ },
57
+ };
@@ -41,7 +41,6 @@ import {
41
41
  NAMESPACE_VALUES,
42
42
  WEB_GLOBALS,
43
43
  } from "../tables.js";
44
- import type { GlobalValue } from "../../../extensions/registry.js";
45
44
  import type { Generator } from "../generator.js";
46
45
  import { newCalleeName } from "../calls/unwrap.js";
47
46
 
@@ -57,7 +56,6 @@ export interface PrimaryExpressionMethods {
57
56
  */
58
57
  emitTypeOf(this: Generator, operand: Expression): string;
59
58
  globalTypeOf(this: Generator, name: string): string | undefined;
60
- emitGlobalValue(this: Generator, value: GlobalValue): string;
61
59
  emitFunctionValue(this: Generator, symbol: SymbolInfo): string;
62
60
  emitTemplate(this: Generator, node: TemplateLiteral): string;
63
61
  emitTaggedTemplate(this: Generator, node: TaggedTemplateExpression): string;
@@ -294,7 +292,10 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
294
292
  case "Infinity":
295
293
  return numberLiteral(Infinity);
296
294
  case "console":
297
- return i64(XT_UNDEFINED);
295
+ /* `console` is a namespace at call sites (`console.log(...)`) and a
296
+ * first-class object as a value: `const log = console.log`,
297
+ * `console.error.bind(console)`, `const { warn } = console`. */
298
+ return this.emitConsoleObject();
298
299
  case "arguments": {
299
300
  const argc = this.reg();
300
301
  this.emit(` ${argc} = load i32, i32* %saved.argc`);
@@ -375,30 +376,6 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
375
376
  }
376
377
  },
377
378
 
378
- /**
379
- * Read an extension-provided global (`window`, `document`, `new Image()`).
380
- * The getter is a normal runtime call with the uniform ABI; the optional
381
- * argument is how one getter serves a whole family of host types.
382
- */
383
- emitGlobalValue(value: GlobalValue): string {
384
- this.extraDeclarations.add(`declare i64 @${value.symbol}(i32, i64*)`);
385
- let argc = "0";
386
- let pointer = "i64* null";
387
- if (value.argument !== undefined) {
388
- const argument = this.stringValue(value.argument);
389
- const slot = `%gval${this.current.allocas.length}`;
390
- this.current.allocas.push(`${slot} = alloca i64, i32 1`);
391
- const cell = this.reg();
392
- this.emit(` ${cell} = getelementptr i64, i64* ${slot}, i32 0`);
393
- this.emit(` store i64 ${argument}, i64* ${cell}`);
394
- argc = "1";
395
- pointer = `i64* ${slot}`;
396
- }
397
- const result = this.reg();
398
- this.emit(` ${result} = call i64 @${value.symbol}(i32 ${argc}, ${pointer})`);
399
- return result;
400
- },
401
-
402
379
  emitFunctionValue(symbol: SymbolInfo): string {
403
380
  const fn = implementationFunctionInfo(this.binding, symbol);
404
381
  if (!fn) return i64(XT_UNDEFINED);
@@ -9,12 +9,14 @@
9
9
  */
10
10
 
11
11
  import { primaryExpressionMethods, type PrimaryExpressionMethods } from "./expressions/primary.js";
12
+ import { globalValueMethods, type GlobalValueMethods } from "./expressions/global-values.js";
12
13
  import { moduleValueExpressionMethods, type ModuleValueExpressionMethods } from "./expressions/module-values.js";
13
14
  import { operatorExpressionMethods, type OperatorExpressionMethods } from "./expressions/operators.js";
14
15
  import { assignmentExpressionMethods, type AssignmentExpressionMethods } from "./expressions/assignment.js";
15
16
 
16
17
  export interface ExpressionMethods
17
18
  extends PrimaryExpressionMethods,
19
+ GlobalValueMethods,
18
20
  ModuleValueExpressionMethods,
19
21
  OperatorExpressionMethods,
20
22
  AssignmentExpressionMethods {}
@@ -22,6 +24,7 @@ export interface ExpressionMethods
22
24
  export const expressionMethods: ExpressionMethods = Object.assign(
23
25
  {},
24
26
  primaryExpressionMethods,
27
+ globalValueMethods,
25
28
  moduleValueExpressionMethods,
26
29
  operatorExpressionMethods,
27
30
  assignmentExpressionMethods,
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Byte offsets into the runtime's container structs that generated code reads
3
+ * directly.
4
+ *
5
+ * The element fast path (`element-inline.ts`) skips the generic dispatch by
6
+ * looking at a value's tag and then loading the fields it needs — an array's
7
+ * `items`/`length`, a typed-array view's `view_bytes`/`view_length`/kind — out of
8
+ * the object header. That only works if the compiler knows the layout, so these
9
+ * constants mirror `runtime/rt_object.h`; `tests/codegen/element-layout.test.ts`
10
+ * compiles a C probe against the runtime header and fails when the two drift
11
+ * apart.
12
+ */
13
+
14
+ import { XT_ARRAY, XT_NUMBER_MASK, XT_OBJECT, XT_TAG_MASK } from "../values.js";
15
+
16
+ export const XT_LAYOUT = {
17
+ /** `xt_header` size: the payload starts here in every heap object. */
18
+ headerSize: 16,
19
+ /** `xt_array.length` (uint32). */
20
+ arrayLength: 16,
21
+ /** `xt_array.items` (i64 pointer to the element vector). */
22
+ arrayItems: 24,
23
+ /** `xt_object.reserved2` (uint16): a typed-array view's `kind + 1`. */
24
+ objectTypedKind: 50,
25
+ /** `xt_object.view_bytes` (i64 raw pointer): the view's first element. */
26
+ objectViewBytes: 96,
27
+ /** `xt_object.view_length` (uint32): bytes available from `view_bytes`. */
28
+ objectViewLength: 104,
29
+ } as const;
30
+
31
+ /** Tags and masks the inline guards compare against (`runtime/rt.h`). */
32
+ export const XT_INLINE_TAGS = {
33
+ tagMask: XT_TAG_MASK,
34
+ numberMask: XT_NUMBER_MASK,
35
+ array: XT_ARRAY,
36
+ object: XT_OBJECT,
37
+ } as const;
38
+
39
+ /** Typed-array element kinds, in `XT_TA_*` order (`runtime/xt_typed_array.c`). */
40
+ export const XT_TYPED_KINDS = [
41
+ { name: "Uint8Array", width: 1 },
42
+ { name: "Int8Array", width: 1 },
43
+ { name: "Uint8ClampedArray", width: 1 },
44
+ { name: "Uint16Array", width: 2 },
45
+ { name: "Int16Array", width: 2 },
46
+ { name: "Uint32Array", width: 4 },
47
+ { name: "Int32Array", width: 4 },
48
+ { name: "Float32Array", width: 4 },
49
+ { name: "Float64Array", width: 8 },
50
+ ] as const;
51
+
52
+ /** Index of `Float32Array` / `Float64Array` in {@link XT_TYPED_KINDS}. */
53
+ export const XT_KIND_F32 = 7;
54
+ export const XT_KIND_F64 = 8;
@@ -375,6 +375,9 @@ export const RUNTIME_DECLARATIONS: readonly string[] = [
375
375
  "declare i64 @xt_symbol_static(i64, i32, i64*)",
376
376
  "declare i64 @xt_symbol_get(i64)",
377
377
  "declare i64 @xt_get(i64, i64)",
378
+ "declare i64 @xt_get_element(i64, i64, i64*)",
379
+ "declare i64 @xt_set_element(i64, i64, i64)",
380
+ "declare double @llvm.trunc.f64(double)",
378
381
  "declare i64 @xt_get_ic(i64, i64, i64*)",
379
382
  "declare i64 @xt_set(i64, i64, i64)",
380
383
  "declare i64 @xt_box_new(i64)",
@@ -395,4 +398,6 @@ export const RUNTIME_DECLARATIONS: readonly string[] = [
395
398
  "declare void @xt_console_info(i32, i64*)",
396
399
  "declare void @xt_console_warn(i32, i64*)",
397
400
  "declare void @xt_console_error(i32, i64*)",
401
+ "declare i64 @xt_console_object(i32, i64*)",
398
402
  ];
403
+
@@ -120,7 +120,7 @@ export function formatDiagnostic(d: Diagnostic, source?: SourceFile): string {
120
120
  if (source && d.start !== undefined) {
121
121
  const { line, column } = source.positionAt(d.start);
122
122
  location = `${source.fileName}:${line}:${column}`;
123
- const lineText = source.text.split("\n")[line - 1] ?? "";
123
+ const lineText = source.lineText(line);
124
124
  const end = d.end ?? d.start;
125
125
  const endCol = source.positionAt(end).column;
126
126
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Source text is a byte sequence.
2
+ * Source text is a byte sequence, one code unit per UTF-8 byte.
3
3
  *
4
4
  * A compiled string is a sequence of UTF-8 bytes (`"e".length` is 1 for an
5
5
  * accent and 4 for an emoji - see doc/ai/language-support.md), and the compiler
@@ -7,26 +7,116 @@
7
7
  * file's own bytes, one per code unit, and the runtime has no UTF-8 decoder to
8
8
  * change that. A host whose strings are UTF-16 must be given the text in the
9
9
  * same shape, or the same program emits different bytes depending on which
10
- * generation of the compiler read it - which is how a non-ASCII literal ended
11
- * up double-encoded and broke the self-hosting fixpoint.
10
+ * generation of the compiler read it.
12
11
  *
13
- * `sourceTextBytes` is that shape: a source file's bytes, one code unit each.
14
- * The driver reads every source file through it, and codegen emits those bytes
15
- * unchanged.
12
+ * The conversion is explicit at the boundary:
13
+ *
14
+ * - `sourceTextBytes(hostText)` UTF-8 encodes text a host decoded for us (a
15
+ * `compileString` argument, a test fixture);
16
+ * - `sourceTextFromBytes(fileBytes)` keeps a file's bytes as they are, which is
17
+ * the only correct reading for a source file on either host;
18
+ * - `readSourceText(path)` reads a UTF-8 source file through the second one.
19
+ *
20
+ * There is deliberately no "does this string look like text?" heuristic: a
21
+ * Latin-1-range character such as `é` has the same code unit (`0xE9`) whether
22
+ * it was decoded from UTF-8 or is a raw byte, and guessing wrong emitted it as
23
+ * a single invalid byte instead of the two-byte UTF-8 sequence.
16
24
  */
17
25
 
26
+ import { readFileSync } from "node:fs";
27
+
18
28
  /**
19
- * The UTF-8 bytes of `text`, one code unit each. Text that is already a byte
20
- * sequence is kept as it is, so this is idempotent and safe to apply to a read
21
- * on either host.
29
+ * The UTF-8 bytes of host text, one code unit each.
30
+ *
31
+ * Use this only for text a host decoded (a string literal in a test, a
32
+ * `compileString` argument). A file's bytes must go through
33
+ * {@link sourceTextFromBytes}; encoding those again doubles the non-ASCII
34
+ * sequence and breaks the self-hosting fixpoint.
22
35
  */
23
36
  export function sourceTextBytes(text: string): string {
24
- if (!hasCharacter(text)) return startsWithBom(text) ? text.slice(3) : text;
25
- const encoded = encodeUtf8(text);
26
- return startsWithBom(encoded) ? encoded.slice(3) : encoded;
37
+ return stripBom(encodeUtf8(text));
38
+ }
39
+
40
+ /**
41
+ * Internal source text from a file's raw bytes.
42
+ *
43
+ * `readFileSync` returns a `Buffer` on Node and a byte string (one code unit
44
+ * per byte) in a self-hosted xbintsc; both arrive here. A UTF-8 BOM is dropped
45
+ * so positions match the scanner's normalized text.
46
+ */
47
+ export function sourceTextFromBytes(bytes: Uint8Array | string): string {
48
+ return stripBom(typeof bytes === "string" ? bytes : bytesToString(bytes));
49
+ }
50
+
51
+ /** Read a UTF-8 source file as internal (byte-string) text. */
52
+ export function readSourceText(path: string): string {
53
+ const data: Uint8Array | string = readFileSync(path);
54
+ return sourceTextFromBytes(data);
55
+ }
56
+
57
+ /**
58
+ * Decode internal byte text back to host text for display (diagnostics).
59
+ *
60
+ * Invalid sequences decode to U+FFFD, which is what a terminal would show for
61
+ * a malformed byte; the parser never consumes the result.
62
+ */
63
+ export function decodeSourceBytes(bytes: string): string {
64
+ const chunks: string[] = [];
65
+ const units: number[] = [];
66
+ let index = 0;
67
+ while (index < bytes.length) {
68
+ const lead = bytes.charCodeAt(index) & 0xff;
69
+ if (lead < 0x80) {
70
+ units.push(lead);
71
+ index += 1;
72
+ } else if ((lead & 0xe0) === 0xc0) {
73
+ const b1 = bytes.charCodeAt(index + 1);
74
+ if ((b1 & 0xc0) === 0x80) {
75
+ units.push(((lead & 0x1f) << 6) | (b1 & 0x3f));
76
+ index += 2;
77
+ } else {
78
+ units.push(0xfffd);
79
+ index += 1;
80
+ }
81
+ } else if ((lead & 0xf0) === 0xe0) {
82
+ const b1 = bytes.charCodeAt(index + 1);
83
+ const b2 = bytes.charCodeAt(index + 2);
84
+ if ((b1 & 0xc0) === 0x80 && (b2 & 0xc0) === 0x80) {
85
+ units.push(((lead & 0x0f) << 12) | ((b1 & 0x3f) << 6) | (b2 & 0x3f));
86
+ index += 3;
87
+ } else {
88
+ units.push(0xfffd);
89
+ index += 1;
90
+ }
91
+ } else if ((lead & 0xf8) === 0xf0) {
92
+ const b1 = bytes.charCodeAt(index + 1);
93
+ const b2 = bytes.charCodeAt(index + 2);
94
+ const b3 = bytes.charCodeAt(index + 3);
95
+ if ((b1 & 0xc0) === 0x80 && (b2 & 0xc0) === 0x80 && (b3 & 0xc0) === 0x80) {
96
+ let code = ((lead & 0x07) << 18) | ((b1 & 0x3f) << 12) | ((b2 & 0x3f) << 6) | (b3 & 0x3f);
97
+ if (code > 0x10ffff) code = 0xfffd;
98
+ if (code >= 0x10000) {
99
+ code -= 0x10000;
100
+ units.push(0xd800 + (code >> 10), 0xdc00 + (code & 0x3ff));
101
+ } else {
102
+ units.push(code);
103
+ }
104
+ index += 4;
105
+ } else {
106
+ units.push(0xfffd);
107
+ index += 1;
108
+ }
109
+ } else {
110
+ units.push(0xfffd);
111
+ index += 1;
112
+ }
113
+ if (units.length >= 512) flushUnits(units, chunks);
114
+ }
115
+ flushUnits(units, chunks);
116
+ return chunks.join("");
27
117
  }
28
118
 
29
- /** Encode text as UTF-8, spelled one code unit per byte. */
119
+ /** Encode host text as a UTF-8 byte string. */
30
120
  function encodeUtf8(text: string): string {
31
121
  const chunks: string[] = [];
32
122
  const units: number[] = [];
@@ -57,17 +147,23 @@ function encodeUtf8(text: string): string {
57
147
  return chunks.join("");
58
148
  }
59
149
 
60
- /** Whether any code unit is above one byte, which means text, not bytes. */
61
- function hasCharacter(text: string): boolean {
62
- for (let index = 0; index < text.length; index++) {
63
- if (text.charCodeAt(index) > 0xff) return true;
150
+ /** One code unit per byte of a file buffer. */
151
+ function bytesToString(bytes: Uint8Array): string {
152
+ const chunks: string[] = [];
153
+ const units: number[] = [];
154
+ for (let index = 0; index < bytes.length; index++) {
155
+ units.push(bytes[index]!);
156
+ if (units.length >= 512) flushUnits(units, chunks);
64
157
  }
65
- return false;
158
+ flushUnits(units, chunks);
159
+ return chunks.join("");
66
160
  }
67
161
 
68
- /** Whether a decoded read started with a UTF-8 byte order mark. */
69
- function startsWithBom(text: string): boolean {
70
- return text.charCodeAt(0) === 0xef && text.charCodeAt(1) === 0xbb && text.charCodeAt(2) === 0xbf;
162
+ /** Whether the text starts with the UTF-8 encoding of a BOM. */
163
+ function stripBom(text: string): string {
164
+ return text.charCodeAt(0) === 0xef && text.charCodeAt(1) === 0xbb && text.charCodeAt(2) === 0xbf
165
+ ? text.slice(3)
166
+ : text;
71
167
  }
72
168
 
73
169
  /** Append the pending code units as one chunk of the byte string. */
@@ -75,4 +171,4 @@ function flushUnits(units: number[], chunks: string[]): void {
75
171
  if (units.length === 0) return;
76
172
  chunks.push(String.fromCharCode(...units));
77
173
  units.length = 0;
78
- }
174
+ }
@@ -1,19 +1,28 @@
1
1
  /**
2
- * Source file abstraction: owns the raw text plus a line-offset index so that
3
- * positions (character offsets) can be mapped back to line/column pairs for
2
+ * Source file abstraction: owns the raw byte text plus a line-offset index so
3
+ * that positions (byte offsets) can be mapped back to line/column pairs for
4
4
  * diagnostics and for incremental-compilation fingerprints.
5
+ *
6
+ * `text` is the compiler's internal representation: UTF-8 bytes, one code unit
7
+ * per byte (see `source-text.ts`). Offsets in the AST and diagnostics are
8
+ * indexes into that byte string. `positionAt` reports the line and the column
9
+ * a reader sees, so the column is counted in UTF-16 code units after decoding
10
+ * the line prefix; the raw byte column would drift from an editor's column as
11
+ * soon as a line contains non-ASCII text.
5
12
  */
6
13
 
14
+ import { decodeSourceBytes } from "./source-text.js";
15
+
7
16
  export interface LineAndColumn {
8
17
  /** 1-based line number. */
9
18
  readonly line: number;
10
- /** 1-based column number (UTF-16 code units). */
19
+ /** 1-based column number (UTF-16 code units, as an editor counts). */
11
20
  readonly column: number;
12
21
  }
13
22
 
14
23
  /**
15
- * A text position. `offset` is a UTF-16 code-unit index into the source text,
16
- * matching how the JavaScript/TypeScript toolchain measures positions.
24
+ * A text position. `offset` is a byte index into the source's internal UTF-8
25
+ * representation (`SourceFile.text`), not a UTF-16 code-unit index.
17
26
  */
18
27
  export interface TextPosition {
19
28
  readonly offset: number;
@@ -26,6 +35,7 @@ export interface TextRange {
26
35
 
27
36
  export class SourceFile {
28
37
  readonly fileName: string;
38
+ /** Internal UTF-8 byte text: one code unit per byte. */
29
39
  readonly text: string;
30
40
  /** Content hash used by the incremental compiler. */
31
41
  readonly hash: string;
@@ -34,6 +44,8 @@ export class SourceFile {
34
44
  constructor(fileName: string, text: string) {
35
45
  this.fileName = fileName;
36
46
  // Normalize BOM and line endings so downstream stages only deal with "\n".
47
+ // A file read through `readSourceText` already dropped the byte BOM; a
48
+ // host text argument may still carry the U+FEFF code unit.
37
49
  const normalized = text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;
38
50
  this.text = normalized.replace(/\r\n?/g, "\n");
39
51
  this.hash = hashText(this.text);
@@ -66,10 +78,20 @@ export class SourceFile {
66
78
  if (starts[mid]! <= clamped) lo = mid;
67
79
  else hi = mid - 1;
68
80
  }
69
- return { line: lo + 1, column: clamped - starts[lo]! + 1 };
81
+ const prefix = this.text.slice(starts[lo]!, clamped);
82
+ return { line: lo + 1, column: decodeSourceBytes(prefix).length + 1 };
83
+ }
84
+
85
+ /** The display text of a 1-based line, without its trailing newline. */
86
+ lineText(line: number): string {
87
+ const starts = this.getLineStarts();
88
+ if (line < 1 || line > starts.length) return "";
89
+ const start = starts[line - 1]!;
90
+ const next = line < starts.length ? starts[line]! - 1 : this.text.length;
91
+ return decodeSourceBytes(this.text.slice(start, next));
70
92
  }
71
93
 
72
- /** Extract the raw source text covered by a range. */
94
+ /** Extract the raw source text covered by a range (internal byte text). */
73
95
  slice(range: TextRange): string {
74
96
  return this.text.slice(range.start, range.end);
75
97
  }
@@ -27,6 +27,8 @@ export interface CacheKeyInput {
27
27
  readonly sourceText: string;
28
28
  readonly emit: string;
29
29
  readonly optimize: string;
30
+ /** Host architecture; a shared cache must not serve an x64 binary to arm64. */
31
+ readonly arch: string;
30
32
  readonly registry: ExtensionRegistry;
31
33
  readonly runtimeDir: string;
32
34
  readonly icon?: IconInfo;
@@ -41,11 +43,24 @@ export interface CacheKeyInput {
41
43
  readonly pgoDir: string;
42
44
  /** Active optional link features; they change which objects/archives link. */
43
45
  readonly features?: readonly string[];
46
+ /**
47
+ * The compiler the build will invoke. `undefined` for `emit: "ir"`, which
48
+ * needs no toolchain. A different clang/SDK produces a different binary, so
49
+ * it must invalidate the cache.
50
+ */
51
+ readonly toolchain?: CacheKeyToolchain;
52
+ }
53
+
54
+ /** The toolchain inputs that change the linked output. */
55
+ export interface CacheKeyToolchain {
56
+ readonly clang: string;
57
+ readonly sdkRoot?: string;
58
+ readonly linkerArgs: readonly string[];
44
59
  }
45
60
 
46
61
  /** Hash every input that can change the produced binary. */
47
62
  export function buildCacheKey(input: CacheKeyInput): string {
48
- const { app, icon, pgo, storage } = input;
63
+ const { app, icon, pgo, storage, toolchain } = input;
49
64
  return hashParts([
50
65
  COMPILER_VERSION,
51
66
  compilerFingerprint(),
@@ -53,6 +68,10 @@ export function buildCacheKey(input: CacheKeyInput): string {
53
68
  input.emit,
54
69
  input.optimize,
55
70
  process.platform,
71
+ input.arch,
72
+ toolchain?.clang ?? "",
73
+ toolchain?.sdkRoot ?? "",
74
+ [...(toolchain?.linkerArgs ?? [])].join(" "),
56
75
  registryFingerprint(input.registry),
57
76
  runtimeFingerprint(input.runtimeDir),
58
77
  vendoredRuntimeFingerprint(input.runtimeDir),
@@ -60,6 +79,7 @@ export function buildCacheKey(input: CacheKeyInput): string {
60
79
  app.name ?? "",
61
80
  String(app.bundle ?? false),
62
81
  app.bundleId ?? "",
82
+ String(app.console === true),
63
83
  storage.backend,
64
84
  storage.path,
65
85
  String(input.debug),
@@ -24,6 +24,7 @@ import {
24
24
  type VariableDeclarationList,
25
25
  } from "../../ast/nodes.js";
26
26
  import { SymbolKind } from "../../binder/binder.js";
27
+ import type { AssetSourceRange } from "../../extensions/registry.js";
27
28
  import {
28
29
  assignmentStatement,
29
30
  deferredAliasDeclarations,
@@ -78,17 +79,22 @@ export function concatenateModules(options: ConcatenateOptions): SourceFileNode
78
79
  * src="app.js">` body, say. Nodes inside such a span keep that file, so a
79
80
  * diagnostic points at real source and a plain-`.js` script stays exempt
80
81
  * from the type checker. */
81
- const originOf = (record: ModuleRecord, node: Node): string => {
82
+ const originOf = (record: ModuleRecord, node: Node): AssetSourceRange | undefined => {
82
83
  const ranges = record.originRanges;
83
- if (ranges === undefined) return record.path;
84
+ if (ranges === undefined) return undefined;
84
85
  for (const range of ranges) {
85
- if (node.start >= range.start && node.end <= range.end) return range.file;
86
+ if (node.start >= range.start && node.end <= range.end) return range;
86
87
  }
87
- return record.path;
88
+ return undefined;
88
89
  };
90
+ /* Inline `<script>` bodies in an HTML page are JavaScript unless the tag says
91
+ * otherwise; the checker must not infer types from them. */
92
+ const untypedNodes = new Set<object>();
89
93
  const trackOrigin = (record: ModuleRecord, root: Node): void => {
90
94
  const visit = (node: Node): void => {
91
- origins.set(node, originOf(record, node));
95
+ const range = originOf(record, node);
96
+ origins.set(node, range?.file ?? record.path);
97
+ if (range?.untyped) untypedNodes.add(node);
92
98
  const fields = node as unknown as Record<string, unknown>;
93
99
  for (const key of Object.keys(fields)) {
94
100
  if (key === "kind" || key === "start" || key === "end" || key === "text" || key === "value" || key === "raw") {
@@ -254,6 +260,7 @@ export function concatenateModules(options: ConcatenateOptions): SourceFileNode
254
260
  statements: merged,
255
261
  fileName: first.path,
256
262
  origins,
263
+ ...(untypedNodes.size > 0 ? { untypedNodes } : {}),
257
264
  moduleTexts: new Map(records.map((record) => [record.path, record.text])),
258
265
  modulePrefixes: records.map((record) => record.prefix),
259
266
  text: records.map((record) => record.text).join("\n"),
@@ -9,7 +9,7 @@ import { SyntaxKind, type ExportDeclaration, type ImportDeclaration, type NamedE
9
9
  import { bind } from "../../binder/binder.js";
10
10
  import { DiagnosticBag, DiagnosticCode } from "../../diagnostics/diagnostic.js";
11
11
  import { SourceFile } from "../../diagnostics/source.js";
12
- import { sourceTextBytes } from "../../diagnostics/source-text.js";
12
+ import { sourceTextFromBytes } from "../../diagnostics/source-text.js";
13
13
  import { Parser } from "../../parser/parser.js";
14
14
  import type { AssetLoader } from "../../extensions/registry.js";
15
15
  import { classifyDependency } from "./resolve.js";
@@ -103,7 +103,7 @@ export function loadGraph(
103
103
  const fileBytes = readFileSync(path);
104
104
  const raw = loader?.binary === true
105
105
  ? fileBytes.toString("latin1")
106
- : sourceTextBytes(fileBytes.toString("utf8"));
106
+ : sourceTextFromBytes(fileBytes);
107
107
  let text = raw;
108
108
  let originRanges: readonly OriginRange[] | undefined;
109
109
  if (loader) {
@@ -115,9 +115,15 @@ export function bundleModules(
115
115
  }
116
116
  }
117
117
  } else if (!declaration.exportClause && declaration.moduleSpecifier) {
118
- // `export * from "..."`: copy every re-exported name.
118
+ // `export * from "..."`: copy every re-exported name. A star export
119
+ // never re-exports `default`; the module's own default must win.
119
120
  const dependency = dependencyOf(record, declaration.moduleSpecifier.value);
120
- if (dependency) for (const [name, value] of dependency.exports) record.exports.set(name, value);
121
+ if (dependency) {
122
+ for (const [name, value] of dependency.exports) {
123
+ if (name === "default") continue;
124
+ record.exports.set(name, value);
125
+ }
126
+ }
121
127
  } else if (declaration.exportClause?.kind === SyntaxKind.NamespaceImport && declaration.moduleSpecifier) {
122
128
  // `export * as ns from "..."`: re-export the dependency's namespace.
123
129
  const nsName = (declaration.exportClause as { name: Identifier }).name.text;
@@ -198,9 +204,10 @@ export function bundleModules(
198
204
  }
199
205
  } else if (!clause) {
200
206
  /* `export * from "./dep"`: alias every runtime export the deferred
201
- * dependency contributes, so our own wrapper can return them. */
207
+ * dependency contributes, so our own wrapper can return them.
208
+ * `default` is not part of a star export. */
202
209
  for (const [name, target] of dependency.exports) {
203
- if (!target) continue;
210
+ if (name === "default" || !target) continue;
204
211
  const alias = deferredAliasName(record, aliases.length, `re_${name}`);
205
212
  aliases.push({
206
213
  name: alias,
@@ -64,6 +64,8 @@ export function resolveReexports(
64
64
  }
65
65
  } else if (!clause) {
66
66
  for (const [name, value] of dependency.exports) {
67
+ // `export *` re-exports named exports only, never `default`.
68
+ if (name === "default") continue;
67
69
  if (record.exports.get(name) !== value) {
68
70
  record.exports.set(name, value);
69
71
  changed = true;