@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,1224 @@
1
+ import ts from 'typescript';
2
+
3
+ import { SOUND_DIAGNOSTIC_CODES } from '../engine/diagnostic_codes.ts';
4
+ import type {
5
+ AnalysisContext,
6
+ NamespacePathFact,
7
+ NamespacePathSegment,
8
+ NamespaceResolverFact,
9
+ NamespaceShapeFact,
10
+ } from '../engine/types.ts';
11
+ import { getNodeDiagnosticRange, type SoundDiagnostic } from '../diagnostics.ts';
12
+ import { collectExportedSymbolsBySourceFile } from './non_ordinary_recovery.ts';
13
+ import { isImportCall, isRequireCall } from './foreign_boundary.ts';
14
+ import { getResolvedBuiltinSignatureInfo } from './resolved_builtins.ts';
15
+
16
+ const MODULE_NAMESPACE_MESSAGE =
17
+ 'Module namespace objects cannot be assigned, aliased, passed, or returned in soundscript.';
18
+ const MODULE_NAMESPACE_NOTES = [
19
+ 'Only direct exported-member reads from a namespace import are allowed.',
20
+ ];
21
+ const MODULE_NAMESPACE_HINT =
22
+ 'Read the exported member you need immediately instead of storing or forwarding the namespace object.';
23
+
24
+ type LocalFunctionLikeWithBody =
25
+ | ts.ArrowFunction
26
+ | ts.FunctionDeclaration
27
+ | ts.FunctionExpression
28
+ | ts.MethodDeclaration;
29
+
30
+ function createNamespaceEscapeDiagnostic(node: ts.Node): SoundDiagnostic {
31
+ return {
32
+ source: 'sound',
33
+ code: SOUND_DIAGNOSTIC_CODES.exoticObjectWidening,
34
+ category: 'error',
35
+ message: MODULE_NAMESPACE_MESSAGE,
36
+ metadata: {
37
+ rule: 'module_namespace_escape',
38
+ fixability: 'local_rewrite',
39
+ invariant:
40
+ 'Module namespace objects may only be used for immediate exported-member reads inside soundscript.',
41
+ replacementFamily: 'direct_exported_member_read',
42
+ counterexample:
43
+ 'Forwarding a namespace object hides which export is actually used and lets module-namespace behavior escape ordinary code.',
44
+ example: 'Read the member immediately, for example `const add = math.add;` instead of storing `math`.',
45
+ },
46
+ notes: MODULE_NAMESPACE_NOTES,
47
+ hint: MODULE_NAMESPACE_HINT,
48
+ ...getNodeDiagnosticRange(node),
49
+ };
50
+ }
51
+
52
+ function createWholeNamespacePath(guard?: 'fulfilled'): NamespacePathFact {
53
+ return { guard, path: [] };
54
+ }
55
+
56
+ function createWholeNamespaceShape(
57
+ origin: NamespaceShapeFact['origin'],
58
+ guard?: 'fulfilled',
59
+ ): NamespaceShapeFact {
60
+ return {
61
+ origin,
62
+ paths: [createWholeNamespacePath(guard)],
63
+ };
64
+ }
65
+
66
+ function createWholeNamespaceResolver(
67
+ origin: NamespaceResolverFact['origin'],
68
+ ): NamespaceResolverFact {
69
+ return {
70
+ ambiguous: false,
71
+ origin,
72
+ paths: [createWholeNamespacePath()],
73
+ };
74
+ }
75
+
76
+ function unwrapTransparentExpression(expression: ts.Expression): ts.Expression {
77
+ let current = expression;
78
+
79
+ while (true) {
80
+ if (ts.isParenthesizedExpression(current) || ts.isNonNullExpression(current)) {
81
+ current = current.expression;
82
+ continue;
83
+ }
84
+
85
+ if (ts.isSatisfiesExpression(current) || ts.isAsExpression(current)) {
86
+ current = current.expression;
87
+ continue;
88
+ }
89
+
90
+ return current;
91
+ }
92
+ }
93
+
94
+ function isConstVariableDeclaration(node: ts.VariableDeclaration): boolean {
95
+ return ts.isVariableDeclarationList(node.parent) &&
96
+ (node.parent.flags & ts.NodeFlags.Const) !== 0;
97
+ }
98
+
99
+ function isTypePositionIdentifier(node: ts.Identifier): boolean {
100
+ const parent = node.parent;
101
+
102
+ return (ts.isTypeReferenceNode(parent) && parent.typeName === node) ||
103
+ (ts.isExpressionWithTypeArguments(parent) && parent.expression === node) ||
104
+ ts.isTypeQueryNode(parent) ||
105
+ ts.isImportTypeNode(parent) ||
106
+ ts.isQualifiedName(parent);
107
+ }
108
+
109
+ function isLocalFunctionLikeWithBody(node: ts.Node): node is LocalFunctionLikeWithBody {
110
+ return (ts.isArrowFunction(node) ||
111
+ ts.isFunctionDeclaration(node) ||
112
+ ts.isFunctionExpression(node) ||
113
+ ts.isMethodDeclaration(node)) &&
114
+ node.body !== undefined;
115
+ }
116
+
117
+ function getLocalSymbol(
118
+ context: AnalysisContext,
119
+ expression: ts.Expression,
120
+ ): ts.Symbol | undefined {
121
+ if (
122
+ ts.isIdentifier(expression) &&
123
+ ts.isShorthandPropertyAssignment(expression.parent) &&
124
+ expression.parent.name === expression
125
+ ) {
126
+ return context.checker.getShorthandAssignmentValueSymbol(expression.parent) ??
127
+ context.checker.getSymbolAtLocation(expression);
128
+ }
129
+
130
+ return context.checker.getSymbolAtLocation(expression);
131
+ }
132
+
133
+ function isTransparentNamespaceUseParent(parent: ts.Node, child: ts.Node): boolean {
134
+ return ((ts.isParenthesizedExpression(parent) ||
135
+ ts.isNonNullExpression(parent) ||
136
+ ts.isSatisfiesExpression(parent) ||
137
+ ts.isAsExpression(parent)) &&
138
+ parent.expression === child);
139
+ }
140
+
141
+ function pathSegmentEquals(left: NamespacePathSegment, right: NamespacePathSegment): boolean {
142
+ if (left.kind !== right.kind) {
143
+ return false;
144
+ }
145
+
146
+ return left.kind === 'index'
147
+ ? left.index === (right as NamespacePathSegment & { kind: 'index' }).index
148
+ : left.name === (right as NamespacePathSegment & { kind: 'property' }).name;
149
+ }
150
+
151
+ function getPropertySegmentName(
152
+ expression:
153
+ | ts.ElementAccessChain
154
+ | ts.ElementAccessExpression
155
+ | ts.PropertyAccessChain
156
+ | ts.PropertyAccessExpression,
157
+ ): string | undefined {
158
+ if (ts.isPropertyAccessExpression(expression) || ts.isPropertyAccessChain(expression)) {
159
+ return expression.name.text;
160
+ }
161
+
162
+ const argument = expression.argumentExpression;
163
+ if (
164
+ argument &&
165
+ (ts.isStringLiteral(argument) || ts.isNoSubstitutionTemplateLiteral(argument))
166
+ ) {
167
+ return argument.text;
168
+ }
169
+
170
+ return undefined;
171
+ }
172
+
173
+ function getIndexSegmentValue(
174
+ expression: ts.ElementAccessChain | ts.ElementAccessExpression,
175
+ ): number | undefined {
176
+ const argument = expression.argumentExpression;
177
+ if (!argument) {
178
+ return undefined;
179
+ }
180
+
181
+ if (ts.isNumericLiteral(argument)) {
182
+ return Number(argument.text);
183
+ }
184
+
185
+ if (
186
+ ts.isStringLiteral(argument) ||
187
+ ts.isNoSubstitutionTemplateLiteral(argument)
188
+ ) {
189
+ const numericValue = Number(argument.text);
190
+ return Number.isInteger(numericValue) ? numericValue : undefined;
191
+ }
192
+
193
+ return undefined;
194
+ }
195
+
196
+ function projectShapeBySegment(
197
+ shape: NamespaceShapeFact,
198
+ segment: NamespacePathSegment,
199
+ ): NamespaceShapeFact | undefined {
200
+ const nextPaths: NamespacePathFact[] = [];
201
+
202
+ for (const pathFact of shape.paths) {
203
+ const [head, ...tail] = pathFact.path;
204
+ if (!head || !pathSegmentEquals(head, segment)) {
205
+ continue;
206
+ }
207
+
208
+ nextPaths.push({
209
+ guard: pathFact.guard,
210
+ path: tail,
211
+ });
212
+ }
213
+
214
+ return nextPaths.length > 0
215
+ ? {
216
+ origin: shape.origin,
217
+ paths: nextPaths,
218
+ }
219
+ : undefined;
220
+ }
221
+
222
+ function prependPathSegment(
223
+ pathFact: NamespacePathFact,
224
+ segment: NamespacePathSegment,
225
+ ): NamespacePathFact {
226
+ return {
227
+ guard: pathFact.guard,
228
+ path: [segment, ...pathFact.path],
229
+ };
230
+ }
231
+
232
+ function appendPathSegment(
233
+ pathFact: NamespacePathFact,
234
+ segment: NamespacePathSegment,
235
+ ): NamespacePathFact {
236
+ return {
237
+ guard: pathFact.guard,
238
+ path: [...pathFact.path, segment],
239
+ };
240
+ }
241
+
242
+ function withFulfilledGuard(
243
+ pathFact: NamespacePathFact,
244
+ ): NamespacePathFact {
245
+ return {
246
+ guard: 'fulfilled',
247
+ path: pathFact.path,
248
+ };
249
+ }
250
+
251
+ function normalizeNamespaceShapeKey(
252
+ shape: Pick<NamespaceResolverFact | NamespaceShapeFact, 'paths'>,
253
+ ): string {
254
+ return shape.paths.map((pathFact) =>
255
+ `${pathFact.guard ?? 'none'}:${
256
+ pathFact.path.map((segment) =>
257
+ segment.kind === 'index' ? `[${segment.index}]` : `.${segment.name}`
258
+ ).join('')
259
+ }`
260
+ ).sort().join('|');
261
+ }
262
+
263
+ function createArrayResolverResult(
264
+ resolverMethod: 'all' | 'allSettled',
265
+ elementResolvers: readonly NamespaceResolverFact[],
266
+ ): NamespaceResolverFact {
267
+ const paths: NamespacePathFact[] = [];
268
+
269
+ for (const [index, resolver] of elementResolvers.entries()) {
270
+ for (const pathFact of resolver.paths) {
271
+ const indexedPath = prependPathSegment(pathFact, { index, kind: 'index' });
272
+ paths.push(
273
+ resolverMethod === 'allSettled'
274
+ ? appendPathSegment(withFulfilledGuard(indexedPath), {
275
+ kind: 'property',
276
+ name: 'value',
277
+ })
278
+ : indexedPath,
279
+ );
280
+ }
281
+ }
282
+
283
+ return {
284
+ ambiguous: false,
285
+ origin: 'resolver',
286
+ paths,
287
+ };
288
+ }
289
+
290
+ function getConstInitializerForIdentifier(
291
+ context: AnalysisContext,
292
+ expression: ts.Expression,
293
+ seenSymbols = new Set<ts.Symbol>(),
294
+ ): ts.Expression | undefined {
295
+ const current = unwrapTransparentExpression(expression);
296
+ if (!ts.isIdentifier(current)) {
297
+ return undefined;
298
+ }
299
+
300
+ const symbol = getLocalSymbol(context, current);
301
+ if (!symbol || seenSymbols.has(symbol)) {
302
+ return undefined;
303
+ }
304
+ seenSymbols.add(symbol);
305
+
306
+ for (const declaration of symbol.getDeclarations() ?? []) {
307
+ if (
308
+ ts.isVariableDeclaration(declaration) &&
309
+ declaration.initializer &&
310
+ isConstVariableDeclaration(declaration)
311
+ ) {
312
+ return declaration.initializer;
313
+ }
314
+ }
315
+
316
+ return undefined;
317
+ }
318
+
319
+ function getResolverElementExpressions(
320
+ context: AnalysisContext,
321
+ expression: ts.Expression,
322
+ seenSymbols = new Set<ts.Symbol>(),
323
+ ): readonly ts.Expression[] | undefined {
324
+ const current = unwrapTransparentExpression(expression);
325
+
326
+ if (ts.isArrayLiteralExpression(current)) {
327
+ if (current.elements.some(ts.isSpreadElement)) {
328
+ return undefined;
329
+ }
330
+
331
+ return current.elements.filter(ts.isExpression);
332
+ }
333
+
334
+ const initializer = getConstInitializerForIdentifier(context, current, seenSymbols);
335
+ return initializer ? getResolverElementExpressions(context, initializer, seenSymbols) : undefined;
336
+ }
337
+
338
+ function getPromiseStaticMethodName(
339
+ context: AnalysisContext,
340
+ node: ts.CallExpression,
341
+ ): 'all' | 'allSettled' | 'any' | 'race' | 'resolve' | undefined {
342
+ const info = getResolvedBuiltinSignatureInfo(context, node);
343
+ if (!info || info.ownerName !== 'PromiseConstructor') {
344
+ return undefined;
345
+ }
346
+
347
+ switch (info.memberName) {
348
+ case 'all':
349
+ case 'allSettled':
350
+ case 'any':
351
+ case 'race':
352
+ case 'resolve':
353
+ return info.memberName;
354
+ default:
355
+ return undefined;
356
+ }
357
+ }
358
+
359
+ function getPromiseInstanceMethodInfo(
360
+ context: AnalysisContext,
361
+ node: ts.CallExpression,
362
+ ): { method: 'catch' | 'finally' | 'then'; target: ts.Expression } | undefined {
363
+ const info = getResolvedBuiltinSignatureInfo(context, node);
364
+ if (
365
+ !info ||
366
+ (info.ownerName !== 'Promise' && info.ownerName !== 'PromiseLike') ||
367
+ (info.memberName !== 'then' && info.memberName !== 'catch' && info.memberName !== 'finally')
368
+ ) {
369
+ return undefined;
370
+ }
371
+
372
+ if (ts.isPropertyAccessExpression(node.expression)) {
373
+ const method = node.expression.name.text;
374
+ if (method === 'then' || method === 'catch' || method === 'finally') {
375
+ return { method, target: node.expression.expression };
376
+ }
377
+ }
378
+
379
+ if (
380
+ ts.isElementAccessExpression(node.expression) &&
381
+ node.expression.argumentExpression &&
382
+ (ts.isStringLiteral(node.expression.argumentExpression) ||
383
+ ts.isNoSubstitutionTemplateLiteral(node.expression.argumentExpression))
384
+ ) {
385
+ const method = node.expression.argumentExpression.text;
386
+ if (method === 'then' || method === 'catch' || method === 'finally') {
387
+ return { method, target: node.expression.expression };
388
+ }
389
+ }
390
+
391
+ return undefined;
392
+ }
393
+
394
+ function getNamespaceShapeFromModuleNamespaceExportSummary(
395
+ summary: ReturnType<AnalysisContext['exportSummaries']['get']>,
396
+ ): NamespaceShapeFact | undefined {
397
+ return summary?.kind === 'value' && summary.fact.family === 'moduleNamespace'
398
+ ? createWholeNamespaceShape('staticImport')
399
+ : undefined;
400
+ }
401
+
402
+ function computeNamespaceShapeFromExportSummary(
403
+ context: AnalysisContext,
404
+ symbol: ts.Symbol,
405
+ seenSymbols = new Set<ts.Symbol>(),
406
+ ): NamespaceShapeFact | undefined {
407
+ const canonicalSymbol = context.exportSummaries.canonicalizeSymbol(symbol);
408
+ if (seenSymbols.has(canonicalSymbol)) {
409
+ return undefined;
410
+ }
411
+ seenSymbols.add(canonicalSymbol);
412
+
413
+ const cachedShape = getNamespaceShapeFromModuleNamespaceExportSummary(
414
+ context.exportSummaries.get(canonicalSymbol),
415
+ );
416
+ if (cachedShape) {
417
+ return cachedShape;
418
+ }
419
+
420
+ for (const declaration of canonicalSymbol.getDeclarations() ?? []) {
421
+ let shape: NamespaceShapeFact | undefined;
422
+
423
+ if (
424
+ ts.isVariableDeclaration(declaration) &&
425
+ declaration.initializer &&
426
+ ts.isIdentifier(declaration.name)
427
+ ) {
428
+ shape = getWholeNamespaceExportShape(context, declaration.initializer);
429
+ } else if (ts.isExportAssignment(declaration) && !declaration.isExportEquals) {
430
+ shape = getWholeNamespaceExportShape(context, declaration.expression);
431
+ } else if (ts.isExportSpecifier(declaration)) {
432
+ const localSymbol = context.checker.getSymbolAtLocation(
433
+ declaration.propertyName ?? declaration.name,
434
+ );
435
+ shape = localSymbol
436
+ ? computeNamespaceShapeFromExportSummary(context, localSymbol, seenSymbols) ??
437
+ getKnownNamespaceShape(context, declaration.propertyName ?? declaration.name)
438
+ : undefined;
439
+ } else if (ts.isNamespaceExport(declaration)) {
440
+ shape = createWholeNamespaceShape('staticImport');
441
+ }
442
+
443
+ if (shape && isWholeNamespaceShape(shape)) {
444
+ context.exportSummaries.set(canonicalSymbol, {
445
+ kind: 'value',
446
+ fact: { family: 'moduleNamespace' },
447
+ });
448
+ return createWholeNamespaceShape('staticImport');
449
+ }
450
+ }
451
+
452
+ return undefined;
453
+ }
454
+
455
+ function getNamespaceShapeFromExportSummary(
456
+ context: AnalysisContext,
457
+ symbol: ts.Symbol,
458
+ ): NamespaceShapeFact | undefined {
459
+ return computeNamespaceShapeFromExportSummary(context, symbol);
460
+ }
461
+
462
+ function getIdentifierNamespaceShape(
463
+ context: AnalysisContext,
464
+ expression: ts.Identifier,
465
+ ): NamespaceShapeFact | undefined {
466
+ const symbol = getLocalSymbol(context, expression);
467
+ if (!symbol) {
468
+ return undefined;
469
+ }
470
+
471
+ return context.facts.getNamespaceShapeSymbol(symbol) ??
472
+ getNamespaceShapeFromExportSummary(context, symbol) ??
473
+ ((symbol.getDeclarations() ?? []).some(ts.isNamespaceImport)
474
+ ? createWholeNamespaceShape('staticImport')
475
+ : undefined);
476
+ }
477
+
478
+ function getDefaultExportSymbol(
479
+ context: AnalysisContext,
480
+ sourceFile: ts.SourceFile,
481
+ ): ts.Symbol | undefined {
482
+ const moduleSymbol = context.checker.getSymbolAtLocation(sourceFile);
483
+ if (!moduleSymbol) {
484
+ return undefined;
485
+ }
486
+
487
+ return context.checker.getExportsOfModule(moduleSymbol).find((symbol) =>
488
+ symbol.escapedName === 'default'
489
+ );
490
+ }
491
+
492
+ function getIdentifierNamespaceResolver(
493
+ context: AnalysisContext,
494
+ expression: ts.Identifier,
495
+ ): NamespaceResolverFact | undefined {
496
+ const symbol = getLocalSymbol(context, expression);
497
+ return symbol ? context.facts.getNamespaceResolverSymbol(symbol) : undefined;
498
+ }
499
+
500
+ function getNamespaceResolverInternal(
501
+ context: AnalysisContext,
502
+ expression: ts.Expression,
503
+ ): NamespaceResolverFact | undefined {
504
+ const current = unwrapTransparentExpression(expression);
505
+
506
+ if (ts.isIdentifier(current)) {
507
+ return getIdentifierNamespaceResolver(context, current);
508
+ }
509
+
510
+ if (ts.isCallExpression(current)) {
511
+ if (isImportCall(current)) {
512
+ return createWholeNamespaceResolver('dynamicImport');
513
+ }
514
+
515
+ const staticMethod = getPromiseStaticMethodName(context, current);
516
+ if (staticMethod === 'resolve') {
517
+ const wrapped = current.arguments[0];
518
+ return wrapped ? getNamespaceResolver(context, wrapped) : undefined;
519
+ }
520
+
521
+ if (
522
+ staticMethod === 'all' ||
523
+ staticMethod === 'allSettled' ||
524
+ staticMethod === 'race' ||
525
+ staticMethod === 'any'
526
+ ) {
527
+ const input = current.arguments[0];
528
+ if (!input) {
529
+ return undefined;
530
+ }
531
+
532
+ const elementExpressions = getResolverElementExpressions(context, input);
533
+ if (!elementExpressions || elementExpressions.length === 0) {
534
+ return undefined;
535
+ }
536
+
537
+ const elementResolvers = elementExpressions.map((element) =>
538
+ getNamespaceResolver(context, element)
539
+ );
540
+ if (elementResolvers.some((resolver) => resolver?.ambiguous)) {
541
+ return {
542
+ ambiguous: true,
543
+ origin: 'resolver',
544
+ paths: [],
545
+ };
546
+ }
547
+
548
+ const presentResolvers = elementResolvers.filter((
549
+ resolver,
550
+ ): resolver is NamespaceResolverFact => resolver !== undefined);
551
+ if (presentResolvers.length === 0) {
552
+ return undefined;
553
+ }
554
+
555
+ if (staticMethod === 'all' || staticMethod === 'allSettled') {
556
+ return presentResolvers.length === elementResolvers.length
557
+ ? createArrayResolverResult(staticMethod, presentResolvers)
558
+ : {
559
+ ambiguous: true,
560
+ origin: 'resolver',
561
+ paths: [],
562
+ };
563
+ }
564
+
565
+ const firstShape = presentResolvers[0];
566
+ if (!firstShape) {
567
+ return undefined;
568
+ }
569
+
570
+ const normalizedKey = normalizeNamespaceShapeKey(firstShape);
571
+ const allCompatible = presentResolvers.length === elementResolvers.length &&
572
+ presentResolvers.every((resolver) =>
573
+ normalizeNamespaceShapeKey(resolver) === normalizedKey
574
+ );
575
+ return allCompatible
576
+ ? {
577
+ ambiguous: false,
578
+ origin: 'resolver',
579
+ paths: firstShape.paths,
580
+ }
581
+ : {
582
+ ambiguous: true,
583
+ origin: 'resolver',
584
+ paths: [],
585
+ };
586
+ }
587
+
588
+ const promiseMethod = getPromiseInstanceMethodInfo(context, current);
589
+ if (promiseMethod?.method === 'catch' || promiseMethod?.method === 'finally') {
590
+ return getNamespaceResolver(context, promiseMethod.target);
591
+ }
592
+ }
593
+
594
+ return undefined;
595
+ }
596
+
597
+ function getNamespaceShapeInternal(
598
+ context: AnalysisContext,
599
+ expression: ts.Expression,
600
+ ): NamespaceShapeFact | undefined {
601
+ const current = unwrapTransparentExpression(expression);
602
+
603
+ if (ts.isIdentifier(current)) {
604
+ return getIdentifierNamespaceShape(context, current);
605
+ }
606
+
607
+ if (ts.isAwaitExpression(current)) {
608
+ const resolver = getNamespaceResolver(context, current.expression);
609
+ return resolver && !resolver.ambiguous
610
+ ? {
611
+ origin: resolver.origin === 'dynamicImport' ? 'dynamicImport' : 'resolver',
612
+ paths: resolver.paths,
613
+ }
614
+ : undefined;
615
+ }
616
+
617
+ if (ts.isCallExpression(current) && isRequireCall(current)) {
618
+ return createWholeNamespaceShape('require');
619
+ }
620
+
621
+ if (ts.isPropertyAccessExpression(current) || ts.isPropertyAccessChain(current)) {
622
+ const baseShape = getKnownNamespaceShape(context, current.expression);
623
+ if (!baseShape) {
624
+ return undefined;
625
+ }
626
+
627
+ return projectShapeBySegment(baseShape, {
628
+ kind: 'property',
629
+ name: current.name.text,
630
+ });
631
+ }
632
+
633
+ if (ts.isElementAccessExpression(current) || ts.isElementAccessChain(current)) {
634
+ const baseShape = getKnownNamespaceShape(context, current.expression);
635
+ if (!baseShape) {
636
+ return undefined;
637
+ }
638
+
639
+ const index = getIndexSegmentValue(current);
640
+ if (index !== undefined) {
641
+ return projectShapeBySegment(baseShape, {
642
+ index,
643
+ kind: 'index',
644
+ });
645
+ }
646
+
647
+ const propertyName = getPropertySegmentName(current);
648
+ return propertyName
649
+ ? projectShapeBySegment(baseShape, {
650
+ kind: 'property',
651
+ name: propertyName,
652
+ })
653
+ : undefined;
654
+ }
655
+
656
+ return undefined;
657
+ }
658
+
659
+ export function getNamespaceResolver(
660
+ context: AnalysisContext,
661
+ expression: ts.Expression,
662
+ ): NamespaceResolverFact | undefined {
663
+ return context.facts.getNamespaceResolver(
664
+ expression,
665
+ () => getNamespaceResolverInternal(context, expression),
666
+ );
667
+ }
668
+
669
+ export function getKnownNamespaceShape(
670
+ context: AnalysisContext,
671
+ expression: ts.Expression,
672
+ ): NamespaceShapeFact | undefined {
673
+ return context.facts.getNamespaceShape(
674
+ expression,
675
+ () => getNamespaceShapeInternal(context, expression),
676
+ );
677
+ }
678
+
679
+ function isWholeNamespaceShape(shape: NamespaceShapeFact): boolean {
680
+ return shape.paths.some((pathFact) => pathFact.path.length === 0);
681
+ }
682
+
683
+ function getAllowedNamespaceSeedShape(
684
+ context: AnalysisContext,
685
+ expression: ts.Expression,
686
+ ): NamespaceShapeFact | undefined {
687
+ const current = unwrapTransparentExpression(expression);
688
+
689
+ if (ts.isAwaitExpression(current)) {
690
+ const resolver = getNamespaceResolver(context, current.expression);
691
+ return resolver && !resolver.ambiguous
692
+ ? {
693
+ origin: resolver.origin === 'dynamicImport' ? 'dynamicImport' : 'resolver',
694
+ paths: resolver.paths,
695
+ }
696
+ : undefined;
697
+ }
698
+
699
+ if (ts.isCallExpression(current) && isRequireCall(current)) {
700
+ return createWholeNamespaceShape('require');
701
+ }
702
+
703
+ return undefined;
704
+ }
705
+
706
+ function getWholeNamespaceExportShape(
707
+ context: AnalysisContext,
708
+ expression: ts.Expression,
709
+ ): NamespaceShapeFact | undefined {
710
+ const shape = getAllowedNamespaceSeedShape(context, expression) ??
711
+ getKnownNamespaceShape(context, expression);
712
+ return shape && isWholeNamespaceShape(shape) ? shape : undefined;
713
+ }
714
+
715
+ function getShapeAtArrayIndex(
716
+ shape: NamespaceShapeFact,
717
+ index: number,
718
+ ): NamespaceShapeFact | undefined {
719
+ return projectShapeBySegment(shape, {
720
+ index,
721
+ kind: 'index',
722
+ });
723
+ }
724
+
725
+ function isSimpleNamespaceProjectionObjectPattern(pattern: ts.ObjectBindingPattern): boolean {
726
+ return pattern.elements.every((element) => {
727
+ if (element.dotDotDotToken) {
728
+ return false;
729
+ }
730
+
731
+ return ts.isIdentifier(element.name);
732
+ });
733
+ }
734
+
735
+ function seedBindingNameFromShape(
736
+ context: AnalysisContext,
737
+ bindingName: ts.BindingName,
738
+ shape: NamespaceShapeFact,
739
+ ): boolean {
740
+ if (!canBindFromShape(bindingName, shape)) {
741
+ return false;
742
+ }
743
+
744
+ if (ts.isIdentifier(bindingName)) {
745
+ const symbol = context.checker.getSymbolAtLocation(bindingName);
746
+ if (!symbol) {
747
+ return false;
748
+ }
749
+
750
+ context.facts.setNamespaceShapeSymbol(symbol, shape);
751
+ return true;
752
+ }
753
+
754
+ if (ts.isObjectBindingPattern(bindingName)) {
755
+ return true;
756
+ }
757
+
758
+ for (const [index, element] of bindingName.elements.entries()) {
759
+ if (!element) {
760
+ continue;
761
+ }
762
+
763
+ if (ts.isOmittedExpression(element)) {
764
+ continue;
765
+ }
766
+
767
+ const elementShape = getShapeAtArrayIndex(shape, index);
768
+ if (!elementShape) {
769
+ continue;
770
+ }
771
+
772
+ if (!seedBindingNameFromShape(context, element.name, elementShape)) {
773
+ return false;
774
+ }
775
+ }
776
+
777
+ return true;
778
+ }
779
+
780
+ function canBindFromShape(
781
+ bindingName: ts.BindingName,
782
+ shape: NamespaceShapeFact,
783
+ ): boolean {
784
+ if (ts.isIdentifier(bindingName)) {
785
+ return true;
786
+ }
787
+
788
+ if (ts.isObjectBindingPattern(bindingName)) {
789
+ return isWholeNamespaceShape(shape) && isSimpleNamespaceProjectionObjectPattern(bindingName);
790
+ }
791
+
792
+ if (isWholeNamespaceShape(shape)) {
793
+ return false;
794
+ }
795
+
796
+ return bindingName.elements.every((element, index) => {
797
+ if (!element || ts.isOmittedExpression(element)) {
798
+ return true;
799
+ }
800
+
801
+ if (element.dotDotDotToken) {
802
+ return false;
803
+ }
804
+
805
+ const elementShape = getShapeAtArrayIndex(shape, index);
806
+ return elementShape ? canBindFromShape(element.name, elementShape) : true;
807
+ });
808
+ }
809
+
810
+ function seedVariableDeclaration(
811
+ context: AnalysisContext,
812
+ node: ts.VariableDeclaration,
813
+ ): boolean {
814
+ if (!node.initializer || !isConstVariableDeclaration(node)) {
815
+ return false;
816
+ }
817
+
818
+ const resolver = getNamespaceResolver(context, node.initializer);
819
+ if (resolver && !resolver.ambiguous && ts.isIdentifier(node.name)) {
820
+ const symbol = context.checker.getSymbolAtLocation(node.name);
821
+ if (symbol) {
822
+ context.facts.setNamespaceResolverSymbol(symbol, resolver);
823
+ return true;
824
+ }
825
+ }
826
+
827
+ const seedShape = getAllowedNamespaceSeedShape(context, node.initializer);
828
+ if (seedShape) {
829
+ return seedBindingNameFromShape(context, node.name, seedShape);
830
+ }
831
+
832
+ return false;
833
+ }
834
+
835
+ function getThenCallback(node: ts.CallExpression): LocalFunctionLikeWithBody | undefined {
836
+ const callback = node.arguments[0];
837
+ return callback && isLocalFunctionLikeWithBody(callback) ? callback : undefined;
838
+ }
839
+
840
+ function seedThenCallbackParameter(
841
+ context: AnalysisContext,
842
+ callback: LocalFunctionLikeWithBody,
843
+ shape: NamespaceShapeFact,
844
+ ): boolean {
845
+ const [parameter] = callback.parameters;
846
+ if (!parameter) {
847
+ return true;
848
+ }
849
+
850
+ return seedBindingNameFromShape(context, parameter.name, shape);
851
+ }
852
+
853
+ function seedNamespaceFacts(context: AnalysisContext): SoundDiagnostic[] {
854
+ const diagnostics: SoundDiagnostic[] = [];
855
+ const exportedSymbolsBySourceFile = collectExportedSymbolsBySourceFile(context);
856
+
857
+ context.forEachSourceFile((sourceFile) => {
858
+ for (const statement of sourceFile.statements) {
859
+ if (context.isGeneratedNode(statement)) {
860
+ continue;
861
+ }
862
+
863
+ if (
864
+ ts.isImportDeclaration(statement) &&
865
+ statement.importClause?.namedBindings &&
866
+ ts.isNamespaceImport(statement.importClause.namedBindings)
867
+ ) {
868
+ const symbol = context.checker.getSymbolAtLocation(
869
+ statement.importClause.namedBindings.name,
870
+ );
871
+ if (symbol) {
872
+ context.facts.setNamespaceShapeSymbol(symbol, createWholeNamespaceShape('staticImport'));
873
+ }
874
+ }
875
+
876
+ if (
877
+ ts.isImportEqualsDeclaration(statement) &&
878
+ ts.isExternalModuleReference(statement.moduleReference)
879
+ ) {
880
+ const symbol = context.checker.getSymbolAtLocation(statement.name);
881
+ if (symbol) {
882
+ context.facts.setNamespaceShapeSymbol(symbol, createWholeNamespaceShape('require'));
883
+ }
884
+ }
885
+ }
886
+
887
+ const exportedSymbols = exportedSymbolsBySourceFile.get(sourceFile);
888
+
889
+ context.traverse(sourceFile, (node) => {
890
+ if (ts.isVariableDeclaration(node)) {
891
+ if (
892
+ exportedSymbols &&
893
+ isConstVariableDeclaration(node) &&
894
+ node.initializer &&
895
+ ts.isIdentifier(node.name)
896
+ ) {
897
+ const exportSymbol = context.checker.getSymbolAtLocation(node.name);
898
+ if (
899
+ exportSymbol &&
900
+ exportedSymbols.has(context.exportSummaries.canonicalizeSymbol(exportSymbol)) &&
901
+ getWholeNamespaceExportShape(context, node.initializer)
902
+ ) {
903
+ context.exportSummaries.set(exportSymbol, {
904
+ kind: 'value',
905
+ fact: { family: 'moduleNamespace' },
906
+ });
907
+ }
908
+ }
909
+
910
+ if (
911
+ node.initializer &&
912
+ !seedVariableDeclaration(context, node) &&
913
+ getAllowedNamespaceSeedShape(context, node.initializer) &&
914
+ !ts.isIdentifier(node.name)
915
+ ) {
916
+ diagnostics.push(createNamespaceEscapeDiagnostic(node.name));
917
+ }
918
+ return;
919
+ }
920
+
921
+ if (
922
+ ts.isCallExpression(node) &&
923
+ getNamespaceResolver(context, node)?.ambiguous
924
+ ) {
925
+ diagnostics.push(createNamespaceEscapeDiagnostic(node));
926
+ return;
927
+ }
928
+
929
+ let exportSymbol: ts.Symbol | undefined;
930
+ let exportInitializer: ts.Expression | undefined;
931
+
932
+ if (ts.isExportAssignment(node) && !node.isExportEquals) {
933
+ exportSymbol = getDefaultExportSymbol(context, sourceFile);
934
+ exportInitializer = node.expression;
935
+ }
936
+
937
+ const exportedSymbolsInSource = exportedSymbols;
938
+ if (
939
+ exportSymbol &&
940
+ exportInitializer &&
941
+ exportedSymbolsInSource?.has(context.exportSummaries.canonicalizeSymbol(exportSymbol)) &&
942
+ getWholeNamespaceExportShape(context, exportInitializer)
943
+ ) {
944
+ context.exportSummaries.set(exportSymbol, {
945
+ kind: 'value',
946
+ fact: { family: 'moduleNamespace' },
947
+ });
948
+ }
949
+
950
+ if (!ts.isCallExpression(node)) {
951
+ return;
952
+ }
953
+
954
+ const promiseMethod = getPromiseInstanceMethodInfo(context, node);
955
+ if (promiseMethod?.method !== 'then') {
956
+ return;
957
+ }
958
+
959
+ const targetResolver = getNamespaceResolver(context, promiseMethod.target);
960
+ if (!targetResolver || targetResolver.ambiguous) {
961
+ return;
962
+ }
963
+
964
+ const callback = getThenCallback(node);
965
+ if (!callback) {
966
+ return;
967
+ }
968
+
969
+ const callbackShape: NamespaceShapeFact = {
970
+ origin: targetResolver.origin === 'dynamicImport' ? 'dynamicImport' : 'resolver',
971
+ paths: targetResolver.paths,
972
+ };
973
+ if (!seedThenCallbackParameter(context, callback, callbackShape)) {
974
+ diagnostics.push(createNamespaceEscapeDiagnostic(callback.parameters[0]?.name ?? callback));
975
+ }
976
+ });
977
+
978
+ if (!exportedSymbols) {
979
+ return;
980
+ }
981
+
982
+ context.traverse(sourceFile, (node) => {
983
+ if (
984
+ !ts.isExportDeclaration(node) ||
985
+ !node.moduleSpecifier ||
986
+ !ts.isStringLiteral(node.moduleSpecifier) ||
987
+ !node.exportClause ||
988
+ !ts.isNamespaceExport(node.exportClause)
989
+ ) {
990
+ return;
991
+ }
992
+
993
+ const symbol = context.checker.getSymbolAtLocation(node.exportClause.name);
994
+ if (!symbol) {
995
+ return;
996
+ }
997
+
998
+ if (!exportedSymbols.has(context.exportSummaries.canonicalizeSymbol(symbol))) {
999
+ return;
1000
+ }
1001
+
1002
+ context.exportSummaries.set(symbol, {
1003
+ kind: 'value',
1004
+ fact: { family: 'moduleNamespace' },
1005
+ });
1006
+ });
1007
+ });
1008
+
1009
+ return diagnostics;
1010
+ }
1011
+
1012
+ function isAllowedNamespaceUse(
1013
+ context: AnalysisContext,
1014
+ expression: ts.Expression,
1015
+ shape: NamespaceShapeFact,
1016
+ ): boolean {
1017
+ const parent = expression.parent;
1018
+ if (!parent) {
1019
+ return false;
1020
+ }
1021
+
1022
+ if (isTransparentNamespaceUseParent(parent, expression)) {
1023
+ return true;
1024
+ }
1025
+
1026
+ if (
1027
+ (ts.isPropertyAccessExpression(parent) || ts.isPropertyAccessChain(parent)) &&
1028
+ parent.expression === expression
1029
+ ) {
1030
+ if (isWholeNamespaceShape(shape)) {
1031
+ return true;
1032
+ }
1033
+
1034
+ if (
1035
+ parent.name.text === 'status' &&
1036
+ shape.paths.some((pathFact) =>
1037
+ pathFact.guard === 'fulfilled' &&
1038
+ pathFact.path[0]?.kind === 'property' &&
1039
+ pathFact.path[0].name === 'value'
1040
+ )
1041
+ ) {
1042
+ return true;
1043
+ }
1044
+
1045
+ return shape.paths.some((pathFact) => {
1046
+ const [head] = pathFact.path;
1047
+ return head?.kind === 'property' && head.name === parent.name.text;
1048
+ });
1049
+ }
1050
+
1051
+ if (
1052
+ (ts.isElementAccessExpression(parent) || ts.isElementAccessChain(parent)) &&
1053
+ parent.expression === expression
1054
+ ) {
1055
+ const propertyName = getPropertySegmentName(parent);
1056
+ if (isWholeNamespaceShape(shape) && propertyName !== undefined) {
1057
+ return true;
1058
+ }
1059
+
1060
+ const index = getIndexSegmentValue(parent);
1061
+ return shape.paths.some((pathFact) => {
1062
+ const [head] = pathFact.path;
1063
+ if (!head) {
1064
+ return false;
1065
+ }
1066
+
1067
+ if (index !== undefined) {
1068
+ return head.kind === 'index' && head.index === index;
1069
+ }
1070
+
1071
+ return propertyName !== undefined && head.kind === 'property' && head.name === propertyName;
1072
+ });
1073
+ }
1074
+
1075
+ if (
1076
+ ts.isVariableDeclaration(parent) &&
1077
+ parent.initializer === expression &&
1078
+ isConstVariableDeclaration(parent)
1079
+ ) {
1080
+ const seedShape = getAllowedNamespaceSeedShape(context, expression);
1081
+ if (seedShape && canBindFromShape(parent.name, seedShape)) {
1082
+ return true;
1083
+ }
1084
+
1085
+ return isWholeNamespaceShape(shape) &&
1086
+ ts.isObjectBindingPattern(parent.name) &&
1087
+ isSimpleNamespaceProjectionObjectPattern(parent.name);
1088
+ }
1089
+
1090
+ if (ts.isExportAssignment(parent) && parent.expression === expression && !parent.isExportEquals) {
1091
+ return false;
1092
+ }
1093
+
1094
+ if (
1095
+ ts.isPropertyAssignment(parent) &&
1096
+ parent.initializer === expression
1097
+ ) {
1098
+ return false;
1099
+ }
1100
+
1101
+ if (ts.isShorthandPropertyAssignment(parent) && parent.name === expression) {
1102
+ return false;
1103
+ }
1104
+
1105
+ if (ts.isArrayLiteralExpression(parent)) {
1106
+ return false;
1107
+ }
1108
+
1109
+ if (
1110
+ ts.isBinaryExpression(parent) &&
1111
+ parent.right === expression
1112
+ ) {
1113
+ return false;
1114
+ }
1115
+
1116
+ if (
1117
+ (ts.isCallExpression(parent) || ts.isNewExpression(parent)) &&
1118
+ parent.arguments?.includes(expression)
1119
+ ) {
1120
+ return false;
1121
+ }
1122
+
1123
+ if (ts.isReturnStatement(parent) && parent.expression === expression) {
1124
+ return false;
1125
+ }
1126
+
1127
+ if (
1128
+ (ts.isArrowFunction(parent) || ts.isFunctionExpression(parent)) &&
1129
+ parent.body === expression
1130
+ ) {
1131
+ return false;
1132
+ }
1133
+
1134
+ if (ts.isConditionalExpression(parent) || ts.isExpressionStatement(parent)) {
1135
+ return false;
1136
+ }
1137
+
1138
+ return false;
1139
+ }
1140
+
1141
+ function shouldCheckNamespaceExpression(node: ts.Node): node is ts.Expression {
1142
+ if (
1143
+ !ts.isExpression(node) ||
1144
+ ts.isStringLiteral(node) ||
1145
+ ts.isNoSubstitutionTemplateLiteral(node) ||
1146
+ ts.isNumericLiteral(node)
1147
+ ) {
1148
+ return false;
1149
+ }
1150
+
1151
+ if (!ts.isIdentifier(node)) {
1152
+ return true;
1153
+ }
1154
+
1155
+ const parent = node.parent;
1156
+ if (!parent) {
1157
+ return true;
1158
+ }
1159
+
1160
+ return !(
1161
+ (ts.isImportClause(parent) && parent.name === node) ||
1162
+ ts.isNamespaceImport(parent) ||
1163
+ (ts.isImportSpecifier(parent) && parent.name === node) ||
1164
+ isTypePositionIdentifier(node) ||
1165
+ (ts.isVariableDeclaration(parent) && parent.name === node) ||
1166
+ (ts.isBindingElement(parent) && parent.name === node) ||
1167
+ (ts.isParameter(parent) && parent.name === node) ||
1168
+ (ts.isFunctionDeclaration(parent) && parent.name === node) ||
1169
+ (ts.isFunctionExpression(parent) && parent.name === node) ||
1170
+ (ts.isMethodDeclaration(parent) && parent.name === node) ||
1171
+ (ts.isPropertyAccessExpression(parent) && parent.name === node) ||
1172
+ (ts.isExportSpecifier(parent) && (parent.name === node || parent.propertyName === node))
1173
+ );
1174
+ }
1175
+
1176
+ function validateExportSpecifiers(
1177
+ context: AnalysisContext,
1178
+ diagnostics: SoundDiagnostic[],
1179
+ ): void {
1180
+ context.forEachSourceFile((sourceFile) => {
1181
+ context.traverse(sourceFile, (node) => {
1182
+ if (
1183
+ !ts.isExportSpecifier(node) ||
1184
+ node.parent.parent.moduleSpecifier
1185
+ ) {
1186
+ return;
1187
+ }
1188
+
1189
+ const localName = node.propertyName ?? node.name;
1190
+ if (!ts.isIdentifier(localName)) {
1191
+ return;
1192
+ }
1193
+
1194
+ const shape = getKnownNamespaceShape(context, localName);
1195
+ if (shape) {
1196
+ diagnostics.push(createNamespaceEscapeDiagnostic(node.name));
1197
+ }
1198
+ });
1199
+ });
1200
+ }
1201
+
1202
+ export function runNamespaceObjectRules(context: AnalysisContext): SoundDiagnostic[] {
1203
+ const diagnostics = seedNamespaceFacts(context);
1204
+ validateExportSpecifiers(context, diagnostics);
1205
+
1206
+ context.forEachSourceFile((sourceFile) => {
1207
+ context.traverse(sourceFile, (node) => {
1208
+ if (!shouldCheckNamespaceExpression(node)) {
1209
+ return;
1210
+ }
1211
+
1212
+ const shape = getKnownNamespaceShape(context, node);
1213
+ if (!shape) {
1214
+ return;
1215
+ }
1216
+
1217
+ if (!isAllowedNamespaceUse(context, node, shape)) {
1218
+ diagnostics.push(createNamespaceEscapeDiagnostic(node));
1219
+ }
1220
+ });
1221
+ });
1222
+
1223
+ return diagnostics;
1224
+ }