@soundscript/soundscript 0.1.12 → 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,885 @@
1
+ function emittedArrowText(functionExpr, fallbackTypeText) {
2
+ if (!functionExpr) {
3
+ return '';
4
+ }
5
+ const [parameter] = functionExpr.parameters;
6
+ if (!parameter || parameter.hasExplicitType() || parameter.name === null) {
7
+ return functionExpr.text();
8
+ }
9
+ if (!fallbackTypeText) {
10
+ return functionExpr.text();
11
+ }
12
+ const blockBody = functionExpr.body();
13
+ const exprBody = functionExpr.returnedExpr();
14
+ const bodyText = blockBody?.text() ?? exprBody?.text();
15
+ if (!bodyText) {
16
+ return functionExpr.text();
17
+ }
18
+ return `((${parameter.name}: ${fallbackTypeText}) => ${bodyText})`;
19
+ }
20
+ function spanContains(span, position) {
21
+ return position >= span.start && position <= span.end;
22
+ }
23
+ function validateExplicitObjectTypeArmAnnotation(ctx, parameter) {
24
+ const explicitType = parameter.explicitType()?.asObjectLiteral();
25
+ if (!explicitType) {
26
+ return;
27
+ }
28
+ const shorthandMembers = explicitType.members.filter((member) => member.memberKind === 'property_signature' && !member.hasExplicitType());
29
+ if (shorthandMembers.length === 0) {
30
+ return;
31
+ }
32
+ ctx.error(`Match object-type arm annotations do not support untyped shorthand members in \`${explicitType.text()}\`. Use explicit property types, or destructure against a named type like \`({ value }: Ok) => ...\`.`, explicitType);
33
+ }
34
+ function appendParameterSemanticTokens(tokens, parameter) {
35
+ for (const binding of parameter.bindingIdentifiers()) {
36
+ tokens.push({
37
+ modifiers: ['declaration'],
38
+ span: binding.span,
39
+ type: 'parameter',
40
+ });
41
+ }
42
+ }
43
+ function appendArmSemanticTokens(tokens, expression) {
44
+ const functionExpr = expression.unparenthesized().asFunction();
45
+ if (functionExpr?.functionKind === 'arrow') {
46
+ for (const parameter of functionExpr.parameters) {
47
+ appendParameterSemanticTokens(tokens, parameter);
48
+ }
49
+ return;
50
+ }
51
+ const call = expression.unparenthesized().asCall();
52
+ if (call?.callee.asIdentifier() === 'where') {
53
+ for (const argument of call.args) {
54
+ appendArmSemanticTokens(tokens, argument);
55
+ }
56
+ }
57
+ }
58
+ const MATCH_REJECTED_LEGACY_NUMERIC_TYPES = new Set(['NumberLike', 'BigintLike', 'numeric']);
59
+ const MATCH_MACHINE_NUMERIC_RUNTIME_KINDS = new Set([
60
+ 'f64',
61
+ 'f32',
62
+ 'i8',
63
+ 'i16',
64
+ 'i32',
65
+ 'i64',
66
+ 'u8',
67
+ 'u16',
68
+ 'u32',
69
+ 'u64',
70
+ ]);
71
+ function normalizedExplicitTypeText(parameter) {
72
+ return parameter.explicitType()?.text().replace(/\s+/gu, '') ?? null;
73
+ }
74
+ function validateNumericMatchTypeText(ctx, parameter) {
75
+ const normalizedTypeText = normalizedExplicitTypeText(parameter);
76
+ if (!normalizedTypeText) {
77
+ return;
78
+ }
79
+ if (MATCH_REJECTED_LEGACY_NUMERIC_TYPES.has(normalizedTypeText)) {
80
+ ctx.error('Match no longer supports legacy NumberLike, BigintLike, or numeric patterns. Use host `number`/`bigint`, exact machine leaves like `u8`, or machine families like `Int`, `Float`, and `Numeric`.');
81
+ }
82
+ }
83
+ function isIdentifierText(text) {
84
+ return /^[A-Za-z_$][A-Za-z0-9_$]*$/u.test(text);
85
+ }
86
+ function finiteCaseKeyToPatternKey(key) {
87
+ return isIdentifierText(key)
88
+ ? { kind: 'identifier', text: key }
89
+ : { kind: 'literal', code: JSON.stringify(key) };
90
+ }
91
+ function patternFromFiniteCase(finiteCase, narrowedTypeText) {
92
+ switch (finiteCase.kind) {
93
+ case 'literal':
94
+ return { kind: 'literal', code: finiteCase.code };
95
+ case 'runtime':
96
+ return { kind: 'typeof', bindingName: null, typeName: finiteCase.typeName };
97
+ case 'class':
98
+ return {
99
+ kind: 'instanceof',
100
+ bindingName: null,
101
+ className: finiteCase.className,
102
+ narrowedTypeText,
103
+ };
104
+ case 'object':
105
+ return {
106
+ kind: 'object',
107
+ properties: finiteCase.properties.map((property) => ({
108
+ key: finiteCaseKeyToPatternKey(property.key),
109
+ pattern: property.finiteCase
110
+ ? patternFromFiniteCase(property.finiteCase)
111
+ : { kind: 'wildcard' },
112
+ })),
113
+ rest: null,
114
+ };
115
+ case 'array':
116
+ return {
117
+ kind: 'array',
118
+ elements: finiteCase.elements.map((element) => element.finiteCase ? patternFromFiniteCase(element.finiteCase) : { kind: 'wildcard' }),
119
+ rest: null,
120
+ };
121
+ }
122
+ }
123
+ function preludeConstructorPredicate(className) {
124
+ switch (simpleClassName(className)) {
125
+ case 'Ok':
126
+ return 'isOk';
127
+ case 'Err':
128
+ return 'isErr';
129
+ case 'Some':
130
+ return 'isSome';
131
+ case 'None':
132
+ return 'isNone';
133
+ default:
134
+ return null;
135
+ }
136
+ }
137
+ function fallbackNarrowedTypeForClass(className) {
138
+ switch (simpleClassName(className)) {
139
+ case 'Ok':
140
+ return 'Ok<unknown>';
141
+ case 'Err':
142
+ return 'Err<unknown>';
143
+ case 'Some':
144
+ return 'Some<unknown>';
145
+ case 'None':
146
+ return 'None';
147
+ default:
148
+ return className;
149
+ }
150
+ }
151
+ function hasCatchAllArm(arm) {
152
+ return arm.guardText === null && arm.isCatchAll;
153
+ }
154
+ function armCoversFiniteCase(arm, finiteCase) {
155
+ if (arm.guardText !== null) {
156
+ return false;
157
+ }
158
+ return arm.isCatchAll ||
159
+ arm.patterns.some((pattern) => patternCoversFiniteCase(pattern, finiteCase));
160
+ }
161
+ function indentLines(lines) {
162
+ return lines.map((line) => line.length === 0 ? line : ` ${line}`);
163
+ }
164
+ function wrapGuard(condition, successLines) {
165
+ return [
166
+ `if (${condition}) {`,
167
+ ...indentLines(successLines),
168
+ '}',
169
+ ];
170
+ }
171
+ function canonicalLiteralCode(code) {
172
+ const trimmed = code.trim();
173
+ if ((trimmed.startsWith("'") && trimmed.endsWith("'")) ||
174
+ (trimmed.startsWith('"') && trimmed.endsWith('"')) ||
175
+ (trimmed.startsWith('`') && trimmed.endsWith('`'))) {
176
+ return JSON.stringify(trimmed.slice(1, -1));
177
+ }
178
+ return trimmed;
179
+ }
180
+ function simpleClassName(text) {
181
+ const segments = text.split('.');
182
+ return segments[segments.length - 1] ?? text;
183
+ }
184
+ function staticObjectKeyCode(key) {
185
+ switch (key.kind) {
186
+ case 'computed':
187
+ return null;
188
+ case 'identifier':
189
+ return JSON.stringify(key.text);
190
+ case 'literal':
191
+ return canonicalLiteralCode(key.code);
192
+ }
193
+ }
194
+ function typeofTypeConstraint(typeName) {
195
+ switch (typeName) {
196
+ case 'bigint':
197
+ return 'bigint';
198
+ case 'boolean':
199
+ return 'boolean';
200
+ case 'f32':
201
+ return 'f32';
202
+ case 'f64':
203
+ return 'f64';
204
+ case 'function':
205
+ return 'Function';
206
+ case 'i8':
207
+ return 'i8';
208
+ case 'i16':
209
+ return 'i16';
210
+ case 'i32':
211
+ return 'i32';
212
+ case 'i64':
213
+ return 'i64';
214
+ case 'number':
215
+ return 'number';
216
+ case 'object':
217
+ return 'object | null';
218
+ case 'string':
219
+ return 'string';
220
+ case 'symbol':
221
+ return 'symbol';
222
+ case 'u8':
223
+ return 'u8';
224
+ case 'u16':
225
+ return 'u16';
226
+ case 'u32':
227
+ return 'u32';
228
+ case 'u64':
229
+ return 'u64';
230
+ case 'undefined':
231
+ return 'undefined';
232
+ }
233
+ }
234
+ function machineNumericKindCondition(subjectExpr, kind) {
235
+ return `typeof ${subjectExpr} === "object" && ${subjectExpr} !== null && (${subjectExpr} as { __soundscript_numeric_kind?: unknown }).__soundscript_numeric_kind === ${JSON.stringify(kind)}`;
236
+ }
237
+ function isStringLiteralCode(code) {
238
+ const trimmed = canonicalLiteralCode(code);
239
+ return trimmed.startsWith('"') && trimmed.endsWith('"');
240
+ }
241
+ function isNumberLiteralCode(code) {
242
+ return /^-?\d+(?:\.\d+)?$/u.test(canonicalLiteralCode(code));
243
+ }
244
+ function isBooleanLiteralCode(code) {
245
+ const trimmed = canonicalLiteralCode(code);
246
+ return trimmed === 'true' || trimmed === 'false';
247
+ }
248
+ function finiteObjectProperty(finiteCase, propertyKey) {
249
+ return finiteCase.properties.find((property) => property.key === propertyKey) ?? null;
250
+ }
251
+ function finiteCaseFromTupleSlice(finiteCase, startIndex) {
252
+ return {
253
+ kind: 'array',
254
+ exactLength: Math.max(0, finiteCase.exactLength - startIndex),
255
+ elements: finiteCase.elements.slice(startIndex),
256
+ };
257
+ }
258
+ function patternCoversNestedFiniteCase(pattern, finiteCase) {
259
+ if (finiteCase === null) {
260
+ return pattern.kind === 'binding' || pattern.kind === 'wildcard';
261
+ }
262
+ return patternCoversFiniteCase(pattern, finiteCase);
263
+ }
264
+ function patternCoversFiniteCase(pattern, finiteCase) {
265
+ switch (pattern.kind) {
266
+ case 'wildcard':
267
+ case 'binding':
268
+ return true;
269
+ case 'literal':
270
+ return finiteCase.kind === 'literal' &&
271
+ finiteCase.code === canonicalLiteralCode(pattern.code);
272
+ case 'instanceof':
273
+ return finiteCase.kind === 'class' &&
274
+ finiteCase.className === simpleClassName(pattern.className);
275
+ case 'typeof':
276
+ if (finiteCase.kind === 'runtime') {
277
+ return finiteCase.typeName === pattern.typeName;
278
+ }
279
+ switch (pattern.typeName) {
280
+ case 'string':
281
+ return finiteCase.kind === 'literal' && isStringLiteralCode(finiteCase.code);
282
+ case 'number':
283
+ return finiteCase.kind === 'literal' && isNumberLiteralCode(finiteCase.code);
284
+ case 'boolean':
285
+ return finiteCase.kind === 'literal' && isBooleanLiteralCode(finiteCase.code);
286
+ case 'object':
287
+ return finiteCase.kind === 'object' ||
288
+ finiteCase.kind === 'array' ||
289
+ finiteCase.kind === 'class' ||
290
+ (finiteCase.kind === 'literal' && finiteCase.code === 'null');
291
+ default:
292
+ return false;
293
+ }
294
+ case 'array':
295
+ if (finiteCase.kind !== 'array') {
296
+ return false;
297
+ }
298
+ if (finiteCase.exactLength < pattern.elements.length) {
299
+ return false;
300
+ }
301
+ for (let index = 0; index < pattern.elements.length; index += 1) {
302
+ const element = pattern.elements[index];
303
+ if (element.kind === 'elision') {
304
+ continue;
305
+ }
306
+ if (!patternCoversNestedFiniteCase(element, finiteCase.elements[index]?.finiteCase ?? null)) {
307
+ return false;
308
+ }
309
+ }
310
+ if (pattern.rest !== null) {
311
+ return patternCoversNestedFiniteCase(pattern.rest, finiteCaseFromTupleSlice(finiteCase, pattern.elements.length));
312
+ }
313
+ return true;
314
+ case 'object':
315
+ if (finiteCase.kind !== 'object') {
316
+ return false;
317
+ }
318
+ return pattern.properties.every((property) => {
319
+ const staticKey = staticObjectKeyCode(property.key);
320
+ if (!staticKey) {
321
+ return false;
322
+ }
323
+ const propertyKey = staticKey.startsWith('"') && staticKey.endsWith('"')
324
+ ? JSON.parse(staticKey)
325
+ : staticKey;
326
+ const finiteProperty = finiteObjectProperty(finiteCase, propertyKey);
327
+ if (!finiteProperty) {
328
+ return false;
329
+ }
330
+ return patternCoversNestedFiniteCase(property.pattern, finiteProperty.finiteCase);
331
+ });
332
+ }
333
+ }
334
+ function parseArrayMatchArm(ctx, armSyntax) {
335
+ let armNode = armSyntax;
336
+ let guardNode = null;
337
+ const whereCall = armSyntax.unparenthesized().asCall();
338
+ if (whereCall?.callee.asIdentifier() === 'where') {
339
+ if (whereCall.args.length !== 2) {
340
+ ctx.error('Match where(...) arms require exactly two arguments: where(arm, predicate).');
341
+ }
342
+ armNode = whereCall.args[0];
343
+ guardNode = whereCall.args[1];
344
+ }
345
+ const armFunction = armNode.asFunction();
346
+ if (!armFunction) {
347
+ ctx.error('Match array arms must be single-parameter arrow functions or where(arm, predicate).');
348
+ }
349
+ if (armFunction.functionKind !== 'arrow') {
350
+ ctx.error('Match array arms currently require arrow functions.');
351
+ }
352
+ if (armFunction.typeParameterCount() > 0) {
353
+ ctx.error('Match array arms do not support type-parameterized arrows.');
354
+ }
355
+ if (armFunction.hasAsyncModifier()) {
356
+ ctx.error('Match array arms do not support async arrows.');
357
+ }
358
+ if (armFunction.parameters.length !== 1) {
359
+ ctx.error('Match array arms require exactly one parameter.');
360
+ }
361
+ const [parameter] = armFunction.parameters;
362
+ if (!parameter) {
363
+ ctx.error('Match array arms require exactly one parameter.');
364
+ }
365
+ if (parameter.isRest()) {
366
+ ctx.error('Match array arms do not support rest parameters.');
367
+ }
368
+ if (parameter.hasDefault()) {
369
+ ctx.error('Match array arms do not support default parameter values.');
370
+ }
371
+ const scrutineeTypeText = ctx.semantics.argType(0)?.displayText ?? 'unknown';
372
+ const emittedArmText = emittedArrowText(armFunction, scrutineeTypeText);
373
+ const guardFunction = guardNode?.asFunction() ?? null;
374
+ const emittedGuardText = guardFunction
375
+ ? emittedArrowText(guardFunction, parameter.hasExplicitType() ? parameter.explicitType()?.text() ?? scrutineeTypeText : scrutineeTypeText)
376
+ : guardNode?.text() ?? null;
377
+ if (!parameter.hasExplicitType()) {
378
+ if (parameter.name === null) {
379
+ ctx.error('Match destructuring arms require an explicit runtime-matchable parameter type.');
380
+ }
381
+ return {
382
+ armText: armNode.text(),
383
+ emittedArmText,
384
+ emittedGuardText,
385
+ fallbackTypeText: scrutineeTypeText,
386
+ guardText: guardNode?.text() ?? null,
387
+ isCatchAll: true,
388
+ parameter,
389
+ patterns: [],
390
+ };
391
+ }
392
+ validateExplicitObjectTypeArmAnnotation(ctx, parameter);
393
+ validateNumericMatchTypeText(ctx, parameter);
394
+ const parameterType = ctx.semantics.parameterType(parameter);
395
+ if (parameterType === null) {
396
+ ctx.error('Match arm parameter types must lower to honest runtime matchers.');
397
+ }
398
+ const finiteCases = ctx.semantics.finiteCases(parameterType);
399
+ if (!finiteCases || finiteCases.length === 0) {
400
+ ctx.error('Match arm parameter types must lower to honest runtime matchers.');
401
+ }
402
+ return {
403
+ armText: armNode.text(),
404
+ emittedArmText,
405
+ emittedGuardText,
406
+ fallbackTypeText: scrutineeTypeText,
407
+ guardText: guardNode?.text() ?? null,
408
+ isCatchAll: false,
409
+ parameter,
410
+ patterns: finiteCases.map((finiteCase) => patternFromFiniteCase(finiteCase, finiteCases.length === 1 ? parameter.explicitType()?.text() : undefined)),
411
+ };
412
+ }
413
+ function parseArrayMatchArms(ctx, armArrayExpr) {
414
+ const expandedArmArrayExpr = ctx.semantics.argExpanded(1)?.asArrayLiteral() ?? armArrayExpr;
415
+ const arms = expandedArmArrayExpr.elements.map((element) => {
416
+ if (element.isSpread || element.expression() === null) {
417
+ ctx.error('Match arms do not support spreads or omitted array elements.');
418
+ }
419
+ return parseArrayMatchArm(ctx, element.expression());
420
+ });
421
+ if (arms.length === 0) {
422
+ ctx.error('Match requires at least one arm.');
423
+ }
424
+ return arms;
425
+ }
426
+ function requiresCatchAllForArms(ctx, arms) {
427
+ const scrutineeType = ctx.semantics.argType(0);
428
+ if (!scrutineeType) {
429
+ return true;
430
+ }
431
+ const finiteCases = ctx.semantics.finiteCases(scrutineeType);
432
+ if (!finiteCases || finiteCases.length === 0) {
433
+ return true;
434
+ }
435
+ return finiteCases.some((finiteCase) => !arms.some((arm) => armCoversFiniteCase(arm, finiteCase)));
436
+ }
437
+ function validateArrayMatchArms(ctx, arms) {
438
+ const catchAllIndex = arms.findIndex(hasCatchAllArm);
439
+ if (catchAllIndex === -1 && requiresCatchAllForArms(ctx, arms)) {
440
+ ctx.error('Match requires a final catch-all arm unless the scrutinee type is provably exhaustive.');
441
+ }
442
+ if (catchAllIndex >= 0 && catchAllIndex !== arms.length - 1) {
443
+ ctx.error('Match catch-all arms must be the final arm.');
444
+ }
445
+ }
446
+ function collectLoweringState(pattern) {
447
+ const computedKeyOrder = [];
448
+ const computedKeyTemps = new WeakMap();
449
+ let nextTempIndex = 1;
450
+ let needsArrayExtractHelper = false;
451
+ let needsObjectRestHelper = false;
452
+ function visit(current) {
453
+ switch (current.kind) {
454
+ case 'array':
455
+ needsArrayExtractHelper = true;
456
+ for (const element of current.elements) {
457
+ if (element.kind !== 'elision') {
458
+ visit(element);
459
+ }
460
+ }
461
+ if (current.rest) {
462
+ visit(current.rest);
463
+ }
464
+ break;
465
+ case 'binding':
466
+ case 'instanceof':
467
+ case 'literal':
468
+ case 'typeof':
469
+ case 'wildcard':
470
+ break;
471
+ case 'object':
472
+ if (current.rest !== null) {
473
+ needsObjectRestHelper = true;
474
+ }
475
+ for (const property of current.properties) {
476
+ if (property.key.kind === 'computed' && !computedKeyTemps.has(property.key)) {
477
+ computedKeyTemps.set(property.key, `__sts_match_key_${nextTempIndex++}`);
478
+ computedKeyOrder.push(property.key);
479
+ }
480
+ visit(property.pattern);
481
+ }
482
+ break;
483
+ }
484
+ }
485
+ visit(pattern);
486
+ return {
487
+ computedKeyOrder,
488
+ computedKeyTemps,
489
+ needsArrayExtractHelper,
490
+ needsObjectRestHelper,
491
+ };
492
+ }
493
+ function runtimeObjectKeyExpression(key, state) {
494
+ switch (key.kind) {
495
+ case 'computed': {
496
+ const temp = state.computedKeyTemps.get(key);
497
+ if (!temp) {
498
+ throw new Error('Missing computed object key temp.');
499
+ }
500
+ return temp;
501
+ }
502
+ case 'identifier':
503
+ return JSON.stringify(key.text);
504
+ case 'literal':
505
+ return key.code;
506
+ }
507
+ }
508
+ function objectRestExcludedType(key, state) {
509
+ switch (key.kind) {
510
+ case 'computed':
511
+ return `typeof ${runtimeObjectKeyExpression(key, state)}`;
512
+ case 'identifier':
513
+ return JSON.stringify(key.text);
514
+ case 'literal':
515
+ return canonicalLiteralCode(key.code);
516
+ }
517
+ }
518
+ function propertyAccessExpression(subjectExpr, key, state) {
519
+ switch (key.kind) {
520
+ case 'identifier':
521
+ return /^[A-Za-z_$][A-Za-z0-9_$]*$/u.test(key.text)
522
+ ? `${subjectExpr}.${key.text}`
523
+ : `${subjectExpr}[${JSON.stringify(key.text)}]`;
524
+ case 'literal':
525
+ return `${subjectExpr}[${key.code}]`;
526
+ case 'computed':
527
+ return `${subjectExpr}[${runtimeObjectKeyExpression(key, state)}]`;
528
+ }
529
+ }
530
+ function objectLikeCondition(subjectExpr) {
531
+ return `((typeof ${subjectExpr} === "object" || typeof ${subjectExpr} === "function") && ${subjectExpr} !== null)`;
532
+ }
533
+ function objectRestExpression(subjectExpr, properties, state) {
534
+ return `__sts_match_object_rest(${subjectExpr}, [${properties.map((property) => runtimeObjectKeyExpression(property.key, state)).join(', ')}])`;
535
+ }
536
+ function objectRestBindingStatement(bindingName, subjectExpr, properties, state, typed) {
537
+ const expression = objectRestExpression(subjectExpr, properties, state);
538
+ if (!typed) {
539
+ return `const ${bindingName} = ${expression};`;
540
+ }
541
+ const excludedType = properties.length === 0
542
+ ? 'never'
543
+ : properties.map((property) => objectRestExcludedType(property.key, state)).join(' | ');
544
+ return `const ${bindingName} = ${expression} as __sts_match_omit<typeof ${subjectExpr}, ${excludedType}>;`;
545
+ }
546
+ function bindingStatementsForPattern(pattern, subjectExpr, state, typed = false) {
547
+ switch (pattern.kind) {
548
+ case 'binding':
549
+ return [`const ${pattern.name} = ${subjectExpr};`];
550
+ case 'wildcard':
551
+ case 'literal':
552
+ return [];
553
+ case 'typeof':
554
+ return pattern.bindingName ? [`const ${pattern.bindingName} = ${subjectExpr};`] : [];
555
+ case 'instanceof':
556
+ return pattern.bindingName ? [`const ${pattern.bindingName} = ${subjectExpr};`] : [];
557
+ case 'object': {
558
+ const lines = [];
559
+ for (const property of pattern.properties) {
560
+ lines.push(...bindingStatementsForPattern(property.pattern, propertyAccessExpression(subjectExpr, property.key, state), state, typed));
561
+ }
562
+ if (pattern.rest) {
563
+ lines.push(objectRestBindingStatement(pattern.rest, subjectExpr, pattern.properties, state, typed));
564
+ }
565
+ return lines;
566
+ }
567
+ case 'array': {
568
+ const lines = [];
569
+ pattern.elements.forEach((element, index) => {
570
+ if (element.kind === 'elision') {
571
+ return;
572
+ }
573
+ lines.push(...bindingStatementsForPattern(element, `${subjectExpr}[${index}]`, state, typed));
574
+ });
575
+ if (pattern.rest) {
576
+ lines.push(...bindingStatementsForPattern(pattern.rest, `${subjectExpr}.slice(${pattern.elements.length})`, state, typed));
577
+ }
578
+ return lines;
579
+ }
580
+ }
581
+ }
582
+ function lowerObjectProperty(property, subjectExpr, successLines, state) {
583
+ const keyExpr = runtimeObjectKeyExpression(property.key, state);
584
+ let lines = lowerPattern(property.pattern, propertyAccessExpression(subjectExpr, property.key, state), successLines, state);
585
+ lines = wrapGuard(`${keyExpr} in ${subjectExpr}`, lines);
586
+ if (property.key.kind === 'computed') {
587
+ lines = [
588
+ `const ${keyExpr} = (${property.key.expressionText});`,
589
+ ...lines,
590
+ ];
591
+ }
592
+ return lines;
593
+ }
594
+ function lowerPattern(pattern, subjectExpr, successLines, state) {
595
+ switch (pattern.kind) {
596
+ case 'binding':
597
+ return [`const ${pattern.name} = ${subjectExpr};`, ...successLines];
598
+ case 'wildcard':
599
+ return [...successLines];
600
+ case 'literal':
601
+ return wrapGuard(`${subjectExpr} === ${pattern.code}`, successLines);
602
+ case 'typeof': {
603
+ const inner = pattern.bindingName
604
+ ? [`const ${pattern.bindingName} = ${subjectExpr};`, ...successLines]
605
+ : [...successLines];
606
+ const condition = pattern.typeName === 'object'
607
+ ? objectLikeCondition(subjectExpr)
608
+ : MATCH_MACHINE_NUMERIC_RUNTIME_KINDS.has(pattern.typeName)
609
+ ? machineNumericKindCondition(subjectExpr, pattern.typeName)
610
+ : `typeof ${subjectExpr} === ${JSON.stringify(pattern.typeName)}`;
611
+ return wrapGuard(condition, inner);
612
+ }
613
+ case 'instanceof': {
614
+ const inner = pattern.bindingName
615
+ ? [`const ${pattern.bindingName} = ${subjectExpr};`, ...successLines]
616
+ : [...successLines];
617
+ const predicate = preludeConstructorPredicate(pattern.className);
618
+ return wrapGuard(predicate ? `${predicate}(${subjectExpr})` : `${subjectExpr} instanceof ${pattern.className}`, inner);
619
+ }
620
+ case 'object': {
621
+ let lines = [...successLines];
622
+ if (pattern.rest) {
623
+ lines = [
624
+ objectRestBindingStatement(pattern.rest, subjectExpr, pattern.properties, state, false),
625
+ ...lines,
626
+ ];
627
+ }
628
+ for (let index = pattern.properties.length - 1; index >= 0; index -= 1) {
629
+ lines = lowerObjectProperty(pattern.properties[index], subjectExpr, lines, state);
630
+ }
631
+ return wrapGuard(objectLikeCondition(subjectExpr), lines);
632
+ }
633
+ case 'array': {
634
+ let lines = [...successLines];
635
+ if (pattern.rest) {
636
+ lines = lowerPattern(pattern.rest, `${subjectExpr}.slice(${pattern.elements.length})`, lines, state);
637
+ }
638
+ for (let index = pattern.elements.length - 1; index >= 0; index -= 1) {
639
+ const element = pattern.elements[index];
640
+ if (element.kind === 'elision') {
641
+ continue;
642
+ }
643
+ lines = lowerPattern(element, `${subjectExpr}[${index}]`, lines, state);
644
+ }
645
+ return wrapGuard(`Array.isArray(${subjectExpr}) && ${subjectExpr}.length >= ${pattern.elements.length}`, lines);
646
+ }
647
+ }
648
+ }
649
+ function formatPatternTypeKey(key) {
650
+ switch (key.kind) {
651
+ case 'computed':
652
+ return `[${key.expressionText}]`;
653
+ case 'identifier':
654
+ return /^[A-Za-z_$][A-Za-z0-9_$]*$/u.test(key.text) ? key.text : JSON.stringify(key.text);
655
+ case 'literal':
656
+ return key.code;
657
+ }
658
+ }
659
+ function arrayTypeConstraint(pattern) {
660
+ if (pattern.elements.length === 0 && pattern.rest === null) {
661
+ return 'readonly unknown[]';
662
+ }
663
+ const entries = pattern.elements.map((element) => element.kind === 'elision' ? 'unknown' : typeConstraintForPattern(element));
664
+ return `readonly [${entries.join(', ')}${entries.length > 0 ? ', ' : ''}...unknown[]]`;
665
+ }
666
+ function objectTypeConstraint(pattern) {
667
+ const staticProperties = pattern.properties
668
+ .filter((property) => property.key.kind !== 'computed')
669
+ .map((property) => `${formatPatternTypeKey(property.key)}: ${typeConstraintForPattern(property.pattern)}`);
670
+ if (staticProperties.length === 0) {
671
+ return 'object';
672
+ }
673
+ return `{ ${staticProperties.join('; ')} }`;
674
+ }
675
+ function typeConstraintForPattern(pattern) {
676
+ switch (pattern.kind) {
677
+ case 'binding':
678
+ case 'wildcard':
679
+ return 'unknown';
680
+ case 'literal':
681
+ return pattern.code;
682
+ case 'typeof':
683
+ return typeofTypeConstraint(pattern.typeName);
684
+ case 'instanceof':
685
+ return pattern.narrowedTypeText ?? fallbackNarrowedTypeForClass(pattern.className);
686
+ case 'object':
687
+ return objectTypeConstraint(pattern);
688
+ case 'array':
689
+ return arrayTypeConstraint(pattern);
690
+ }
691
+ }
692
+ function narrowedTypeForPattern(scrutineeType, pattern) {
693
+ switch (pattern.kind) {
694
+ case 'binding':
695
+ case 'wildcard':
696
+ return scrutineeType;
697
+ case 'literal':
698
+ return `Extract<${scrutineeType}, ${pattern.code}>`;
699
+ case 'typeof':
700
+ return `Extract<${scrutineeType}, ${typeofTypeConstraint(pattern.typeName)}>`;
701
+ case 'instanceof':
702
+ return `Extract<${scrutineeType}, ${pattern.narrowedTypeText ?? fallbackNarrowedTypeForClass(pattern.className)}>`;
703
+ case 'object':
704
+ return `Extract<${scrutineeType}, ${objectTypeConstraint(pattern)}>`;
705
+ case 'array':
706
+ return `Extract<${scrutineeType}, ${arrayTypeConstraint(pattern)}>`;
707
+ }
708
+ }
709
+ function usesNativeControlFlowNarrowing(pattern) {
710
+ switch (pattern.kind) {
711
+ case 'binding':
712
+ case 'instanceof':
713
+ case 'literal':
714
+ case 'wildcard':
715
+ return true;
716
+ case 'typeof':
717
+ return !MATCH_MACHINE_NUMERIC_RUNTIME_KINDS.has(pattern.typeName);
718
+ case 'array':
719
+ case 'object':
720
+ return false;
721
+ }
722
+ }
723
+ function lowerArrayMatchArm(arm, subjectExpr) {
724
+ if (arm.isCatchAll) {
725
+ const successLines = arm.emittedGuardText
726
+ ? wrapGuard(`(${arm.emittedGuardText})(${subjectExpr})`, [
727
+ `return (${arm.emittedArmText})(${subjectExpr});`,
728
+ ])
729
+ : [`return (${arm.emittedArmText})(${subjectExpr});`];
730
+ return successLines.join('\n');
731
+ }
732
+ return arm.patterns.map((pattern) => {
733
+ const narrowedSubjectExpr = usesNativeControlFlowNarrowing(pattern)
734
+ ? subjectExpr
735
+ : `(${subjectExpr} as ${narrowedTypeForPattern(arm.fallbackTypeText, pattern)})`;
736
+ const successLines = arm.emittedGuardText
737
+ ? wrapGuard(`(${arm.emittedGuardText})(${narrowedSubjectExpr})`, [
738
+ `return (${arm.emittedArmText})(${narrowedSubjectExpr});`,
739
+ ])
740
+ : [`return (${arm.emittedArmText})(${narrowedSubjectExpr});`];
741
+ return lowerPattern(pattern, subjectExpr, successLines, collectLoweringState(pattern)).join('\n');
742
+ }).join('\n');
743
+ }
744
+ export function semanticTokensForMatchMacro(ctx) {
745
+ const node = ctx.node;
746
+ const armArraySyntax = node.args[1]?.asArrayLiteral();
747
+ if (!armArraySyntax) {
748
+ return [];
749
+ }
750
+ const tokens = [];
751
+ for (const element of armArraySyntax.elements) {
752
+ const expression = element.expression();
753
+ if (element.isSpread || expression === null) {
754
+ continue;
755
+ }
756
+ appendArmSemanticTokens(tokens, expression);
757
+ }
758
+ return tokens;
759
+ }
760
+ export function hoverMatchMacro(ctx) {
761
+ return {
762
+ contents: [
763
+ '**macro** `Match`',
764
+ '',
765
+ 'Evaluates the scrutinee once and returns the first matching arm.',
766
+ '',
767
+ 'Preferred form:',
768
+ '- `Match (value) [ ({ value }: Ok) => value, (x: string) => x.length, (_) => 0 ]`',
769
+ '- guards layer through `where(arm, predicate)`',
770
+ ].join('\n'),
771
+ };
772
+ }
773
+ export function hoverMatchMacroPosition(ctx) {
774
+ const invocation = ctx.node;
775
+ const armArrayExpr = invocation.args[1]?.asArrayLiteral();
776
+ if (!armArrayExpr) {
777
+ return null;
778
+ }
779
+ const sourcePosition = ctx.node.span.start + ctx.offset;
780
+ const invocationText = invocation.text();
781
+ const invocationTextOffset = sourcePosition - invocation.span.start;
782
+ const fallbackTypeText = ctx.macro.semantics.argType(0)?.displayText ?? 'unknown';
783
+ for (const element of armArrayExpr.elements) {
784
+ if (element.isSpread) {
785
+ continue;
786
+ }
787
+ const expression = element.expression();
788
+ if (!expression) {
789
+ continue;
790
+ }
791
+ const whereCall = expression.unparenthesized().asCall();
792
+ const armNode = whereCall?.callee.asIdentifier() === 'where'
793
+ ? (whereCall.args[0] ?? expression)
794
+ : expression;
795
+ const armFunction = armNode.asFunction();
796
+ const parameter = armFunction?.parameters[0];
797
+ if (!parameter) {
798
+ continue;
799
+ }
800
+ const armTypeText = parameter.hasExplicitType()
801
+ ? parameter.explicitType()?.text() ?? fallbackTypeText
802
+ : fallbackTypeText;
803
+ if (!parameter.hasExplicitType()) {
804
+ for (const binding of parameter.bindingIdentifiers()) {
805
+ if (spanContains(binding.span, sourcePosition)) {
806
+ return {
807
+ contents: `\`\`\`ts\n${binding.name}: ${armTypeText}\n\`\`\``,
808
+ };
809
+ }
810
+ if (identifierAtOffsetEquals(invocationText, invocationTextOffset, binding.name) && isPositionInsideFunctionBody(armFunction, sourcePosition)) {
811
+ return {
812
+ contents: `\`\`\`ts\n${binding.name}: ${armTypeText}\n\`\`\``,
813
+ };
814
+ }
815
+ }
816
+ }
817
+ const guardFunction = whereCall?.callee.asIdentifier() === 'where'
818
+ ? whereCall.args[1]?.asFunction() ?? null
819
+ : null;
820
+ const guardParameter = guardFunction?.parameters[0];
821
+ if (!guardParameter || guardParameter.hasExplicitType()) {
822
+ continue;
823
+ }
824
+ for (const binding of guardParameter.bindingIdentifiers()) {
825
+ if (spanContains(binding.span, sourcePosition)) {
826
+ return {
827
+ contents: `\`\`\`ts\n${binding.name}: ${armTypeText}\n\`\`\``,
828
+ };
829
+ }
830
+ if (identifierAtOffsetEquals(invocationText, invocationTextOffset, binding.name) && isPositionInsideFunctionBody(guardFunction, sourcePosition)) {
831
+ return {
832
+ contents: `\`\`\`ts\n${binding.name}: ${armTypeText}\n\`\`\``,
833
+ };
834
+ }
835
+ }
836
+ }
837
+ return null;
838
+ }
839
+ function isIdentifierPart(character) {
840
+ return character !== undefined && /[\p{ID_Continue}_$\u200C\u200D]/u.test(character);
841
+ }
842
+ function identifierAtOffsetEquals(text, offset, name) {
843
+ if (offset < 0 || offset >= text.length) {
844
+ return false;
845
+ }
846
+ const start = offset;
847
+ const end = offset + name.length;
848
+ if (text.slice(start, end) !== name) {
849
+ return false;
850
+ }
851
+ const before = start > 0 ? text[start - 1] : undefined;
852
+ const after = end < text.length ? text[end] : undefined;
853
+ return !isIdentifierPart(before) && !isIdentifierPart(after);
854
+ }
855
+ function isPositionInsideFunctionBody(fn, sourcePosition) {
856
+ if (!fn) {
857
+ return false;
858
+ }
859
+ const blockBody = fn.body();
860
+ if (blockBody && spanContains(blockBody.span, sourcePosition)) {
861
+ return true;
862
+ }
863
+ const returnedExpr = fn.returnedExpr();
864
+ if (returnedExpr && spanContains(returnedExpr.span, sourcePosition)) {
865
+ return true;
866
+ }
867
+ const returnedJsx = fn.returnedJsx();
868
+ return returnedJsx ? spanContains(returnedJsx.span, sourcePosition) : false;
869
+ }
870
+ function expandArrayMatchMacro(ctx, valueExpr, armArrayExpr) {
871
+ const arms = parseArrayMatchArms(ctx, armArrayExpr);
872
+ validateArrayMatchArms(ctx, arms);
873
+ const scrutinee = '__sts_match_value';
874
+ const armCode = arms.map((arm) => lowerArrayMatchArm(arm, scrutinee)).join('\n');
875
+ return ctx.output.expr(ctx.quote.expr `
876
+ (() => {
877
+ const ${scrutinee} = (${valueExpr.text()});
878
+ ${armCode}
879
+ throw new Error("Match reached an unexpected non-exhaustive state.");
880
+ })()
881
+ `);
882
+ }
883
+ export function expandMatchMacro(ctx, valueExpr, armArrayExpr) {
884
+ return expandArrayMatchMacro(ctx, valueExpr, armArrayExpr);
885
+ }