@soundscript/soundscript 0.1.13 → 0.1.15

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 (441) hide show
  1. package/package.json +15 -6
  2. package/project-transform/index.js +2 -0
  3. package/project-transform/index.ts +8 -0
  4. package/project-transform/src/annotation_syntax.js +948 -0
  5. package/project-transform/src/annotation_syntax.ts +1217 -0
  6. package/project-transform/src/build_package.js +475 -0
  7. package/project-transform/src/build_package.ts +683 -0
  8. package/project-transform/src/bundled/portable-web-globals.d.ts +153 -0
  9. package/project-transform/src/bundled/runtime_externs.js +220 -0
  10. package/project-transform/src/bundled/runtime_externs.ts +237 -0
  11. package/project-transform/src/bundled/sound-libs/lib.decorators.d.ts +385 -0
  12. package/project-transform/src/bundled/sound-libs/lib.decorators.legacy.d.ts +22 -0
  13. package/project-transform/src/bundled/sound-libs/lib.dom.asynciterable.d.ts +42 -0
  14. package/project-transform/src/bundled/sound-libs/lib.dom.d.ts +39440 -0
  15. package/project-transform/src/bundled/sound-libs/lib.es2015.collection.d.ts +149 -0
  16. package/project-transform/src/bundled/sound-libs/lib.es2015.core.d.ts +657 -0
  17. package/project-transform/src/bundled/sound-libs/lib.es2015.d.ts +28 -0
  18. package/project-transform/src/bundled/sound-libs/lib.es2015.generator.d.ts +77 -0
  19. package/project-transform/src/bundled/sound-libs/lib.es2015.iterable.d.ts +616 -0
  20. package/project-transform/src/bundled/sound-libs/lib.es2015.promise.d.ts +80 -0
  21. package/project-transform/src/bundled/sound-libs/lib.es2015.proxy.d.ts +128 -0
  22. package/project-transform/src/bundled/sound-libs/lib.es2015.reflect.d.ts +144 -0
  23. package/project-transform/src/bundled/sound-libs/lib.es2015.symbol.d.ts +46 -0
  24. package/project-transform/src/bundled/sound-libs/lib.es2015.symbol.wellknown.d.ts +170 -0
  25. package/project-transform/src/bundled/sound-libs/lib.es2016.array.include.d.ts +116 -0
  26. package/project-transform/src/bundled/sound-libs/lib.es2016.d.ts +21 -0
  27. package/project-transform/src/bundled/sound-libs/lib.es2017.arraybuffer.d.ts +21 -0
  28. package/project-transform/src/bundled/sound-libs/lib.es2017.d.ts +26 -0
  29. package/project-transform/src/bundled/sound-libs/lib.es2017.date.d.ts +31 -0
  30. package/project-transform/src/bundled/sound-libs/lib.es2017.object.d.ts +49 -0
  31. package/project-transform/src/bundled/sound-libs/lib.es2017.string.d.ts +45 -0
  32. package/project-transform/src/bundled/sound-libs/lib.es2017.typedarrays.d.ts +53 -0
  33. package/project-transform/src/bundled/sound-libs/lib.es2018.asyncgenerator.d.ts +77 -0
  34. package/project-transform/src/bundled/sound-libs/lib.es2018.asynciterable.d.ts +57 -0
  35. package/project-transform/src/bundled/sound-libs/lib.es2018.d.ts +24 -0
  36. package/project-transform/src/bundled/sound-libs/lib.es2018.promise.d.ts +30 -0
  37. package/project-transform/src/bundled/sound-libs/lib.es2018.regexp.d.ts +37 -0
  38. package/project-transform/src/bundled/sound-libs/lib.es2019.array.d.ts +79 -0
  39. package/project-transform/src/bundled/sound-libs/lib.es2019.d.ts +24 -0
  40. package/project-transform/src/bundled/sound-libs/lib.es2019.object.d.ts +47 -0
  41. package/project-transform/src/bundled/sound-libs/lib.es2019.string.d.ts +37 -0
  42. package/project-transform/src/bundled/sound-libs/lib.es2019.symbol.d.ts +24 -0
  43. package/project-transform/src/bundled/sound-libs/lib.es2020.bigint.d.ts +765 -0
  44. package/project-transform/src/bundled/sound-libs/lib.es2020.d.ts +27 -0
  45. package/project-transform/src/bundled/sound-libs/lib.es2020.date.d.ts +42 -0
  46. package/project-transform/src/bundled/sound-libs/lib.es2020.number.d.ts +28 -0
  47. package/project-transform/src/bundled/sound-libs/lib.es2020.promise.d.ts +49 -0
  48. package/project-transform/src/bundled/sound-libs/lib.es2020.string.d.ts +44 -0
  49. package/project-transform/src/bundled/sound-libs/lib.es2020.symbol.wellknown.d.ts +41 -0
  50. package/project-transform/src/bundled/sound-libs/lib.es2021.d.ts +23 -0
  51. package/project-transform/src/bundled/sound-libs/lib.es2021.promise.d.ts +48 -0
  52. package/project-transform/src/bundled/sound-libs/lib.es2021.string.d.ts +33 -0
  53. package/project-transform/src/bundled/sound-libs/lib.es2021.weakref.d.ts +78 -0
  54. package/project-transform/src/bundled/sound-libs/lib.es2022.array.d.ts +121 -0
  55. package/project-transform/src/bundled/sound-libs/lib.es2022.d.ts +25 -0
  56. package/project-transform/src/bundled/sound-libs/lib.es2022.error.d.ts +75 -0
  57. package/project-transform/src/bundled/sound-libs/lib.es2022.object.d.ts +26 -0
  58. package/project-transform/src/bundled/sound-libs/lib.es2022.regexp.d.ts +39 -0
  59. package/project-transform/src/bundled/sound-libs/lib.es2022.string.d.ts +25 -0
  60. package/project-transform/src/bundled/sound-libs/lib.es2023.array.d.ts +924 -0
  61. package/project-transform/src/bundled/sound-libs/lib.es2023.collection.d.ts +21 -0
  62. package/project-transform/src/bundled/sound-libs/lib.es2023.d.ts +22 -0
  63. package/project-transform/src/bundled/sound-libs/lib.es2024.arraybuffer.d.ts +65 -0
  64. package/project-transform/src/bundled/sound-libs/lib.es2024.collection.d.ts +29 -0
  65. package/project-transform/src/bundled/sound-libs/lib.es2024.d.ts +26 -0
  66. package/project-transform/src/bundled/sound-libs/lib.es2024.object.d.ts +33 -0
  67. package/project-transform/src/bundled/sound-libs/lib.es2024.promise.d.ts +35 -0
  68. package/project-transform/src/bundled/sound-libs/lib.es2024.regexp.d.ts +25 -0
  69. package/project-transform/src/bundled/sound-libs/lib.es2024.string.d.ts +29 -0
  70. package/project-transform/src/bundled/sound-libs/lib.es5.d.ts +4924 -0
  71. package/project-transform/src/bundled/sound_stdlib.js +142 -0
  72. package/project-transform/src/bundled/sound_stdlib.ts +180 -0
  73. package/project-transform/src/checker/analyze_project.js +1361 -0
  74. package/project-transform/src/checker/analyze_project.ts +2246 -0
  75. package/project-transform/src/checker/diagnostics.js +112 -0
  76. package/project-transform/src/checker/diagnostics.ts +222 -0
  77. package/project-transform/src/checker/engine/context.js +235 -0
  78. package/project-transform/src/checker/engine/context.ts +340 -0
  79. package/project-transform/src/checker/engine/diagnostic_codes.js +72 -0
  80. package/project-transform/src/checker/engine/diagnostic_codes.ts +95 -0
  81. package/project-transform/src/checker/engine/facts.js +35 -0
  82. package/project-transform/src/checker/engine/facts.ts +48 -0
  83. package/project-transform/src/checker/engine/types.js +1 -0
  84. package/project-transform/src/checker/engine/types.ts +485 -0
  85. package/project-transform/src/checker/proof_escape_hatch_diagnostics.js +104 -0
  86. package/project-transform/src/checker/proof_escape_hatch_diagnostics.ts +173 -0
  87. package/project-transform/src/checker/rules/async_surface.js +231 -0
  88. package/project-transform/src/checker/rules/async_surface.ts +335 -0
  89. package/project-transform/src/checker/rules/class_lifecycle.js +798 -0
  90. package/project-transform/src/checker/rules/class_lifecycle.ts +1276 -0
  91. package/project-transform/src/checker/rules/directive_validation.js +571 -0
  92. package/project-transform/src/checker/rules/directive_validation.ts +938 -0
  93. package/project-transform/src/checker/rules/directives.js +23 -0
  94. package/project-transform/src/checker/rules/directives.ts +25 -0
  95. package/project-transform/src/checker/rules/flow.js +202 -0
  96. package/project-transform/src/checker/rules/flow.ts +333 -0
  97. package/project-transform/src/checker/rules/flow_facts.js +601 -0
  98. package/project-transform/src/checker/rules/flow_facts.ts +978 -0
  99. package/project-transform/src/checker/rules/flow_invalidation.js +1119 -0
  100. package/project-transform/src/checker/rules/flow_invalidation.ts +2150 -0
  101. package/project-transform/src/checker/rules/flow_shared.js +2822 -0
  102. package/project-transform/src/checker/rules/flow_shared.ts +4383 -0
  103. package/project-transform/src/checker/rules/foreign_boundary.js +120 -0
  104. package/project-transform/src/checker/rules/foreign_boundary.ts +196 -0
  105. package/project-transform/src/checker/rules/foreign_projection.js +279 -0
  106. package/project-transform/src/checker/rules/foreign_projection.ts +425 -0
  107. package/project-transform/src/checker/rules/generated_helpers.js +13 -0
  108. package/project-transform/src/checker/rules/generated_helpers.ts +18 -0
  109. package/project-transform/src/checker/rules/index.js +35 -0
  110. package/project-transform/src/checker/rules/index.ts +49 -0
  111. package/project-transform/src/checker/rules/namespace_object.js +845 -0
  112. package/project-transform/src/checker/rules/namespace_object.ts +1224 -0
  113. package/project-transform/src/checker/rules/non_ordinary_recovery.js +1328 -0
  114. package/project-transform/src/checker/rules/non_ordinary_recovery.ts +2391 -0
  115. package/project-transform/src/checker/rules/null_prototype.js +3 -0
  116. package/project-transform/src/checker/rules/null_prototype.ts +6 -0
  117. package/project-transform/src/checker/rules/overloads.js +181 -0
  118. package/project-transform/src/checker/rules/overloads.ts +317 -0
  119. package/project-transform/src/checker/rules/predicate_verification.js +691 -0
  120. package/project-transform/src/checker/rules/predicate_verification.ts +1088 -0
  121. package/project-transform/src/checker/rules/prototype_hardening.js +237 -0
  122. package/project-transform/src/checker/rules/prototype_hardening.ts +343 -0
  123. package/project-transform/src/checker/rules/receiver_discipline.js +263 -0
  124. package/project-transform/src/checker/rules/receiver_discipline.ts +356 -0
  125. package/project-transform/src/checker/rules/relations.js +6861 -0
  126. package/project-transform/src/checker/rules/relations.ts +12158 -0
  127. package/project-transform/src/checker/rules/resolved_builtins.js +274 -0
  128. package/project-transform/src/checker/rules/resolved_builtins.ts +438 -0
  129. package/project-transform/src/checker/rules/trust.js +217 -0
  130. package/project-transform/src/checker/rules/trust.ts +301 -0
  131. package/project-transform/src/checker/rules/type_guards.js +173 -0
  132. package/project-transform/src/checker/rules/type_guards.ts +257 -0
  133. package/project-transform/src/checker/rules/universal.js +17 -0
  134. package/project-transform/src/checker/rules/universal.ts +22 -0
  135. package/project-transform/src/checker/rules/unsafe_value_origin.js +80 -0
  136. package/project-transform/src/checker/rules/unsafe_value_origin.ts +125 -0
  137. package/project-transform/src/checker/rules/unsound_imports.js +218 -0
  138. package/project-transform/src/checker/rules/unsound_imports.ts +301 -0
  139. package/project-transform/src/checker/rules/unsound_syntax.js +1695 -0
  140. package/project-transform/src/checker/rules/unsound_syntax.ts +2540 -0
  141. package/project-transform/src/checker/rules/value_types.js +206 -0
  142. package/project-transform/src/checker/rules/value_types.ts +407 -0
  143. package/project-transform/src/checker/timing.js +43 -0
  144. package/project-transform/src/checker/timing.ts +78 -0
  145. package/project-transform/src/checker/unsupported_feature_messages.js +337 -0
  146. package/project-transform/src/checker/unsupported_feature_messages.ts +531 -0
  147. package/project-transform/src/cli.js +892 -0
  148. package/project-transform/src/cli.ts +1476 -0
  149. package/project-transform/src/compiler/compile_project.js +319 -0
  150. package/project-transform/src/compiler/compile_project.ts +508 -0
  151. package/project-transform/src/compiler/errors.js +10 -0
  152. package/project-transform/src/compiler/errors.ts +29 -0
  153. package/project-transform/src/compiler/ir.js +1 -0
  154. package/project-transform/src/compiler/ir.ts +1526 -0
  155. package/project-transform/src/compiler/lower.js +30550 -0
  156. package/project-transform/src/compiler/lower.ts +43645 -0
  157. package/project-transform/src/compiler/lower_arrays.js +140 -0
  158. package/project-transform/src/compiler/lower_arrays.ts +190 -0
  159. package/project-transform/src/compiler/lower_strings.js +121 -0
  160. package/project-transform/src/compiler/lower_strings.ts +198 -0
  161. package/project-transform/src/compiler/lower_tagged.js +329 -0
  162. package/project-transform/src/compiler/lower_tagged.ts +427 -0
  163. package/project-transform/src/compiler/lower_views.js +171 -0
  164. package/project-transform/src/compiler/lower_views.ts +251 -0
  165. package/project-transform/src/compiler/object_keys.js +25 -0
  166. package/project-transform/src/compiler/object_keys.ts +35 -0
  167. package/project-transform/src/compiler/runtime_ir.js +30 -0
  168. package/project-transform/src/compiler/runtime_ir.ts +727 -0
  169. package/project-transform/src/compiler/tagged_boundary.js +18 -0
  170. package/project-transform/src/compiler/tagged_boundary.ts +37 -0
  171. package/project-transform/src/compiler/toolchain.js +170 -0
  172. package/project-transform/src/compiler/toolchain.ts +229 -0
  173. package/project-transform/src/compiler/unicode_case_data.js +2102 -0
  174. package/project-transform/src/compiler/unicode_case_data.ts +2112 -0
  175. package/project-transform/src/compiler/wasm_js_host_runtime.js +656 -0
  176. package/project-transform/src/compiler/wasm_js_host_runtime.ts +762 -0
  177. package/project-transform/src/compiler/wat_arrays.js +3132 -0
  178. package/project-transform/src/compiler/wat_arrays.ts +3768 -0
  179. package/project-transform/src/compiler/wat_emitter.js +17952 -0
  180. package/project-transform/src/compiler/wat_emitter.ts +22812 -0
  181. package/project-transform/src/compiler/wat_strings.js +129 -0
  182. package/project-transform/src/compiler/wat_strings.ts +187 -0
  183. package/project-transform/src/compiler/wat_tagged.js +548 -0
  184. package/project-transform/src/compiler/wat_tagged.ts +674 -0
  185. package/project-transform/src/compiler_generator_runner.js +153 -0
  186. package/project-transform/src/compiler_generator_runner.ts +171 -0
  187. package/project-transform/src/compiler_object_test_helpers.js +69 -0
  188. package/project-transform/src/compiler_object_test_helpers.ts +96 -0
  189. package/project-transform/src/compiler_promise_runner.js +2116 -0
  190. package/project-transform/src/compiler_promise_runner.ts +2184 -0
  191. package/project-transform/src/compiler_test_helpers.js +854 -0
  192. package/project-transform/src/compiler_test_helpers.ts +1087 -0
  193. package/project-transform/src/config.js +568 -0
  194. package/project-transform/src/config.ts +892 -0
  195. package/project-transform/src/diagnostic_metadata.js +67 -0
  196. package/project-transform/src/diagnostic_metadata.ts +99 -0
  197. package/project-transform/src/diagnostic_reference.js +1368 -0
  198. package/project-transform/src/diagnostic_reference.ts +1523 -0
  199. package/project-transform/src/editor_diagnostics_worker.js +176 -0
  200. package/project-transform/src/editor_diagnostics_worker.ts +250 -0
  201. package/project-transform/src/editor_projection.js +224 -0
  202. package/project-transform/src/editor_projection.ts +421 -0
  203. package/project-transform/src/frontend/builtin_expanded_program_test_cleanup.js +47 -0
  204. package/project-transform/src/frontend/builtin_expanded_program_test_cleanup.ts +72 -0
  205. package/project-transform/src/frontend/builtin_macro_support.js +842 -0
  206. package/project-transform/src/frontend/builtin_macro_support.ts +1386 -0
  207. package/project-transform/src/frontend/builtin_macros.js +409 -0
  208. package/project-transform/src/frontend/builtin_macros.ts +542 -0
  209. package/project-transform/src/frontend/component_poc_runtime.js +279 -0
  210. package/project-transform/src/frontend/component_poc_runtime.ts +372 -0
  211. package/project-transform/src/frontend/css_macro.js +148 -0
  212. package/project-transform/src/frontend/css_macro.ts +222 -0
  213. package/project-transform/src/frontend/derive_macros.js +2072 -0
  214. package/project-transform/src/frontend/derive_macros.ts +3188 -0
  215. package/project-transform/src/frontend/embedded_fragment_support.js +106 -0
  216. package/project-transform/src/frontend/embedded_fragment_support.ts +172 -0
  217. package/project-transform/src/frontend/error_normalization.js +403 -0
  218. package/project-transform/src/frontend/error_normalization.ts +832 -0
  219. package/project-transform/src/frontend/error_stdlib_support.js +1 -0
  220. package/project-transform/src/frontend/error_stdlib_support.ts +6 -0
  221. package/project-transform/src/frontend/expand_project.js +169 -0
  222. package/project-transform/src/frontend/expand_project.ts +248 -0
  223. package/project-transform/src/frontend/format_soundscript.js +297 -0
  224. package/project-transform/src/frontend/format_soundscript.ts +582 -0
  225. package/project-transform/src/frontend/graphql_macro.js +174 -0
  226. package/project-transform/src/frontend/graphql_macro.ts +253 -0
  227. package/project-transform/src/frontend/hash_context.js +83 -0
  228. package/project-transform/src/frontend/hash_context.ts +113 -0
  229. package/project-transform/src/frontend/hkt_macro.js +448 -0
  230. package/project-transform/src/frontend/hkt_macro.ts +897 -0
  231. package/project-transform/src/frontend/import_binding_usage.js +190 -0
  232. package/project-transform/src/frontend/import_binding_usage.ts +277 -0
  233. package/project-transform/src/frontend/macro_advanced_backend_adapter.js +58 -0
  234. package/project-transform/src/frontend/macro_advanced_backend_adapter.ts +123 -0
  235. package/project-transform/src/frontend/macro_advanced_context.js +826 -0
  236. package/project-transform/src/frontend/macro_advanced_context.ts +1102 -0
  237. package/project-transform/src/frontend/macro_advanced_output.js +21 -0
  238. package/project-transform/src/frontend/macro_advanced_output.ts +41 -0
  239. package/project-transform/src/frontend/macro_api.js +353 -0
  240. package/project-transform/src/frontend/macro_api.ts +1722 -0
  241. package/project-transform/src/frontend/macro_api_internal.js +35 -0
  242. package/project-transform/src/frontend/macro_api_internal.ts +80 -0
  243. package/project-transform/src/frontend/macro_api_module_support.js +39 -0
  244. package/project-transform/src/frontend/macro_api_module_support.ts +65 -0
  245. package/project-transform/src/frontend/macro_backend_adapter.js +272 -0
  246. package/project-transform/src/frontend/macro_backend_adapter.ts +420 -0
  247. package/project-transform/src/frontend/macro_context.js +816 -0
  248. package/project-transform/src/frontend/macro_context.ts +1105 -0
  249. package/project-transform/src/frontend/macro_debug.js +99 -0
  250. package/project-transform/src/frontend/macro_debug.ts +157 -0
  251. package/project-transform/src/frontend/macro_definition_support.js +28 -0
  252. package/project-transform/src/frontend/macro_definition_support.ts +73 -0
  253. package/project-transform/src/frontend/macro_errors.js +40 -0
  254. package/project-transform/src/frontend/macro_errors.ts +70 -0
  255. package/project-transform/src/frontend/macro_expander.js +919 -0
  256. package/project-transform/src/frontend/macro_expander.ts +1611 -0
  257. package/project-transform/src/frontend/macro_factory_support.js +176 -0
  258. package/project-transform/src/frontend/macro_factory_support.ts +263 -0
  259. package/project-transform/src/frontend/macro_host_ast_internal.js +64 -0
  260. package/project-transform/src/frontend/macro_host_ast_internal.ts +109 -0
  261. package/project-transform/src/frontend/macro_index.js +27 -0
  262. package/project-transform/src/frontend/macro_index.ts +50 -0
  263. package/project-transform/src/frontend/macro_loader.js +281 -0
  264. package/project-transform/src/frontend/macro_loader.ts +506 -0
  265. package/project-transform/src/frontend/macro_operand_semantics.js +838 -0
  266. package/project-transform/src/frontend/macro_operand_semantics.ts +1489 -0
  267. package/project-transform/src/frontend/macro_output.js +54 -0
  268. package/project-transform/src/frontend/macro_output.ts +123 -0
  269. package/project-transform/src/frontend/macro_parser.js +611 -0
  270. package/project-transform/src/frontend/macro_parser.ts +832 -0
  271. package/project-transform/src/frontend/macro_resolver.js +69 -0
  272. package/project-transform/src/frontend/macro_resolver.ts +125 -0
  273. package/project-transform/src/frontend/macro_rewrite.js +285 -0
  274. package/project-transform/src/frontend/macro_rewrite.ts +442 -0
  275. package/project-transform/src/frontend/macro_runtime_support.js +232 -0
  276. package/project-transform/src/frontend/macro_runtime_support.ts +324 -0
  277. package/project-transform/src/frontend/macro_scanner.js +393 -0
  278. package/project-transform/src/frontend/macro_scanner.ts +455 -0
  279. package/project-transform/src/frontend/macro_semantic_backend_adapter.js +87 -0
  280. package/project-transform/src/frontend/macro_semantic_backend_adapter.ts +166 -0
  281. package/project-transform/src/frontend/macro_semantic_context.js +5 -0
  282. package/project-transform/src/frontend/macro_semantic_context.ts +12 -0
  283. package/project-transform/src/frontend/macro_semantic_output.js +24 -0
  284. package/project-transform/src/frontend/macro_semantic_output.ts +47 -0
  285. package/project-transform/src/frontend/macro_semantic_types.js +1 -0
  286. package/project-transform/src/frontend/macro_semantic_types.ts +98 -0
  287. package/project-transform/src/frontend/macro_semantics.js +1172 -0
  288. package/project-transform/src/frontend/macro_semantics.ts +1502 -0
  289. package/project-transform/src/frontend/macro_site_kind_support.js +164 -0
  290. package/project-transform/src/frontend/macro_site_kind_support.ts +255 -0
  291. package/project-transform/src/frontend/macro_syntax_internal.js +1950 -0
  292. package/project-transform/src/frontend/macro_syntax_internal.ts +3338 -0
  293. package/project-transform/src/frontend/macro_templates.js +57 -0
  294. package/project-transform/src/frontend/macro_templates.ts +143 -0
  295. package/project-transform/src/frontend/macro_test_helpers.js +82 -0
  296. package/project-transform/src/frontend/macro_test_helpers.ts +136 -0
  297. package/project-transform/src/frontend/macro_types.js +1 -0
  298. package/project-transform/src/frontend/macro_types.ts +103 -0
  299. package/project-transform/src/frontend/macro_vm.js +39 -0
  300. package/project-transform/src/frontend/macro_vm.ts +113 -0
  301. package/project-transform/src/frontend/match_macro.js +885 -0
  302. package/project-transform/src/frontend/match_macro.ts +1220 -0
  303. package/project-transform/src/frontend/numeric_normalization.js +824 -0
  304. package/project-transform/src/frontend/numeric_normalization.ts +1380 -0
  305. package/project-transform/src/frontend/numeric_prelude.js +278 -0
  306. package/project-transform/src/frontend/numeric_prelude.ts +370 -0
  307. package/project-transform/src/frontend/project_frontend.js +2396 -0
  308. package/project-transform/src/frontend/project_frontend.ts +3776 -0
  309. package/project-transform/src/frontend/project_macro_support.js +1401 -0
  310. package/project-transform/src/frontend/project_macro_support.ts +2137 -0
  311. package/project-transform/src/frontend/sql_macro.js +175 -0
  312. package/project-transform/src/frontend/sql_macro.ts +254 -0
  313. package/project-transform/src/frontend/sql_stdlib_support.js +1 -0
  314. package/project-transform/src/frontend/sql_stdlib_support.ts +6 -0
  315. package/project-transform/src/frontend/std_package_support.js +228 -0
  316. package/project-transform/src/frontend/std_package_support.ts +400 -0
  317. package/project-transform/src/frontend/value_normalization.js +306 -0
  318. package/project-transform/src/frontend/value_normalization.ts +599 -0
  319. package/project-transform/src/lsp/project_service.js +4771 -0
  320. package/project-transform/src/lsp/project_service.ts +7580 -0
  321. package/project-transform/src/lsp/protocol.js +9 -0
  322. package/project-transform/src/lsp/protocol.ts +38 -0
  323. package/project-transform/src/lsp/server.js +355 -0
  324. package/project-transform/src/lsp/server.ts +671 -0
  325. package/project-transform/src/lsp/session.js +49 -0
  326. package/project-transform/src/lsp/session.ts +48 -0
  327. package/project-transform/src/lsp/timing.js +43 -0
  328. package/project-transform/src/lsp/timing.ts +76 -0
  329. package/project-transform/src/lsp/transport.js +205 -0
  330. package/project-transform/src/lsp/transport.ts +253 -0
  331. package/project-transform/src/lsp_main.js +5 -0
  332. package/project-transform/src/lsp_main.ts +7 -0
  333. package/project-transform/src/macros.d.ts +1 -0
  334. package/project-transform/src/macros.js +1 -0
  335. package/project-transform/src/macros.ts +1 -0
  336. package/project-transform/src/main.js +24 -0
  337. package/project-transform/src/main.ts +28 -0
  338. package/project-transform/src/platform/host.js +264 -0
  339. package/project-transform/src/platform/host.ts +343 -0
  340. package/project-transform/src/platform/path.js +8 -0
  341. package/project-transform/src/platform/path.ts +20 -0
  342. package/project-transform/src/public_macro_api/macro_api.d.ts +1054 -0
  343. package/project-transform/src/public_macro_api/macro_semantic_types.d.ts +66 -0
  344. package/project-transform/src/public_macro_api/macro_types.d.ts +70 -0
  345. package/project-transform/src/run_program.js +14 -0
  346. package/project-transform/src/run_program.ts +33 -0
  347. package/project-transform/src/runtime/materialize.js +371 -0
  348. package/project-transform/src/runtime/materialize.ts +502 -0
  349. package/project-transform/src/runtime/on_demand.js +203 -0
  350. package/project-transform/src/runtime/on_demand.ts +305 -0
  351. package/project-transform/src/runtime/source_maps.js +205 -0
  352. package/project-transform/src/runtime/source_maps.ts +297 -0
  353. package/project-transform/src/runtime/transform.js +148 -0
  354. package/project-transform/src/runtime/transform.ts +295 -0
  355. package/project-transform/src/service/types.js +1 -0
  356. package/project-transform/src/service/types.ts +22 -0
  357. package/project-transform/src/soundscript_packages.js +477 -0
  358. package/project-transform/src/soundscript_packages.ts +754 -0
  359. package/project-transform/src/soundscript_runtime_specifiers.js +88 -0
  360. package/project-transform/src/soundscript_runtime_specifiers.ts +96 -0
  361. package/project-transform/src/stdlib/async.d.ts +81 -0
  362. package/project-transform/src/stdlib/async.js +213 -0
  363. package/project-transform/src/stdlib/async.ts +315 -0
  364. package/project-transform/src/stdlib/codec.d.ts +32 -0
  365. package/project-transform/src/stdlib/codec.js +30 -0
  366. package/project-transform/src/stdlib/codec.ts +76 -0
  367. package/project-transform/src/stdlib/compare.d.ts +28 -0
  368. package/project-transform/src/stdlib/compare.js +115 -0
  369. package/project-transform/src/stdlib/compare.ts +151 -0
  370. package/project-transform/src/stdlib/css.d.ts +16 -0
  371. package/project-transform/src/stdlib/css.js +9 -0
  372. package/project-transform/src/stdlib/css.ts +28 -0
  373. package/project-transform/src/stdlib/debug.d.ts +2 -0
  374. package/project-transform/src/stdlib/debug.js +9 -0
  375. package/project-transform/src/stdlib/debug.ts +10 -0
  376. package/project-transform/src/stdlib/decode.d.ts +86 -0
  377. package/project-transform/src/stdlib/decode.js +254 -0
  378. package/project-transform/src/stdlib/decode.ts +390 -0
  379. package/project-transform/src/stdlib/derive.d.ts +6 -0
  380. package/project-transform/src/stdlib/derive.js +7 -0
  381. package/project-transform/src/stdlib/derive.ts +7 -0
  382. package/project-transform/src/stdlib/encode.d.ts +100 -0
  383. package/project-transform/src/stdlib/encode.js +130 -0
  384. package/project-transform/src/stdlib/encode.ts +259 -0
  385. package/project-transform/src/stdlib/failures.d.ts +23 -0
  386. package/project-transform/src/stdlib/failures.js +41 -0
  387. package/project-transform/src/stdlib/failures.ts +64 -0
  388. package/project-transform/src/stdlib/fetch.d.ts +67 -0
  389. package/project-transform/src/stdlib/fetch.js +5 -0
  390. package/project-transform/src/stdlib/fetch.ts +11 -0
  391. package/project-transform/src/stdlib/graphql.d.ts +16 -0
  392. package/project-transform/src/stdlib/graphql.js +9 -0
  393. package/project-transform/src/stdlib/graphql.ts +28 -0
  394. package/project-transform/src/stdlib/hash.d.ts +34 -0
  395. package/project-transform/src/stdlib/hash.js +110 -0
  396. package/project-transform/src/stdlib/hash.ts +188 -0
  397. package/project-transform/src/stdlib/hkt.d.ts +40 -0
  398. package/project-transform/src/stdlib/hkt.js +3 -0
  399. package/project-transform/src/stdlib/hkt.ts +41 -0
  400. package/project-transform/src/stdlib/index.d.ts +9 -0
  401. package/project-transform/src/stdlib/index.js +15 -0
  402. package/project-transform/src/stdlib/index.ts +23 -0
  403. package/project-transform/src/stdlib/json.d.ts +125 -0
  404. package/project-transform/src/stdlib/json.js +764 -0
  405. package/project-transform/src/stdlib/json.ts +1034 -0
  406. package/project-transform/src/stdlib/match.d.ts +11 -0
  407. package/project-transform/src/stdlib/match.js +13 -0
  408. package/project-transform/src/stdlib/match.ts +26 -0
  409. package/project-transform/src/stdlib/numerics.d.ts +523 -0
  410. package/project-transform/src/stdlib/numerics.js +1356 -0
  411. package/project-transform/src/stdlib/numerics.ts +1937 -0
  412. package/project-transform/src/stdlib/random.d.ts +19 -0
  413. package/project-transform/src/stdlib/random.js +3 -0
  414. package/project-transform/src/stdlib/random.ts +5 -0
  415. package/project-transform/src/stdlib/result.d.ts +68 -0
  416. package/project-transform/src/stdlib/result.js +139 -0
  417. package/project-transform/src/stdlib/result.ts +248 -0
  418. package/project-transform/src/stdlib/sql.d.ts +22 -0
  419. package/project-transform/src/stdlib/sql.js +23 -0
  420. package/project-transform/src/stdlib/sql.ts +53 -0
  421. package/project-transform/src/stdlib/text.d.ts +24 -0
  422. package/project-transform/src/stdlib/text.js +3 -0
  423. package/project-transform/src/stdlib/text.ts +4 -0
  424. package/project-transform/src/stdlib/thunk.d.ts +2 -0
  425. package/project-transform/src/stdlib/thunk.js +9 -0
  426. package/project-transform/src/stdlib/thunk.ts +15 -0
  427. package/project-transform/src/stdlib/typeclasses.d.ts +57 -0
  428. package/project-transform/src/stdlib/typeclasses.js +78 -0
  429. package/project-transform/src/stdlib/typeclasses.ts +173 -0
  430. package/project-transform/src/stdlib/url.d.ts +37 -0
  431. package/project-transform/src/stdlib/url.js +3 -0
  432. package/project-transform/src/stdlib/url.ts +4 -0
  433. package/project-transform/src/stdlib/value.d.ts +9 -0
  434. package/project-transform/src/stdlib/value.js +104 -0
  435. package/project-transform/src/stdlib/value.ts +133 -0
  436. package/project-transform/src/test_installed_stdlib.js +147 -0
  437. package/project-transform/src/test_installed_stdlib.ts +245 -0
  438. package/project-transform/src/test_macro_package_fixture.js +50 -0
  439. package/project-transform/src/test_macro_package_fixture.ts +68 -0
  440. package/project-transform/src/value_deep_safe.js +191 -0
  441. package/project-transform/src/value_deep_safe.ts +273 -0
