@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,1328 @@
1
+ import ts from 'typescript';
2
+ import { getResolvedBuiltinSignatureInfo } from './resolved_builtins.js';
3
+ export function isLocalFunctionLikeWithBody(node) {
4
+ return (ts.isArrowFunction(node) ||
5
+ ts.isFunctionDeclaration(node) ||
6
+ ts.isFunctionExpression(node) ||
7
+ ts.isMethodDeclaration(node)) &&
8
+ node.body !== undefined;
9
+ }
10
+ function isConstVariableDeclaration(node) {
11
+ return ts.isVariableDeclarationList(node.parent) &&
12
+ (node.parent.flags & ts.NodeFlags.Const) !== 0;
13
+ }
14
+ function hasDefaultModifier(node) {
15
+ return ts.canHaveModifiers(node) &&
16
+ (ts.getModifiers(node)?.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword) ??
17
+ false);
18
+ }
19
+ function getDefaultExportSymbol(context, sourceFile) {
20
+ const moduleSymbol = context.checker.getSymbolAtLocation(sourceFile);
21
+ if (!moduleSymbol) {
22
+ return undefined;
23
+ }
24
+ return context.checker.getExportsOfModule(moduleSymbol).find((symbol) => symbol.name === ts.InternalSymbolName.Default);
25
+ }
26
+ function getFunctionLikeSummarySymbol(context, node) {
27
+ if (ts.isFunctionDeclaration(node)) {
28
+ if (node.name) {
29
+ return context.checker.getSymbolAtLocation(node.name);
30
+ }
31
+ return hasDefaultModifier(node)
32
+ ? getDefaultExportSymbol(context, node.getSourceFile())
33
+ : undefined;
34
+ }
35
+ if (ts.isMethodDeclaration(node)) {
36
+ return context.checker.getSymbolAtLocation(node.name);
37
+ }
38
+ if ((ts.isArrowFunction(node) || ts.isFunctionExpression(node)) &&
39
+ ts.isVariableDeclaration(node.parent) &&
40
+ ts.isIdentifier(node.parent.name)) {
41
+ return context.checker.getSymbolAtLocation(node.parent.name);
42
+ }
43
+ if ((ts.isArrowFunction(node) || ts.isFunctionExpression(node)) &&
44
+ ts.isExportAssignment(node.parent) &&
45
+ !node.parent.isExportEquals) {
46
+ return getDefaultExportSymbol(context, node.getSourceFile());
47
+ }
48
+ return ts.isFunctionExpression(node) && node.name
49
+ ? context.checker.getSymbolAtLocation(node.name)
50
+ : undefined;
51
+ }
52
+ function getDirectReturnExpression(node) {
53
+ if (!node.body) {
54
+ return undefined;
55
+ }
56
+ if (!ts.isBlock(node.body)) {
57
+ return node.body;
58
+ }
59
+ if (node.body.statements.length !== 1) {
60
+ return undefined;
61
+ }
62
+ const [statement] = node.body.statements;
63
+ return ts.isReturnStatement(statement) ? statement.expression : undefined;
64
+ }
65
+ function getReturnedParameterIndex(context, node, expression) {
66
+ const current = getUnwrappedExpression(expression);
67
+ if (!ts.isIdentifier(current)) {
68
+ return undefined;
69
+ }
70
+ const returnedSymbol = context.checker.getSymbolAtLocation(current);
71
+ if (!returnedSymbol) {
72
+ return undefined;
73
+ }
74
+ return getParameterIndexForSymbol(context, node, returnedSymbol);
75
+ }
76
+ function getParameterIndexForSymbol(context, node, symbol) {
77
+ for (const [index, parameter] of node.parameters.entries()) {
78
+ if (!ts.isIdentifier(parameter.name)) {
79
+ continue;
80
+ }
81
+ const parameterSymbol = context.checker.getSymbolAtLocation(parameter.name);
82
+ if (parameterSymbol === symbol) {
83
+ return index;
84
+ }
85
+ }
86
+ return undefined;
87
+ }
88
+ function summarizeReturnedParameter(context, node) {
89
+ const returnExpression = getDirectReturnExpression(node);
90
+ return returnExpression ? getReturnedParameterIndex(context, node, returnExpression) : undefined;
91
+ }
92
+ export function getUnwrappedExpression(expression) {
93
+ if (ts.isParenthesizedExpression(expression)) {
94
+ return getUnwrappedExpression(expression.expression);
95
+ }
96
+ if (ts.isSatisfiesExpression(expression)) {
97
+ return getUnwrappedExpression(expression.expression);
98
+ }
99
+ if (ts.isAwaitExpression(expression)) {
100
+ return getUnwrappedExpression(expression.expression);
101
+ }
102
+ return expression;
103
+ }
104
+ function getCallExpressionCalleeSymbol(context, node) {
105
+ if (ts.isIdentifier(node.expression)) {
106
+ return context.checker.getSymbolAtLocation(node.expression);
107
+ }
108
+ if (ts.isPropertyAccessExpression(node.expression)) {
109
+ return context.checker.getSymbolAtLocation(node.expression.name);
110
+ }
111
+ return undefined;
112
+ }
113
+ function getThenCallTargetExpression(context, node) {
114
+ return getPromiseMethodTargetExpression(context, node, 'then');
115
+ }
116
+ function getCatchCallTargetExpression(context, node) {
117
+ return getPromiseMethodTargetExpression(context, node, 'catch');
118
+ }
119
+ function getFinallyCallTargetExpression(context, node) {
120
+ return getPromiseMethodTargetExpression(context, node, 'finally');
121
+ }
122
+ function getPromiseMethodTargetExpression(context, node, methodName) {
123
+ const info = getResolvedBuiltinSignatureInfo(context, node);
124
+ if (!info ||
125
+ (info.ownerName !== 'Promise' && info.ownerName !== 'PromiseLike') ||
126
+ info.memberName !== methodName) {
127
+ return undefined;
128
+ }
129
+ if (ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === methodName) {
130
+ return node.expression.expression;
131
+ }
132
+ if (ts.isElementAccessExpression(node.expression) &&
133
+ node.expression.argumentExpression &&
134
+ (ts.isStringLiteral(node.expression.argumentExpression) ||
135
+ ts.isNoSubstitutionTemplateLiteral(node.expression.argumentExpression)) &&
136
+ node.expression.argumentExpression.text === methodName) {
137
+ return node.expression.expression;
138
+ }
139
+ return undefined;
140
+ }
141
+ function getPromisePassthroughTargetExpression(context, node) {
142
+ return getFinallyCallTargetExpression(context, node) ??
143
+ getCatchCallTargetExpression(context, node);
144
+ }
145
+ function getPromiseResolveWrappedExpression(context, node) {
146
+ const info = getResolvedBuiltinSignatureInfo(context, node);
147
+ if (!info || info.ownerName !== 'PromiseConstructor' || info.memberName !== 'resolve') {
148
+ return undefined;
149
+ }
150
+ return node.arguments[0];
151
+ }
152
+ function getThenCallback(node) {
153
+ const callback = node.arguments[0];
154
+ return callback && isLocalFunctionLikeWithBody(callback) ? callback : undefined;
155
+ }
156
+ function getLocalFunctionLikeFromSymbol(symbol) {
157
+ for (const declaration of symbol.getDeclarations() ?? []) {
158
+ if (isLocalFunctionLikeWithBody(declaration)) {
159
+ return declaration;
160
+ }
161
+ if (ts.isVariableDeclaration(declaration) &&
162
+ declaration.initializer &&
163
+ isLocalFunctionLikeWithBody(declaration.initializer)) {
164
+ return declaration.initializer;
165
+ }
166
+ }
167
+ return undefined;
168
+ }
169
+ function getDirectReturnLocalCall(context, callExpression) {
170
+ const calleeSymbol = getCallExpressionCalleeSymbol(context, callExpression);
171
+ if (!calleeSymbol) {
172
+ return undefined;
173
+ }
174
+ const declaration = getLocalFunctionLikeFromSymbol(calleeSymbol);
175
+ if (!declaration) {
176
+ return undefined;
177
+ }
178
+ const returnExpression = getDirectReturnExpression(declaration);
179
+ return returnExpression ? { declaration, returnExpression } : undefined;
180
+ }
181
+ function mergeParameterBindings(baseBindings, extraBindings) {
182
+ const merged = new Map(baseBindings);
183
+ for (const [symbol, expression] of extraBindings) {
184
+ merged.set(symbol, expression);
185
+ }
186
+ return merged;
187
+ }
188
+ function resolveBoundExpression(context, expression, bindings) {
189
+ const current = getUnwrappedExpression(expression);
190
+ if (!ts.isIdentifier(current)) {
191
+ return expression;
192
+ }
193
+ const symbol = context.checker.getSymbolAtLocation(current);
194
+ const boundExpression = symbol ? bindings.get(symbol) : undefined;
195
+ return boundExpression ? resolveBoundExpression(context, boundExpression, bindings) : expression;
196
+ }
197
+ function createParameterBindings(context, declaration, argumentsList, outerBindings) {
198
+ const bindings = new Map();
199
+ declaration.parameters.forEach((parameter, index) => {
200
+ if (!ts.isIdentifier(parameter.name)) {
201
+ return;
202
+ }
203
+ const parameterSymbol = context.checker.getSymbolAtLocation(parameter.name);
204
+ const argument = argumentsList[index];
205
+ if (!parameterSymbol || !argument) {
206
+ return;
207
+ }
208
+ bindings.set(parameterSymbol, resolveBoundExpression(context, argument, outerBindings));
209
+ });
210
+ return bindings;
211
+ }
212
+ function getEquivalentRecoveryExpressions(expression) {
213
+ const current = getUnwrappedExpression(expression);
214
+ if (ts.isConditionalExpression(current)) {
215
+ return [current.whenTrue, current.whenFalse];
216
+ }
217
+ if (ts.isBinaryExpression(current) &&
218
+ current.operatorToken.kind === ts.SyntaxKind.QuestionQuestionToken) {
219
+ return [current.left, current.right];
220
+ }
221
+ return undefined;
222
+ }
223
+ function doesRecoveryPathStartWith(path, prefix) {
224
+ return prefix.length <= path.length &&
225
+ prefix.every((segment, index) => {
226
+ const candidate = path[index];
227
+ if (!candidate || candidate.kind !== segment.kind) {
228
+ return false;
229
+ }
230
+ if (segment.kind === 'property') {
231
+ if (candidate.kind !== 'property') {
232
+ return false;
233
+ }
234
+ return segment.name === candidate.name;
235
+ }
236
+ if (candidate.kind !== 'index') {
237
+ return false;
238
+ }
239
+ return segment.index === candidate.index;
240
+ });
241
+ }
242
+ function serializeRecoveryPath(path) {
243
+ return path.map((segment) => segment.kind === 'property' ? `p:${segment.name}` : `i:${segment.index}`).join('/');
244
+ }
245
+ function getRecoveryAccessSegment(expression) {
246
+ const current = getUnwrappedExpression(expression);
247
+ if (ts.isPropertyAccessExpression(current)) {
248
+ return {
249
+ base: current.expression,
250
+ segment: { kind: 'property', name: current.name.text },
251
+ };
252
+ }
253
+ if (ts.isElementAccessExpression(current) &&
254
+ current.argumentExpression &&
255
+ (ts.isStringLiteral(current.argumentExpression) ||
256
+ ts.isNumericLiteral(current.argumentExpression))) {
257
+ return ts.isNumericLiteral(current.argumentExpression)
258
+ ? {
259
+ base: current.expression,
260
+ segment: { kind: 'index', index: Number(current.argumentExpression.text) },
261
+ }
262
+ : {
263
+ base: current.expression,
264
+ segment: { kind: 'property', name: current.argumentExpression.text },
265
+ };
266
+ }
267
+ return undefined;
268
+ }
269
+ function getBindingPatternRecoveryPath(context, bindingName, targetSymbol, currentPath = []) {
270
+ if (ts.isIdentifier(bindingName)) {
271
+ const bindingSymbol = context.checker.getSymbolAtLocation(bindingName);
272
+ return bindingSymbol === targetSymbol ? currentPath : undefined;
273
+ }
274
+ if (ts.isArrayBindingPattern(bindingName)) {
275
+ for (const [index, element] of bindingName.elements.entries()) {
276
+ if (ts.isOmittedExpression(element) || element.dotDotDotToken) {
277
+ continue;
278
+ }
279
+ const path = getBindingPatternRecoveryPath(context, element.name, targetSymbol, [...currentPath, { kind: 'index', index }]);
280
+ if (path) {
281
+ return path;
282
+ }
283
+ }
284
+ return undefined;
285
+ }
286
+ for (const element of bindingName.elements) {
287
+ if (element.dotDotDotToken) {
288
+ continue;
289
+ }
290
+ const propertyName = element.propertyName
291
+ ? getObjectLiteralPropertyNameText(element.propertyName)
292
+ : ts.isIdentifier(element.name)
293
+ ? element.name.text
294
+ : undefined;
295
+ if (!propertyName) {
296
+ continue;
297
+ }
298
+ const path = getBindingPatternRecoveryPath(context, element.name, targetSymbol, [...currentPath, { kind: 'property', name: propertyName }]);
299
+ if (path) {
300
+ return path;
301
+ }
302
+ }
303
+ return undefined;
304
+ }
305
+ function getEnclosingConstBindingInitializer(declaration) {
306
+ let current = declaration;
307
+ while (current.parent) {
308
+ current = current.parent;
309
+ if (ts.isVariableDeclaration(current)) {
310
+ return current.initializer && isConstVariableDeclaration(current)
311
+ ? { bindingName: current.name, initializer: current.initializer }
312
+ : undefined;
313
+ }
314
+ }
315
+ return undefined;
316
+ }
317
+ function getPromiseStaticMethodName(context, node) {
318
+ const info = getResolvedBuiltinSignatureInfo(context, node);
319
+ if (!info || info.ownerName !== 'PromiseConstructor') {
320
+ return undefined;
321
+ }
322
+ switch (info.memberName) {
323
+ case 'all':
324
+ case 'allSettled':
325
+ case 'any':
326
+ case 'race':
327
+ case 'resolve':
328
+ return info.memberName;
329
+ default:
330
+ return undefined;
331
+ }
332
+ }
333
+ function getFreshArrayExtractionMethodName(node) {
334
+ if (ts.isPropertyAccessExpression(node.expression)) {
335
+ switch (node.expression.name.text) {
336
+ case 'at':
337
+ case 'filter':
338
+ case 'find':
339
+ case 'flatMap':
340
+ return node.expression.name.text;
341
+ }
342
+ }
343
+ if (ts.isElementAccessExpression(node.expression) &&
344
+ node.expression.argumentExpression &&
345
+ (ts.isStringLiteral(node.expression.argumentExpression) ||
346
+ ts.isNoSubstitutionTemplateLiteral(node.expression.argumentExpression))) {
347
+ switch (node.expression.argumentExpression.text) {
348
+ case 'at':
349
+ case 'filter':
350
+ case 'find':
351
+ case 'flatMap':
352
+ return node.expression.argumentExpression.text;
353
+ }
354
+ }
355
+ return undefined;
356
+ }
357
+ function getFreshArrayExtractionTargetExpression(node) {
358
+ const methodName = getFreshArrayExtractionMethodName(node);
359
+ if (!methodName) {
360
+ return undefined;
361
+ }
362
+ if (ts.isPropertyAccessExpression(node.expression)) {
363
+ return node.expression.expression;
364
+ }
365
+ if (ts.isElementAccessExpression(node.expression)) {
366
+ return node.expression.expression;
367
+ }
368
+ return undefined;
369
+ }
370
+ function getFreshArrayMethodInputs(context, callExpression, bindings, seenSymbols) {
371
+ const targetExpression = getFreshArrayExtractionTargetExpression(callExpression);
372
+ if (!targetExpression) {
373
+ return undefined;
374
+ }
375
+ const arrayLiteral = getArrayLiteralFromExpression(context, targetExpression, bindings, seenSymbols);
376
+ return arrayLiteral?.elements.filter((element) => !ts.isOmittedExpression(element));
377
+ }
378
+ function getIntegerArgumentValue(expression) {
379
+ if (!expression) {
380
+ return undefined;
381
+ }
382
+ const current = getUnwrappedExpression(expression);
383
+ if (ts.isNumericLiteral(current)) {
384
+ const value = Number(current.text);
385
+ return Number.isInteger(value) ? value : undefined;
386
+ }
387
+ if (ts.isPrefixUnaryExpression(current) &&
388
+ current.operator === ts.SyntaxKind.MinusToken &&
389
+ ts.isNumericLiteral(current.operand)) {
390
+ const value = Number(current.operand.text);
391
+ return Number.isInteger(value) ? -value : undefined;
392
+ }
393
+ return undefined;
394
+ }
395
+ function getFreshArrayAtIndex(callExpression, inputCount) {
396
+ const index = getIntegerArgumentValue(callExpression.arguments[0]);
397
+ if (index === undefined) {
398
+ return undefined;
399
+ }
400
+ const normalizedIndex = index >= 0 ? index : inputCount + index;
401
+ return normalizedIndex >= 0 && normalizedIndex < inputCount ? normalizedIndex : undefined;
402
+ }
403
+ function getLocalFunctionLikeFromExpression(context, expression) {
404
+ if (!expression) {
405
+ return undefined;
406
+ }
407
+ const current = getUnwrappedExpression(expression);
408
+ if (isLocalFunctionLikeWithBody(current)) {
409
+ return current;
410
+ }
411
+ if (!ts.isIdentifier(current)) {
412
+ return undefined;
413
+ }
414
+ const symbol = context.checker.getSymbolAtLocation(current);
415
+ return symbol ? getLocalFunctionLikeFromSymbol(symbol) : undefined;
416
+ }
417
+ function getFreshArrayFlatMapReturnInfo(context, callExpression) {
418
+ if (getFreshArrayExtractionMethodName(callExpression) !== 'flatMap') {
419
+ return undefined;
420
+ }
421
+ const callback = getLocalFunctionLikeFromExpression(context, callExpression.arguments[0]);
422
+ const returnExpression = callback ? getDirectReturnExpression(callback) : undefined;
423
+ return callback && returnExpression ? { callback, returnExpression } : undefined;
424
+ }
425
+ function getFlatMapElementCandidatePaths(path) {
426
+ const [segment, ...restPath] = path;
427
+ if (!segment || segment.kind !== 'index') {
428
+ return undefined;
429
+ }
430
+ return [restPath, path];
431
+ }
432
+ function getArrayLiteralFromExpression(context, expression, bindings, seenSymbols) {
433
+ const resolvedExpression = resolveBoundExpression(context, expression, bindings);
434
+ const current = getUnwrappedExpression(resolvedExpression);
435
+ if (ts.isArrayLiteralExpression(current)) {
436
+ return current;
437
+ }
438
+ if (ts.isIdentifier(current)) {
439
+ const symbol = context.checker.getSymbolAtLocation(current);
440
+ if (!symbol || seenSymbols.has(symbol)) {
441
+ return undefined;
442
+ }
443
+ seenSymbols.add(symbol);
444
+ for (const declaration of symbol.getDeclarations() ?? []) {
445
+ if (ts.isVariableDeclaration(declaration) &&
446
+ declaration.initializer &&
447
+ isConstVariableDeclaration(declaration)) {
448
+ return getArrayLiteralFromExpression(context, declaration.initializer, bindings, seenSymbols);
449
+ }
450
+ }
451
+ return undefined;
452
+ }
453
+ const equivalentExpressions = getEquivalentRecoveryExpressions(resolvedExpression);
454
+ if (equivalentExpressions) {
455
+ for (const equivalentExpression of equivalentExpressions) {
456
+ const arrayLiteral = getArrayLiteralFromExpression(context, equivalentExpression, bindings, seenSymbols);
457
+ if (arrayLiteral) {
458
+ return arrayLiteral;
459
+ }
460
+ }
461
+ return undefined;
462
+ }
463
+ if (!ts.isCallExpression(current)) {
464
+ return undefined;
465
+ }
466
+ const promiseContinuation = getPromiseRecoveryContinuation(context, current, bindings);
467
+ if (promiseContinuation) {
468
+ return getArrayLiteralFromExpression(context, promiseContinuation.expression, promiseContinuation.bindings, seenSymbols);
469
+ }
470
+ const localDirectReturn = getDirectReturnLocalCall(context, current);
471
+ if (!localDirectReturn) {
472
+ return undefined;
473
+ }
474
+ const localBindings = mergeParameterBindings(bindings, createParameterBindings(context, localDirectReturn.declaration, current.arguments, bindings));
475
+ return getArrayLiteralFromExpression(context, localDirectReturn.returnExpression, localBindings, seenSymbols);
476
+ }
477
+ function getPromiseCombinatorInputs(context, callExpression, bindings, seenSymbols) {
478
+ const methodName = getPromiseStaticMethodName(context, callExpression);
479
+ if (methodName !== 'all' &&
480
+ methodName !== 'allSettled' &&
481
+ methodName !== 'any' &&
482
+ methodName !== 'race') {
483
+ return undefined;
484
+ }
485
+ const arrayLiteral = callExpression.arguments[0]
486
+ ? getArrayLiteralFromExpression(context, callExpression.arguments[0], bindings, seenSymbols)
487
+ : undefined;
488
+ return arrayLiteral?.elements.filter((element) => !ts.isOmittedExpression(element));
489
+ }
490
+ function getPromiseRecoveryContinuation(context, callExpression, bindings) {
491
+ const thenTarget = getThenCallTargetExpression(context, callExpression);
492
+ const thenCallback = getThenCallback(callExpression);
493
+ const thenReturnExpression = thenCallback ? getDirectReturnExpression(thenCallback) : undefined;
494
+ if (thenTarget && thenCallback && thenReturnExpression) {
495
+ return {
496
+ bindings: mergeParameterBindings(bindings, createParameterBindings(context, thenCallback, [thenTarget], bindings)),
497
+ expression: thenReturnExpression,
498
+ };
499
+ }
500
+ const passthroughTarget = getPromisePassthroughTargetExpression(context, callExpression);
501
+ if (passthroughTarget) {
502
+ return { bindings, expression: passthroughTarget };
503
+ }
504
+ const resolvedPromiseValue = getPromiseResolveWrappedExpression(context, callExpression);
505
+ if (resolvedPromiseValue) {
506
+ return { bindings, expression: resolvedPromiseValue };
507
+ }
508
+ return undefined;
509
+ }
510
+ function getObjectLiteralPropertyNameText(name) {
511
+ if (ts.isIdentifier(name) ||
512
+ ts.isStringLiteral(name) ||
513
+ ts.isNumericLiteral(name) ||
514
+ ts.isNoSubstitutionTemplateLiteral(name)) {
515
+ return name.text;
516
+ }
517
+ if (ts.isComputedPropertyName(name) &&
518
+ (ts.isStringLiteral(name.expression) || ts.isNumericLiteral(name.expression))) {
519
+ return name.expression.text;
520
+ }
521
+ return undefined;
522
+ }
523
+ function dedupeHelperWrapperEntries(entries) {
524
+ const seenPaths = new Set();
525
+ for (const entry of entries) {
526
+ const pathKey = serializeRecoveryPath(entry.recoveryPath);
527
+ if (seenPaths.has(pathKey)) {
528
+ return undefined;
529
+ }
530
+ seenPaths.add(pathKey);
531
+ }
532
+ return entries;
533
+ }
534
+ function collectHelperWrapperEntries(context, node, expression, currentPath = []) {
535
+ const current = getUnwrappedExpression(expression);
536
+ const returnedParameterIndex = getReturnedParameterIndex(context, node, current);
537
+ if (returnedParameterIndex !== undefined) {
538
+ return [{ parameterIndex: returnedParameterIndex, recoveryPath: currentPath }];
539
+ }
540
+ if (ts.isObjectLiteralExpression(current)) {
541
+ const entries = [];
542
+ const seenPropertyNames = new Set();
543
+ for (const property of current.properties) {
544
+ if (ts.isSpreadAssignment(property)) {
545
+ return undefined;
546
+ }
547
+ if (ts.isPropertyAssignment(property)) {
548
+ const propertyName = getObjectLiteralPropertyNameText(property.name);
549
+ if (!propertyName || seenPropertyNames.has(propertyName)) {
550
+ return undefined;
551
+ }
552
+ seenPropertyNames.add(propertyName);
553
+ const propertyEntries = collectHelperWrapperEntries(context, node, property.initializer, [...currentPath, { kind: 'property', name: propertyName }]);
554
+ if (!propertyEntries) {
555
+ return undefined;
556
+ }
557
+ entries.push(...propertyEntries);
558
+ continue;
559
+ }
560
+ if (ts.isShorthandPropertyAssignment(property)) {
561
+ const propertyName = property.name.text;
562
+ if (seenPropertyNames.has(propertyName)) {
563
+ return undefined;
564
+ }
565
+ seenPropertyNames.add(propertyName);
566
+ const valueSymbol = context.checker.getShorthandAssignmentValueSymbol(property);
567
+ const parameterIndex = valueSymbol
568
+ ? getParameterIndexForSymbol(context, node, valueSymbol)
569
+ : undefined;
570
+ if (parameterIndex !== undefined) {
571
+ entries.push({
572
+ parameterIndex,
573
+ recoveryPath: [...currentPath, { kind: 'property', name: propertyName }],
574
+ });
575
+ }
576
+ continue;
577
+ }
578
+ return undefined;
579
+ }
580
+ return dedupeHelperWrapperEntries(entries);
581
+ }
582
+ if (ts.isArrayLiteralExpression(current)) {
583
+ const entries = [];
584
+ for (const [index, element] of current.elements.entries()) {
585
+ if (!ts.isExpression(element) || ts.isSpreadElement(element)) {
586
+ return undefined;
587
+ }
588
+ const elementEntries = collectHelperWrapperEntries(context, node, element, [...currentPath, { kind: 'index', index }]);
589
+ if (!elementEntries) {
590
+ return undefined;
591
+ }
592
+ entries.push(...elementEntries);
593
+ }
594
+ return dedupeHelperWrapperEntries(entries);
595
+ }
596
+ return [];
597
+ }
598
+ function getArrayLiteralElementValue(arrayLiteral, index) {
599
+ const element = arrayLiteral.elements[index];
600
+ return element && !ts.isOmittedExpression(element) ? element : undefined;
601
+ }
602
+ function getObjectLiteralPropertyFamilyAtPathWithBindings(context, objectLiteral, propertyName, restPath, spec, seenSymbols, bindings) {
603
+ for (const property of objectLiteral.properties) {
604
+ if (ts.isPropertyAssignment(property) &&
605
+ getObjectLiteralPropertyNameText(property.name) === propertyName) {
606
+ return getFamilyAtRecoveryPathWithBindings(context, property.initializer, restPath, spec, seenSymbols, bindings);
607
+ }
608
+ if (ts.isShorthandPropertyAssignment(property) &&
609
+ property.name.text === propertyName) {
610
+ const valueSymbol = context.checker.getShorthandAssignmentValueSymbol(property);
611
+ if (!valueSymbol) {
612
+ return undefined;
613
+ }
614
+ const boundExpression = bindings.get(valueSymbol);
615
+ if (boundExpression) {
616
+ return getFamilyAtRecoveryPathWithBindings(context, boundExpression, restPath, spec, seenSymbols, bindings);
617
+ }
618
+ return getAliasedKnownNonOrdinaryFamily(context, valueSymbol, restPath, spec, seenSymbols);
619
+ }
620
+ }
621
+ return undefined;
622
+ }
623
+ function getPromiseCombinatorFamilyAtPathWithBindings(context, callExpression, path, spec, seenSymbols, bindings) {
624
+ const methodName = getPromiseStaticMethodName(context, callExpression);
625
+ if (methodName !== 'all' &&
626
+ methodName !== 'allSettled' &&
627
+ methodName !== 'any' &&
628
+ methodName !== 'race') {
629
+ return undefined;
630
+ }
631
+ const inputs = getPromiseCombinatorInputs(context, callExpression, bindings, seenSymbols);
632
+ if (!inputs) {
633
+ return undefined;
634
+ }
635
+ if (methodName === 'all') {
636
+ const [segment, ...restPath] = path;
637
+ if (!segment || segment.kind !== 'index') {
638
+ return undefined;
639
+ }
640
+ const inputExpression = inputs[segment.index];
641
+ return inputExpression
642
+ ? getFamilyAtRecoveryPathWithBindings(context, inputExpression, restPath, spec, seenSymbols, bindings)
643
+ : undefined;
644
+ }
645
+ if (methodName === 'allSettled') {
646
+ const [indexSegment, valueSegment, ...restPath] = path;
647
+ if (!indexSegment ||
648
+ indexSegment.kind !== 'index' ||
649
+ !valueSegment ||
650
+ valueSegment.kind !== 'property' ||
651
+ valueSegment.name !== 'value') {
652
+ return undefined;
653
+ }
654
+ const inputExpression = inputs[indexSegment.index];
655
+ return inputExpression
656
+ ? getFamilyAtRecoveryPathWithBindings(context, inputExpression, restPath, spec, seenSymbols, bindings)
657
+ : undefined;
658
+ }
659
+ for (const inputExpression of inputs) {
660
+ const family = getFamilyAtRecoveryPathWithBindings(context, inputExpression, path, spec, seenSymbols, bindings);
661
+ if (family) {
662
+ return family;
663
+ }
664
+ }
665
+ return undefined;
666
+ }
667
+ function getFreshArrayExtractionFamilyAtPathWithBindings(context, callExpression, path, spec, seenSymbols, bindings) {
668
+ const methodName = getFreshArrayExtractionMethodName(callExpression);
669
+ if (!methodName) {
670
+ return undefined;
671
+ }
672
+ const inputs = getFreshArrayMethodInputs(context, callExpression, bindings, seenSymbols);
673
+ if (!inputs) {
674
+ return undefined;
675
+ }
676
+ switch (methodName) {
677
+ case 'at': {
678
+ const index = getFreshArrayAtIndex(callExpression, inputs.length);
679
+ if (index === undefined) {
680
+ return undefined;
681
+ }
682
+ const inputExpression = inputs[index];
683
+ return inputExpression
684
+ ? getFamilyAtRecoveryPathWithBindings(context, inputExpression, path, spec, seenSymbols, bindings)
685
+ : undefined;
686
+ }
687
+ case 'find':
688
+ for (const inputExpression of inputs) {
689
+ const family = getFamilyAtRecoveryPathWithBindings(context, inputExpression, path, spec, seenSymbols, bindings);
690
+ if (family) {
691
+ return family;
692
+ }
693
+ }
694
+ return undefined;
695
+ case 'filter': {
696
+ const [segment, ...restPath] = path;
697
+ if (!segment || segment.kind !== 'index') {
698
+ return undefined;
699
+ }
700
+ for (const inputExpression of inputs) {
701
+ const family = getFamilyAtRecoveryPathWithBindings(context, inputExpression, restPath, spec, seenSymbols, bindings);
702
+ if (family) {
703
+ return family;
704
+ }
705
+ }
706
+ return undefined;
707
+ }
708
+ case 'flatMap': {
709
+ const flatMapReturn = getFreshArrayFlatMapReturnInfo(context, callExpression);
710
+ const candidatePaths = getFlatMapElementCandidatePaths(path);
711
+ if (!flatMapReturn || !candidatePaths) {
712
+ return undefined;
713
+ }
714
+ for (const inputExpression of inputs) {
715
+ const callbackBindings = mergeParameterBindings(bindings, createParameterBindings(context, flatMapReturn.callback, [inputExpression], bindings));
716
+ for (const candidatePath of candidatePaths) {
717
+ const family = getFamilyAtRecoveryPathWithBindings(context, flatMapReturn.returnExpression, candidatePath, spec, seenSymbols, callbackBindings);
718
+ if (family) {
719
+ return family;
720
+ }
721
+ }
722
+ }
723
+ return undefined;
724
+ }
725
+ }
726
+ }
727
+ function getFamilyAtRecoveryPathWithBindings(context, expression, path, spec, seenSymbols, bindings) {
728
+ const resolvedExpression = resolveBoundExpression(context, expression, bindings);
729
+ const accessSegment = getRecoveryAccessSegment(resolvedExpression);
730
+ if (accessSegment) {
731
+ return getFamilyAtRecoveryPathWithBindings(context, accessSegment.base, [accessSegment.segment, ...path], spec, seenSymbols, bindings);
732
+ }
733
+ if (path.length === 0) {
734
+ const directFamily = spec.getDirectFamily(context, resolvedExpression);
735
+ if (directFamily) {
736
+ return directFamily;
737
+ }
738
+ }
739
+ const current = getUnwrappedExpression(resolvedExpression);
740
+ if (ts.isIdentifier(current)) {
741
+ const symbol = context.checker.getSymbolAtLocation(current);
742
+ return symbol
743
+ ? getAliasedKnownNonOrdinaryFamily(context, symbol, path, spec, seenSymbols)
744
+ : undefined;
745
+ }
746
+ const [segment, ...restPath] = path;
747
+ if (ts.isObjectLiteralExpression(current)) {
748
+ if (!segment || segment.kind !== 'property') {
749
+ return undefined;
750
+ }
751
+ return getObjectLiteralPropertyFamilyAtPathWithBindings(context, current, segment.name, restPath, spec, seenSymbols, bindings);
752
+ }
753
+ if (ts.isArrayLiteralExpression(current)) {
754
+ if (!segment || segment.kind !== 'index') {
755
+ return undefined;
756
+ }
757
+ const element = getArrayLiteralElementValue(current, segment.index);
758
+ return element
759
+ ? getFamilyAtRecoveryPathWithBindings(context, element, restPath, spec, seenSymbols, bindings)
760
+ : undefined;
761
+ }
762
+ const equivalentExpressions = getEquivalentRecoveryExpressions(resolvedExpression);
763
+ if (equivalentExpressions) {
764
+ for (const equivalentExpression of equivalentExpressions) {
765
+ const equivalentFamily = getFamilyAtRecoveryPathWithBindings(context, equivalentExpression, path, spec, seenSymbols, bindings);
766
+ if (equivalentFamily) {
767
+ return equivalentFamily;
768
+ }
769
+ }
770
+ return undefined;
771
+ }
772
+ if (!ts.isCallExpression(current)) {
773
+ return undefined;
774
+ }
775
+ const promiseContinuation = getPromiseRecoveryContinuation(context, current, bindings);
776
+ if (promiseContinuation) {
777
+ return getFamilyAtRecoveryPathWithBindings(context, promiseContinuation.expression, path, spec, seenSymbols, promiseContinuation.bindings);
778
+ }
779
+ const promiseCombinatorFamily = getPromiseCombinatorFamilyAtPathWithBindings(context, current, path, spec, seenSymbols, bindings);
780
+ if (promiseCombinatorFamily) {
781
+ return promiseCombinatorFamily;
782
+ }
783
+ const freshArrayExtractionFamily = getFreshArrayExtractionFamilyAtPathWithBindings(context, current, path, spec, seenSymbols, bindings);
784
+ if (freshArrayExtractionFamily) {
785
+ return freshArrayExtractionFamily;
786
+ }
787
+ const localDirectReturn = getDirectReturnLocalCall(context, current);
788
+ if (localDirectReturn) {
789
+ const localBindings = mergeParameterBindings(bindings, createParameterBindings(context, localDirectReturn.declaration, current.arguments, bindings));
790
+ return getFamilyAtRecoveryPathWithBindings(context, localDirectReturn.returnExpression, path, spec, seenSymbols, localBindings);
791
+ }
792
+ const calleeSymbol = getCallExpressionCalleeSymbol(context, current);
793
+ if (!calleeSymbol) {
794
+ return undefined;
795
+ }
796
+ const summary = context.exportSummaries.get(calleeSymbol);
797
+ if (!summary) {
798
+ return undefined;
799
+ }
800
+ if (summary.kind === 'callableReturnedParameter') {
801
+ const forwardedArgument = current.arguments[summary.parameterIndex];
802
+ return forwardedArgument
803
+ ? getFamilyAtRecoveryPathWithBindings(context, forwardedArgument, path, spec, seenSymbols, bindings)
804
+ : undefined;
805
+ }
806
+ if (summary.kind === 'callableHelperWrapper') {
807
+ for (const entry of summary.entries) {
808
+ if (!doesRecoveryPathStartWith(path, entry.recoveryPath)) {
809
+ continue;
810
+ }
811
+ const wrappedArgument = current.arguments[entry.parameterIndex];
812
+ if (!wrappedArgument) {
813
+ continue;
814
+ }
815
+ const restPath = path.slice(entry.recoveryPath.length);
816
+ const family = getFamilyAtRecoveryPathWithBindings(context, wrappedArgument, restPath, spec, seenSymbols, bindings);
817
+ if (family) {
818
+ return family;
819
+ }
820
+ }
821
+ return undefined;
822
+ }
823
+ if (path.length > 0) {
824
+ return undefined;
825
+ }
826
+ return getSupportedSummaryFamily(summary, spec);
827
+ }
828
+ function getObjectLiteralCarriedFamilyAtPathWithBindings(context, objectLiteral, path, spec, seenSymbols, bindings) {
829
+ const [segment, ...restPath] = path;
830
+ if (segment) {
831
+ if (segment.kind !== 'property') {
832
+ return undefined;
833
+ }
834
+ return getObjectLiteralPropertyFamilyAtPathWithBindings(context, objectLiteral, segment.name, restPath, spec, seenSymbols, bindings);
835
+ }
836
+ for (const property of objectLiteral.properties) {
837
+ if (ts.isPropertyAssignment(property)) {
838
+ const carriedFamily = getCarriedFamilyAtRecoveryPathWithBindings(context, property.initializer, [], spec, seenSymbols, bindings);
839
+ if (carriedFamily) {
840
+ return carriedFamily;
841
+ }
842
+ continue;
843
+ }
844
+ if (ts.isShorthandPropertyAssignment(property)) {
845
+ const valueSymbol = context.checker.getShorthandAssignmentValueSymbol(property);
846
+ if (!valueSymbol) {
847
+ continue;
848
+ }
849
+ const boundExpression = bindings.get(valueSymbol);
850
+ const carriedFamily = boundExpression
851
+ ? getCarriedFamilyAtRecoveryPathWithBindings(context, boundExpression, [], spec, seenSymbols, bindings)
852
+ : getAliasedKnownCarriedNonOrdinaryFamily(context, valueSymbol, [], spec, seenSymbols);
853
+ if (carriedFamily) {
854
+ return carriedFamily;
855
+ }
856
+ }
857
+ }
858
+ return undefined;
859
+ }
860
+ function getArrayLiteralCarriedFamilyAtPathWithBindings(context, arrayLiteral, path, spec, seenSymbols, bindings) {
861
+ const [segment, ...restPath] = path;
862
+ if (segment) {
863
+ if (segment.kind !== 'index') {
864
+ return undefined;
865
+ }
866
+ const element = getArrayLiteralElementValue(arrayLiteral, segment.index);
867
+ return element
868
+ ? getCarriedFamilyAtRecoveryPathWithBindings(context, element, restPath, spec, seenSymbols, bindings)
869
+ : undefined;
870
+ }
871
+ for (const element of arrayLiteral.elements) {
872
+ if (!ts.isExpression(element)) {
873
+ continue;
874
+ }
875
+ const carriedFamily = getCarriedFamilyAtRecoveryPathWithBindings(context, element, [], spec, seenSymbols, bindings);
876
+ if (carriedFamily) {
877
+ return carriedFamily;
878
+ }
879
+ }
880
+ return undefined;
881
+ }
882
+ function getPromiseCombinatorCarriedFamilyAtPathWithBindings(context, callExpression, path, spec, seenSymbols, bindings) {
883
+ const methodName = getPromiseStaticMethodName(context, callExpression);
884
+ if (methodName !== 'all' &&
885
+ methodName !== 'allSettled' &&
886
+ methodName !== 'any' &&
887
+ methodName !== 'race') {
888
+ return undefined;
889
+ }
890
+ const inputs = getPromiseCombinatorInputs(context, callExpression, bindings, seenSymbols);
891
+ if (!inputs) {
892
+ return undefined;
893
+ }
894
+ if (methodName === 'all') {
895
+ if (path.length === 0) {
896
+ for (const inputExpression of inputs) {
897
+ const carriedFamily = getCarriedFamilyAtRecoveryPathWithBindings(context, inputExpression, [], spec, seenSymbols, bindings);
898
+ if (carriedFamily) {
899
+ return carriedFamily;
900
+ }
901
+ }
902
+ return undefined;
903
+ }
904
+ const [segment, ...restPath] = path;
905
+ if (!segment || segment.kind !== 'index') {
906
+ return undefined;
907
+ }
908
+ const inputExpression = inputs[segment.index];
909
+ return inputExpression
910
+ ? getCarriedFamilyAtRecoveryPathWithBindings(context, inputExpression, restPath, spec, seenSymbols, bindings)
911
+ : undefined;
912
+ }
913
+ if (methodName === 'allSettled') {
914
+ if (path.length === 0) {
915
+ for (const inputExpression of inputs) {
916
+ const carriedFamily = getCarriedFamilyAtRecoveryPathWithBindings(context, inputExpression, [], spec, seenSymbols, bindings);
917
+ if (carriedFamily) {
918
+ return carriedFamily;
919
+ }
920
+ }
921
+ return undefined;
922
+ }
923
+ const [indexSegment, valueSegment, ...restPath] = path;
924
+ if (!indexSegment ||
925
+ indexSegment.kind !== 'index' ||
926
+ !valueSegment ||
927
+ valueSegment.kind !== 'property' ||
928
+ valueSegment.name !== 'value') {
929
+ return undefined;
930
+ }
931
+ const inputExpression = inputs[indexSegment.index];
932
+ return inputExpression
933
+ ? getCarriedFamilyAtRecoveryPathWithBindings(context, inputExpression, restPath, spec, seenSymbols, bindings)
934
+ : undefined;
935
+ }
936
+ for (const inputExpression of inputs) {
937
+ const carriedFamily = getCarriedFamilyAtRecoveryPathWithBindings(context, inputExpression, path, spec, seenSymbols, bindings);
938
+ if (carriedFamily) {
939
+ return carriedFamily;
940
+ }
941
+ }
942
+ return undefined;
943
+ }
944
+ function getFreshArrayExtractionCarriedFamilyAtPathWithBindings(context, callExpression, path, spec, seenSymbols, bindings) {
945
+ const methodName = getFreshArrayExtractionMethodName(callExpression);
946
+ if (!methodName) {
947
+ return undefined;
948
+ }
949
+ const inputs = getFreshArrayMethodInputs(context, callExpression, bindings, seenSymbols);
950
+ if (!inputs) {
951
+ return undefined;
952
+ }
953
+ switch (methodName) {
954
+ case 'at': {
955
+ const index = getFreshArrayAtIndex(callExpression, inputs.length);
956
+ if (index === undefined) {
957
+ return undefined;
958
+ }
959
+ const inputExpression = inputs[index];
960
+ return inputExpression
961
+ ? getCarriedFamilyAtRecoveryPathWithBindings(context, inputExpression, path, spec, seenSymbols, bindings)
962
+ : undefined;
963
+ }
964
+ case 'find':
965
+ for (const inputExpression of inputs) {
966
+ const family = getCarriedFamilyAtRecoveryPathWithBindings(context, inputExpression, path, spec, seenSymbols, bindings);
967
+ if (family) {
968
+ return family;
969
+ }
970
+ }
971
+ return undefined;
972
+ case 'filter': {
973
+ if (path.length === 0) {
974
+ for (const inputExpression of inputs) {
975
+ const family = getCarriedFamilyAtRecoveryPathWithBindings(context, inputExpression, [], spec, seenSymbols, bindings);
976
+ if (family) {
977
+ return family;
978
+ }
979
+ }
980
+ return undefined;
981
+ }
982
+ const [segment, ...restPath] = path;
983
+ if (segment.kind !== 'index') {
984
+ return undefined;
985
+ }
986
+ for (const inputExpression of inputs) {
987
+ const family = getCarriedFamilyAtRecoveryPathWithBindings(context, inputExpression, restPath, spec, seenSymbols, bindings);
988
+ if (family) {
989
+ return family;
990
+ }
991
+ }
992
+ return undefined;
993
+ }
994
+ case 'flatMap': {
995
+ const flatMapReturn = getFreshArrayFlatMapReturnInfo(context, callExpression);
996
+ if (!flatMapReturn) {
997
+ return undefined;
998
+ }
999
+ const candidatePaths = path.length === 0 ? [[]] : getFlatMapElementCandidatePaths(path);
1000
+ if (!candidatePaths) {
1001
+ return undefined;
1002
+ }
1003
+ for (const inputExpression of inputs) {
1004
+ const callbackBindings = mergeParameterBindings(bindings, createParameterBindings(context, flatMapReturn.callback, [inputExpression], bindings));
1005
+ for (const candidatePath of candidatePaths) {
1006
+ const family = getCarriedFamilyAtRecoveryPathWithBindings(context, flatMapReturn.returnExpression, candidatePath, spec, seenSymbols, callbackBindings);
1007
+ if (family) {
1008
+ return family;
1009
+ }
1010
+ }
1011
+ }
1012
+ return undefined;
1013
+ }
1014
+ }
1015
+ }
1016
+ function getAliasedKnownCarriedNonOrdinaryFamily(context, symbol, path, spec, seenSymbols) {
1017
+ if (seenSymbols.has(symbol)) {
1018
+ return undefined;
1019
+ }
1020
+ seenSymbols.add(symbol);
1021
+ const summary = context.exportSummaries.get(symbol);
1022
+ if (summary) {
1023
+ if (path.length === 0) {
1024
+ return summary.kind === 'value' ? getSupportedSummaryFamily(summary, spec) : undefined;
1025
+ }
1026
+ return undefined;
1027
+ }
1028
+ for (const declaration of symbol.getDeclarations() ?? []) {
1029
+ if (ts.isVariableDeclaration(declaration) &&
1030
+ isConstVariableDeclaration(declaration) &&
1031
+ declaration.initializer) {
1032
+ if (ts.isIdentifier(declaration.name)) {
1033
+ return getCarriedFamilyAtRecoveryPathWithBindings(context, declaration.initializer, path, spec, seenSymbols, new Map());
1034
+ }
1035
+ const bindingPath = getBindingPatternRecoveryPath(context, declaration.name, symbol);
1036
+ if (bindingPath) {
1037
+ return getCarriedFamilyAtRecoveryPathWithBindings(context, declaration.initializer, [...bindingPath, ...path], spec, seenSymbols, new Map());
1038
+ }
1039
+ }
1040
+ if (ts.isBindingElement(declaration)) {
1041
+ const bindingRoot = getEnclosingConstBindingInitializer(declaration);
1042
+ if (!bindingRoot) {
1043
+ continue;
1044
+ }
1045
+ const bindingPath = getBindingPatternRecoveryPath(context, bindingRoot.bindingName, symbol);
1046
+ if (bindingPath) {
1047
+ return getCarriedFamilyAtRecoveryPathWithBindings(context, bindingRoot.initializer, [...bindingPath, ...path], spec, seenSymbols, new Map());
1048
+ }
1049
+ }
1050
+ }
1051
+ return undefined;
1052
+ }
1053
+ function getCarriedFamilyAtRecoveryPathWithBindings(context, expression, path, spec, seenSymbols, bindings) {
1054
+ const exactFamily = getFamilyAtRecoveryPathWithBindings(context, expression, path, spec, new Set(seenSymbols), bindings);
1055
+ if (exactFamily) {
1056
+ return exactFamily;
1057
+ }
1058
+ const resolvedExpression = resolveBoundExpression(context, expression, bindings);
1059
+ const accessSegment = getRecoveryAccessSegment(resolvedExpression);
1060
+ if (accessSegment) {
1061
+ return getCarriedFamilyAtRecoveryPathWithBindings(context, accessSegment.base, [accessSegment.segment, ...path], spec, seenSymbols, bindings);
1062
+ }
1063
+ const current = getUnwrappedExpression(resolvedExpression);
1064
+ if (ts.isIdentifier(current)) {
1065
+ const symbol = context.checker.getSymbolAtLocation(current);
1066
+ return symbol
1067
+ ? getAliasedKnownCarriedNonOrdinaryFamily(context, symbol, path, spec, seenSymbols)
1068
+ : undefined;
1069
+ }
1070
+ if (ts.isObjectLiteralExpression(current)) {
1071
+ return getObjectLiteralCarriedFamilyAtPathWithBindings(context, current, path, spec, seenSymbols, bindings);
1072
+ }
1073
+ if (ts.isArrayLiteralExpression(current)) {
1074
+ return getArrayLiteralCarriedFamilyAtPathWithBindings(context, current, path, spec, seenSymbols, bindings);
1075
+ }
1076
+ const equivalentExpressions = getEquivalentRecoveryExpressions(resolvedExpression);
1077
+ if (equivalentExpressions) {
1078
+ for (const equivalentExpression of equivalentExpressions) {
1079
+ const equivalentFamily = getCarriedFamilyAtRecoveryPathWithBindings(context, equivalentExpression, path, spec, seenSymbols, bindings);
1080
+ if (equivalentFamily) {
1081
+ return equivalentFamily;
1082
+ }
1083
+ }
1084
+ return undefined;
1085
+ }
1086
+ if (!ts.isCallExpression(current)) {
1087
+ return undefined;
1088
+ }
1089
+ const promiseContinuation = getPromiseRecoveryContinuation(context, current, bindings);
1090
+ if (promiseContinuation) {
1091
+ return getCarriedFamilyAtRecoveryPathWithBindings(context, promiseContinuation.expression, path, spec, seenSymbols, promiseContinuation.bindings);
1092
+ }
1093
+ const promiseCombinatorFamily = getPromiseCombinatorCarriedFamilyAtPathWithBindings(context, current, path, spec, seenSymbols, bindings);
1094
+ if (promiseCombinatorFamily) {
1095
+ return promiseCombinatorFamily;
1096
+ }
1097
+ const freshArrayExtractionFamily = getFreshArrayExtractionCarriedFamilyAtPathWithBindings(context, current, path, spec, seenSymbols, bindings);
1098
+ if (freshArrayExtractionFamily) {
1099
+ return freshArrayExtractionFamily;
1100
+ }
1101
+ const localDirectReturn = getDirectReturnLocalCall(context, current);
1102
+ if (localDirectReturn) {
1103
+ const localBindings = mergeParameterBindings(bindings, createParameterBindings(context, localDirectReturn.declaration, current.arguments, bindings));
1104
+ return getCarriedFamilyAtRecoveryPathWithBindings(context, localDirectReturn.returnExpression, path, spec, seenSymbols, localBindings);
1105
+ }
1106
+ const calleeSymbol = getCallExpressionCalleeSymbol(context, current);
1107
+ if (!calleeSymbol) {
1108
+ return undefined;
1109
+ }
1110
+ const summary = context.exportSummaries.get(calleeSymbol);
1111
+ if (!summary) {
1112
+ return undefined;
1113
+ }
1114
+ if (summary.kind === 'callableReturnedParameter') {
1115
+ const forwardedArgument = current.arguments[summary.parameterIndex];
1116
+ return forwardedArgument
1117
+ ? getCarriedFamilyAtRecoveryPathWithBindings(context, forwardedArgument, path, spec, seenSymbols, bindings)
1118
+ : undefined;
1119
+ }
1120
+ if (summary.kind === 'callableHelperWrapper') {
1121
+ for (const entry of summary.entries) {
1122
+ if (!doesRecoveryPathStartWith(path, entry.recoveryPath)) {
1123
+ continue;
1124
+ }
1125
+ const wrappedArgument = current.arguments[entry.parameterIndex];
1126
+ if (!wrappedArgument) {
1127
+ continue;
1128
+ }
1129
+ const restPath = path.slice(entry.recoveryPath.length);
1130
+ const family = getCarriedFamilyAtRecoveryPathWithBindings(context, wrappedArgument, restPath, spec, seenSymbols, bindings);
1131
+ if (family) {
1132
+ return family;
1133
+ }
1134
+ }
1135
+ return undefined;
1136
+ }
1137
+ if (path.length === 0) {
1138
+ return getSupportedSummaryFamily(summary, spec);
1139
+ }
1140
+ return undefined;
1141
+ }
1142
+ function getSupportedSummaryFamily(summary, spec) {
1143
+ switch (summary.kind) {
1144
+ case 'callableDirectReturn':
1145
+ case 'value':
1146
+ return spec.isSupportedFamily(summary.fact.family) ? summary.fact.family : undefined;
1147
+ case 'callableHelperWrapper':
1148
+ case 'callableReturnedParameter':
1149
+ return undefined;
1150
+ default: {
1151
+ const exhaustiveCheck = summary;
1152
+ return exhaustiveCheck;
1153
+ }
1154
+ }
1155
+ }
1156
+ function getAliasedKnownNonOrdinaryFamily(context, symbol, path, spec, seenSymbols) {
1157
+ if (seenSymbols.has(symbol)) {
1158
+ return undefined;
1159
+ }
1160
+ seenSymbols.add(symbol);
1161
+ const summary = context.exportSummaries.get(symbol);
1162
+ if (summary) {
1163
+ return path.length === 0 && summary.kind === 'value'
1164
+ ? getSupportedSummaryFamily(summary, spec)
1165
+ : undefined;
1166
+ }
1167
+ for (const declaration of symbol.getDeclarations() ?? []) {
1168
+ if (ts.isVariableDeclaration(declaration) &&
1169
+ isConstVariableDeclaration(declaration) &&
1170
+ declaration.initializer) {
1171
+ if (ts.isIdentifier(declaration.name)) {
1172
+ return getFamilyAtRecoveryPathWithBindings(context, declaration.initializer, path, spec, seenSymbols, new Map());
1173
+ }
1174
+ const bindingPath = getBindingPatternRecoveryPath(context, declaration.name, symbol);
1175
+ if (bindingPath) {
1176
+ return getFamilyAtRecoveryPathWithBindings(context, declaration.initializer, [...bindingPath, ...path], spec, seenSymbols, new Map());
1177
+ }
1178
+ }
1179
+ if (ts.isBindingElement(declaration)) {
1180
+ const bindingRoot = getEnclosingConstBindingInitializer(declaration);
1181
+ if (!bindingRoot) {
1182
+ continue;
1183
+ }
1184
+ const bindingPath = getBindingPatternRecoveryPath(context, bindingRoot.bindingName, symbol);
1185
+ if (bindingPath) {
1186
+ return getFamilyAtRecoveryPathWithBindings(context, bindingRoot.initializer, [...bindingPath, ...path], spec, seenSymbols, new Map());
1187
+ }
1188
+ }
1189
+ }
1190
+ return undefined;
1191
+ }
1192
+ export function getKnownRecoveredNonOrdinaryFamily(context, expression, spec, seenSymbols = new Set()) {
1193
+ if (seenSymbols.size === 0) {
1194
+ let computedFamily;
1195
+ const recovery = context.facts.getNonOrdinaryRecovery(expression, spec.getDirectFamily(context, expression) ?? inferRecoveryFactFamily(spec), () => ({
1196
+ family: computedFamily = getKnownRecoveredNonOrdinaryFamilyInternal(context, expression, spec, new Set()),
1197
+ }));
1198
+ return computedFamily ?? recovery.family;
1199
+ }
1200
+ return getKnownRecoveredNonOrdinaryFamilyInternal(context, expression, spec, seenSymbols);
1201
+ }
1202
+ export function getKnownCarriedNonOrdinaryFamily(context, expression, spec, seenSymbols = new Set()) {
1203
+ return getCarriedFamilyAtRecoveryPathWithBindings(context, expression, [], spec, seenSymbols, new Map());
1204
+ }
1205
+ function getKnownRecoveredNonOrdinaryFamilyInternal(context, expression, spec, seenSymbols) {
1206
+ return getFamilyAtRecoveryPathWithBindings(context, expression, [], spec, seenSymbols, new Map());
1207
+ }
1208
+ function inferRecoveryFactFamily(spec) {
1209
+ const knownFamilies = [
1210
+ 'moduleNamespace',
1211
+ 'nullPrototype',
1212
+ ];
1213
+ for (const family of knownFamilies) {
1214
+ if (spec.isSupportedFamily(family)) {
1215
+ return family;
1216
+ }
1217
+ }
1218
+ throw new Error('Unsupported non-ordinary recovery spec family');
1219
+ }
1220
+ export function collectLocalFunctionLikes(context) {
1221
+ const functionLikes = [];
1222
+ function visit(node) {
1223
+ if (isLocalFunctionLikeWithBody(node)) {
1224
+ functionLikes.push(node);
1225
+ }
1226
+ ts.forEachChild(node, visit);
1227
+ }
1228
+ context.forEachSourceFile((sourceFile) => visit(sourceFile));
1229
+ return functionLikes;
1230
+ }
1231
+ export function collectExportedSymbolsBySourceFile(context) {
1232
+ const exportedSymbolsBySourceFile = new Map();
1233
+ context.forEachSourceFile((sourceFile) => {
1234
+ const moduleSymbol = context.checker.getSymbolAtLocation(sourceFile);
1235
+ if (!moduleSymbol) {
1236
+ return;
1237
+ }
1238
+ const exportedSymbols = new Set();
1239
+ for (const exportSymbol of context.checker.getExportsOfModule(moduleSymbol)) {
1240
+ exportedSymbols.add(context.exportSummaries.canonicalizeSymbol(exportSymbol));
1241
+ }
1242
+ exportedSymbolsBySourceFile.set(sourceFile, exportedSymbols);
1243
+ });
1244
+ return exportedSymbolsBySourceFile;
1245
+ }
1246
+ export function populateDirectExportValueSummaries(context, exportedSymbolsBySourceFile, spec) {
1247
+ context.forEachSourceFile((sourceFile) => {
1248
+ const exportedSymbols = exportedSymbolsBySourceFile.get(sourceFile);
1249
+ if (!exportedSymbols) {
1250
+ return;
1251
+ }
1252
+ context.traverse(sourceFile, (node) => {
1253
+ let symbol;
1254
+ let initializer;
1255
+ if (ts.isVariableDeclaration(node) &&
1256
+ isConstVariableDeclaration(node) &&
1257
+ node.initializer &&
1258
+ ts.isIdentifier(node.name)) {
1259
+ symbol = context.checker.getSymbolAtLocation(node.name);
1260
+ initializer = node.initializer;
1261
+ }
1262
+ else if (ts.isExportAssignment(node) && !node.isExportEquals) {
1263
+ symbol = getDefaultExportSymbol(context, sourceFile);
1264
+ initializer = node.expression;
1265
+ }
1266
+ else {
1267
+ return;
1268
+ }
1269
+ if (!symbol || !initializer) {
1270
+ return;
1271
+ }
1272
+ if (!exportedSymbols.has(context.exportSummaries.canonicalizeSymbol(symbol))) {
1273
+ return;
1274
+ }
1275
+ const family = spec.getDirectFamily(context, initializer);
1276
+ if (!family) {
1277
+ return;
1278
+ }
1279
+ context.exportSummaries.set(symbol, {
1280
+ kind: 'value',
1281
+ fact: { family },
1282
+ });
1283
+ });
1284
+ });
1285
+ }
1286
+ export function populateFunctionLikeNonOrdinarySummaries(context, exportedSymbolsBySourceFile, spec) {
1287
+ for (const functionLike of collectLocalFunctionLikes(context)) {
1288
+ const symbol = getFunctionLikeSummarySymbol(context, functionLike);
1289
+ if (!symbol) {
1290
+ continue;
1291
+ }
1292
+ const exportedSymbols = exportedSymbolsBySourceFile.get(functionLike.getSourceFile());
1293
+ if (!exportedSymbols?.has(context.exportSummaries.canonicalizeSymbol(symbol))) {
1294
+ continue;
1295
+ }
1296
+ const returnExpression = getDirectReturnExpression(functionLike);
1297
+ const family = returnExpression
1298
+ ? (spec.getDirectFamily(context, returnExpression) ??
1299
+ getKnownRecoveredNonOrdinaryFamily(context, returnExpression, spec))
1300
+ : undefined;
1301
+ if (family) {
1302
+ context.exportSummaries.set(symbol, {
1303
+ kind: 'callableDirectReturn',
1304
+ fact: { family },
1305
+ });
1306
+ continue;
1307
+ }
1308
+ const returnedParameterIndex = summarizeReturnedParameter(context, functionLike);
1309
+ if (returnedParameterIndex !== undefined) {
1310
+ context.exportSummaries.set(symbol, {
1311
+ kind: 'callableReturnedParameter',
1312
+ parameterIndex: returnedParameterIndex,
1313
+ });
1314
+ continue;
1315
+ }
1316
+ if (!returnExpression) {
1317
+ continue;
1318
+ }
1319
+ const helperWrapperEntries = collectHelperWrapperEntries(context, functionLike, returnExpression);
1320
+ if (!helperWrapperEntries || helperWrapperEntries.length === 0) {
1321
+ continue;
1322
+ }
1323
+ context.exportSummaries.set(symbol, {
1324
+ kind: 'callableHelperWrapper',
1325
+ entries: helperWrapperEntries,
1326
+ });
1327
+ }
1328
+ }