@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,826 @@
1
+ import ts from 'typescript';
2
+ import { createAnnotationLookup } from '../annotation_syntax.js';
3
+ import { createMacroContext } from './macro_context.js';
4
+ import { createMacroError } from './macro_errors.js';
5
+ import { resolveExprArgumentOperand, resolvePrimaryExprOperand, } from './macro_operand_semantics.js';
6
+ import { createMacroSemantics } from './macro_semantics.js';
7
+ import { createMacroScopeExitOutput, createMacroValueRewriteOutput } from './macro_output.js';
8
+ import { scanMacroCandidates } from './macro_scanner.js';
9
+ import { createDeclSyntaxFromNode, createExprSyntaxFromNode, createStmtListSyntaxFromCode, getHostBlock, getHostExpression, getHostNode, getHostStatement, } from './macro_syntax_internal.js';
10
+ import { synthesizeHostNode } from './macro_host_ast_internal.js';
11
+ function sanitizeBindingHint(hint) {
12
+ const sanitized = hint.replace(/[^A-Za-z0-9_$]/g, '_');
13
+ return sanitized.length > 0 ? sanitized : '__sts_macro_tmp';
14
+ }
15
+ function classifyPlacement(resolved) {
16
+ const callExpression = resolved.callExpression;
17
+ let current = callExpression;
18
+ let parent = callExpression.parent;
19
+ while (parent && !ts.isStatement(parent) && !ts.isSourceFile(parent)) {
20
+ if (ts.isFunctionLike(parent) &&
21
+ parent.kind !== ts.SyntaxKind.Constructor &&
22
+ !(ts.isArrowFunction(parent) && parent.body === current && !ts.isBlock(parent.body))) {
23
+ return { kind: 'unsupported', reason: 'unsupported-site' };
24
+ }
25
+ if (ts.isVariableDeclarationList(parent) && parent.declarations.length !== 1) {
26
+ return { kind: 'unsupported', reason: 'multi-declaration' };
27
+ }
28
+ if (ts.isCallExpression(parent) &&
29
+ parent.arguments.some((argument) => argument === current)) {
30
+ const isOptionalCall = !!parent.questionDotToken ||
31
+ (ts.isPropertyAccessExpression(parent.expression) &&
32
+ !!parent.expression.questionDotToken) ||
33
+ (ts.isElementAccessExpression(parent.expression) && !!parent.expression.questionDotToken);
34
+ if (isOptionalCall) {
35
+ current = parent;
36
+ parent = parent.parent;
37
+ continue;
38
+ }
39
+ }
40
+ if (ts.isElementAccessExpression(parent) &&
41
+ parent.questionDotToken &&
42
+ parent.argumentExpression === current) {
43
+ current = parent;
44
+ parent = parent.parent;
45
+ continue;
46
+ }
47
+ if ('questionDotToken' in parent && parent.questionDotToken) {
48
+ if ('expression' in parent && parent.expression === current) {
49
+ current = parent;
50
+ parent = parent.parent;
51
+ continue;
52
+ }
53
+ return { kind: 'unsupported', reason: 'unsupported-site' };
54
+ }
55
+ current = parent;
56
+ parent = parent.parent;
57
+ }
58
+ if (!parent || ts.isSourceFile(parent)) {
59
+ return { kind: 'unsupported', reason: 'unsupported-site' };
60
+ }
61
+ if (ts.isVariableStatement(parent)) {
62
+ const declarationList = parent.declarationList;
63
+ if (declarationList.declarations.length !== 1) {
64
+ return { kind: 'unsupported', reason: 'multi-declaration' };
65
+ }
66
+ return { kind: 'statement-region' };
67
+ }
68
+ if (ts.isExpressionStatement(parent)) {
69
+ return { kind: 'statement-region' };
70
+ }
71
+ if (ts.isReturnStatement(parent) || ts.isThrowStatement(parent)) {
72
+ return parent.expression === current
73
+ ? { kind: 'statement-region' }
74
+ : { kind: 'unsupported', reason: 'unsupported-site' };
75
+ }
76
+ if ((ts.isIfStatement(parent) ||
77
+ ts.isWhileStatement(parent) ||
78
+ ts.isDoStatement(parent) ||
79
+ ts.isSwitchStatement(parent) ||
80
+ ts.isForOfStatement(parent) ||
81
+ ts.isForInStatement(parent)) &&
82
+ parent.expression === current) {
83
+ return { kind: 'statement-region' };
84
+ }
85
+ if (ts.isForStatement(parent) &&
86
+ (parent.initializer === current ||
87
+ parent.condition === current ||
88
+ parent.incrementor === current)) {
89
+ return { kind: 'statement-region' };
90
+ }
91
+ return { kind: 'unsupported', reason: 'unsupported-site' };
92
+ }
93
+ export function createAdvancedMacroContext(preparedProgram, resolved, nestedRegistries = { advanced: new Map(), rewrite: new Map() }, runtimeResolver = null, hostAccess) {
94
+ const baseContext = createMacroContext(resolved, runtimeResolver, hostAccess, preparedProgram.runtime);
95
+ const hostSemantics = createMacroSemantics(preparedProgram.program);
96
+ let freshCounter = 0;
97
+ let primaryExprOperand = undefined;
98
+ const originalSourceFileCache = new Map();
99
+ const originalAnnotationLookupCache = new Map();
100
+ const exprArgumentOperands = new Map();
101
+ function scriptKindForFileName(fileName) {
102
+ const lowered = fileName.toLowerCase();
103
+ if (lowered.endsWith('.sts') || lowered.endsWith('.tsx') || lowered.endsWith('.jsx')) {
104
+ return ts.ScriptKind.TSX;
105
+ }
106
+ if (lowered.endsWith('.js') || lowered.endsWith('.mjs') || lowered.endsWith('.cjs')) {
107
+ return ts.ScriptKind.JS;
108
+ }
109
+ return ts.ScriptKind.TS;
110
+ }
111
+ function originalSourceFileForNode(node) {
112
+ const programFileName = node.getSourceFile().fileName;
113
+ const sourceFileName = preparedProgram.toSourceFileName(programFileName);
114
+ const cached = originalSourceFileCache.get(sourceFileName);
115
+ if (cached) {
116
+ return cached;
117
+ }
118
+ const preparedSource = preparedProgram.preparedHost.getPreparedSourceFile(sourceFileName);
119
+ const sourceText = preparedSource?.originalText ?? node.getSourceFile().text;
120
+ const sourceFile = ts.createSourceFile(sourceFileName, sourceText, ts.ScriptTarget.Latest, true, scriptKindForFileName(sourceFileName));
121
+ originalSourceFileCache.set(sourceFileName, sourceFile);
122
+ return sourceFile;
123
+ }
124
+ function originalAnnotationLookupForNode(node) {
125
+ const sourceFile = originalSourceFileForNode(node);
126
+ const cached = originalAnnotationLookupCache.get(sourceFile.fileName);
127
+ if (cached) {
128
+ return cached;
129
+ }
130
+ const lookup = createAnnotationLookup(sourceFile);
131
+ originalAnnotationLookupCache.set(sourceFile.fileName, lookup);
132
+ return lookup;
133
+ }
134
+ function originalClassDeclarationForTypeNode(node) {
135
+ if (!ts.isTypeReferenceNode(node) || !ts.isIdentifier(node.typeName)) {
136
+ return null;
137
+ }
138
+ const sourceFile = originalSourceFileForNode(node);
139
+ const className = node.typeName.text;
140
+ let found = null;
141
+ const visit = (current) => {
142
+ if (found) {
143
+ return;
144
+ }
145
+ if (ts.isClassDeclaration(current) && current.name?.text === className) {
146
+ found = current;
147
+ return;
148
+ }
149
+ ts.forEachChild(current, visit);
150
+ };
151
+ visit(sourceFile);
152
+ return found;
153
+ }
154
+ function getPrimaryExprOperand() {
155
+ if (primaryExprOperand === undefined) {
156
+ primaryExprOperand = resolvePrimaryExprOperand(preparedProgram, resolved, nestedRegistries);
157
+ }
158
+ return primaryExprOperand;
159
+ }
160
+ function getExprArgumentOperand(index) {
161
+ if (!exprArgumentOperands.has(index)) {
162
+ exprArgumentOperands.set(index, resolveExprArgumentOperand(preparedProgram, resolved, index, nestedRegistries));
163
+ }
164
+ return exprArgumentOperands.get(index) ?? null;
165
+ }
166
+ function exprArgumentIndexForSyntax(expr) {
167
+ const match = baseContext.invocation.args.find((argument) => argument.span.fileName === expr.span.fileName &&
168
+ argument.span.start === expr.span.start &&
169
+ argument.span.end === expr.span.end);
170
+ return match?.index ?? null;
171
+ }
172
+ function findOriginalNodeForSyntaxNode(node) {
173
+ const hostNode = getHostNode(node);
174
+ if (!hostNode) {
175
+ return null;
176
+ }
177
+ const sourceFile = originalSourceFileForNode(hostNode);
178
+ let match = null;
179
+ const visit = (current) => {
180
+ if (match) {
181
+ return;
182
+ }
183
+ if (current.getStart(sourceFile, false) === node.span.start &&
184
+ current.end === node.span.end) {
185
+ match = current;
186
+ return;
187
+ }
188
+ ts.forEachChild(current, visit);
189
+ };
190
+ visit(sourceFile);
191
+ return match;
192
+ }
193
+ function annotationsForNode(node) {
194
+ const originalNode = findOriginalNodeForSyntaxNode(node);
195
+ return originalNode
196
+ ? originalAnnotationLookupForNode(originalNode).getAttachedAnnotations(originalNode)
197
+ : baseContext.syntax.annotations(node);
198
+ }
199
+ function reflectedSyntaxNode(node, kind = 'reflected_syntax') {
200
+ const sourceFile = node.getSourceFile();
201
+ return {
202
+ kind,
203
+ span: {
204
+ fileName: sourceFile.fileName,
205
+ start: node.getStart(sourceFile, false),
206
+ end: node.end,
207
+ },
208
+ };
209
+ }
210
+ function propertyNameText(name) {
211
+ if (ts.isIdentifier(name) || ts.isStringLiteral(name) || ts.isNumericLiteral(name)) {
212
+ return name.text;
213
+ }
214
+ return null;
215
+ }
216
+ function simpleTypeReferenceName(typeName) {
217
+ return ts.isIdentifier(typeName) ? typeName.text : typeName.right.text;
218
+ }
219
+ function reflectedTypeText(node) {
220
+ return node.getText(node.getSourceFile());
221
+ }
222
+ function buildReflectedFieldFromTypeMember(member, originKind) {
223
+ if (!ts.isPropertySignature(member) || !member.name) {
224
+ return null;
225
+ }
226
+ const name = propertyNameText(member.name);
227
+ if (name === null) {
228
+ return null;
229
+ }
230
+ return {
231
+ annotations: originalAnnotationLookupForNode(member).getAttachedAnnotations(member),
232
+ name,
233
+ node: reflectedSyntaxNode(member, 'type_member'),
234
+ optional: !!member.questionToken,
235
+ originKind,
236
+ text: member.getText(member.getSourceFile()),
237
+ type: member.type ? buildTypeShapeFromTypeNode(member.type) : null,
238
+ };
239
+ }
240
+ function buildReflectedFieldFromObjectMember(member, originKind) {
241
+ if (member.memberKind !== 'property_signature' || member.name === null) {
242
+ return null;
243
+ }
244
+ const explicitType = member.explicitType();
245
+ return {
246
+ annotations: annotationsForNode(member),
247
+ name: member.name,
248
+ node: member,
249
+ optional: member.isOptional(),
250
+ originKind,
251
+ text: member.text(),
252
+ type: explicitType ? reflectTypeShape(explicitType) : null,
253
+ };
254
+ }
255
+ function buildReflectedFieldFromClassField(field) {
256
+ if (field.name === null || field.hasModifier('private') || field.hasModifier('protected') ||
257
+ field.hasModifier('static')) {
258
+ return null;
259
+ }
260
+ const explicitType = field.explicitType();
261
+ return {
262
+ annotations: annotationsForNode(field),
263
+ name: field.name,
264
+ node: field,
265
+ optional: field.isOptional(),
266
+ originKind: 'classField',
267
+ text: field.text(),
268
+ type: explicitType ? reflectTypeShape(explicitType) : null,
269
+ };
270
+ }
271
+ function buildObjectFieldShapesFromTypeLiteral(node) {
272
+ const fields = node.members.map((member) => buildReflectedFieldFromTypeMember(member, 'typeLiteralProperty'));
273
+ return fields.every((field) => field !== null)
274
+ ? fields
275
+ : null;
276
+ }
277
+ function buildTypeShapeFromTypeNode(node) {
278
+ if (ts.isParenthesizedTypeNode(node)) {
279
+ return buildTypeShapeFromTypeNode(node.type);
280
+ }
281
+ if (ts.isTypeOperatorNode(node) && node.operator === ts.SyntaxKind.ReadonlyKeyword) {
282
+ if (ts.isArrayTypeNode(node.type)) {
283
+ return {
284
+ element: buildTypeShapeFromTypeNode(node.type.elementType),
285
+ kind: 'array',
286
+ readonly: true,
287
+ text: reflectedTypeText(node),
288
+ };
289
+ }
290
+ if (ts.isTupleTypeNode(node.type)) {
291
+ return {
292
+ elements: node.type.elements.map((element) => buildTypeShapeFromTypeNode(element)),
293
+ kind: 'tuple',
294
+ readonly: true,
295
+ text: reflectedTypeText(node),
296
+ };
297
+ }
298
+ }
299
+ if (ts.isArrayTypeNode(node)) {
300
+ return {
301
+ element: buildTypeShapeFromTypeNode(node.elementType),
302
+ kind: 'array',
303
+ readonly: false,
304
+ text: reflectedTypeText(node),
305
+ };
306
+ }
307
+ if (ts.isTupleTypeNode(node)) {
308
+ return {
309
+ elements: node.elements.map((element) => buildTypeShapeFromTypeNode(element)),
310
+ kind: 'tuple',
311
+ readonly: false,
312
+ text: reflectedTypeText(node),
313
+ };
314
+ }
315
+ if (ts.isTypeLiteralNode(node)) {
316
+ const fields = buildObjectFieldShapesFromTypeLiteral(node);
317
+ return fields
318
+ ? {
319
+ fields,
320
+ kind: 'object',
321
+ text: reflectedTypeText(node),
322
+ }
323
+ : { kind: 'unsupported', text: reflectedTypeText(node) };
324
+ }
325
+ if (ts.isUnionTypeNode(node)) {
326
+ return {
327
+ kind: 'union',
328
+ members: node.types.map((member) => buildTypeShapeFromTypeNode(member)),
329
+ text: reflectedTypeText(node),
330
+ };
331
+ }
332
+ if (ts.isLiteralTypeNode(node)) {
333
+ if (ts.isStringLiteral(node.literal)) {
334
+ return {
335
+ kind: 'literal',
336
+ literalKind: 'string',
337
+ text: reflectedTypeText(node),
338
+ value: node.literal.text,
339
+ };
340
+ }
341
+ if (ts.isNumericLiteral(node.literal)) {
342
+ return {
343
+ kind: 'literal',
344
+ literalKind: 'number',
345
+ text: reflectedTypeText(node),
346
+ value: Number(node.literal.text),
347
+ };
348
+ }
349
+ if (node.literal.kind === ts.SyntaxKind.TrueKeyword) {
350
+ return {
351
+ kind: 'literal',
352
+ literalKind: 'boolean',
353
+ text: reflectedTypeText(node),
354
+ value: true,
355
+ };
356
+ }
357
+ if (node.literal.kind === ts.SyntaxKind.FalseKeyword) {
358
+ return {
359
+ kind: 'literal',
360
+ literalKind: 'boolean',
361
+ text: reflectedTypeText(node),
362
+ value: false,
363
+ };
364
+ }
365
+ return { kind: 'unsupported', text: reflectedTypeText(node) };
366
+ }
367
+ switch (node.kind) {
368
+ case ts.SyntaxKind.StringKeyword:
369
+ return {
370
+ kind: 'primitive',
371
+ primitiveKind: 'string',
372
+ text: reflectedTypeText(node),
373
+ };
374
+ case ts.SyntaxKind.NumberKeyword:
375
+ return {
376
+ kind: 'primitive',
377
+ primitiveKind: 'number',
378
+ text: reflectedTypeText(node),
379
+ };
380
+ case ts.SyntaxKind.BooleanKeyword:
381
+ return {
382
+ kind: 'primitive',
383
+ primitiveKind: 'boolean',
384
+ text: reflectedTypeText(node),
385
+ };
386
+ case ts.SyntaxKind.BigIntKeyword:
387
+ return {
388
+ kind: 'primitive',
389
+ primitiveKind: 'bigint',
390
+ text: reflectedTypeText(node),
391
+ };
392
+ }
393
+ if (ts.isTypeReferenceNode(node)) {
394
+ const name = node.typeName.getText(node.getSourceFile());
395
+ const simpleName = simpleTypeReferenceName(node.typeName);
396
+ const typeArguments = (node.typeArguments ?? []).map((argument) => buildTypeShapeFromTypeNode(argument));
397
+ if (simpleName === 'Option' && typeArguments.length === 1) {
398
+ return {
399
+ kind: 'option',
400
+ text: reflectedTypeText(node),
401
+ value: typeArguments[0],
402
+ };
403
+ }
404
+ if (simpleName === 'Result' && typeArguments.length === 2) {
405
+ return {
406
+ err: typeArguments[1],
407
+ kind: 'result',
408
+ ok: typeArguments[0],
409
+ text: reflectedTypeText(node),
410
+ };
411
+ }
412
+ if (simpleName === 'Array' && typeArguments.length === 1) {
413
+ return {
414
+ element: typeArguments[0],
415
+ kind: 'array',
416
+ readonly: false,
417
+ text: reflectedTypeText(node),
418
+ };
419
+ }
420
+ if (simpleName === 'ReadonlyArray' && typeArguments.length === 1) {
421
+ return {
422
+ element: typeArguments[0],
423
+ kind: 'array',
424
+ readonly: true,
425
+ text: reflectedTypeText(node),
426
+ };
427
+ }
428
+ return {
429
+ kind: 'named',
430
+ name,
431
+ text: reflectedTypeText(node),
432
+ typeArguments,
433
+ };
434
+ }
435
+ return { kind: 'unsupported', text: reflectedTypeText(node) };
436
+ }
437
+ function reflectTypeShape(type) {
438
+ const originalNode = findOriginalNodeForSyntaxNode(type);
439
+ if (originalNode && ts.isTypeNode(originalNode)) {
440
+ return buildTypeShapeFromTypeNode(originalNode);
441
+ }
442
+ const hostNode = getHostNode(type);
443
+ if (hostNode && ts.isTypeNode(hostNode)) {
444
+ return buildTypeShapeFromTypeNode(hostNode);
445
+ }
446
+ return { kind: 'unsupported', text: type.text() };
447
+ }
448
+ function reflectObjectLikeDeclarationShape(declaration) {
449
+ if (declaration.declarationKind === 'class') {
450
+ const fields = declaration.members()
451
+ .filter((member) => member.memberKind === 'field')
452
+ .map((member) => buildReflectedFieldFromClassField(member))
453
+ .filter((field) => field !== null);
454
+ return {
455
+ declarationKind: 'class',
456
+ fields,
457
+ kind: 'objectLike',
458
+ name: declaration.name,
459
+ node: declaration,
460
+ text: declaration.text(),
461
+ };
462
+ }
463
+ if (declaration.declarationKind === 'interface') {
464
+ const fields = declaration.members.map((member) => buildReflectedFieldFromObjectMember(member, 'interfaceProperty'));
465
+ if (!fields.every((field) => field !== null)) {
466
+ return {
467
+ kind: 'unsupported',
468
+ node: declaration,
469
+ reason: 'notObjectLike',
470
+ text: declaration.text(),
471
+ };
472
+ }
473
+ return {
474
+ declarationKind: 'interface',
475
+ fields: fields,
476
+ kind: 'objectLike',
477
+ name: declaration.name,
478
+ node: declaration,
479
+ text: declaration.text(),
480
+ };
481
+ }
482
+ const objectType = declaration.type.asObjectLiteral();
483
+ if (!objectType) {
484
+ return {
485
+ kind: 'unsupported',
486
+ node: declaration,
487
+ reason: 'notObjectLike',
488
+ text: declaration.text(),
489
+ };
490
+ }
491
+ const fields = objectType.members.map((member) => buildReflectedFieldFromObjectMember(member, 'typeLiteralProperty'));
492
+ if (!fields.every((field) => field !== null)) {
493
+ return {
494
+ kind: 'unsupported',
495
+ node: declaration,
496
+ reason: 'notObjectLike',
497
+ text: declaration.text(),
498
+ };
499
+ }
500
+ return {
501
+ declarationKind: 'typeAlias',
502
+ fields: fields,
503
+ kind: 'objectLike',
504
+ name: declaration.name,
505
+ node: declaration,
506
+ text: declaration.text(),
507
+ };
508
+ }
509
+ function discriminantsForVariantObjectType(objectType) {
510
+ const discriminants = [];
511
+ const fields = [];
512
+ for (const member of objectType.members) {
513
+ const reflectedField = buildReflectedFieldFromObjectMember(member, 'typeLiteralProperty');
514
+ if (!reflectedField) {
515
+ return null;
516
+ }
517
+ const explicitType = member.explicitType();
518
+ const literal = explicitType?.asLiteral();
519
+ if (literal?.literalKind === 'string') {
520
+ discriminants.push({
521
+ name: reflectedField.name,
522
+ tag: String(literal.value),
523
+ });
524
+ continue;
525
+ }
526
+ fields.push(reflectedField);
527
+ }
528
+ return discriminants.length === 0 ? null : { discriminants, fields };
529
+ }
530
+ function reflectDeclarationShape(declaration) {
531
+ const classDecl = declaration.asClass();
532
+ if (classDecl) {
533
+ return reflectObjectLikeDeclarationShape(classDecl);
534
+ }
535
+ const interfaceDecl = declaration.asInterface();
536
+ if (interfaceDecl) {
537
+ return reflectObjectLikeDeclarationShape(interfaceDecl);
538
+ }
539
+ const typeAliasDecl = declaration.asTypeAlias();
540
+ if (!typeAliasDecl) {
541
+ return {
542
+ kind: 'unsupported',
543
+ node: declaration,
544
+ reason: 'unsupportedDeclarationKind',
545
+ text: declaration.text(),
546
+ };
547
+ }
548
+ const objectLike = reflectObjectLikeDeclarationShape(typeAliasDecl);
549
+ if (objectLike.kind === 'objectLike') {
550
+ return objectLike;
551
+ }
552
+ const unionType = typeAliasDecl.type.asUnion();
553
+ if (!unionType) {
554
+ return objectLike;
555
+ }
556
+ const variants = [];
557
+ for (const member of unionType.members) {
558
+ const objectType = member.asObjectLiteral();
559
+ if (!objectType) {
560
+ return {
561
+ kind: 'unsupported',
562
+ node: declaration,
563
+ reason: 'notDiscriminatedUnion',
564
+ text: declaration.text(),
565
+ };
566
+ }
567
+ const variant = discriminantsForVariantObjectType(objectType);
568
+ if (!variant) {
569
+ return {
570
+ kind: 'unsupported',
571
+ node: declaration,
572
+ reason: 'notDiscriminatedUnion',
573
+ text: declaration.text(),
574
+ };
575
+ }
576
+ variants.push({
577
+ discriminants: variant.discriminants,
578
+ fields: variant.fields,
579
+ node: member,
580
+ text: member.text(),
581
+ });
582
+ }
583
+ const commonDiscriminantNames = variants
584
+ .map((variant) => new Set(variant.discriminants.map((discriminant) => discriminant.name)))
585
+ .reduce((current, names) => {
586
+ if (current === null) {
587
+ return new Set(names);
588
+ }
589
+ return new Set([...current].filter((name) => names.has(name)));
590
+ }, null);
591
+ if (!commonDiscriminantNames || commonDiscriminantNames.size === 0) {
592
+ return {
593
+ kind: 'unsupported',
594
+ node: declaration,
595
+ reason: 'notDiscriminatedUnion',
596
+ text: declaration.text(),
597
+ };
598
+ }
599
+ return {
600
+ commonDiscriminantNames: [...commonDiscriminantNames],
601
+ kind: 'discriminatedUnion',
602
+ name: typeAliasDecl.name,
603
+ node: typeAliasDecl,
604
+ text: typeAliasDecl.text(),
605
+ variants,
606
+ };
607
+ }
608
+ return {
609
+ ...baseContext,
610
+ controlFlow: {
611
+ deferCleanup(cleanup) {
612
+ const statements = Array.isArray(cleanup)
613
+ ? cleanup.map((statement) => synthesizeHostNode(getHostStatement(statement)))
614
+ : getHostBlock(cleanup).statements.map((statement) => synthesizeHostNode(statement));
615
+ return createMacroScopeExitOutput(statements, baseContext.runtimeImports());
616
+ },
617
+ freshBinding(hint) {
618
+ freshCounter += 1;
619
+ return `${sanitizeBindingHint(hint)}_${resolved.placeholder.id}_${freshCounter}`;
620
+ },
621
+ placement() {
622
+ return classifyPlacement(resolved);
623
+ },
624
+ rewriteWithValue(preludeStatements, replacementExpr) {
625
+ const placement = classifyPlacement(resolved);
626
+ if (placement.kind === 'unsupported') {
627
+ const message = placement.reason === 'multi-declaration'
628
+ ? 'Semantic control-flow rewrites currently only support declarations with a single variable declarator.'
629
+ : 'Semantic control-flow rewrites currently only support expression sites that can be hoisted through the nearest enclosing statement.';
630
+ throw createMacroError(resolved, message);
631
+ }
632
+ return createMacroValueRewriteOutput(preludeStatements.map((statement) => synthesizeHostNode(getHostStatement(statement))), synthesizeHostNode(getHostExpression(replacementExpr)), baseContext.runtimeImports());
633
+ },
634
+ },
635
+ syntax: {
636
+ ...baseContext.syntax,
637
+ annotations(node) {
638
+ return annotationsForNode(node);
639
+ },
640
+ },
641
+ reflect: {
642
+ declarationShape(declaration) {
643
+ return reflectDeclarationShape(declaration);
644
+ },
645
+ typeShape(type) {
646
+ return reflectTypeShape(type);
647
+ },
648
+ },
649
+ semantics: {
650
+ argExpanded(index) {
651
+ const operand = getExprArgumentOperand(index);
652
+ return operand
653
+ ? createExprSyntaxFromNode(operand.node, operand.sourceFile, baseContext.invocation.args[index]?.span ?? baseContext.invocationSpan(), operand.expandedText)
654
+ : null;
655
+ },
656
+ argType(index) {
657
+ const operand = getExprArgumentOperand(index);
658
+ return operand ? operand.semantics.typeOfNode(operand.node) : null;
659
+ },
660
+ awaitedType(type) {
661
+ return hostSemantics.awaitedType(type);
662
+ },
663
+ classDeclarationOfType(type) {
664
+ const hostNode = getHostNode(type);
665
+ if (!hostNode || !ts.isTypeNode(hostNode)) {
666
+ return null;
667
+ }
668
+ const classDeclaration = hostSemantics.classDeclarationOfTypeNode(hostNode) ??
669
+ originalClassDeclarationForTypeNode(hostNode);
670
+ if (!classDeclaration) {
671
+ return null;
672
+ }
673
+ const sourceFile = classDeclaration.getSourceFile();
674
+ return createDeclSyntaxFromNode(classDeclaration, sourceFile, {
675
+ fileName: sourceFile.fileName,
676
+ start: classDeclaration.getStart(sourceFile),
677
+ end: classDeclaration.getEnd(),
678
+ }).asClass();
679
+ },
680
+ classifyCanonicalFailureType(type) {
681
+ return hostSemantics.classifyCanonicalFailureType(type);
682
+ },
683
+ classifyCanonicalResultType(type) {
684
+ return hostSemantics.classifyCanonicalResultType(type);
685
+ },
686
+ classifyTryCarrierType(type) {
687
+ return hostSemantics.classifyTryCarrierType(type);
688
+ },
689
+ exprType(expr) {
690
+ const hostNode = getHostNode(expr);
691
+ if (hostNode) {
692
+ return hostSemantics.typeOfNode(hostNode);
693
+ }
694
+ const index = exprArgumentIndexForSyntax(expr);
695
+ return index === null ? null : this.argType(index);
696
+ },
697
+ classifyCanonicalResultCarrierType(type) {
698
+ return hostSemantics.classifyCanonicalResultCarrierType(type);
699
+ },
700
+ enclosingFunction() {
701
+ return hostSemantics.enclosingFunctionOfNode(resolved.callExpression) ?? null;
702
+ },
703
+ enclosingFunctionCanonicalResult() {
704
+ return hostSemantics.canonicalResultOfEnclosingFunctionNode(resolved.callExpression) ??
705
+ null;
706
+ },
707
+ finiteCases(type) {
708
+ return hostSemantics.finiteCases(type);
709
+ },
710
+ isAssignable(from, to) {
711
+ return hostSemantics.isAssignable(from, to);
712
+ },
713
+ localDeclarationHasAnnotation(name, annotationName, node) {
714
+ const hostNode = node
715
+ ? findOriginalNodeForSyntaxNode(node) ??
716
+ getHostNode(node)?.getSourceFile() ??
717
+ resolved.callExpression
718
+ : resolved.callExpression;
719
+ if (!hostNode) {
720
+ return false;
721
+ }
722
+ const sourceFile = originalSourceFileForNode(hostNode);
723
+ const annotationLookup = originalAnnotationLookupForNode(hostNode);
724
+ return sourceFile.statements.some((statement) => {
725
+ if (!(ts.isClassDeclaration(statement) ||
726
+ ts.isFunctionDeclaration(statement) ||
727
+ ts.isInterfaceDeclaration(statement) ||
728
+ ts.isTypeAliasDeclaration(statement))) {
729
+ return false;
730
+ }
731
+ return statement.name?.text === name &&
732
+ annotationLookup.hasAttachedAnnotation(statement, annotationName);
733
+ });
734
+ },
735
+ nullType() {
736
+ return hostSemantics.nullType();
737
+ },
738
+ parameterType(parameter) {
739
+ const node = getHostNode(parameter);
740
+ return node ? hostSemantics.typeOfNode(node) : null;
741
+ },
742
+ primaryExprEnclosingFunction() {
743
+ const operand = getPrimaryExprOperand();
744
+ return operand ? operand.semantics.enclosingFunctionOfNode(operand.node) ?? null : null;
745
+ },
746
+ primaryExprEnclosingFunctionCanonicalResult() {
747
+ const operand = getPrimaryExprOperand();
748
+ return operand
749
+ ? operand.semantics.canonicalResultOfEnclosingFunctionNode(operand.node) ?? null
750
+ : null;
751
+ },
752
+ primaryExprExpanded() {
753
+ const operand = getPrimaryExprOperand();
754
+ return operand
755
+ ? createExprSyntaxFromNode(operand.node, operand.sourceFile, baseContext.syntax.primaryExpr().span, operand.expandedText)
756
+ : null;
757
+ },
758
+ primaryExprPrelude() {
759
+ const operand = getPrimaryExprOperand();
760
+ return operand
761
+ ? operand.preludeTexts.flatMap((statementText, index) => createStmtListSyntaxFromCode(resolved.callExpression.getSourceFile().fileName, `macro_primary_expr_prelude_${index}`, statementText))
762
+ : null;
763
+ },
764
+ primaryExprCanonicalResultCarrier() {
765
+ const operand = getPrimaryExprOperand();
766
+ return operand
767
+ ? operand.semantics.classifyCanonicalResultCarrierType(operand.semantics.typeOfNode(operand.node))
768
+ : null;
769
+ },
770
+ primaryExprCanonicalResult() {
771
+ const operand = getPrimaryExprOperand();
772
+ return operand
773
+ ? operand.semantics.classifyCanonicalResultType(operand.semantics.typeOfNode(operand.node))
774
+ : null;
775
+ },
776
+ primaryExprContainsMacroInvocations() {
777
+ if (baseContext.invocation.form !== 'arglist' || baseContext.invocation.args.length !== 1 ||
778
+ baseContext.hasBlock() || resolved.placeholder.invocation.declarationSpan) {
779
+ return false;
780
+ }
781
+ return scanMacroCandidates(resolved.placeholder.invocation.fileName, baseContext.syntax.primaryExpr().text()).hashes.some((hash) => hash.kind === 'macro-start');
782
+ },
783
+ primaryExprTryCarrier() {
784
+ const operand = getPrimaryExprOperand();
785
+ return operand
786
+ ? operand.semantics.classifyTryCarrierType(operand.semantics.typeOfNode(operand.node))
787
+ : null;
788
+ },
789
+ primaryExprType() {
790
+ const operand = getPrimaryExprOperand();
791
+ return operand ? operand.semantics.typeOfNode(operand.node) : null;
792
+ },
793
+ readSet(node) {
794
+ const hostNode = getHostNode(node);
795
+ return hostNode
796
+ ? hostSemantics.readSetOfNode(hostNode)
797
+ : { dependencies: [], unknown: false };
798
+ },
799
+ undefinedType() {
800
+ return hostSemantics.undefinedType();
801
+ },
802
+ valueBindingCallableInScope(name, node) {
803
+ const hostNode = node
804
+ ? findOriginalNodeForSyntaxNode(node) ??
805
+ getHostNode(node)?.getSourceFile() ??
806
+ resolved.callExpression
807
+ : resolved.callExpression;
808
+ return hostNode ? hostSemantics.valueBindingCallableInScope(name, hostNode) : false;
809
+ },
810
+ valueBindingInScope(name, node) {
811
+ const hostNode = node
812
+ ? findOriginalNodeForSyntaxNode(node) ??
813
+ getHostNode(node)?.getSourceFile() ??
814
+ resolved.callExpression
815
+ : resolved.callExpression;
816
+ return hostNode ? hostSemantics.valueBindingInScope(name, hostNode) : false;
817
+ },
818
+ writeSet(node) {
819
+ const hostNode = getHostNode(node);
820
+ return hostNode
821
+ ? hostSemantics.writeSetOfNode(hostNode)
822
+ : { dependencies: [], unknown: false };
823
+ },
824
+ },
825
+ };
826
+ }