@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,1119 @@
1
+ import ts from 'typescript';
2
+ import { bindFunctionBindingName, appendSegment, arrayMutationCallAffectsNarrow, assignmentAffectsNarrow, bindFunctionReceiverPath, cloneState, getCalledMember, getExpressionSymbol, getFunctionBindings, getFunctionBodyCalledMember, getFunctionLikeFromBoundMemberCall, getFunctionLikeFromBoundValue, getFunctionLikeFromCallExpression, getStateExpressionBoundValue, getUniformArrayElementBindingFromExpression, getUniformArrayElementBindingFromFunctionBodyExpression, getUniformMapEntryBindingsFromExpression, getUniformMapEntryBindingsFromFunctionBodyExpression, getUniformSetElementBindingFromExpression, getUniformSetElementBindingFromFunctionBodyExpression, getNestedFunctionBindings, getMutableBindingSymbol, getShorthandStateBoundValue, getSymbolId, getUpdateExpressionOperand, isConstLocalBindingPath, isFunctionLikeWithBody, isLocalBindingPath, isStableConstLocalBindingPath, MUTATING_ASSIGNMENT_OPERATORS, mutationAffectsNarrow, normalizeExpressionPath, normalizeExpressionSourcePath, normalizeFunctionBodyPath, opaqueArgumentEscapeAffectsNarrow, pathsMatch, recordForOfLoopHeaderAliases, recordFunctionBodyConstBindings, recordExecutedExpressionAliases, recordVariableAliases, typeMayAliasMutableState, typedUpdateExpressionAffectsNarrow, } from './flow_shared.js';
3
+ export { appendSegment, cloneState, isFunctionLikeWithBody, normalizeExpressionPath, recordExecutedExpressionAliases, recordVariableAliases, } from './flow_shared.js';
4
+ const SYNCHRONOUS_ARRAY_CALLBACK_PARAMETER_BINDINGS = new Map([
5
+ ['every', { callbackArgumentIndex: 0, elementParameterIndex: 0, arrayParameterIndex: 2 }],
6
+ ['filter', { callbackArgumentIndex: 0, elementParameterIndex: 0, arrayParameterIndex: 2 }],
7
+ ['find', { callbackArgumentIndex: 0, elementParameterIndex: 0, arrayParameterIndex: 2 }],
8
+ ['findIndex', { callbackArgumentIndex: 0, elementParameterIndex: 0, arrayParameterIndex: 2 }],
9
+ ['findLast', { callbackArgumentIndex: 0, elementParameterIndex: 0, arrayParameterIndex: 2 }],
10
+ ['findLastIndex', { callbackArgumentIndex: 0, elementParameterIndex: 0, arrayParameterIndex: 2 }],
11
+ ['flatMap', { callbackArgumentIndex: 0, elementParameterIndex: 0, arrayParameterIndex: 2 }],
12
+ ['forEach', { callbackArgumentIndex: 0, elementParameterIndex: 0, arrayParameterIndex: 2 }],
13
+ ['map', { callbackArgumentIndex: 0, elementParameterIndex: 0, arrayParameterIndex: 2 }],
14
+ ['reduce', { callbackArgumentIndex: 0, elementParameterIndex: 1, arrayParameterIndex: 3 }],
15
+ ['reduceRight', { callbackArgumentIndex: 0, elementParameterIndex: 1, arrayParameterIndex: 3 }],
16
+ ['some', { callbackArgumentIndex: 0, elementParameterIndex: 0, arrayParameterIndex: 2 }],
17
+ ]);
18
+ const SYNCHRONOUS_SET_CALLBACK_PARAMETER_BINDINGS = new Map([
19
+ ['forEach', { callbackArgumentIndex: 0, elementParameterIndexes: [0, 1], receiverParameterIndex: 2 }],
20
+ ]);
21
+ const SYNCHRONOUS_MAP_CALLBACK_PARAMETER_BINDINGS = new Map([
22
+ ['forEach', { callbackArgumentIndex: 0, valueParameterIndex: 0, keyParameterIndex: 1, receiverParameterIndex: 2 }],
23
+ ]);
24
+ function unwrapTransparentExpression(expression) {
25
+ while (ts.isParenthesizedExpression(expression) ||
26
+ ts.isAsExpression(expression) ||
27
+ ts.isTypeAssertionExpression(expression) ||
28
+ ts.isNonNullExpression(expression) ||
29
+ ts.isSatisfiesExpression(expression)) {
30
+ expression = expression.expression;
31
+ }
32
+ return expression;
33
+ }
34
+ function expressionIsThisLikeInBindings(context, expression, bindings, seen = new Set()) {
35
+ expression = unwrapTransparentExpression(expression);
36
+ if (expression.kind === ts.SyntaxKind.ThisKeyword) {
37
+ return true;
38
+ }
39
+ if (!ts.isIdentifier(expression)) {
40
+ return false;
41
+ }
42
+ const symbol = getExpressionSymbol(context, expression);
43
+ if (!symbol) {
44
+ return false;
45
+ }
46
+ const symbolId = getSymbolId(context, symbol);
47
+ if (seen.has(symbolId)) {
48
+ return false;
49
+ }
50
+ seen.add(symbolId);
51
+ const boundValue = bindings.boundValues.get(symbolId);
52
+ return !!boundValue && ts.isExpression(boundValue) &&
53
+ expressionIsThisLikeInBindings(context, boundValue, bindings, seen);
54
+ }
55
+ function getAssignedReceiverMemberKey(context, expression, bindings) {
56
+ expression = unwrapTransparentExpression(expression);
57
+ if (ts.isPropertyAccessExpression(expression)) {
58
+ return expressionIsThisLikeInBindings(context, expression.expression, bindings)
59
+ ? expression.name.text
60
+ : undefined;
61
+ }
62
+ if (ts.isElementAccessExpression(expression)) {
63
+ if (!expressionIsThisLikeInBindings(context, expression.expression, bindings)) {
64
+ return undefined;
65
+ }
66
+ const argument = expression.argumentExpression;
67
+ if (!argument) {
68
+ return undefined;
69
+ }
70
+ const unwrappedArgument = unwrapTransparentExpression(argument);
71
+ if (ts.isStringLiteral(unwrappedArgument) ||
72
+ ts.isNumericLiteral(unwrappedArgument) ||
73
+ ts.isNoSubstitutionTemplateLiteral(unwrappedArgument)) {
74
+ return unwrappedArgument.text;
75
+ }
76
+ }
77
+ return undefined;
78
+ }
79
+ function getConstructorAssignedReceiverMemberPaths(context, declaration, bindings) {
80
+ if (!ts.isConstructorDeclaration(declaration) || !declaration.body) {
81
+ return undefined;
82
+ }
83
+ const memberPaths = new Map();
84
+ recordFunctionBodyConstBindings(context, declaration.body, bindings);
85
+ for (const candidate of getFlowInvalidationStructure(context, declaration.body, 'functionBody').candidates) {
86
+ if (candidate.kind !== 'assignment' ||
87
+ candidate.node.operatorToken.kind !== ts.SyntaxKind.EqualsToken ||
88
+ context.isGeneratedNode(candidate.node)) {
89
+ continue;
90
+ }
91
+ const key = getAssignedReceiverMemberKey(context, candidate.left, bindings);
92
+ if (!key) {
93
+ continue;
94
+ }
95
+ const rightPath = normalizeFunctionBodyPath(context, candidate.right, bindings);
96
+ if (rightPath) {
97
+ memberPaths.set(key, rightPath);
98
+ }
99
+ }
100
+ return memberPaths.size > 0 ? memberPaths : undefined;
101
+ }
102
+ function getConstructorReceiverBindingFromState(context, declaration, argumentsList, state) {
103
+ if (!isFunctionLikeWithBody(declaration)) {
104
+ return undefined;
105
+ }
106
+ const bindings = getFunctionBindings(context, argumentsList, declaration, state);
107
+ const memberPaths = getConstructorAssignedReceiverMemberPaths(context, declaration, bindings);
108
+ return memberPaths ? { path: undefined, memberPaths } : undefined;
109
+ }
110
+ function getConstructorReceiverBindingFromBindings(context, declaration, argumentsList, bindings) {
111
+ if (!isFunctionLikeWithBody(declaration)) {
112
+ return undefined;
113
+ }
114
+ const nestedBindings = getNestedFunctionBindings(context, argumentsList, declaration, bindings);
115
+ const memberPaths = getConstructorAssignedReceiverMemberPaths(context, declaration, nestedBindings);
116
+ return memberPaths ? { path: undefined, memberPaths } : undefined;
117
+ }
118
+ function getStateConstructedReceiverBinding(context, expression, state, kind, seen = new Set()) {
119
+ expression = unwrapTransparentExpression(expression);
120
+ if (ts.isIdentifier(expression)) {
121
+ const symbol = getExpressionSymbol(context, expression);
122
+ if (!symbol) {
123
+ return undefined;
124
+ }
125
+ const symbolId = getSymbolId(context, symbol);
126
+ if (seen.has(symbolId)) {
127
+ return {
128
+ path: getInvalidationPath(context, expression, state, kind),
129
+ memberPaths: undefined,
130
+ };
131
+ }
132
+ seen.add(symbolId);
133
+ const boundValue = state.boundValues.get(symbolId);
134
+ if (boundValue && ts.isExpression(boundValue)) {
135
+ return getStateConstructedReceiverBinding(context, boundValue, state, kind, seen) ?? {
136
+ path: getInvalidationPath(context, expression, state, kind),
137
+ memberPaths: undefined,
138
+ };
139
+ }
140
+ }
141
+ if (!ts.isNewExpression(expression)) {
142
+ const path = getInvalidationPath(context, expression, state, kind);
143
+ return path ? { path, memberPaths: undefined } : undefined;
144
+ }
145
+ const constructorDeclaration = context.checker.getResolvedSignature(expression)?.declaration;
146
+ return constructorDeclaration
147
+ ? getConstructorReceiverBindingFromState(context, constructorDeclaration, expression.arguments ?? [], state)
148
+ : undefined;
149
+ }
150
+ function getFunctionConstructedReceiverBinding(context, expression, bindings, seen = new Set()) {
151
+ expression = unwrapTransparentExpression(expression);
152
+ if (expression.kind === ts.SyntaxKind.ThisKeyword) {
153
+ return bindings.receiverPath || bindings.receiverMemberPaths
154
+ ? {
155
+ path: bindings.receiverPath,
156
+ memberPaths: bindings.receiverMemberPaths,
157
+ }
158
+ : undefined;
159
+ }
160
+ if (ts.isIdentifier(expression)) {
161
+ const symbol = getExpressionSymbol(context, expression);
162
+ if (!symbol) {
163
+ return undefined;
164
+ }
165
+ const symbolId = getSymbolId(context, symbol);
166
+ if (seen.has(symbolId)) {
167
+ const path = normalizeFunctionBodyPath(context, expression, bindings);
168
+ return path ? { path, memberPaths: undefined } : undefined;
169
+ }
170
+ seen.add(symbolId);
171
+ const boundValue = bindings.boundValues.get(symbolId);
172
+ if (boundValue && ts.isExpression(boundValue)) {
173
+ return getFunctionConstructedReceiverBinding(context, boundValue, bindings, seen) ?? {
174
+ path: normalizeFunctionBodyPath(context, expression, bindings),
175
+ memberPaths: undefined,
176
+ };
177
+ }
178
+ }
179
+ if (!ts.isNewExpression(expression)) {
180
+ const path = normalizeFunctionBodyPath(context, expression, bindings);
181
+ return path ? { path, memberPaths: undefined } : undefined;
182
+ }
183
+ const constructorDeclaration = context.checker.getResolvedSignature(expression)?.declaration;
184
+ return constructorDeclaration
185
+ ? getConstructorReceiverBindingFromBindings(context, constructorDeclaration, expression.arguments ?? [], bindings)
186
+ : undefined;
187
+ }
188
+ function getExpressionPathInfo(context, expression, state) {
189
+ const readPath = normalizeExpressionPath(context, expression, state);
190
+ const sourcePath = normalizeExpressionSourcePath(context, expression, state);
191
+ return {
192
+ readPath,
193
+ sourcePath,
194
+ extracted: !!readPath && !!sourcePath && !pathsMatch(readPath, sourcePath),
195
+ };
196
+ }
197
+ function getInvalidationPath(context, expression, state, kind) {
198
+ const pathInfo = getExpressionPathInfo(context, expression, state);
199
+ if (!pathInfo.extracted) {
200
+ return pathInfo.readPath;
201
+ }
202
+ if (!pathInfo.sourcePath) {
203
+ return pathInfo.readPath;
204
+ }
205
+ if (kind === 'opaqueEscape' && pathInfo.sourcePath.segments.length > 0) {
206
+ const type = context.checker.getTypeAtLocation(expression);
207
+ if (!typeMayAliasMutableState(context, type)) {
208
+ return undefined;
209
+ }
210
+ }
211
+ if (kind === 'return' && pathInfo.sourcePath.segments.length > 0) {
212
+ return undefined;
213
+ }
214
+ return pathInfo.sourcePath;
215
+ }
216
+ function isExtractedReadOnlyReturnArgument(context, expression, state) {
217
+ const sourcePath = normalizeExpressionSourcePath(context, expression, state);
218
+ return !!sourcePath && sourcePath.segments.length > 0;
219
+ }
220
+ function expressionPathEscapesNarrow(context, expression, narrowPath, state) {
221
+ const expressionPath = normalizeExpressionPath(context, expression, state);
222
+ return expressionPath !== undefined &&
223
+ opaqueArgumentEscapeAffectsNarrow(expressionPath, narrowPath);
224
+ }
225
+ function functionBodyPathEscapesNarrow(context, expression, bindings, narrowPath) {
226
+ const expressionPath = normalizeFunctionBodyPath(context, expression, bindings);
227
+ return expressionPath !== undefined &&
228
+ opaqueArgumentEscapeAffectsNarrow(expressionPath, narrowPath);
229
+ }
230
+ function boundParameterAffectsNarrow(context, node, bindings, narrowPath, state) {
231
+ if ((ts.isCallExpression(node.parent) || ts.isNewExpression(node.parent)) &&
232
+ node.parent.expression === node) {
233
+ return false;
234
+ }
235
+ const parameterSymbol = getExpressionSymbol(context, node);
236
+ if (!parameterSymbol) {
237
+ return false;
238
+ }
239
+ const boundValue = bindings.boundValues.get(getSymbolId(context, parameterSymbol));
240
+ if (!boundValue) {
241
+ return false;
242
+ }
243
+ if (ts.isExpression(boundValue) &&
244
+ !expressionPathEscapesNarrow(context, boundValue, narrowPath, state) &&
245
+ escapingExpressionAffectsNarrow(context, boundValue, narrowPath, state)) {
246
+ return true;
247
+ }
248
+ const boundFunction = getFunctionLikeFromBoundValue(context, boundValue);
249
+ return boundFunction
250
+ ? functionLikeAffectsNarrow(context, boundFunction, [], narrowPath, state, false)
251
+ : false;
252
+ }
253
+ function isNodeWithinScope(node, scope) {
254
+ for (let current = node; current; current = current.parent) {
255
+ if (current === scope) {
256
+ return true;
257
+ }
258
+ }
259
+ return false;
260
+ }
261
+ function getLocalConstInitializer(context, identifier, scope) {
262
+ const symbol = getExpressionSymbol(context, identifier);
263
+ if (!symbol) {
264
+ return undefined;
265
+ }
266
+ const declaration = symbol.valueDeclaration;
267
+ if (!declaration ||
268
+ !ts.isVariableDeclaration(declaration) ||
269
+ !declaration.initializer ||
270
+ !declaration.parent ||
271
+ !ts.isVariableDeclarationList(declaration.parent) ||
272
+ (declaration.parent.flags & ts.NodeFlags.Const) === 0 ||
273
+ !isNodeWithinScope(declaration, scope)) {
274
+ return undefined;
275
+ }
276
+ return declaration.initializer;
277
+ }
278
+ function forEachReturnExpression(root, callback) {
279
+ const visit = (node) => {
280
+ if (node !== root && isFunctionLikeWithBody(node)) {
281
+ return false;
282
+ }
283
+ if (ts.isReturnStatement(node) && node.expression) {
284
+ return callback(node.expression);
285
+ }
286
+ return ts.forEachChild(node, visit) ?? false;
287
+ };
288
+ return visit(root);
289
+ }
290
+ function functionBodyExpressionEscapesNarrow(context, expression, bindings, narrowPath, state, scope, activeDeclarations, seenExpressions) {
291
+ if (seenExpressions.has(expression)) {
292
+ return false;
293
+ }
294
+ seenExpressions.add(expression);
295
+ if (isFunctionLikeWithBody(expression)) {
296
+ const nestedBindings = getNestedFunctionBindings(context, [], expression, bindings);
297
+ return functionLikeAffectsNarrow(context, expression, [], narrowPath, state, false, undefined, nestedBindings);
298
+ }
299
+ for (const candidate of getFlowInvalidationStructure(context, expression, 'functionBodyResultExpression').candidates) {
300
+ if (candidate.kind === 'access') {
301
+ if (functionBodyPathEscapesNarrow(context, candidate.node, bindings, narrowPath)) {
302
+ return true;
303
+ }
304
+ if (ts.isIdentifier(candidate.node)) {
305
+ const initializer = getLocalConstInitializer(context, candidate.node, scope);
306
+ if (initializer &&
307
+ functionBodyExpressionEscapesNarrow(context, initializer, bindings, narrowPath, state, scope, activeDeclarations, seenExpressions)) {
308
+ return true;
309
+ }
310
+ }
311
+ }
312
+ if (candidate.kind === 'call') {
313
+ const calleeDeclaration = getFunctionLikeFromCallExpression(context, candidate.node);
314
+ if (calleeDeclaration &&
315
+ functionLikeResultEscapesNarrow(context, calleeDeclaration, candidate.node.arguments, narrowPath, state, activeDeclarations)) {
316
+ return true;
317
+ }
318
+ }
319
+ }
320
+ return false;
321
+ }
322
+ function functionLikeResultEscapesNarrow(context, declaration, argumentsList, narrowPath, state, activeDeclarations = new Set()) {
323
+ const body = declaration.body;
324
+ if (!body || activeDeclarations.has(declaration)) {
325
+ return false;
326
+ }
327
+ activeDeclarations.add(declaration);
328
+ try {
329
+ const bindings = getFunctionBindings(context, argumentsList, declaration, state);
330
+ return forEachReturnExpression(body, (expression) => functionBodyExpressionEscapesNarrow(context, expression, bindings, narrowPath, state, body, activeDeclarations, new Set()));
331
+ }
332
+ finally {
333
+ activeDeclarations.delete(declaration);
334
+ }
335
+ }
336
+ function opaqueArgumentExpressionAffectsNarrow(context, expression, narrowPath, state) {
337
+ const pathInfo = getExpressionPathInfo(context, expression, state);
338
+ if (pathInfo.sourcePath &&
339
+ pathInfo.sourcePath.segments.length > 0 &&
340
+ !typeMayAliasMutableState(context, context.checker.getTypeAtLocation(expression))) {
341
+ return false;
342
+ }
343
+ if (pathInfo.extracted &&
344
+ pathInfo.sourcePath &&
345
+ pathInfo.sourcePath.segments.length > 0 &&
346
+ !typeMayAliasMutableState(context, context.checker.getTypeAtLocation(expression))) {
347
+ return false;
348
+ }
349
+ const invalidationPath = getInvalidationPath(context, expression, state, 'opaqueEscape');
350
+ if (invalidationPath && opaqueArgumentEscapeAffectsNarrow(invalidationPath, narrowPath)) {
351
+ return true;
352
+ }
353
+ if (!pathInfo.extracted) {
354
+ if (expressionPathEscapesNarrow(context, expression, narrowPath, state)) {
355
+ return true;
356
+ }
357
+ if (escapingExpressionAffectsNarrow(context, expression, narrowPath, state)) {
358
+ return true;
359
+ }
360
+ if (stateBoundValueAffectsNarrow(context, expression, narrowPath, state)) {
361
+ return true;
362
+ }
363
+ }
364
+ if (!ts.isCallExpression(expression)) {
365
+ return false;
366
+ }
367
+ const calleeDeclaration = getFunctionLikeFromCallExpression(context, expression);
368
+ return calleeDeclaration
369
+ ? functionLikeResultEscapesNarrow(context, calleeDeclaration, expression.arguments, narrowPath, state)
370
+ : false;
371
+ }
372
+ function opaqueFunctionBodyArgumentExpressionAffectsNarrow(context, expression, bindings, narrowPath, state, scope) {
373
+ const functionBodyPath = normalizeFunctionBodyPath(context, expression, bindings);
374
+ if (functionBodyPath &&
375
+ functionBodyPath.segments.length > 0 &&
376
+ !typeMayAliasMutableState(context, context.checker.getTypeAtLocation(expression))) {
377
+ return false;
378
+ }
379
+ return functionBodyPathEscapesNarrow(context, expression, bindings, narrowPath) ||
380
+ functionBodyExpressionEscapesNarrow(context, expression, bindings, narrowPath, state, scope, new Set(), new Set());
381
+ }
382
+ function getLocalCallbackFunctionLike(context, expression, bindings) {
383
+ expression = unwrapTransparentExpression(expression);
384
+ if (isFunctionLikeWithBody(expression)) {
385
+ return expression;
386
+ }
387
+ if (!ts.isIdentifier(expression)) {
388
+ return undefined;
389
+ }
390
+ const symbol = getExpressionSymbol(context, expression);
391
+ if (!symbol) {
392
+ return undefined;
393
+ }
394
+ const boundValue = bindings.boundValues.get(getSymbolId(context, symbol));
395
+ return boundValue ? getFunctionLikeFromBoundValue(context, boundValue) : undefined;
396
+ }
397
+ function arrayCallbackArgumentAffectsNarrow(context, receiver, member, callExpression, bindings, narrowPath, state) {
398
+ const callbackBinding = member
399
+ ? SYNCHRONOUS_ARRAY_CALLBACK_PARAMETER_BINDINGS.get(member)
400
+ : undefined;
401
+ if (!callbackBinding) {
402
+ return false;
403
+ }
404
+ const callbackArgument = callExpression.arguments[callbackBinding.callbackArgumentIndex];
405
+ if (!callbackArgument) {
406
+ return false;
407
+ }
408
+ const callbackDeclaration = getLocalCallbackFunctionLike(context, callbackArgument, bindings);
409
+ if (!callbackDeclaration) {
410
+ return false;
411
+ }
412
+ const representativeElement = getUniformArrayElementBindingFromFunctionBodyExpression(context, receiver, bindings);
413
+ if (!representativeElement) {
414
+ return false;
415
+ }
416
+ const nestedBindings = getNestedFunctionBindings(context, [], callbackDeclaration, bindings);
417
+ const elementParameter = callbackDeclaration.parameters[callbackBinding.elementParameterIndex];
418
+ if (elementParameter) {
419
+ bindFunctionBindingName(context, elementParameter.name, representativeElement.path, representativeElement.value, nestedBindings);
420
+ }
421
+ if (callbackBinding.arrayParameterIndex !== undefined) {
422
+ const arrayParameter = callbackDeclaration.parameters[callbackBinding.arrayParameterIndex];
423
+ if (arrayParameter) {
424
+ bindFunctionBindingName(context, arrayParameter.name, normalizeFunctionBodyPath(context, receiver, bindings), receiver, nestedBindings);
425
+ }
426
+ }
427
+ return functionLikeAffectsNarrow(context, callbackDeclaration, [], narrowPath, state, false, undefined, nestedBindings);
428
+ }
429
+ function arrayCallbackExpressionAffectsNarrow(context, receiver, member, callExpression, narrowPath, state) {
430
+ const callbackBinding = member
431
+ ? SYNCHRONOUS_ARRAY_CALLBACK_PARAMETER_BINDINGS.get(member)
432
+ : undefined;
433
+ if (!callbackBinding) {
434
+ return false;
435
+ }
436
+ const callbackArgument = callExpression.arguments[callbackBinding.callbackArgumentIndex];
437
+ if (!callbackArgument) {
438
+ return false;
439
+ }
440
+ const callbackDeclaration = isFunctionLikeWithBody(callbackArgument)
441
+ ? callbackArgument
442
+ : (() => {
443
+ const boundValue = getStateExpressionBoundValue(context, callbackArgument, state);
444
+ return boundValue ? getFunctionLikeFromBoundValue(context, boundValue) : undefined;
445
+ })();
446
+ if (!callbackDeclaration) {
447
+ return false;
448
+ }
449
+ const representativeElement = getUniformArrayElementBindingFromExpression(context, receiver, state);
450
+ if (!representativeElement) {
451
+ return false;
452
+ }
453
+ const bindings = getFunctionBindings(context, [], callbackDeclaration, state);
454
+ const elementParameter = callbackDeclaration.parameters[callbackBinding.elementParameterIndex];
455
+ if (elementParameter) {
456
+ bindFunctionBindingName(context, elementParameter.name, representativeElement.path, representativeElement.value, bindings);
457
+ }
458
+ if (callbackBinding.arrayParameterIndex !== undefined) {
459
+ const arrayParameter = callbackDeclaration.parameters[callbackBinding.arrayParameterIndex];
460
+ if (arrayParameter) {
461
+ bindFunctionBindingName(context, arrayParameter.name, normalizeExpressionPath(context, receiver, state), getStateExpressionBoundValue(context, receiver, state) ?? receiver, bindings);
462
+ }
463
+ }
464
+ return functionLikeAffectsNarrow(context, callbackDeclaration, [], narrowPath, state, false, undefined, bindings);
465
+ }
466
+ function setCallbackArgumentAffectsNarrow(context, receiver, member, callExpression, bindings, narrowPath, state) {
467
+ const callbackBinding = member
468
+ ? SYNCHRONOUS_SET_CALLBACK_PARAMETER_BINDINGS.get(member)
469
+ : undefined;
470
+ if (!callbackBinding) {
471
+ return false;
472
+ }
473
+ const callbackArgument = callExpression.arguments[callbackBinding.callbackArgumentIndex];
474
+ if (!callbackArgument) {
475
+ return false;
476
+ }
477
+ const callbackDeclaration = getLocalCallbackFunctionLike(context, callbackArgument, bindings);
478
+ if (!callbackDeclaration) {
479
+ return false;
480
+ }
481
+ const representativeElement = getUniformSetElementBindingFromFunctionBodyExpression(context, receiver, bindings);
482
+ if (!representativeElement) {
483
+ return false;
484
+ }
485
+ const nestedBindings = getNestedFunctionBindings(context, [], callbackDeclaration, bindings);
486
+ for (const parameterIndex of callbackBinding.elementParameterIndexes) {
487
+ const parameter = callbackDeclaration.parameters[parameterIndex];
488
+ if (!parameter) {
489
+ continue;
490
+ }
491
+ bindFunctionBindingName(context, parameter.name, representativeElement.path, representativeElement.value, nestedBindings);
492
+ }
493
+ if (callbackBinding.receiverParameterIndex !== undefined) {
494
+ const receiverParameter = callbackDeclaration.parameters[callbackBinding.receiverParameterIndex];
495
+ if (receiverParameter) {
496
+ bindFunctionBindingName(context, receiverParameter.name, normalizeFunctionBodyPath(context, receiver, bindings), receiver, nestedBindings);
497
+ }
498
+ }
499
+ return functionLikeAffectsNarrow(context, callbackDeclaration, [], narrowPath, state, false, undefined, nestedBindings);
500
+ }
501
+ function setCallbackExpressionAffectsNarrow(context, receiver, member, callExpression, narrowPath, state) {
502
+ const callbackBinding = member
503
+ ? SYNCHRONOUS_SET_CALLBACK_PARAMETER_BINDINGS.get(member)
504
+ : undefined;
505
+ if (!callbackBinding) {
506
+ return false;
507
+ }
508
+ const callbackArgument = callExpression.arguments[callbackBinding.callbackArgumentIndex];
509
+ if (!callbackArgument) {
510
+ return false;
511
+ }
512
+ const callbackDeclaration = isFunctionLikeWithBody(callbackArgument)
513
+ ? callbackArgument
514
+ : (() => {
515
+ const boundValue = getStateExpressionBoundValue(context, callbackArgument, state);
516
+ return boundValue ? getFunctionLikeFromBoundValue(context, boundValue) : undefined;
517
+ })();
518
+ if (!callbackDeclaration) {
519
+ return false;
520
+ }
521
+ const representativeElement = getUniformSetElementBindingFromExpression(context, receiver, state);
522
+ if (!representativeElement) {
523
+ return false;
524
+ }
525
+ const bindings = getFunctionBindings(context, [], callbackDeclaration, state);
526
+ for (const parameterIndex of callbackBinding.elementParameterIndexes) {
527
+ const parameter = callbackDeclaration.parameters[parameterIndex];
528
+ if (!parameter) {
529
+ continue;
530
+ }
531
+ bindFunctionBindingName(context, parameter.name, representativeElement.path, representativeElement.value, bindings);
532
+ }
533
+ if (callbackBinding.receiverParameterIndex !== undefined) {
534
+ const receiverParameter = callbackDeclaration.parameters[callbackBinding.receiverParameterIndex];
535
+ if (receiverParameter) {
536
+ bindFunctionBindingName(context, receiverParameter.name, normalizeExpressionPath(context, receiver, state), getStateExpressionBoundValue(context, receiver, state) ?? receiver, bindings);
537
+ }
538
+ }
539
+ return functionLikeAffectsNarrow(context, callbackDeclaration, [], narrowPath, state, false, undefined, bindings);
540
+ }
541
+ function mapCallbackArgumentAffectsNarrow(context, receiver, member, callExpression, bindings, narrowPath, state) {
542
+ const callbackBinding = member
543
+ ? SYNCHRONOUS_MAP_CALLBACK_PARAMETER_BINDINGS.get(member)
544
+ : undefined;
545
+ if (!callbackBinding) {
546
+ return false;
547
+ }
548
+ const callbackArgument = callExpression.arguments[callbackBinding.callbackArgumentIndex];
549
+ if (!callbackArgument) {
550
+ return false;
551
+ }
552
+ const callbackDeclaration = getLocalCallbackFunctionLike(context, callbackArgument, bindings);
553
+ if (!callbackDeclaration) {
554
+ return false;
555
+ }
556
+ const representativeEntry = getUniformMapEntryBindingsFromFunctionBodyExpression(context, receiver, bindings);
557
+ if (!representativeEntry) {
558
+ return false;
559
+ }
560
+ const nestedBindings = getNestedFunctionBindings(context, [], callbackDeclaration, bindings);
561
+ if (callbackBinding.valueParameterIndex !== undefined && representativeEntry.value) {
562
+ const parameter = callbackDeclaration.parameters[callbackBinding.valueParameterIndex];
563
+ if (parameter) {
564
+ bindFunctionBindingName(context, parameter.name, representativeEntry.value.path, representativeEntry.value.value, nestedBindings);
565
+ }
566
+ }
567
+ if (callbackBinding.keyParameterIndex !== undefined && representativeEntry.key) {
568
+ const parameter = callbackDeclaration.parameters[callbackBinding.keyParameterIndex];
569
+ if (parameter) {
570
+ bindFunctionBindingName(context, parameter.name, representativeEntry.key.path, representativeEntry.key.value, nestedBindings);
571
+ }
572
+ }
573
+ if (callbackBinding.receiverParameterIndex !== undefined) {
574
+ const receiverParameter = callbackDeclaration.parameters[callbackBinding.receiverParameterIndex];
575
+ if (receiverParameter) {
576
+ bindFunctionBindingName(context, receiverParameter.name, normalizeFunctionBodyPath(context, receiver, bindings), receiver, nestedBindings);
577
+ }
578
+ }
579
+ return functionLikeAffectsNarrow(context, callbackDeclaration, [], narrowPath, state, false, undefined, nestedBindings);
580
+ }
581
+ function mapCallbackExpressionAffectsNarrow(context, receiver, member, callExpression, narrowPath, state) {
582
+ const callbackBinding = member
583
+ ? SYNCHRONOUS_MAP_CALLBACK_PARAMETER_BINDINGS.get(member)
584
+ : undefined;
585
+ if (!callbackBinding) {
586
+ return false;
587
+ }
588
+ const callbackArgument = callExpression.arguments[callbackBinding.callbackArgumentIndex];
589
+ if (!callbackArgument) {
590
+ return false;
591
+ }
592
+ const callbackDeclaration = isFunctionLikeWithBody(callbackArgument)
593
+ ? callbackArgument
594
+ : (() => {
595
+ const boundValue = getStateExpressionBoundValue(context, callbackArgument, state);
596
+ return boundValue ? getFunctionLikeFromBoundValue(context, boundValue) : undefined;
597
+ })();
598
+ if (!callbackDeclaration) {
599
+ return false;
600
+ }
601
+ const representativeEntry = getUniformMapEntryBindingsFromExpression(context, receiver, state);
602
+ if (!representativeEntry) {
603
+ return false;
604
+ }
605
+ const bindings = getFunctionBindings(context, [], callbackDeclaration, state);
606
+ if (callbackBinding.valueParameterIndex !== undefined && representativeEntry.value) {
607
+ const parameter = callbackDeclaration.parameters[callbackBinding.valueParameterIndex];
608
+ if (parameter) {
609
+ bindFunctionBindingName(context, parameter.name, representativeEntry.value.path, representativeEntry.value.value, bindings);
610
+ }
611
+ }
612
+ if (callbackBinding.keyParameterIndex !== undefined && representativeEntry.key) {
613
+ const parameter = callbackDeclaration.parameters[callbackBinding.keyParameterIndex];
614
+ if (parameter) {
615
+ bindFunctionBindingName(context, parameter.name, representativeEntry.key.path, representativeEntry.key.value, bindings);
616
+ }
617
+ }
618
+ if (callbackBinding.receiverParameterIndex !== undefined) {
619
+ const receiverParameter = callbackDeclaration.parameters[callbackBinding.receiverParameterIndex];
620
+ if (receiverParameter) {
621
+ bindFunctionBindingName(context, receiverParameter.name, normalizeExpressionPath(context, receiver, state), getStateExpressionBoundValue(context, receiver, state) ?? receiver, bindings);
622
+ }
623
+ }
624
+ return functionLikeAffectsNarrow(context, callbackDeclaration, [], narrowPath, state, false, undefined, bindings);
625
+ }
626
+ function functionLikeAffectsNarrow(context, declaration, argumentsList, narrowPath, state, allowCapturedRead, receiverBinding, precomputedBindings, activeDeclarations = new Set()) {
627
+ const body = declaration.body;
628
+ if (!body || activeDeclarations.has(declaration)) {
629
+ return false;
630
+ }
631
+ activeDeclarations.add(declaration);
632
+ try {
633
+ const bindings = precomputedBindings ?? getFunctionBindings(context, argumentsList, declaration, state);
634
+ if (receiverBinding) {
635
+ bindFunctionReceiverPath(bindings, receiverBinding.path);
636
+ bindings.receiverMemberPaths = receiverBinding.memberPaths;
637
+ }
638
+ recordFunctionBodyConstBindings(context, body, bindings);
639
+ for (const candidate of getFlowInvalidationStructure(context, body, 'functionBody').candidates) {
640
+ if (candidate.kind === 'assignment') {
641
+ const leftPath = normalizeFunctionBodyPath(context, candidate.left, bindings);
642
+ if (leftPath && assignmentAffectsNarrow(context, candidate.node, leftPath, narrowPath)) {
643
+ return true;
644
+ }
645
+ }
646
+ if (candidate.kind === 'delete') {
647
+ const targetPath = normalizeFunctionBodyPath(context, candidate.expression, bindings);
648
+ if (targetPath && mutationAffectsNarrow(targetPath, narrowPath)) {
649
+ return true;
650
+ }
651
+ }
652
+ if (candidate.kind === 'update') {
653
+ const operandPath = normalizeFunctionBodyPath(context, candidate.operand, bindings);
654
+ if (operandPath &&
655
+ typedUpdateExpressionAffectsNarrow(context, candidate.node, operandPath, narrowPath)) {
656
+ return true;
657
+ }
658
+ }
659
+ if (candidate.kind === 'call') {
660
+ const directCalleeDeclaration = getFunctionLikeFromCallExpression(context, candidate.node);
661
+ const directCalleeHasBody = directCalleeDeclaration &&
662
+ isFunctionLikeWithBody(directCalleeDeclaration);
663
+ const calledMember = getFunctionBodyCalledMember(context, candidate.node.expression, bindings);
664
+ if (calledMember &&
665
+ arrayMutationCallAffectsNarrow(context, calledMember.receiver, normalizeFunctionBodyPath(context, calledMember.receiver, bindings), calledMember.member, calledMember.memberType, narrowPath)) {
666
+ return true;
667
+ }
668
+ if (calledMember &&
669
+ arrayCallbackArgumentAffectsNarrow(context, calledMember.receiver, calledMember.member, candidate.node, bindings, narrowPath, state)) {
670
+ return true;
671
+ }
672
+ if (calledMember &&
673
+ setCallbackArgumentAffectsNarrow(context, calledMember.receiver, calledMember.member, candidate.node, bindings, narrowPath, state)) {
674
+ return true;
675
+ }
676
+ if (calledMember &&
677
+ mapCallbackArgumentAffectsNarrow(context, calledMember.receiver, calledMember.member, candidate.node, bindings, narrowPath, state)) {
678
+ return true;
679
+ }
680
+ const boundMemberDeclaration = getFunctionLikeFromBoundMemberCall(context, candidate.node.expression, bindings);
681
+ const boundMemberHasBody = boundMemberDeclaration && isFunctionLikeWithBody(boundMemberDeclaration);
682
+ const receiverBinding = calledMember
683
+ ? getFunctionConstructedReceiverBinding(context, calledMember.receiver, bindings)
684
+ : undefined;
685
+ if (boundMemberHasBody &&
686
+ functionLikeAffectsNarrow(context, boundMemberDeclaration, candidate.node.arguments, narrowPath, state, false, receiverBinding, undefined, activeDeclarations)) {
687
+ return true;
688
+ }
689
+ if (ts.isElementAccessExpression(candidate.node.expression) ||
690
+ candidate.node.questionDotToken !== undefined) {
691
+ const receiver = ts.isPropertyAccessExpression(candidate.node.expression) ||
692
+ ts.isElementAccessExpression(candidate.node.expression)
693
+ ? candidate.node.expression.expression
694
+ : undefined;
695
+ if (receiver) {
696
+ const receiverPath = normalizeFunctionBodyPath(context, receiver, bindings);
697
+ if (receiverPath &&
698
+ receiverPath.baseSymbol === narrowPath.baseSymbol &&
699
+ receiverPath.segments.length === 0 &&
700
+ narrowPath.segments.length > 0) {
701
+ return true;
702
+ }
703
+ }
704
+ }
705
+ if (directCalleeHasBody &&
706
+ functionLikeAffectsNarrow(context, directCalleeDeclaration, candidate.node.arguments, narrowPath, state, false, receiverBinding, undefined, activeDeclarations)) {
707
+ return true;
708
+ }
709
+ if (ts.isIdentifier(candidate.node.expression)) {
710
+ const parameterSymbol = getExpressionSymbol(context, candidate.node.expression);
711
+ if (parameterSymbol) {
712
+ const boundValue = bindings.boundValues.get(getSymbolId(context, parameterSymbol));
713
+ const boundFunction = boundValue
714
+ ? getFunctionLikeFromBoundValue(context, boundValue)
715
+ : undefined;
716
+ const boundFunctionHasBody = boundFunction && isFunctionLikeWithBody(boundFunction);
717
+ if (boundFunctionHasBody &&
718
+ functionLikeAffectsNarrow(context, boundFunction, candidate.node.arguments, narrowPath, state, false, undefined, undefined, activeDeclarations)) {
719
+ return true;
720
+ }
721
+ }
722
+ }
723
+ if (!directCalleeHasBody &&
724
+ !boundMemberHasBody &&
725
+ candidate.node.arguments.some((argument) => opaqueFunctionBodyArgumentExpressionAffectsNarrow(context, argument, bindings, narrowPath, state, body))) {
726
+ return true;
727
+ }
728
+ }
729
+ if (allowCapturedRead &&
730
+ getMutableBindingSymbol(narrowPath) &&
731
+ candidate.kind === 'access') {
732
+ const usedPath = normalizeFunctionBodyPath(context, candidate.node, bindings);
733
+ if (usedPath && pathsMatch(usedPath, narrowPath)) {
734
+ return true;
735
+ }
736
+ }
737
+ if (candidate.kind === 'access' &&
738
+ ts.isIdentifier(candidate.node) &&
739
+ boundParameterAffectsNarrow(context, candidate.node, bindings, narrowPath, state)) {
740
+ return true;
741
+ }
742
+ }
743
+ return false;
744
+ }
745
+ finally {
746
+ activeDeclarations.delete(declaration);
747
+ }
748
+ }
749
+ function classInstanceMethodsAffectNarrow(context, constructorDeclaration, argumentsList, narrowPath, state) {
750
+ const classLike = constructorDeclaration.parent;
751
+ if (!ts.isClassLike(classLike)) {
752
+ return false;
753
+ }
754
+ let hasInstanceMethod = false;
755
+ const receiverBinding = getConstructorReceiverBindingFromState(context, constructorDeclaration, argumentsList, state);
756
+ for (const member of classLike.members) {
757
+ if ((ts.isMethodDeclaration(member) || ts.isGetAccessorDeclaration(member) ||
758
+ ts.isSetAccessorDeclaration(member)) &&
759
+ !hasStaticModifier(member)) {
760
+ hasInstanceMethod = true;
761
+ if (isFunctionLikeWithBody(member) &&
762
+ functionLikeAffectsNarrow(context, member, [], narrowPath, state, false, receiverBinding)) {
763
+ return true;
764
+ }
765
+ }
766
+ }
767
+ return hasInstanceMethod &&
768
+ argumentsList.some((argument) => expressionPathEscapesNarrow(context, argument, narrowPath, state));
769
+ }
770
+ function hasStaticModifier(node) {
771
+ return (ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Static) !== 0;
772
+ }
773
+ function escapingExpressionAffectsNarrow(context, expression, narrowPath, state, seenExpressions = new Set()) {
774
+ expression = ts.isParenthesizedExpression(expression) ? expression.expression : expression;
775
+ if (seenExpressions.has(expression)) {
776
+ return false;
777
+ }
778
+ seenExpressions.add(expression);
779
+ for (const candidate of getFlowInvalidationStructure(context, expression, 'expression').candidates) {
780
+ if (candidate.kind === 'access' &&
781
+ expressionPathEscapesNarrow(context, candidate.node, narrowPath, state)) {
782
+ return true;
783
+ }
784
+ if (candidate.kind === 'shorthandProperty') {
785
+ const boundValue = getShorthandStateBoundValue(context, candidate.node, state);
786
+ if (!boundValue) {
787
+ continue;
788
+ }
789
+ if (ts.isExpression(boundValue) &&
790
+ escapingExpressionAffectsNarrow(context, boundValue, narrowPath, state, seenExpressions)) {
791
+ return true;
792
+ }
793
+ const boundFunction = getFunctionLikeFromBoundValue(context, boundValue);
794
+ if (boundFunction &&
795
+ functionLikeAffectsNarrow(context, boundFunction, [], narrowPath, state, false)) {
796
+ return true;
797
+ }
798
+ }
799
+ if (candidate.kind === 'access' &&
800
+ ts.isIdentifier(candidate.node) &&
801
+ stateBoundValueAffectsNarrow(context, candidate.node, narrowPath, state, seenExpressions)) {
802
+ return true;
803
+ }
804
+ if (candidate.kind === 'functionLike' &&
805
+ functionLikeAffectsNarrow(context, candidate.node, [], narrowPath, state, false)) {
806
+ return true;
807
+ }
808
+ if (candidate.kind === 'call') {
809
+ const calledMember = getCalledMember(context, candidate.node.expression);
810
+ if (calledMember &&
811
+ arrayMutationCallAffectsNarrow(context, calledMember.receiver, normalizeExpressionPath(context, calledMember.receiver, state), calledMember.member, calledMember.memberType, narrowPath)) {
812
+ return true;
813
+ }
814
+ if (ts.isElementAccessExpression(candidate.node.expression) ||
815
+ candidate.node.questionDotToken !== undefined) {
816
+ const receiver = ts.isPropertyAccessExpression(candidate.node.expression) ||
817
+ ts.isElementAccessExpression(candidate.node.expression)
818
+ ? candidate.node.expression.expression
819
+ : undefined;
820
+ if (receiver) {
821
+ const receiverPath = normalizeExpressionPath(context, receiver, state);
822
+ if (receiverPath &&
823
+ receiverPath.baseSymbol === narrowPath.baseSymbol &&
824
+ receiverPath.segments.length === 0 &&
825
+ narrowPath.segments.length > 0) {
826
+ return true;
827
+ }
828
+ }
829
+ }
830
+ const calleeDeclaration = getFunctionLikeFromCallExpression(context, candidate.node);
831
+ if (calleeDeclaration &&
832
+ functionLikeAffectsNarrow(context, calleeDeclaration, candidate.node.arguments, narrowPath, state, true, calledMember
833
+ ? getStateConstructedReceiverBinding(context, calledMember.receiver, state, 'mutation')
834
+ : undefined)) {
835
+ return true;
836
+ }
837
+ if (!calleeDeclaration &&
838
+ candidate.node.arguments.some((argument) => opaqueArgumentExpressionAffectsNarrow(context, argument, narrowPath, state))) {
839
+ return true;
840
+ }
841
+ }
842
+ if (candidate.kind === 'new') {
843
+ const constructorDeclaration = context.checker.getResolvedSignature(candidate.node)
844
+ ?.declaration;
845
+ if (constructorDeclaration &&
846
+ ((isFunctionLikeWithBody(constructorDeclaration) &&
847
+ functionLikeAffectsNarrow(context, constructorDeclaration, candidate.node.arguments ?? [], narrowPath, state, false)) ||
848
+ classInstanceMethodsAffectNarrow(context, constructorDeclaration, candidate.node.arguments ?? [], narrowPath, state))) {
849
+ return true;
850
+ }
851
+ }
852
+ }
853
+ return false;
854
+ }
855
+ export const FLOW_FACT_ENVIRONMENT = {
856
+ appendSegment,
857
+ escapingExpressionAffectsNarrow,
858
+ normalizeExpressionPath,
859
+ normalizeWholeValueFactPath(context, expression, state) {
860
+ const path = normalizeExpressionPath(context, expression, state);
861
+ if (!path) {
862
+ return undefined;
863
+ }
864
+ const unwrappedExpression = ts.isParenthesizedExpression(expression) ||
865
+ ts.isAsExpression(expression) ||
866
+ ts.isTypeAssertionExpression(expression) ||
867
+ ts.isNonNullExpression(expression) ||
868
+ ts.isSatisfiesExpression(expression)
869
+ ? unwrapTransparentExpression(expression)
870
+ : expression;
871
+ if (!ts.isIdentifier(unwrappedExpression)) {
872
+ return path;
873
+ }
874
+ const symbol = getExpressionSymbol(context, unwrappedExpression);
875
+ if (!symbol) {
876
+ return path;
877
+ }
878
+ const localPath = {
879
+ baseSymbol: symbol,
880
+ segments: [],
881
+ };
882
+ return isConstLocalBindingPath(localPath) ? localPath : path;
883
+ },
884
+ shouldTrackFact(context, path) {
885
+ return !isStableConstLocalBindingPath(context, path);
886
+ },
887
+ };
888
+ function stateBoundValueAffectsNarrow(context, expression, narrowPath, state, seenExpressions = new Set()) {
889
+ if (ts.isParenthesizedExpression(expression)) {
890
+ return stateBoundValueAffectsNarrow(context, expression.expression, narrowPath, state, seenExpressions);
891
+ }
892
+ if (!ts.isIdentifier(expression)) {
893
+ return false;
894
+ }
895
+ if (seenExpressions.has(expression)) {
896
+ return false;
897
+ }
898
+ seenExpressions.add(expression);
899
+ const symbol = getExpressionSymbol(context, expression);
900
+ if (!symbol) {
901
+ return false;
902
+ }
903
+ const symbolId = getSymbolId(context, symbol);
904
+ if (state.extractedBindings.has(symbolId)) {
905
+ return false;
906
+ }
907
+ const boundValue = state.boundValues.get(symbolId);
908
+ if (!boundValue) {
909
+ return false;
910
+ }
911
+ if (ts.isExpression(boundValue) &&
912
+ escapingExpressionAffectsNarrow(context, boundValue, narrowPath, state, seenExpressions)) {
913
+ return true;
914
+ }
915
+ const boundFunction = getFunctionLikeFromBoundValue(context, boundValue);
916
+ return boundFunction !== undefined &&
917
+ functionLikeAffectsNarrow(context, boundFunction, [], narrowPath, state, false);
918
+ }
919
+ function getFlowInvalidationStructure(context, node, optionsKey) {
920
+ return context.facts.getFlowInvalidationStructure(node, optionsKey, () => parseFlowInvalidationStructure(node, optionsKey === 'expression'));
921
+ }
922
+ function parseFlowInvalidationStructure(rootNode, includeNestedFunctionLikeCandidates) {
923
+ const candidates = [];
924
+ const visit = (node) => {
925
+ if (isFunctionLikeWithBody(node)) {
926
+ if (includeNestedFunctionLikeCandidates) {
927
+ candidates.push({
928
+ kind: 'functionLike',
929
+ node,
930
+ });
931
+ }
932
+ return;
933
+ }
934
+ if (ts.isIdentifier(node) || ts.isPropertyAccessExpression(node) ||
935
+ ts.isElementAccessExpression(node)) {
936
+ candidates.push({
937
+ kind: 'access',
938
+ node,
939
+ });
940
+ }
941
+ else if (ts.isBinaryExpression(node) &&
942
+ MUTATING_ASSIGNMENT_OPERATORS.has(node.operatorToken.kind)) {
943
+ candidates.push({
944
+ kind: 'assignment',
945
+ left: node.left,
946
+ node,
947
+ right: node.right,
948
+ });
949
+ }
950
+ else if (ts.isDeleteExpression(node)) {
951
+ candidates.push({
952
+ kind: 'delete',
953
+ expression: node.expression,
954
+ node,
955
+ });
956
+ }
957
+ else {
958
+ const updateOperand = getUpdateExpressionOperand(node);
959
+ if (updateOperand &&
960
+ (ts.isPrefixUnaryExpression(node) || ts.isPostfixUnaryExpression(node))) {
961
+ candidates.push({
962
+ kind: 'update',
963
+ node,
964
+ operand: updateOperand,
965
+ });
966
+ }
967
+ else if (ts.isAwaitExpression(node) || ts.isYieldExpression(node)) {
968
+ candidates.push({
969
+ kind: 'awaitYield',
970
+ node,
971
+ });
972
+ }
973
+ else if (ts.isCallExpression(node)) {
974
+ candidates.push({
975
+ kind: 'call',
976
+ node,
977
+ });
978
+ }
979
+ else if (ts.isShorthandPropertyAssignment(node)) {
980
+ candidates.push({
981
+ kind: 'shorthandProperty',
982
+ node,
983
+ });
984
+ }
985
+ else if (ts.isNewExpression(node)) {
986
+ candidates.push({
987
+ kind: 'new',
988
+ node,
989
+ });
990
+ }
991
+ }
992
+ ts.forEachChild(node, visit);
993
+ };
994
+ visit(rootNode);
995
+ return { candidates };
996
+ }
997
+ export function statementAffectsNarrow(context, statement, narrowPath, state) {
998
+ for (const candidate of getFlowInvalidationStructure(context, statement, 'statement').candidates) {
999
+ if (candidate.kind === 'awaitYield') {
1000
+ if (narrowPath.segments.length > 0) {
1001
+ return candidate.node;
1002
+ }
1003
+ }
1004
+ if (candidate.kind === 'assignment') {
1005
+ const leftPath = getInvalidationPath(context, candidate.left, state, 'mutation');
1006
+ if (leftPath && assignmentAffectsNarrow(context, candidate.node, leftPath, narrowPath)) {
1007
+ return candidate.left;
1008
+ }
1009
+ if (leftPath &&
1010
+ !isLocalBindingPath(leftPath) &&
1011
+ escapingExpressionAffectsNarrow(context, candidate.right, narrowPath, state)) {
1012
+ return candidate.left;
1013
+ }
1014
+ }
1015
+ if (candidate.kind === 'delete') {
1016
+ const targetPath = getInvalidationPath(context, candidate.expression, state, 'mutation');
1017
+ if (targetPath && mutationAffectsNarrow(targetPath, narrowPath)) {
1018
+ return candidate.expression;
1019
+ }
1020
+ }
1021
+ if (candidate.kind === 'update') {
1022
+ const operandPath = getInvalidationPath(context, candidate.operand, state, 'mutation');
1023
+ if (operandPath &&
1024
+ typedUpdateExpressionAffectsNarrow(context, candidate.node, operandPath, narrowPath)) {
1025
+ return candidate.operand;
1026
+ }
1027
+ }
1028
+ if (candidate.kind === 'call') {
1029
+ const calledMember = getCalledMember(context, candidate.node.expression);
1030
+ const receiverBinding = calledMember
1031
+ ? getStateConstructedReceiverBinding(context, calledMember.receiver, state, 'mutation')
1032
+ : undefined;
1033
+ if (calledMember &&
1034
+ arrayMutationCallAffectsNarrow(context, calledMember.receiver, receiverBinding?.path, calledMember.member, calledMember.memberType, narrowPath)) {
1035
+ return candidate.node;
1036
+ }
1037
+ if (calledMember &&
1038
+ arrayCallbackExpressionAffectsNarrow(context, calledMember.receiver, calledMember.member, candidate.node, narrowPath, state)) {
1039
+ return candidate.node;
1040
+ }
1041
+ if (calledMember &&
1042
+ setCallbackExpressionAffectsNarrow(context, calledMember.receiver, calledMember.member, candidate.node, narrowPath, state)) {
1043
+ return candidate.node;
1044
+ }
1045
+ if (calledMember &&
1046
+ mapCallbackExpressionAffectsNarrow(context, calledMember.receiver, calledMember.member, candidate.node, narrowPath, state)) {
1047
+ return candidate.node;
1048
+ }
1049
+ if (ts.isElementAccessExpression(candidate.node.expression) ||
1050
+ candidate.node.questionDotToken !== undefined) {
1051
+ const receiver = ts.isPropertyAccessExpression(candidate.node.expression) ||
1052
+ ts.isElementAccessExpression(candidate.node.expression)
1053
+ ? candidate.node.expression.expression
1054
+ : undefined;
1055
+ if (!receiver) {
1056
+ continue;
1057
+ }
1058
+ const receiverPath = normalizeExpressionPath(context, receiver, state);
1059
+ if (receiverPath &&
1060
+ receiverPath.baseSymbol === narrowPath.baseSymbol &&
1061
+ receiverPath.segments.length === 0 &&
1062
+ narrowPath.segments.length > 0) {
1063
+ return candidate.node;
1064
+ }
1065
+ }
1066
+ const calleeDeclaration = getFunctionLikeFromCallExpression(context, candidate.node);
1067
+ if (calleeDeclaration &&
1068
+ functionLikeAffectsNarrow(context, calleeDeclaration, candidate.node.arguments, narrowPath, state, true, receiverBinding)) {
1069
+ return candidate.node;
1070
+ }
1071
+ if (!calleeDeclaration &&
1072
+ candidate.node.arguments.some((argument) => {
1073
+ if (!opaqueArgumentExpressionAffectsNarrow(context, argument, narrowPath, state)) {
1074
+ return false;
1075
+ }
1076
+ if (!ts.isReturnStatement(statement)) {
1077
+ return true;
1078
+ }
1079
+ return !isExtractedReadOnlyReturnArgument(context, argument, state);
1080
+ })) {
1081
+ return candidate.node;
1082
+ }
1083
+ }
1084
+ if (candidate.kind === 'new') {
1085
+ const constructorDeclaration = context.checker.getResolvedSignature(candidate.node)
1086
+ ?.declaration;
1087
+ if (constructorDeclaration &&
1088
+ isFunctionLikeWithBody(constructorDeclaration) &&
1089
+ functionLikeAffectsNarrow(context, constructorDeclaration, candidate.node.arguments ?? [], narrowPath, state, true)) {
1090
+ return candidate.node;
1091
+ }
1092
+ }
1093
+ }
1094
+ return undefined;
1095
+ }
1096
+ export function prepareChildRegionState(context, statement, state) {
1097
+ if (ts.isForStatement(statement) && statement.initializer) {
1098
+ const preparedState = cloneState(state);
1099
+ if (ts.isVariableDeclarationList(statement.initializer)) {
1100
+ for (const declaration of statement.initializer.declarations) {
1101
+ recordVariableAliases(context, declaration, preparedState);
1102
+ }
1103
+ return preparedState;
1104
+ }
1105
+ recordExecutedExpressionAliases(context, statement.initializer, preparedState);
1106
+ return preparedState;
1107
+ }
1108
+ if (ts.isForOfStatement(statement) &&
1109
+ ts.isVariableDeclarationList(statement.initializer)) {
1110
+ const preparedState = cloneState(state);
1111
+ for (const declaration of statement.initializer.declarations) {
1112
+ if (!recordForOfLoopHeaderAliases(context, declaration.name, statement.expression, preparedState)) {
1113
+ recordVariableAliases(context, declaration, preparedState);
1114
+ }
1115
+ }
1116
+ return preparedState;
1117
+ }
1118
+ return state;
1119
+ }