@@ -0,0 +1,1034 @@
1
+ import type { Decoder } from 'sts:decode';
2
+ import type { Encoder } from 'sts:encode';
3
+ import { Failure } from 'sts:failures';
4
+ import { isErr, type Result, resultOf } from 'sts:result';
5
+ import {
6
+ F32,
7
+ F64,
8
+ format as formatNumeric,
9
+ I8,
10
+ I16,
11
+ I32,
12
+ I64,
13
+ isNumeric,
14
+ toHostNumber,
15
+ type Numeric,
16
+ U8,
17
+ U16,
18
+ U32,
19
+ U64,
20
+ } from './numerics.ts';
21
+
22
+ export type JsonArray = JsonValue[];
23
+ export type JsonObject = {
24
+ [key: string]: JsonValue;
25
+ };
26
+ export type JsonValue = string | number | boolean | null | JsonObject | JsonArray;
27
+ type LosslessJsonArray = LosslessJsonValue[];
28
+ type LosslessJsonObject = {
29
+ [key: string]: LosslessJsonValue;
30
+ };
31
+ export type LosslessJsonValue =
32
+ | string
33
+ | number
34
+ | bigint
35
+ | boolean
36
+ | null
37
+ | LosslessJsonObject
38
+ | LosslessJsonArray;
39
+
40
+ export type JsonLikeArray = JsonLikeValue[];
41
+ export type JsonLikeObject = {
42
+ [key: string]: JsonLikeValue;
43
+ };
44
+ export type JsonLikeValue =
45
+ | string
46
+ | number
47
+ | boolean
48
+ | bigint
49
+ | null
50
+ | undefined
51
+ | JsonLikeObject
52
+ | JsonLikeArray;
53
+
54
+ export type MachineJsonArray = MachineJsonLikeValue[];
55
+ export type MachineJsonObject = {
56
+ [key: string]: MachineJsonLikeValue;
57
+ };
58
+ export type MachineJsonLikeValue =
59
+ | string
60
+ | number
61
+ | boolean
62
+ | bigint
63
+ | null
64
+ | undefined
65
+ | Numeric
66
+ | MachineJsonObject
67
+ | MachineJsonArray;
68
+
69
+ export type MachineJsonNumericMode = 'tagged' | 'decimal-string' | 'json-number';
70
+
71
+ export interface JsonParseOptions {
72
+ int64?: 'default' | 'lossless';
73
+ numerics?: 'tagged';
74
+ }
75
+
76
+ export type JsonStringifyBigintMode = 'number' | 'reject' | 'string';
77
+
78
+ export interface JsonStringifyOptions {
79
+ int64?: 'default' | 'string' | 'lossless';
80
+ readonly bigint?: JsonStringifyBigintMode;
81
+ numerics?: MachineJsonNumericMode;
82
+ }
83
+
84
+ const MAX_SAFE_INTEGER_BIGINT = BigInt(Number.MAX_SAFE_INTEGER);
85
+ const MIN_SAFE_INTEGER_BIGINT = BigInt(Number.MIN_SAFE_INTEGER);
86
+
87
+ export class JsonParseFailure extends Failure {
88
+ constructor(cause?: unknown) {
89
+ super('Failed to parse JSON.', { cause });
90
+ }
91
+ }
92
+
93
+ export class JsonStringifyFailure extends Failure {
94
+ constructor(cause?: unknown) {
95
+ super('Failed to stringify JSON.', { cause });
96
+ }
97
+ }
98
+
99
+ export function parseJson(text: string): Result<JsonValue, JsonParseFailure>;
100
+ export function parseJson(
101
+ text: string,
102
+ options: JsonParseOptions & { int64: 'lossless' },
103
+ ): Result<LosslessJsonValue, JsonParseFailure>;
104
+ export function parseJson(
105
+ text: string,
106
+ options: JsonParseOptions & { numerics: 'tagged' },
107
+ ): Result<MachineJsonLikeValue, JsonParseFailure>;
108
+ export function parseJson(
109
+ text: string,
110
+ options: JsonParseOptions = {},
111
+ ): Result<JsonValue | LosslessJsonValue | MachineJsonLikeValue, JsonParseFailure> {
112
+ return resultOf(
113
+ () => {
114
+ const parsed = options.int64 === 'lossless' ? parseLosslessJson(text) : JSON.parse(text);
115
+ return options.numerics === 'tagged'
116
+ ? decodeTaggedMachineJsonValue(parsed as JsonValue | LosslessJsonValue)
117
+ : parsed;
118
+ },
119
+ (cause) => new JsonParseFailure(cause),
120
+ );
121
+ }
122
+
123
+ export function stringifyJson(value: JsonValue): Result<string, JsonStringifyFailure>;
124
+ export function stringifyJson(
125
+ value: LosslessJsonValue,
126
+ options: JsonStringifyOptions & { int64: 'string' | 'lossless' },
127
+ ): Result<string, JsonStringifyFailure>;
128
+ export function stringifyJson(
129
+ value: MachineJsonLikeValue,
130
+ options: JsonStringifyOptions & { numerics: MachineJsonNumericMode },
131
+ ): Result<string, JsonStringifyFailure>;
132
+ export function stringifyJson(
133
+ value: JsonValue | LosslessJsonValue | MachineJsonLikeValue,
134
+ options: JsonStringifyOptions = {},
135
+ ): Result<string, JsonStringifyFailure> {
136
+ return resultOf(
137
+ () => {
138
+ if (options.numerics) {
139
+ const normalized = normalizeMachineJsonLikeValue(
140
+ value as MachineJsonLikeValue,
141
+ new Set<object>(),
142
+ options.numerics,
143
+ 'root',
144
+ );
145
+ const encoded = stringifyJsonLikeInternal(
146
+ normalized,
147
+ new Set<object>(),
148
+ options.bigint ?? 'reject',
149
+ 'root',
150
+ );
151
+ if (encoded === undefined) {
152
+ throw new TypeError('JSON stringification produced no top-level value.');
153
+ }
154
+ return encoded;
155
+ }
156
+
157
+ if (options.int64 === 'string') {
158
+ return stringifyJsonWithInt64Mode(value as LosslessJsonValue, 'string');
159
+ }
160
+ if (options.int64 === 'lossless') {
161
+ return stringifyJsonWithInt64Mode(value as LosslessJsonValue, 'lossless');
162
+ }
163
+
164
+ const encoded = JSON.stringify(value);
165
+ if (encoded === undefined) {
166
+ throw new TypeError(
167
+ 'JSON.stringify returned undefined for a JsonValue input.',
168
+ );
169
+ }
170
+ return encoded;
171
+ },
172
+ (cause) => new JsonStringifyFailure(cause),
173
+ );
174
+ }
175
+
176
+ export function parseAndDecode<T, E>(
177
+ text: string,
178
+ decoder: Decoder<T, E>,
179
+ ): Result<T, JsonParseFailure | E> {
180
+ const parsed = parseJson(text);
181
+ return isErr(parsed) ? parsed : decoder.decode(parsed.value);
182
+ }
183
+
184
+ export function encodeAndStringify<T, E>(
185
+ value: T,
186
+ encoder: Encoder<T, JsonValue, E>,
187
+ ): Result<string, E | JsonStringifyFailure> {
188
+ const encoded = encoder.encode(value);
189
+ return isErr(encoded) ? encoded : stringifyJson(encoded.value);
190
+ }
191
+
192
+ export function isJsonValue(value: unknown): value is JsonValue {
193
+ return isJsonValueInternal(value, new Set<object>());
194
+ }
195
+
196
+ export function parseJsonLike(text: string): Result<JsonLikeValue, JsonParseFailure> {
197
+ return resultOf(
198
+ () => {
199
+ const parser = new JsonLikeParser(text);
200
+ const value = parser.parseValue();
201
+ parser.finish();
202
+ return value;
203
+ },
204
+ (cause) => new JsonParseFailure(cause),
205
+ );
206
+ }
207
+
208
+ export function stringifyJsonLike(
209
+ value: JsonLikeValue,
210
+ options: JsonStringifyOptions = {},
211
+ ): Result<string, JsonStringifyFailure> {
212
+ return resultOf(
213
+ () => {
214
+ const encoded = stringifyJsonLikeInternal(
215
+ value,
216
+ new Set<object>(),
217
+ options.bigint ?? 'reject',
218
+ 'root',
219
+ );
220
+ if (encoded === undefined) {
221
+ throw new TypeError('JSON-like stringification produced no top-level value.');
222
+ }
223
+ return encoded;
224
+ },
225
+ (cause) => new JsonStringifyFailure(cause),
226
+ );
227
+ }
228
+
229
+ export function decodeJson<T, E>(
230
+ text: string,
231
+ decoder: Decoder<T, E>,
232
+ ): Result<T, E | JsonParseFailure> {
233
+ const parsed = parseJsonLike(text);
234
+ return isErr(parsed) ? parsed : decoder.decode(parsed.value);
235
+ }
236
+
237
+ export function encodeJson<T, E>(
238
+ value: T,
239
+ encoder: Encoder<T, JsonLikeValue, E>,
240
+ options: JsonStringifyOptions = {},
241
+ ): Result<string, E | JsonStringifyFailure> {
242
+ const encoded = encoder.encode(value);
243
+ return isErr(encoded) ? encoded : stringifyJsonLike(encoded.value, options);
244
+ }
245
+
246
+ export function isJsonLikeValue(value: unknown): value is JsonLikeValue {
247
+ return isJsonLikeValueInternal(value, new Set<object>());
248
+ }
249
+
250
+ function stringifyJsonWithInt64Mode(
251
+ value: LosslessJsonValue,
252
+ int64Mode: 'string' | 'lossless',
253
+ ): string {
254
+ return stringifyJsonWithInt64ModeInternal(value, int64Mode, new Set<object>());
255
+ }
256
+
257
+ function stringifyJsonWithInt64ModeInternal(
258
+ value: LosslessJsonValue,
259
+ int64Mode: 'string' | 'lossless',
260
+ visited: Set<object>,
261
+ ): string {
262
+ switch (typeof value) {
263
+ case 'string':
264
+ return JSON.stringify(value);
265
+ case 'number': {
266
+ const encoded = JSON.stringify(value);
267
+ if (encoded === undefined) {
268
+ throw new TypeError('JSON.stringify returned undefined for a numeric input.');
269
+ }
270
+ return encoded;
271
+ }
272
+ case 'bigint':
273
+ return int64Mode === 'string'
274
+ ? JSON.stringify(value.toString())
275
+ : value.toString();
276
+ case 'boolean':
277
+ return value ? 'true' : 'false';
278
+ case 'object':
279
+ if (value === null) {
280
+ return 'null';
281
+ }
282
+
283
+ if (visited.has(value)) {
284
+ throw new TypeError('Could not stringify cyclic JSON value.');
285
+ }
286
+
287
+ visited.add(value);
288
+ try {
289
+ if (Array.isArray(value)) {
290
+ return `[${value.map((entry) => stringifyJsonWithInt64ModeInternal(entry, int64Mode, visited)).join(',')}]`;
291
+ }
292
+
293
+ const fields = Object.keys(value).map((key) =>
294
+ `${JSON.stringify(key)}:${stringifyJsonWithInt64ModeInternal(value[key]!, int64Mode, visited)}`
295
+ );
296
+ return `{${fields.join(',')}}`;
297
+ } finally {
298
+ visited.delete(value);
299
+ }
300
+ default:
301
+ throw new TypeError(`Unsupported JSON value kind: ${typeof value}`);
302
+ }
303
+ }
304
+
305
+ function parseLosslessJson(text: string): LosslessJsonValue {
306
+ const parser = new LosslessJsonParser(text);
307
+ const value = parser.parseValue();
308
+ parser.skipWhitespace();
309
+ if (!parser.isAtEnd()) {
310
+ parser.fail('Unexpected trailing characters.');
311
+ }
312
+ return value;
313
+ }
314
+
315
+ function isJsonValueInternal(value: unknown, visited: Set<object>): value is JsonValue {
316
+ switch (typeof value) {
317
+ case 'string':
318
+ case 'number':
319
+ case 'boolean':
320
+ return true;
321
+ case 'object':
322
+ if (value === null) {
323
+ return true;
324
+ }
325
+
326
+ if (visited.has(value)) {
327
+ return true;
328
+ }
329
+
330
+ visited.add(value);
331
+ try {
332
+ if (Array.isArray(value)) {
333
+ return value.every((entry) => isJsonValueInternal(entry, visited));
334
+ }
335
+
336
+ for (const key of Object.keys(value)) {
337
+ if (!isJsonValueInternal((value as Record<string, unknown>)[key], visited)) {
338
+ return false;
339
+ }
340
+ }
341
+
342
+ return true;
343
+ } finally {
344
+ visited.delete(value);
345
+ }
346
+ default:
347
+ return false;
348
+ }
349
+ }
350
+
351
+ function isJsonLikeValueInternal(
352
+ value: unknown,
353
+ visited: Set<object>,
354
+ ): value is JsonLikeValue {
355
+ switch (typeof value) {
356
+ case 'string':
357
+ case 'number':
358
+ case 'boolean':
359
+ case 'bigint':
360
+ case 'undefined':
361
+ return true;
362
+ case 'object':
363
+ if (value === null) {
364
+ return true;
365
+ }
366
+
367
+ if (visited.has(value)) {
368
+ return true;
369
+ }
370
+
371
+ visited.add(value);
372
+ try {
373
+ if (Array.isArray(value)) {
374
+ return value.every((entry) => isJsonLikeValueInternal(entry, visited));
375
+ }
376
+
377
+ for (const key of Object.keys(value)) {
378
+ if (!isJsonLikeValueInternal((value as Record<string, unknown>)[key], visited)) {
379
+ return false;
380
+ }
381
+ }
382
+
383
+ return true;
384
+ } finally {
385
+ visited.delete(value);
386
+ }
387
+ default:
388
+ return false;
389
+ }
390
+ }
391
+
392
+ function normalizeMachineJsonLikeValue(
393
+ value: MachineJsonLikeValue,
394
+ visited: Set<object>,
395
+ numericMode: MachineJsonNumericMode,
396
+ position: 'array' | 'object' | 'root',
397
+ ): JsonLikeValue {
398
+ if (isNumeric(value)) {
399
+ return normalizeMachineNumericJsonValue(value, numericMode);
400
+ }
401
+
402
+ switch (typeof value) {
403
+ case 'string':
404
+ case 'number':
405
+ case 'boolean':
406
+ case 'bigint':
407
+ return value;
408
+ case 'undefined':
409
+ return position === 'array' ? null : undefined;
410
+ case 'object':
411
+ if (value === null) {
412
+ return null;
413
+ }
414
+
415
+ if (visited.has(value)) {
416
+ throw new TypeError('Converting circular structure to machine JSON text.');
417
+ }
418
+
419
+ visited.add(value);
420
+ try {
421
+ if (Array.isArray(value)) {
422
+ return value.map((entry) =>
423
+ normalizeMachineJsonLikeValue(entry, visited, numericMode, 'array') ?? null
424
+ );
425
+ }
426
+
427
+ const result: Record<string, JsonLikeValue> = {};
428
+ for (const key of Object.keys(value)) {
429
+ const normalized = normalizeMachineJsonLikeValue(
430
+ (value as MachineJsonObject)[key]!,
431
+ visited,
432
+ numericMode,
433
+ 'object',
434
+ );
435
+ if (normalized !== undefined) {
436
+ result[key] = normalized;
437
+ }
438
+ }
439
+ return result;
440
+ } finally {
441
+ visited.delete(value);
442
+ }
443
+ default:
444
+ throw new TypeError(`Unsupported machine JSON value kind: ${typeof value}`);
445
+ }
446
+ }
447
+
448
+ function normalizeMachineNumericJsonValue(
449
+ value: Numeric,
450
+ numericMode: MachineJsonNumericMode,
451
+ ): JsonLikeValue {
452
+ switch (numericMode) {
453
+ case 'tagged':
454
+ return value.toJSON();
455
+ case 'decimal-string':
456
+ return formatNumeric(value);
457
+ case 'json-number':
458
+ switch (value.__soundscript_numeric_kind) {
459
+ case 'i64':
460
+ case 'u64':
461
+ throw new TypeError('json-number machine JSON mode does not support bigint-backed machine numerics.');
462
+ default:
463
+ return toHostNumber(value);
464
+ }
465
+ }
466
+ }
467
+
468
+ function decodeTaggedMachineJsonValue(value: JsonValue | LosslessJsonValue): MachineJsonLikeValue {
469
+ if (Array.isArray(value)) {
470
+ return value.map((entry) => decodeTaggedMachineJsonValue(entry));
471
+ }
472
+
473
+ if (value && typeof value === 'object') {
474
+ const taggedNumeric = decodeTaggedMachineNumeric(value);
475
+ if (taggedNumeric) {
476
+ return taggedNumeric;
477
+ }
478
+
479
+ const result: Record<string, MachineJsonLikeValue> = {};
480
+ for (const key of Object.keys(value)) {
481
+ result[key] = decodeTaggedMachineJsonValue(value[key]!);
482
+ }
483
+ return result;
484
+ }
485
+
486
+ return value;
487
+ }
488
+
489
+ function decodeTaggedMachineNumeric(
490
+ value: Record<string, JsonValue | LosslessJsonValue>,
491
+ ): Numeric | undefined {
492
+ const numericKind = value['$numeric'];
493
+ const numericValue = value['value'];
494
+ const keys = Object.keys(value);
495
+ if (
496
+ typeof numericKind !== 'string' ||
497
+ typeof numericValue !== 'string' ||
498
+ keys.length !== 2 ||
499
+ !keys.includes('$numeric') ||
500
+ !keys.includes('value')
501
+ ) {
502
+ return undefined;
503
+ }
504
+
505
+ switch (numericKind) {
506
+ case 'f64':
507
+ return F64.parse(numericValue);
508
+ case 'f32':
509
+ return F32.parse(numericValue);
510
+ case 'i8':
511
+ return I8.parse(numericValue);
512
+ case 'i16':
513
+ return I16.parse(numericValue);
514
+ case 'i32':
515
+ return I32.parse(numericValue);
516
+ case 'i64':
517
+ return I64.parse(numericValue);
518
+ case 'u8':
519
+ return U8.parse(numericValue);
520
+ case 'u16':
521
+ return U16.parse(numericValue);
522
+ case 'u32':
523
+ return U32.parse(numericValue);
524
+ case 'u64':
525
+ return U64.parse(numericValue);
526
+ default:
527
+ return undefined;
528
+ }
529
+ }
530
+
531
+ function stringifyJsonLikeInternal(
532
+ value: JsonLikeValue,
533
+ visited: Set<object>,
534
+ bigintMode: JsonStringifyBigintMode,
535
+ position: 'array' | 'object' | 'root',
536
+ ): string | undefined {
537
+ switch (typeof value) {
538
+ case 'string':
539
+ return JSON.stringify(value);
540
+ case 'number':
541
+ return Number.isFinite(value) ? JSON.stringify(value) : 'null';
542
+ case 'boolean':
543
+ return value ? 'true' : 'false';
544
+ case 'bigint':
545
+ switch (bigintMode) {
546
+ case 'string':
547
+ return JSON.stringify(value.toString());
548
+ case 'number':
549
+ return value.toString();
550
+ case 'reject':
551
+ throw new TypeError('Encountered bigint while stringifying JSON-like data.');
552
+ }
553
+ case 'undefined':
554
+ return position === 'array' ? 'null' : undefined;
555
+ case 'object':
556
+ if (value === null) {
557
+ return 'null';
558
+ }
559
+
560
+ if (visited.has(value)) {
561
+ throw new TypeError('Converting circular structure to JSON-like text.');
562
+ }
563
+
564
+ visited.add(value);
565
+ try {
566
+ if (Array.isArray(value)) {
567
+ return `[${value.map((entry) =>
568
+ stringifyJsonLikeInternal(entry, visited, bigintMode, 'array') ?? 'null'
569
+ ).join(',')}]`;
570
+ }
571
+
572
+ const encodedProperties: string[] = [];
573
+ for (const key of Object.keys(value)) {
574
+ const encodedValue = stringifyJsonLikeInternal(
575
+ (value as Record<string, JsonLikeValue>)[key],
576
+ visited,
577
+ bigintMode,
578
+ 'object',
579
+ );
580
+ if (encodedValue === undefined) {
581
+ continue;
582
+ }
583
+ encodedProperties.push(`${JSON.stringify(key)}:${encodedValue}`);
584
+ }
585
+ return `{${encodedProperties.join(',')}}`;
586
+ } finally {
587
+ visited.delete(value);
588
+ }
589
+ default:
590
+ throw new TypeError('Encountered an unsupported JSON-like value.');
591
+ }
592
+ }
593
+
594
+ class LosslessJsonParser {
595
+ private readonly text: string;
596
+ private index = 0;
597
+
598
+ constructor(text: string) {
599
+ this.text = text;
600
+ }
601
+
602
+ fail(message: string): never {
603
+ throw new SyntaxError(`${message} At character ${this.index}.`);
604
+ }
605
+
606
+ isAtEnd(): boolean {
607
+ return this.index >= this.text.length;
608
+ }
609
+
610
+ skipWhitespace(): void {
611
+ while (!this.isAtEnd() && /\s/u.test(this.text[this.index]!)) {
612
+ this.index += 1;
613
+ }
614
+ }
615
+
616
+ parseValue(): LosslessJsonValue {
617
+ this.skipWhitespace();
618
+ if (this.isAtEnd()) {
619
+ this.fail('Unexpected end of JSON input.');
620
+ }
621
+
622
+ const current = this.text[this.index]!;
623
+ switch (current) {
624
+ case '"':
625
+ return this.parseString();
626
+ case '{':
627
+ return this.parseObject();
628
+ case '[':
629
+ return this.parseArray();
630
+ case 't':
631
+ this.consumeKeyword('true');
632
+ return true;
633
+ case 'f':
634
+ this.consumeKeyword('false');
635
+ return false;
636
+ case 'n':
637
+ this.consumeKeyword('null');
638
+ return null;
639
+ default:
640
+ if (current === '-' || isAsciiDigit(current)) {
641
+ return this.parseNumber();
642
+ }
643
+ this.fail(`Unexpected token ${JSON.stringify(current)}.`);
644
+ }
645
+ }
646
+
647
+ private consumeKeyword(keyword: string): void {
648
+ if (!this.text.startsWith(keyword, this.index)) {
649
+ this.fail(`Expected ${keyword}.`);
650
+ }
651
+ this.index += keyword.length;
652
+ }
653
+
654
+ private parseString(): string {
655
+ let result = '';
656
+ this.index += 1;
657
+
658
+ while (!this.isAtEnd()) {
659
+ const current = this.text[this.index]!;
660
+ if (current === '"') {
661
+ this.index += 1;
662
+ return result;
663
+ }
664
+ if (current === '\\') {
665
+ this.index += 1;
666
+ if (this.isAtEnd()) {
667
+ this.fail('Unexpected end of escape sequence.');
668
+ }
669
+ result += this.parseEscapeSequence();
670
+ continue;
671
+ }
672
+ result += current;
673
+ this.index += 1;
674
+ }
675
+
676
+ this.fail('Unterminated string literal.');
677
+ }
678
+
679
+ private parseEscapeSequence(): string {
680
+ const current = this.text[this.index]!;
681
+ this.index += 1;
682
+ switch (current) {
683
+ case '"':
684
+ case '\\':
685
+ case '/':
686
+ return current;
687
+ case 'b':
688
+ return '\b';
689
+ case 'f':
690
+ return '\f';
691
+ case 'n':
692
+ return '\n';
693
+ case 'r':
694
+ return '\r';
695
+ case 't':
696
+ return '\t';
697
+ case 'u': {
698
+ const hex = this.text.slice(this.index, this.index + 4);
699
+ if (!/^[0-9A-Fa-f]{4}$/u.test(hex)) {
700
+ this.fail('Invalid unicode escape.');
701
+ }
702
+ this.index += 4;
703
+ return String.fromCharCode(Number.parseInt(hex, 16));
704
+ }
705
+ default:
706
+ this.fail(`Invalid escape sequence \\${current}.`);
707
+ }
708
+ }
709
+
710
+ private parseArray(): LosslessJsonArray {
711
+ const result: LosslessJsonArray = [];
712
+ this.index += 1;
713
+ this.skipWhitespace();
714
+ if (this.text[this.index] === ']') {
715
+ this.index += 1;
716
+ return result;
717
+ }
718
+
719
+ while (true) {
720
+ result.push(this.parseValue());
721
+ this.skipWhitespace();
722
+ const current = this.text[this.index];
723
+ if (current === ']') {
724
+ this.index += 1;
725
+ return result;
726
+ }
727
+ if (current !== ',') {
728
+ this.fail('Expected , or ] in array literal.');
729
+ }
730
+ this.index += 1;
731
+ }
732
+ }
733
+
734
+ private parseObject(): LosslessJsonObject {
735
+ const result: LosslessJsonObject = {};
736
+ this.index += 1;
737
+ this.skipWhitespace();
738
+ if (this.text[this.index] === '}') {
739
+ this.index += 1;
740
+ return result;
741
+ }
742
+
743
+ while (true) {
744
+ this.skipWhitespace();
745
+ if (this.text[this.index] !== '"') {
746
+ this.fail('Expected string key in object literal.');
747
+ }
748
+ const key = this.parseString();
749
+ this.skipWhitespace();
750
+ if (this.text[this.index] !== ':') {
751
+ this.fail('Expected : after object key.');
752
+ }
753
+ this.index += 1;
754
+ result[key] = this.parseValue();
755
+ this.skipWhitespace();
756
+ const current = this.text[this.index];
757
+ if (current === '}') {
758
+ this.index += 1;
759
+ return result;
760
+ }
761
+ if (current !== ',') {
762
+ this.fail('Expected , or } in object literal.');
763
+ }
764
+ this.index += 1;
765
+ }
766
+ }
767
+
768
+ private parseNumber(): number | bigint {
769
+ const start = this.index;
770
+ if (this.text[this.index] === '-') {
771
+ this.index += 1;
772
+ }
773
+
774
+ if (this.text[this.index] === '0') {
775
+ this.index += 1;
776
+ } else {
777
+ this.consumeDigits();
778
+ }
779
+
780
+ let isInteger = true;
781
+ if (this.text[this.index] === '.') {
782
+ isInteger = false;
783
+ this.index += 1;
784
+ this.consumeDigits();
785
+ }
786
+
787
+ const exponentMarker = this.text[this.index];
788
+ if (exponentMarker === 'e' || exponentMarker === 'E') {
789
+ isInteger = false;
790
+ this.index += 1;
791
+ const sign = this.text[this.index];
792
+ if (sign === '+' || sign === '-') {
793
+ this.index += 1;
794
+ }
795
+ this.consumeDigits();
796
+ }
797
+
798
+ const token = this.text.slice(start, this.index);
799
+ if (!isInteger) {
800
+ return Number(token);
801
+ }
802
+ if (token === '-0') {
803
+ return -0;
804
+ }
805
+
806
+ const bigintValue = BigInt(token);
807
+ return bigintValue <= MAX_SAFE_INTEGER_BIGINT && bigintValue >= MIN_SAFE_INTEGER_BIGINT
808
+ ? Number(token)
809
+ : bigintValue;
810
+ }
811
+
812
+ private consumeDigits(): void {
813
+ const start = this.index;
814
+ while (!this.isAtEnd() && isAsciiDigit(this.text[this.index]!)) {
815
+ this.index += 1;
816
+ }
817
+ if (start === this.index) {
818
+ this.fail('Expected digits.');
819
+ }
820
+ }
821
+ }
822
+
823
+ class JsonLikeParser {
824
+ #index = 0;
825
+ readonly #text: string;
826
+
827
+ constructor(text: string) {
828
+ this.#text = text;
829
+ }
830
+
831
+ finish(): void {
832
+ this.#skipWhitespace();
833
+ if (this.#index !== this.#text.length) {
834
+ this.#error('Unexpected trailing JSON input');
835
+ }
836
+ }
837
+
838
+ parseValue(): JsonLikeValue {
839
+ this.#skipWhitespace();
840
+ const current = this.#text[this.#index];
841
+ switch (current) {
842
+ case '{':
843
+ return this.#parseObject();
844
+ case '[':
845
+ return this.#parseArray();
846
+ case '"':
847
+ return this.#parseString();
848
+ case 't':
849
+ this.#consumeKeyword('true');
850
+ return true;
851
+ case 'f':
852
+ this.#consumeKeyword('false');
853
+ return false;
854
+ case 'n':
855
+ this.#consumeKeyword('null');
856
+ return null;
857
+ default:
858
+ if (current === '-' || this.#isDigit(current)) {
859
+ return this.#parseNumber();
860
+ }
861
+ this.#error('Unexpected token in JSON input');
862
+ }
863
+ }
864
+
865
+ #consumeKeyword(keyword: string): void {
866
+ if (this.#text.slice(this.#index, this.#index + keyword.length) !== keyword) {
867
+ this.#error(`Expected ${keyword}`);
868
+ }
869
+ this.#index += keyword.length;
870
+ }
871
+
872
+ #parseArray(): JsonLikeArray {
873
+ const values: JsonLikeValue[] = [];
874
+ this.#index += 1;
875
+ this.#skipWhitespace();
876
+ if (this.#text[this.#index] === ']') {
877
+ this.#index += 1;
878
+ return values;
879
+ }
880
+
881
+ while (true) {
882
+ values.push(this.parseValue());
883
+ this.#skipWhitespace();
884
+ const current = this.#text[this.#index];
885
+ if (current === ']') {
886
+ this.#index += 1;
887
+ return values;
888
+ }
889
+ if (current !== ',') {
890
+ this.#error('Expected , or ] in JSON array');
891
+ }
892
+ this.#index += 1;
893
+ }
894
+ }
895
+
896
+ #parseNumber(): number | bigint {
897
+ const start = this.#index;
898
+ if (this.#text[this.#index] === '-') {
899
+ this.#index += 1;
900
+ }
901
+
902
+ if (this.#text[this.#index] === '0') {
903
+ this.#index += 1;
904
+ } else {
905
+ this.#consumeDigits();
906
+ }
907
+
908
+ let isInteger = true;
909
+ if (this.#text[this.#index] === '.') {
910
+ isInteger = false;
911
+ this.#index += 1;
912
+ this.#consumeDigits();
913
+ }
914
+
915
+ const exponent = this.#text[this.#index];
916
+ if (exponent === 'e' || exponent === 'E') {
917
+ isInteger = false;
918
+ this.#index += 1;
919
+ const sign = this.#text[this.#index];
920
+ if (sign === '+' || sign === '-') {
921
+ this.#index += 1;
922
+ }
923
+ this.#consumeDigits();
924
+ }
925
+
926
+ const token = this.#text.slice(start, this.#index);
927
+ if (!isInteger) {
928
+ return Number(token);
929
+ }
930
+
931
+ const bigintValue = BigInt(token);
932
+ const numberValue = Number(token);
933
+ return Number.isSafeInteger(numberValue) && BigInt(numberValue) === bigintValue
934
+ ? numberValue
935
+ : bigintValue;
936
+ }
937
+
938
+ #parseObject(): JsonLikeObject {
939
+ const object: Record<string, JsonLikeValue> = {};
940
+ this.#index += 1;
941
+ this.#skipWhitespace();
942
+ if (this.#text[this.#index] === '}') {
943
+ this.#index += 1;
944
+ return object;
945
+ }
946
+
947
+ while (true) {
948
+ this.#skipWhitespace();
949
+ if (this.#text[this.#index] !== '"') {
950
+ this.#error('Expected string key in JSON object');
951
+ }
952
+ const key = this.#parseString();
953
+ this.#skipWhitespace();
954
+ if (this.#text[this.#index] !== ':') {
955
+ this.#error('Expected : in JSON object');
956
+ }
957
+ this.#index += 1;
958
+ object[key] = this.parseValue();
959
+ this.#skipWhitespace();
960
+ const current = this.#text[this.#index];
961
+ if (current === '}') {
962
+ this.#index += 1;
963
+ return object;
964
+ }
965
+ if (current !== ',') {
966
+ this.#error('Expected , or } in JSON object');
967
+ }
968
+ this.#index += 1;
969
+ }
970
+ }
971
+
972
+ #parseString(): string {
973
+ const start = this.#index;
974
+ this.#index += 1;
975
+ while (this.#index < this.#text.length) {
976
+ const current = this.#text[this.#index];
977
+ if (current === '"') {
978
+ this.#index += 1;
979
+ const parsed = JSON.parse(this.#text.slice(start, this.#index));
980
+ if (typeof parsed !== 'string') {
981
+ this.#error('Expected string literal.');
982
+ }
983
+ return parsed;
984
+ }
985
+ if (current === '\\') {
986
+ this.#index += 1;
987
+ const escaped = this.#text[this.#index];
988
+ if (escaped === undefined) {
989
+ this.#error('Unterminated string escape');
990
+ }
991
+ if (escaped === 'u') {
992
+ for (let index = 0; index < 4; index += 1) {
993
+ this.#index += 1;
994
+ if (!/[0-9A-Fa-f]/u.test(this.#text[this.#index] ?? '')) {
995
+ this.#error('Invalid unicode escape');
996
+ }
997
+ }
998
+ }
999
+ } else if (current !== undefined && current <= '\u001F') {
1000
+ this.#error('Invalid control character in string literal');
1001
+ }
1002
+ this.#index += 1;
1003
+ }
1004
+ this.#error('Unterminated string literal');
1005
+ }
1006
+
1007
+ #consumeDigits(): void {
1008
+ const start = this.#index;
1009
+ while (this.#isDigit(this.#text[this.#index])) {
1010
+ this.#index += 1;
1011
+ }
1012
+ if (start === this.#index) {
1013
+ this.#error('Expected digit in JSON number');
1014
+ }
1015
+ }
1016
+
1017
+ #skipWhitespace(): void {
1018
+ while (/\s/u.test(this.#text[this.#index] ?? '')) {
1019
+ this.#index += 1;
1020
+ }
1021
+ }
1022
+
1023
+ #isDigit(value: string | undefined): boolean {
1024
+ return value !== undefined && value >= '0' && value <= '9';
1025
+ }
1026
+
1027
+ #error(message: string): never {
1028
+ throw new SyntaxError(`${message} at position ${this.#index}.`);
1029
+ }
1030
+ }
1031
+
1032
+ function isAsciiDigit(text: string): boolean {
1033
+ return text >= '0' && text <= '9';
1034
+ }