@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.
- package/package.json +15 -6
- package/project-transform/index.js +2 -0
- package/project-transform/index.ts +8 -0
- package/project-transform/src/annotation_syntax.js +948 -0
- package/project-transform/src/annotation_syntax.ts +1217 -0
- package/project-transform/src/build_package.js +475 -0
- package/project-transform/src/build_package.ts +683 -0
- package/project-transform/src/bundled/portable-web-globals.d.ts +153 -0
- package/project-transform/src/bundled/runtime_externs.js +220 -0
- package/project-transform/src/bundled/runtime_externs.ts +237 -0
- package/project-transform/src/bundled/sound-libs/lib.decorators.d.ts +385 -0
- package/project-transform/src/bundled/sound-libs/lib.decorators.legacy.d.ts +22 -0
- package/project-transform/src/bundled/sound-libs/lib.dom.asynciterable.d.ts +42 -0
- package/project-transform/src/bundled/sound-libs/lib.dom.d.ts +39440 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.collection.d.ts +149 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.core.d.ts +657 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.d.ts +28 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.generator.d.ts +77 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.iterable.d.ts +616 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.promise.d.ts +80 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.proxy.d.ts +128 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.reflect.d.ts +144 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.symbol.d.ts +46 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.symbol.wellknown.d.ts +170 -0
- package/project-transform/src/bundled/sound-libs/lib.es2016.array.include.d.ts +116 -0
- package/project-transform/src/bundled/sound-libs/lib.es2016.d.ts +21 -0
- package/project-transform/src/bundled/sound-libs/lib.es2017.arraybuffer.d.ts +21 -0
- package/project-transform/src/bundled/sound-libs/lib.es2017.d.ts +26 -0
- package/project-transform/src/bundled/sound-libs/lib.es2017.date.d.ts +31 -0
- package/project-transform/src/bundled/sound-libs/lib.es2017.object.d.ts +49 -0
- package/project-transform/src/bundled/sound-libs/lib.es2017.string.d.ts +45 -0
- package/project-transform/src/bundled/sound-libs/lib.es2017.typedarrays.d.ts +53 -0
- package/project-transform/src/bundled/sound-libs/lib.es2018.asyncgenerator.d.ts +77 -0
- package/project-transform/src/bundled/sound-libs/lib.es2018.asynciterable.d.ts +57 -0
- package/project-transform/src/bundled/sound-libs/lib.es2018.d.ts +24 -0
- package/project-transform/src/bundled/sound-libs/lib.es2018.promise.d.ts +30 -0
- package/project-transform/src/bundled/sound-libs/lib.es2018.regexp.d.ts +37 -0
- package/project-transform/src/bundled/sound-libs/lib.es2019.array.d.ts +79 -0
- package/project-transform/src/bundled/sound-libs/lib.es2019.d.ts +24 -0
- package/project-transform/src/bundled/sound-libs/lib.es2019.object.d.ts +47 -0
- package/project-transform/src/bundled/sound-libs/lib.es2019.string.d.ts +37 -0
- package/project-transform/src/bundled/sound-libs/lib.es2019.symbol.d.ts +24 -0
- package/project-transform/src/bundled/sound-libs/lib.es2020.bigint.d.ts +765 -0
- package/project-transform/src/bundled/sound-libs/lib.es2020.d.ts +27 -0
- package/project-transform/src/bundled/sound-libs/lib.es2020.date.d.ts +42 -0
- package/project-transform/src/bundled/sound-libs/lib.es2020.number.d.ts +28 -0
- package/project-transform/src/bundled/sound-libs/lib.es2020.promise.d.ts +49 -0
- package/project-transform/src/bundled/sound-libs/lib.es2020.string.d.ts +44 -0
- package/project-transform/src/bundled/sound-libs/lib.es2020.symbol.wellknown.d.ts +41 -0
- package/project-transform/src/bundled/sound-libs/lib.es2021.d.ts +23 -0
- package/project-transform/src/bundled/sound-libs/lib.es2021.promise.d.ts +48 -0
- package/project-transform/src/bundled/sound-libs/lib.es2021.string.d.ts +33 -0
- package/project-transform/src/bundled/sound-libs/lib.es2021.weakref.d.ts +78 -0
- package/project-transform/src/bundled/sound-libs/lib.es2022.array.d.ts +121 -0
- package/project-transform/src/bundled/sound-libs/lib.es2022.d.ts +25 -0
- package/project-transform/src/bundled/sound-libs/lib.es2022.error.d.ts +75 -0
- package/project-transform/src/bundled/sound-libs/lib.es2022.object.d.ts +26 -0
- package/project-transform/src/bundled/sound-libs/lib.es2022.regexp.d.ts +39 -0
- package/project-transform/src/bundled/sound-libs/lib.es2022.string.d.ts +25 -0
- package/project-transform/src/bundled/sound-libs/lib.es2023.array.d.ts +924 -0
- package/project-transform/src/bundled/sound-libs/lib.es2023.collection.d.ts +21 -0
- package/project-transform/src/bundled/sound-libs/lib.es2023.d.ts +22 -0
- package/project-transform/src/bundled/sound-libs/lib.es2024.arraybuffer.d.ts +65 -0
- package/project-transform/src/bundled/sound-libs/lib.es2024.collection.d.ts +29 -0
- package/project-transform/src/bundled/sound-libs/lib.es2024.d.ts +26 -0
- package/project-transform/src/bundled/sound-libs/lib.es2024.object.d.ts +33 -0
- package/project-transform/src/bundled/sound-libs/lib.es2024.promise.d.ts +35 -0
- package/project-transform/src/bundled/sound-libs/lib.es2024.regexp.d.ts +25 -0
- package/project-transform/src/bundled/sound-libs/lib.es2024.string.d.ts +29 -0
- package/project-transform/src/bundled/sound-libs/lib.es5.d.ts +4924 -0
- package/project-transform/src/bundled/sound_stdlib.js +142 -0
- package/project-transform/src/bundled/sound_stdlib.ts +180 -0
- package/project-transform/src/checker/analyze_project.js +1361 -0
- package/project-transform/src/checker/analyze_project.ts +2246 -0
- package/project-transform/src/checker/diagnostics.js +112 -0
- package/project-transform/src/checker/diagnostics.ts +222 -0
- package/project-transform/src/checker/engine/context.js +235 -0
- package/project-transform/src/checker/engine/context.ts +340 -0
- package/project-transform/src/checker/engine/diagnostic_codes.js +72 -0
- package/project-transform/src/checker/engine/diagnostic_codes.ts +95 -0
- package/project-transform/src/checker/engine/facts.js +35 -0
- package/project-transform/src/checker/engine/facts.ts +48 -0
- package/project-transform/src/checker/engine/types.js +1 -0
- package/project-transform/src/checker/engine/types.ts +485 -0
- package/project-transform/src/checker/proof_escape_hatch_diagnostics.js +104 -0
- package/project-transform/src/checker/proof_escape_hatch_diagnostics.ts +173 -0
- package/project-transform/src/checker/rules/async_surface.js +231 -0
- package/project-transform/src/checker/rules/async_surface.ts +335 -0
- package/project-transform/src/checker/rules/class_lifecycle.js +798 -0
- package/project-transform/src/checker/rules/class_lifecycle.ts +1276 -0
- package/project-transform/src/checker/rules/directive_validation.js +571 -0
- package/project-transform/src/checker/rules/directive_validation.ts +938 -0
- package/project-transform/src/checker/rules/directives.js +23 -0
- package/project-transform/src/checker/rules/directives.ts +25 -0
- package/project-transform/src/checker/rules/flow.js +202 -0
- package/project-transform/src/checker/rules/flow.ts +333 -0
- package/project-transform/src/checker/rules/flow_facts.js +601 -0
- package/project-transform/src/checker/rules/flow_facts.ts +978 -0
- package/project-transform/src/checker/rules/flow_invalidation.js +1119 -0
- package/project-transform/src/checker/rules/flow_invalidation.ts +2150 -0
- package/project-transform/src/checker/rules/flow_shared.js +2822 -0
- package/project-transform/src/checker/rules/flow_shared.ts +4383 -0
- package/project-transform/src/checker/rules/foreign_boundary.js +120 -0
- package/project-transform/src/checker/rules/foreign_boundary.ts +196 -0
- package/project-transform/src/checker/rules/foreign_projection.js +279 -0
- package/project-transform/src/checker/rules/foreign_projection.ts +425 -0
- package/project-transform/src/checker/rules/generated_helpers.js +13 -0
- package/project-transform/src/checker/rules/generated_helpers.ts +18 -0
- package/project-transform/src/checker/rules/index.js +35 -0
- package/project-transform/src/checker/rules/index.ts +49 -0
- package/project-transform/src/checker/rules/namespace_object.js +845 -0
- package/project-transform/src/checker/rules/namespace_object.ts +1224 -0
- package/project-transform/src/checker/rules/non_ordinary_recovery.js +1328 -0
- package/project-transform/src/checker/rules/non_ordinary_recovery.ts +2391 -0
- package/project-transform/src/checker/rules/null_prototype.js +3 -0
- package/project-transform/src/checker/rules/null_prototype.ts +6 -0
- package/project-transform/src/checker/rules/overloads.js +181 -0
- package/project-transform/src/checker/rules/overloads.ts +317 -0
- package/project-transform/src/checker/rules/predicate_verification.js +691 -0
- package/project-transform/src/checker/rules/predicate_verification.ts +1088 -0
- package/project-transform/src/checker/rules/prototype_hardening.js +237 -0
- package/project-transform/src/checker/rules/prototype_hardening.ts +343 -0
- package/project-transform/src/checker/rules/receiver_discipline.js +263 -0
- package/project-transform/src/checker/rules/receiver_discipline.ts +356 -0
- package/project-transform/src/checker/rules/relations.js +6861 -0
- package/project-transform/src/checker/rules/relations.ts +12158 -0
- package/project-transform/src/checker/rules/resolved_builtins.js +274 -0
- package/project-transform/src/checker/rules/resolved_builtins.ts +438 -0
- package/project-transform/src/checker/rules/trust.js +217 -0
- package/project-transform/src/checker/rules/trust.ts +301 -0
- package/project-transform/src/checker/rules/type_guards.js +173 -0
- package/project-transform/src/checker/rules/type_guards.ts +257 -0
- package/project-transform/src/checker/rules/universal.js +17 -0
- package/project-transform/src/checker/rules/universal.ts +22 -0
- package/project-transform/src/checker/rules/unsafe_value_origin.js +80 -0
- package/project-transform/src/checker/rules/unsafe_value_origin.ts +125 -0
- package/project-transform/src/checker/rules/unsound_imports.js +218 -0
- package/project-transform/src/checker/rules/unsound_imports.ts +301 -0
- package/project-transform/src/checker/rules/unsound_syntax.js +1695 -0
- package/project-transform/src/checker/rules/unsound_syntax.ts +2540 -0
- package/project-transform/src/checker/rules/value_types.js +206 -0
- package/project-transform/src/checker/rules/value_types.ts +407 -0
- package/project-transform/src/checker/timing.js +43 -0
- package/project-transform/src/checker/timing.ts +78 -0
- package/project-transform/src/checker/unsupported_feature_messages.js +337 -0
- package/project-transform/src/checker/unsupported_feature_messages.ts +531 -0
- package/project-transform/src/cli.js +892 -0
- package/project-transform/src/cli.ts +1476 -0
- package/project-transform/src/compiler/compile_project.js +319 -0
- package/project-transform/src/compiler/compile_project.ts +508 -0
- package/project-transform/src/compiler/errors.js +10 -0
- package/project-transform/src/compiler/errors.ts +29 -0
- package/project-transform/src/compiler/ir.js +1 -0
- package/project-transform/src/compiler/ir.ts +1526 -0
- package/project-transform/src/compiler/lower.js +30550 -0
- package/project-transform/src/compiler/lower.ts +43645 -0
- package/project-transform/src/compiler/lower_arrays.js +140 -0
- package/project-transform/src/compiler/lower_arrays.ts +190 -0
- package/project-transform/src/compiler/lower_strings.js +121 -0
- package/project-transform/src/compiler/lower_strings.ts +198 -0
- package/project-transform/src/compiler/lower_tagged.js +329 -0
- package/project-transform/src/compiler/lower_tagged.ts +427 -0
- package/project-transform/src/compiler/lower_views.js +171 -0
- package/project-transform/src/compiler/lower_views.ts +251 -0
- package/project-transform/src/compiler/object_keys.js +25 -0
- package/project-transform/src/compiler/object_keys.ts +35 -0
- package/project-transform/src/compiler/runtime_ir.js +30 -0
- package/project-transform/src/compiler/runtime_ir.ts +727 -0
- package/project-transform/src/compiler/tagged_boundary.js +18 -0
- package/project-transform/src/compiler/tagged_boundary.ts +37 -0
- package/project-transform/src/compiler/toolchain.js +170 -0
- package/project-transform/src/compiler/toolchain.ts +229 -0
- package/project-transform/src/compiler/unicode_case_data.js +2102 -0
- package/project-transform/src/compiler/unicode_case_data.ts +2112 -0
- package/project-transform/src/compiler/wasm_js_host_runtime.js +656 -0
- package/project-transform/src/compiler/wasm_js_host_runtime.ts +762 -0
- package/project-transform/src/compiler/wat_arrays.js +3132 -0
- package/project-transform/src/compiler/wat_arrays.ts +3768 -0
- package/project-transform/src/compiler/wat_emitter.js +17952 -0
- package/project-transform/src/compiler/wat_emitter.ts +22812 -0
- package/project-transform/src/compiler/wat_strings.js +129 -0
- package/project-transform/src/compiler/wat_strings.ts +187 -0
- package/project-transform/src/compiler/wat_tagged.js +548 -0
- package/project-transform/src/compiler/wat_tagged.ts +674 -0
- package/project-transform/src/compiler_generator_runner.js +153 -0
- package/project-transform/src/compiler_generator_runner.ts +171 -0
- package/project-transform/src/compiler_object_test_helpers.js +69 -0
- package/project-transform/src/compiler_object_test_helpers.ts +96 -0
- package/project-transform/src/compiler_promise_runner.js +2116 -0
- package/project-transform/src/compiler_promise_runner.ts +2184 -0
- package/project-transform/src/compiler_test_helpers.js +854 -0
- package/project-transform/src/compiler_test_helpers.ts +1087 -0
- package/project-transform/src/config.js +568 -0
- package/project-transform/src/config.ts +892 -0
- package/project-transform/src/diagnostic_metadata.js +67 -0
- package/project-transform/src/diagnostic_metadata.ts +99 -0
- package/project-transform/src/diagnostic_reference.js +1368 -0
- package/project-transform/src/diagnostic_reference.ts +1523 -0
- package/project-transform/src/editor_diagnostics_worker.js +176 -0
- package/project-transform/src/editor_diagnostics_worker.ts +250 -0
- package/project-transform/src/editor_projection.js +224 -0
- package/project-transform/src/editor_projection.ts +421 -0
- package/project-transform/src/frontend/builtin_expanded_program_test_cleanup.js +47 -0
- package/project-transform/src/frontend/builtin_expanded_program_test_cleanup.ts +72 -0
- package/project-transform/src/frontend/builtin_macro_support.js +842 -0
- package/project-transform/src/frontend/builtin_macro_support.ts +1386 -0
- package/project-transform/src/frontend/builtin_macros.js +409 -0
- package/project-transform/src/frontend/builtin_macros.ts +542 -0
- package/project-transform/src/frontend/component_poc_runtime.js +279 -0
- package/project-transform/src/frontend/component_poc_runtime.ts +372 -0
- package/project-transform/src/frontend/css_macro.js +148 -0
- package/project-transform/src/frontend/css_macro.ts +222 -0
- package/project-transform/src/frontend/derive_macros.js +2072 -0
- package/project-transform/src/frontend/derive_macros.ts +3188 -0
- package/project-transform/src/frontend/embedded_fragment_support.js +106 -0
- package/project-transform/src/frontend/embedded_fragment_support.ts +172 -0
- package/project-transform/src/frontend/error_normalization.js +403 -0
- package/project-transform/src/frontend/error_normalization.ts +832 -0
- package/project-transform/src/frontend/error_stdlib_support.js +1 -0
- package/project-transform/src/frontend/error_stdlib_support.ts +6 -0
- package/project-transform/src/frontend/expand_project.js +169 -0
- package/project-transform/src/frontend/expand_project.ts +248 -0
- package/project-transform/src/frontend/format_soundscript.js +297 -0
- package/project-transform/src/frontend/format_soundscript.ts +582 -0
- package/project-transform/src/frontend/graphql_macro.js +174 -0
- package/project-transform/src/frontend/graphql_macro.ts +253 -0
- package/project-transform/src/frontend/hash_context.js +83 -0
- package/project-transform/src/frontend/hash_context.ts +113 -0
- package/project-transform/src/frontend/hkt_macro.js +448 -0
- package/project-transform/src/frontend/hkt_macro.ts +897 -0
- package/project-transform/src/frontend/import_binding_usage.js +190 -0
- package/project-transform/src/frontend/import_binding_usage.ts +277 -0
- package/project-transform/src/frontend/macro_advanced_backend_adapter.js +58 -0
- package/project-transform/src/frontend/macro_advanced_backend_adapter.ts +123 -0
- package/project-transform/src/frontend/macro_advanced_context.js +826 -0
- package/project-transform/src/frontend/macro_advanced_context.ts +1102 -0
- package/project-transform/src/frontend/macro_advanced_output.js +21 -0
- package/project-transform/src/frontend/macro_advanced_output.ts +41 -0
- package/project-transform/src/frontend/macro_api.js +353 -0
- package/project-transform/src/frontend/macro_api.ts +1722 -0
- package/project-transform/src/frontend/macro_api_internal.js +35 -0
- package/project-transform/src/frontend/macro_api_internal.ts +80 -0
- package/project-transform/src/frontend/macro_api_module_support.js +39 -0
- package/project-transform/src/frontend/macro_api_module_support.ts +65 -0
- package/project-transform/src/frontend/macro_backend_adapter.js +272 -0
- package/project-transform/src/frontend/macro_backend_adapter.ts +420 -0
- package/project-transform/src/frontend/macro_context.js +816 -0
- package/project-transform/src/frontend/macro_context.ts +1105 -0
- package/project-transform/src/frontend/macro_debug.js +99 -0
- package/project-transform/src/frontend/macro_debug.ts +157 -0
- package/project-transform/src/frontend/macro_definition_support.js +28 -0
- package/project-transform/src/frontend/macro_definition_support.ts +73 -0
- package/project-transform/src/frontend/macro_errors.js +40 -0
- package/project-transform/src/frontend/macro_errors.ts +70 -0
- package/project-transform/src/frontend/macro_expander.js +919 -0
- package/project-transform/src/frontend/macro_expander.ts +1611 -0
- package/project-transform/src/frontend/macro_factory_support.js +176 -0
- package/project-transform/src/frontend/macro_factory_support.ts +263 -0
- package/project-transform/src/frontend/macro_host_ast_internal.js +64 -0
- package/project-transform/src/frontend/macro_host_ast_internal.ts +109 -0
- package/project-transform/src/frontend/macro_index.js +27 -0
- package/project-transform/src/frontend/macro_index.ts +50 -0
- package/project-transform/src/frontend/macro_loader.js +281 -0
- package/project-transform/src/frontend/macro_loader.ts +506 -0
- package/project-transform/src/frontend/macro_operand_semantics.js +838 -0
- package/project-transform/src/frontend/macro_operand_semantics.ts +1489 -0
- package/project-transform/src/frontend/macro_output.js +54 -0
- package/project-transform/src/frontend/macro_output.ts +123 -0
- package/project-transform/src/frontend/macro_parser.js +611 -0
- package/project-transform/src/frontend/macro_parser.ts +832 -0
- package/project-transform/src/frontend/macro_resolver.js +69 -0
- package/project-transform/src/frontend/macro_resolver.ts +125 -0
- package/project-transform/src/frontend/macro_rewrite.js +285 -0
- package/project-transform/src/frontend/macro_rewrite.ts +442 -0
- package/project-transform/src/frontend/macro_runtime_support.js +232 -0
- package/project-transform/src/frontend/macro_runtime_support.ts +324 -0
- package/project-transform/src/frontend/macro_scanner.js +393 -0
- package/project-transform/src/frontend/macro_scanner.ts +455 -0
- package/project-transform/src/frontend/macro_semantic_backend_adapter.js +87 -0
- package/project-transform/src/frontend/macro_semantic_backend_adapter.ts +166 -0
- package/project-transform/src/frontend/macro_semantic_context.js +5 -0
- package/project-transform/src/frontend/macro_semantic_context.ts +12 -0
- package/project-transform/src/frontend/macro_semantic_output.js +24 -0
- package/project-transform/src/frontend/macro_semantic_output.ts +47 -0
- package/project-transform/src/frontend/macro_semantic_types.js +1 -0
- package/project-transform/src/frontend/macro_semantic_types.ts +98 -0
- package/project-transform/src/frontend/macro_semantics.js +1172 -0
- package/project-transform/src/frontend/macro_semantics.ts +1502 -0
- package/project-transform/src/frontend/macro_site_kind_support.js +164 -0
- package/project-transform/src/frontend/macro_site_kind_support.ts +255 -0
- package/project-transform/src/frontend/macro_syntax_internal.js +1950 -0
- package/project-transform/src/frontend/macro_syntax_internal.ts +3338 -0
- package/project-transform/src/frontend/macro_templates.js +57 -0
- package/project-transform/src/frontend/macro_templates.ts +143 -0
- package/project-transform/src/frontend/macro_test_helpers.js +82 -0
- package/project-transform/src/frontend/macro_test_helpers.ts +136 -0
- package/project-transform/src/frontend/macro_types.js +1 -0
- package/project-transform/src/frontend/macro_types.ts +103 -0
- package/project-transform/src/frontend/macro_vm.js +39 -0
- package/project-transform/src/frontend/macro_vm.ts +113 -0
- package/project-transform/src/frontend/match_macro.js +885 -0
- package/project-transform/src/frontend/match_macro.ts +1220 -0
- package/project-transform/src/frontend/numeric_normalization.js +824 -0
- package/project-transform/src/frontend/numeric_normalization.ts +1380 -0
- package/project-transform/src/frontend/numeric_prelude.js +278 -0
- package/project-transform/src/frontend/numeric_prelude.ts +370 -0
- package/project-transform/src/frontend/project_frontend.js +2396 -0
- package/project-transform/src/frontend/project_frontend.ts +3776 -0
- package/project-transform/src/frontend/project_macro_support.js +1401 -0
- package/project-transform/src/frontend/project_macro_support.ts +2137 -0
- package/project-transform/src/frontend/sql_macro.js +175 -0
- package/project-transform/src/frontend/sql_macro.ts +254 -0
- package/project-transform/src/frontend/sql_stdlib_support.js +1 -0
- package/project-transform/src/frontend/sql_stdlib_support.ts +6 -0
- package/project-transform/src/frontend/std_package_support.js +228 -0
- package/project-transform/src/frontend/std_package_support.ts +400 -0
- package/project-transform/src/frontend/value_normalization.js +306 -0
- package/project-transform/src/frontend/value_normalization.ts +599 -0
- package/project-transform/src/lsp/project_service.js +4771 -0
- package/project-transform/src/lsp/project_service.ts +7580 -0
- package/project-transform/src/lsp/protocol.js +9 -0
- package/project-transform/src/lsp/protocol.ts +38 -0
- package/project-transform/src/lsp/server.js +355 -0
- package/project-transform/src/lsp/server.ts +671 -0
- package/project-transform/src/lsp/session.js +49 -0
- package/project-transform/src/lsp/session.ts +48 -0
- package/project-transform/src/lsp/timing.js +43 -0
- package/project-transform/src/lsp/timing.ts +76 -0
- package/project-transform/src/lsp/transport.js +205 -0
- package/project-transform/src/lsp/transport.ts +253 -0
- package/project-transform/src/lsp_main.js +5 -0
- package/project-transform/src/lsp_main.ts +7 -0
- package/project-transform/src/macros.d.ts +1 -0
- package/project-transform/src/macros.js +1 -0
- package/project-transform/src/macros.ts +1 -0
- package/project-transform/src/main.js +24 -0
- package/project-transform/src/main.ts +28 -0
- package/project-transform/src/platform/host.js +264 -0
- package/project-transform/src/platform/host.ts +343 -0
- package/project-transform/src/platform/path.js +8 -0
- package/project-transform/src/platform/path.ts +20 -0
- package/project-transform/src/public_macro_api/macro_api.d.ts +1054 -0
- package/project-transform/src/public_macro_api/macro_semantic_types.d.ts +66 -0
- package/project-transform/src/public_macro_api/macro_types.d.ts +70 -0
- package/project-transform/src/run_program.js +14 -0
- package/project-transform/src/run_program.ts +33 -0
- package/project-transform/src/runtime/materialize.js +371 -0
- package/project-transform/src/runtime/materialize.ts +502 -0
- package/project-transform/src/runtime/on_demand.js +203 -0
- package/project-transform/src/runtime/on_demand.ts +305 -0
- package/project-transform/src/runtime/source_maps.js +205 -0
- package/project-transform/src/runtime/source_maps.ts +297 -0
- package/project-transform/src/runtime/transform.js +148 -0
- package/project-transform/src/runtime/transform.ts +295 -0
- package/project-transform/src/service/types.js +1 -0
- package/project-transform/src/service/types.ts +22 -0
- package/project-transform/src/soundscript_packages.js +477 -0
- package/project-transform/src/soundscript_packages.ts +754 -0
- package/project-transform/src/soundscript_runtime_specifiers.js +88 -0
- package/project-transform/src/soundscript_runtime_specifiers.ts +96 -0
- package/project-transform/src/stdlib/async.d.ts +81 -0
- package/project-transform/src/stdlib/async.js +213 -0
- package/project-transform/src/stdlib/async.ts +315 -0
- package/project-transform/src/stdlib/codec.d.ts +32 -0
- package/project-transform/src/stdlib/codec.js +30 -0
- package/project-transform/src/stdlib/codec.ts +76 -0
- package/project-transform/src/stdlib/compare.d.ts +28 -0
- package/project-transform/src/stdlib/compare.js +115 -0
- package/project-transform/src/stdlib/compare.ts +151 -0
- package/project-transform/src/stdlib/css.d.ts +16 -0
- package/project-transform/src/stdlib/css.js +9 -0
- package/project-transform/src/stdlib/css.ts +28 -0
- package/project-transform/src/stdlib/debug.d.ts +2 -0
- package/project-transform/src/stdlib/debug.js +9 -0
- package/project-transform/src/stdlib/debug.ts +10 -0
- package/project-transform/src/stdlib/decode.d.ts +86 -0
- package/project-transform/src/stdlib/decode.js +254 -0
- package/project-transform/src/stdlib/decode.ts +390 -0
- package/project-transform/src/stdlib/derive.d.ts +6 -0
- package/project-transform/src/stdlib/derive.js +7 -0
- package/project-transform/src/stdlib/derive.ts +7 -0
- package/project-transform/src/stdlib/encode.d.ts +100 -0
- package/project-transform/src/stdlib/encode.js +130 -0
- package/project-transform/src/stdlib/encode.ts +259 -0
- package/project-transform/src/stdlib/failures.d.ts +23 -0
- package/project-transform/src/stdlib/failures.js +41 -0
- package/project-transform/src/stdlib/failures.ts +64 -0
- package/project-transform/src/stdlib/fetch.d.ts +67 -0
- package/project-transform/src/stdlib/fetch.js +5 -0
- package/project-transform/src/stdlib/fetch.ts +11 -0
- package/project-transform/src/stdlib/graphql.d.ts +16 -0
- package/project-transform/src/stdlib/graphql.js +9 -0
- package/project-transform/src/stdlib/graphql.ts +28 -0
- package/project-transform/src/stdlib/hash.d.ts +34 -0
- package/project-transform/src/stdlib/hash.js +110 -0
- package/project-transform/src/stdlib/hash.ts +188 -0
- package/project-transform/src/stdlib/hkt.d.ts +40 -0
- package/project-transform/src/stdlib/hkt.js +3 -0
- package/project-transform/src/stdlib/hkt.ts +41 -0
- package/project-transform/src/stdlib/index.d.ts +9 -0
- package/project-transform/src/stdlib/index.js +15 -0
- package/project-transform/src/stdlib/index.ts +23 -0
- package/project-transform/src/stdlib/json.d.ts +125 -0
- package/project-transform/src/stdlib/json.js +764 -0
- package/project-transform/src/stdlib/json.ts +1034 -0
- package/project-transform/src/stdlib/match.d.ts +11 -0
- package/project-transform/src/stdlib/match.js +13 -0
- package/project-transform/src/stdlib/match.ts +26 -0
- package/project-transform/src/stdlib/numerics.d.ts +523 -0
- package/project-transform/src/stdlib/numerics.js +1356 -0
- package/project-transform/src/stdlib/numerics.ts +1937 -0
- package/project-transform/src/stdlib/random.d.ts +19 -0
- package/project-transform/src/stdlib/random.js +3 -0
- package/project-transform/src/stdlib/random.ts +5 -0
- package/project-transform/src/stdlib/result.d.ts +68 -0
- package/project-transform/src/stdlib/result.js +139 -0
- package/project-transform/src/stdlib/result.ts +248 -0
- package/project-transform/src/stdlib/sql.d.ts +22 -0
- package/project-transform/src/stdlib/sql.js +23 -0
- package/project-transform/src/stdlib/sql.ts +53 -0
- package/project-transform/src/stdlib/text.d.ts +24 -0
- package/project-transform/src/stdlib/text.js +3 -0
- package/project-transform/src/stdlib/text.ts +4 -0
- package/project-transform/src/stdlib/thunk.d.ts +2 -0
- package/project-transform/src/stdlib/thunk.js +9 -0
- package/project-transform/src/stdlib/thunk.ts +15 -0
- package/project-transform/src/stdlib/typeclasses.d.ts +57 -0
- package/project-transform/src/stdlib/typeclasses.js +78 -0
- package/project-transform/src/stdlib/typeclasses.ts +173 -0
- package/project-transform/src/stdlib/url.d.ts +37 -0
- package/project-transform/src/stdlib/url.js +3 -0
- package/project-transform/src/stdlib/url.ts +4 -0
- package/project-transform/src/stdlib/value.d.ts +9 -0
- package/project-transform/src/stdlib/value.js +104 -0
- package/project-transform/src/stdlib/value.ts +133 -0
- package/project-transform/src/test_installed_stdlib.js +147 -0
- package/project-transform/src/test_installed_stdlib.ts +245 -0
- package/project-transform/src/test_macro_package_fixture.js +50 -0
- package/project-transform/src/test_macro_package_fixture.ts +68 -0
- package/project-transform/src/value_deep_safe.js +191 -0
- package/project-transform/src/value_deep_safe.ts +273 -0
|
@@ -0,0 +1,978 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
AnalysisContext,
|
|
5
|
+
FlowBranchEntryStructureFact,
|
|
6
|
+
FlowBranchStructureFact,
|
|
7
|
+
FlowChildRegionStructureEntryFact,
|
|
8
|
+
FlowChildRegionStructureFact,
|
|
9
|
+
FlowConditionStructureFact,
|
|
10
|
+
FlowConditionSyntaxFact,
|
|
11
|
+
FlowConditionSyntaxFactKind,
|
|
12
|
+
FlowExitKind,
|
|
13
|
+
FlowRegionEntryStructureFact,
|
|
14
|
+
FlowRegionStructureFact,
|
|
15
|
+
FlowStatementStructureFact,
|
|
16
|
+
} from '../engine/types.ts';
|
|
17
|
+
|
|
18
|
+
export type FlowFactKind = FlowConditionSyntaxFactKind;
|
|
19
|
+
|
|
20
|
+
export interface FlowFact<Path> {
|
|
21
|
+
kind: FlowFactKind;
|
|
22
|
+
path: Path;
|
|
23
|
+
polarity: 'negative' | 'positive';
|
|
24
|
+
sourceNode: ts.Node;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface ConditionAnalysis<Path> {
|
|
28
|
+
facts: readonly FlowFact<Path>[];
|
|
29
|
+
invalidatingNode?: ts.Node;
|
|
30
|
+
invalidatedFact?: FlowFact<Path>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface StatementAnalysisOptions {
|
|
34
|
+
treatContinueAsExit?: boolean;
|
|
35
|
+
treatBreakAsExit?: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface FlowFactEnvironment<Path, State> {
|
|
39
|
+
appendSegment(path: Path, segment: string): Path;
|
|
40
|
+
escapingExpressionAffectsNarrow(
|
|
41
|
+
context: AnalysisContext,
|
|
42
|
+
expression: ts.Expression,
|
|
43
|
+
path: Path,
|
|
44
|
+
state: State,
|
|
45
|
+
): boolean;
|
|
46
|
+
normalizeExpressionPath(
|
|
47
|
+
context: AnalysisContext,
|
|
48
|
+
expression: ts.Expression,
|
|
49
|
+
state: State,
|
|
50
|
+
): Path | undefined;
|
|
51
|
+
normalizeWholeValueFactPath(
|
|
52
|
+
context: AnalysisContext,
|
|
53
|
+
expression: ts.Expression,
|
|
54
|
+
state: State,
|
|
55
|
+
): Path | undefined;
|
|
56
|
+
shouldTrackFact(
|
|
57
|
+
context: AnalysisContext,
|
|
58
|
+
path: Path,
|
|
59
|
+
state: State,
|
|
60
|
+
): boolean;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
type SupportedTypeof = 'bigint' | 'boolean' | 'number' | 'object' | 'string' | 'symbol';
|
|
64
|
+
|
|
65
|
+
export function createFlowFact<Path>(
|
|
66
|
+
kind: FlowFactKind,
|
|
67
|
+
path: Path,
|
|
68
|
+
sourceNode: ts.Node,
|
|
69
|
+
polarity: 'negative' | 'positive' = 'positive',
|
|
70
|
+
): FlowFact<Path> {
|
|
71
|
+
return {
|
|
72
|
+
kind,
|
|
73
|
+
path,
|
|
74
|
+
polarity,
|
|
75
|
+
sourceNode,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function analyzeConditionExpression<Path, State>(
|
|
80
|
+
context: AnalysisContext,
|
|
81
|
+
expression: ts.Expression,
|
|
82
|
+
state: State,
|
|
83
|
+
environment: FlowFactEnvironment<Path, State>,
|
|
84
|
+
): ConditionAnalysis<Path> {
|
|
85
|
+
return analyzeConditionStructure(
|
|
86
|
+
context,
|
|
87
|
+
getFlowConditionStructure(context, expression),
|
|
88
|
+
state,
|
|
89
|
+
environment,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function getFlowConditionStructure(
|
|
94
|
+
context: AnalysisContext,
|
|
95
|
+
expression: ts.Expression,
|
|
96
|
+
): FlowConditionStructureFact {
|
|
97
|
+
return context.facts.getFlowConditionStructure(
|
|
98
|
+
expression,
|
|
99
|
+
() => parseConditionStructure(context, expression),
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function analyzeConditionStructure<Path, State>(
|
|
104
|
+
context: AnalysisContext,
|
|
105
|
+
structure: FlowConditionStructureFact,
|
|
106
|
+
state: State,
|
|
107
|
+
environment: FlowFactEnvironment<Path, State>,
|
|
108
|
+
): ConditionAnalysis<Path> {
|
|
109
|
+
return resolveConditionStructure(context, structure, state, environment);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function resolveConditionStructure<Path, State>(
|
|
113
|
+
context: AnalysisContext,
|
|
114
|
+
structure: FlowConditionStructureFact,
|
|
115
|
+
state: State,
|
|
116
|
+
environment: FlowFactEnvironment<Path, State>,
|
|
117
|
+
): ConditionAnalysis<Path> {
|
|
118
|
+
if (structure.kind === 'none') {
|
|
119
|
+
return { facts: [] };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (structure.kind === 'facts') {
|
|
123
|
+
return {
|
|
124
|
+
facts: materializeFlowFacts(context, structure.facts, state, environment),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const left = resolveConditionStructure(context, structure.left, state, environment);
|
|
129
|
+
const right = resolveConditionStructure(context, structure.right, state, environment);
|
|
130
|
+
const leftFacts = left.facts.filter((fact) =>
|
|
131
|
+
!environment.escapingExpressionAffectsNarrow(
|
|
132
|
+
context,
|
|
133
|
+
structure.rightExpression,
|
|
134
|
+
fact.path,
|
|
135
|
+
state,
|
|
136
|
+
)
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
facts: [...leftFacts, ...right.facts],
|
|
141
|
+
invalidatingNode: left.invalidatingNode ??
|
|
142
|
+
(
|
|
143
|
+
left.facts.some((fact) =>
|
|
144
|
+
environment.escapingExpressionAffectsNarrow(
|
|
145
|
+
context,
|
|
146
|
+
structure.rightExpression,
|
|
147
|
+
fact.path,
|
|
148
|
+
state,
|
|
149
|
+
)
|
|
150
|
+
)
|
|
151
|
+
? structure.rightExpression
|
|
152
|
+
: right.invalidatingNode
|
|
153
|
+
),
|
|
154
|
+
invalidatedFact: left.invalidatedFact ??
|
|
155
|
+
left.facts.find((fact) =>
|
|
156
|
+
environment.escapingExpressionAffectsNarrow(
|
|
157
|
+
context,
|
|
158
|
+
structure.rightExpression,
|
|
159
|
+
fact.path,
|
|
160
|
+
state,
|
|
161
|
+
)
|
|
162
|
+
) ??
|
|
163
|
+
right.invalidatedFact,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function materializeFlowFacts<Path, State>(
|
|
168
|
+
context: AnalysisContext,
|
|
169
|
+
facts: readonly FlowConditionSyntaxFact[],
|
|
170
|
+
state: State,
|
|
171
|
+
environment: FlowFactEnvironment<Path, State>,
|
|
172
|
+
): readonly FlowFact<Path>[] {
|
|
173
|
+
const materialized: FlowFact<Path>[] = [];
|
|
174
|
+
|
|
175
|
+
for (const fact of facts) {
|
|
176
|
+
if (fact.kind === 'inProperty') {
|
|
177
|
+
const basePath = environment.normalizeExpressionPath(context, fact.subjectExpression, state);
|
|
178
|
+
if (!basePath) {
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const path = environment.appendSegment(basePath, fact.propertySegment);
|
|
183
|
+
if (!environment.shouldTrackFact(context, path, state)) {
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
materialized.push(
|
|
188
|
+
createFlowFact(
|
|
189
|
+
'inProperty',
|
|
190
|
+
path,
|
|
191
|
+
fact.sourceNode,
|
|
192
|
+
fact.polarity,
|
|
193
|
+
),
|
|
194
|
+
);
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const path = environment.normalizeWholeValueFactPath(
|
|
199
|
+
context,
|
|
200
|
+
fact.subjectExpression,
|
|
201
|
+
state,
|
|
202
|
+
);
|
|
203
|
+
if (!path || !environment.shouldTrackFact(context, path, state)) {
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
materialized.push(
|
|
208
|
+
createFlowFact(fact.kind, path, fact.sourceNode, fact.polarity),
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return materialized;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export function extractSequentialFacts<Path, State>(
|
|
216
|
+
context: AnalysisContext,
|
|
217
|
+
statement: ts.Statement,
|
|
218
|
+
state: State,
|
|
219
|
+
environment: FlowFactEnvironment<Path, State>,
|
|
220
|
+
options: StatementAnalysisOptions = {},
|
|
221
|
+
): readonly FlowFact<Path>[] {
|
|
222
|
+
return materializeConditionStructures(
|
|
223
|
+
context,
|
|
224
|
+
getSequentialConditionStructures(context, statement, options),
|
|
225
|
+
state,
|
|
226
|
+
environment,
|
|
227
|
+
).facts;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export function materializeConditionStructures<Path, State>(
|
|
231
|
+
context: AnalysisContext,
|
|
232
|
+
structures: readonly FlowConditionStructureFact[],
|
|
233
|
+
state: State,
|
|
234
|
+
environment: FlowFactEnvironment<Path, State>,
|
|
235
|
+
): ConditionAnalysis<Path> {
|
|
236
|
+
const facts: FlowFact<Path>[] = [];
|
|
237
|
+
let invalidatingNode: ts.Node | undefined;
|
|
238
|
+
let invalidatedFact: FlowFact<Path> | undefined;
|
|
239
|
+
|
|
240
|
+
for (const structure of structures) {
|
|
241
|
+
const analysis = analyzeConditionStructure(context, structure, state, environment);
|
|
242
|
+
facts.push(...analysis.facts);
|
|
243
|
+
invalidatingNode ??= analysis.invalidatingNode;
|
|
244
|
+
invalidatedFact ??= analysis.invalidatedFact;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return { facts, invalidatingNode, invalidatedFact };
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export function getSequentialConditionStructures(
|
|
251
|
+
context: AnalysisContext,
|
|
252
|
+
statement: ts.Statement,
|
|
253
|
+
options: StatementAnalysisOptions = {},
|
|
254
|
+
): readonly FlowConditionStructureFact[] {
|
|
255
|
+
const structure = getFlowStatementStructure(context, statement);
|
|
256
|
+
|
|
257
|
+
if (
|
|
258
|
+
ts.isIfStatement(statement) &&
|
|
259
|
+
structure.kind === 'if' &&
|
|
260
|
+
structure.elseExitKinds.length === 0 &&
|
|
261
|
+
exitKindsSatisfyOptions(structure.thenExitKinds, options)
|
|
262
|
+
) {
|
|
263
|
+
return [getFallthroughConditionStructure(context, statement.expression)];
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (
|
|
267
|
+
ts.isIfStatement(statement) &&
|
|
268
|
+
structure.kind === 'if' &&
|
|
269
|
+
structure.elseExitKinds.length > 0 &&
|
|
270
|
+
exitKindsSatisfyOptions(structure.elseExitKinds, options)
|
|
271
|
+
) {
|
|
272
|
+
return [structure.condition];
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (structure.kind === 'expressionCall') {
|
|
276
|
+
return [structure.condition];
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (
|
|
280
|
+
structure.kind === 'try' &&
|
|
281
|
+
structure.exitKinds.length === 0 &&
|
|
282
|
+
(
|
|
283
|
+
!structure.hasCatch ||
|
|
284
|
+
(
|
|
285
|
+
structure.catchExitKinds.length > 0 &&
|
|
286
|
+
exitKindsSatisfyOptions(structure.catchExitKinds, options)
|
|
287
|
+
)
|
|
288
|
+
)
|
|
289
|
+
) {
|
|
290
|
+
return structure.tryTerminalConditions;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return [];
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export function getFlowStatementStructure(
|
|
297
|
+
context: AnalysisContext,
|
|
298
|
+
statement: ts.Statement,
|
|
299
|
+
): FlowStatementStructureFact {
|
|
300
|
+
return context.facts.getFlowStatementStructure(
|
|
301
|
+
statement,
|
|
302
|
+
() => parseStatementStructure(context, statement),
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export function getFlowBranchStructure(
|
|
307
|
+
context: AnalysisContext,
|
|
308
|
+
statement: ts.Statement,
|
|
309
|
+
): FlowBranchStructureFact {
|
|
310
|
+
return context.facts.getFlowBranchStructure(
|
|
311
|
+
statement,
|
|
312
|
+
() => createFlowBranchStructure(context, statement),
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export function getFlowChildRegionStructure(
|
|
317
|
+
context: AnalysisContext,
|
|
318
|
+
statement: ts.Statement,
|
|
319
|
+
): FlowChildRegionStructureFact {
|
|
320
|
+
return context.facts.getFlowChildRegionStructure(
|
|
321
|
+
statement,
|
|
322
|
+
() => createFlowChildRegionStructure(context, statement),
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export function getFlowRegionStructure(
|
|
327
|
+
context: AnalysisContext,
|
|
328
|
+
regionNode: ts.Node,
|
|
329
|
+
statements: readonly ts.Statement[],
|
|
330
|
+
options: StatementAnalysisOptions = {},
|
|
331
|
+
): FlowRegionStructureFact {
|
|
332
|
+
return context.facts.getFlowRegionStructure(
|
|
333
|
+
regionNode,
|
|
334
|
+
getStatementOptionsKey(options),
|
|
335
|
+
() => createFlowRegionStructure(context, statements, options),
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function createFlowBranchStructure(
|
|
340
|
+
context: AnalysisContext,
|
|
341
|
+
statement: ts.Statement,
|
|
342
|
+
): FlowBranchStructureFact {
|
|
343
|
+
if (ts.isIfStatement(statement)) {
|
|
344
|
+
const structure = getFlowStatementStructure(context, statement);
|
|
345
|
+
const entries: FlowBranchEntryStructureFact[] = [{
|
|
346
|
+
entryConditions: structure.kind === 'if' ? [structure.condition] : [],
|
|
347
|
+
regionNode: getStatementRegionNode(statement.thenStatement),
|
|
348
|
+
statements: getStatementStatements(statement.thenStatement),
|
|
349
|
+
}];
|
|
350
|
+
|
|
351
|
+
if (statement.elseStatement) {
|
|
352
|
+
entries.push({
|
|
353
|
+
entryConditions: structure.kind === 'if' ? [structure.condition] : [],
|
|
354
|
+
regionNode: getStatementRegionNode(statement.elseStatement),
|
|
355
|
+
statements: getStatementStatements(statement.elseStatement),
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return { entries };
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
if (
|
|
363
|
+
ts.isWhileStatement(statement) ||
|
|
364
|
+
ts.isDoStatement(statement) ||
|
|
365
|
+
ts.isForStatement(statement) ||
|
|
366
|
+
ts.isForOfStatement(statement) ||
|
|
367
|
+
ts.isForInStatement(statement)
|
|
368
|
+
) {
|
|
369
|
+
const structure = getFlowStatementStructure(context, statement);
|
|
370
|
+
return {
|
|
371
|
+
entries: [{
|
|
372
|
+
entryConditions: structure.kind === 'loop' && structure.condition
|
|
373
|
+
? [structure.condition]
|
|
374
|
+
: [],
|
|
375
|
+
regionNode: getStatementRegionNode(statement.statement),
|
|
376
|
+
statements: getStatementStatements(statement.statement),
|
|
377
|
+
}],
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
if (ts.isSwitchStatement(statement)) {
|
|
382
|
+
const switchStructure = getFlowStatementStructure(context, statement);
|
|
383
|
+
let defaultEntryConditions: readonly FlowConditionStructureFact[] = [];
|
|
384
|
+
|
|
385
|
+
return {
|
|
386
|
+
entries: statement.caseBlock.clauses.map((clause, clauseIndex) => {
|
|
387
|
+
const entryConditions = switchStructure.kind === 'switch' &&
|
|
388
|
+
switchStructure.caseConditions[clauseIndex]
|
|
389
|
+
? [switchStructure.caseConditions[clauseIndex]]
|
|
390
|
+
: defaultEntryConditions;
|
|
391
|
+
|
|
392
|
+
if (switchStructure.kind === 'switch' && switchStructure.isSwitchTrue) {
|
|
393
|
+
if (
|
|
394
|
+
ts.isCaseClause(clause) &&
|
|
395
|
+
exitKindsSatisfyOptions(getStatementsExitKinds(context, clause.statements), {
|
|
396
|
+
treatBreakAsExit: true,
|
|
397
|
+
})
|
|
398
|
+
) {
|
|
399
|
+
defaultEntryConditions = [
|
|
400
|
+
...defaultEntryConditions,
|
|
401
|
+
getFallthroughConditionStructure(context, clause.expression),
|
|
402
|
+
];
|
|
403
|
+
} else {
|
|
404
|
+
defaultEntryConditions = [];
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
return {
|
|
409
|
+
entryConditions,
|
|
410
|
+
regionNode: clause,
|
|
411
|
+
statements: clause.statements,
|
|
412
|
+
};
|
|
413
|
+
}),
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
return { entries: [] };
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function createFlowChildRegionStructure(
|
|
421
|
+
context: AnalysisContext,
|
|
422
|
+
statement: ts.Statement,
|
|
423
|
+
): FlowChildRegionStructureFact {
|
|
424
|
+
if (ts.isBlock(statement)) {
|
|
425
|
+
return {
|
|
426
|
+
entries: [{
|
|
427
|
+
entryConditions: [],
|
|
428
|
+
regionNode: statement,
|
|
429
|
+
statements: statement.statements,
|
|
430
|
+
treatBreakAsExit: false,
|
|
431
|
+
treatContinueAsExit: false,
|
|
432
|
+
}],
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
if (ts.isTryStatement(statement)) {
|
|
437
|
+
const entries: FlowChildRegionStructureEntryFact[] = [{
|
|
438
|
+
entryConditions: [],
|
|
439
|
+
regionNode: statement.tryBlock,
|
|
440
|
+
statements: statement.tryBlock.statements,
|
|
441
|
+
treatBreakAsExit: false,
|
|
442
|
+
treatContinueAsExit: false,
|
|
443
|
+
}];
|
|
444
|
+
|
|
445
|
+
if (statement.catchClause) {
|
|
446
|
+
entries.push({
|
|
447
|
+
entryConditions: [],
|
|
448
|
+
regionNode: statement.catchClause.block,
|
|
449
|
+
statements: statement.catchClause.block.statements,
|
|
450
|
+
treatBreakAsExit: false,
|
|
451
|
+
treatContinueAsExit: false,
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
if (statement.finallyBlock) {
|
|
456
|
+
entries.push({
|
|
457
|
+
entryConditions: [],
|
|
458
|
+
regionNode: statement.finallyBlock,
|
|
459
|
+
statements: statement.finallyBlock.statements,
|
|
460
|
+
treatBreakAsExit: false,
|
|
461
|
+
treatContinueAsExit: false,
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
return { entries };
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
if (
|
|
469
|
+
ts.isIfStatement(statement) ||
|
|
470
|
+
ts.isSwitchStatement(statement) ||
|
|
471
|
+
ts.isWhileStatement(statement) ||
|
|
472
|
+
ts.isDoStatement(statement) ||
|
|
473
|
+
ts.isForStatement(statement) ||
|
|
474
|
+
ts.isForOfStatement(statement) ||
|
|
475
|
+
ts.isForInStatement(statement)
|
|
476
|
+
) {
|
|
477
|
+
const branchStructure = getFlowBranchStructure(context, statement);
|
|
478
|
+
return {
|
|
479
|
+
entries: branchStructure.entries.map((entry) => ({
|
|
480
|
+
entryConditions: entry.entryConditions,
|
|
481
|
+
regionNode: entry.regionNode,
|
|
482
|
+
statements: entry.statements,
|
|
483
|
+
treatBreakAsExit: ts.isWhileStatement(statement) ||
|
|
484
|
+
ts.isDoStatement(statement) ||
|
|
485
|
+
ts.isForStatement(statement) ||
|
|
486
|
+
ts.isForOfStatement(statement) ||
|
|
487
|
+
ts.isForInStatement(statement),
|
|
488
|
+
treatContinueAsExit: ts.isWhileStatement(statement) ||
|
|
489
|
+
ts.isDoStatement(statement) ||
|
|
490
|
+
ts.isForStatement(statement) ||
|
|
491
|
+
ts.isForOfStatement(statement) ||
|
|
492
|
+
ts.isForInStatement(statement),
|
|
493
|
+
})),
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
return { entries: [] };
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
function createFlowRegionStructure(
|
|
501
|
+
context: AnalysisContext,
|
|
502
|
+
statements: readonly ts.Statement[],
|
|
503
|
+
options: StatementAnalysisOptions,
|
|
504
|
+
): FlowRegionStructureFact {
|
|
505
|
+
const entries: FlowRegionEntryStructureFact[] = [];
|
|
506
|
+
let sequentialConditions: readonly FlowConditionStructureFact[] = [];
|
|
507
|
+
|
|
508
|
+
for (const statement of statements) {
|
|
509
|
+
if (context.isGeneratedNode(statement)) {
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
entries.push({
|
|
514
|
+
statement,
|
|
515
|
+
sequentialConditions,
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
sequentialConditions = [
|
|
519
|
+
...sequentialConditions,
|
|
520
|
+
...getSequentialConditionStructures(context, statement, options),
|
|
521
|
+
];
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
return {
|
|
525
|
+
entries,
|
|
526
|
+
terminalConditions: sequentialConditions,
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function getStatementStatements(statement: ts.Statement): readonly ts.Statement[] {
|
|
531
|
+
return ts.isBlock(statement) ? statement.statements : [statement];
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
function getStatementRegionNode(statement: ts.Statement): ts.Node {
|
|
535
|
+
return statement;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
function parseStatementStructure(
|
|
539
|
+
context: AnalysisContext,
|
|
540
|
+
statement: ts.Statement,
|
|
541
|
+
): FlowStatementStructureFact {
|
|
542
|
+
if (ts.isReturnStatement(statement) || ts.isThrowStatement(statement)) {
|
|
543
|
+
return { kind: 'other', exitKinds: ['returnThrow'] };
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
if (ts.isBreakStatement(statement)) {
|
|
547
|
+
return { kind: 'other', exitKinds: ['break'] };
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
if (ts.isContinueStatement(statement)) {
|
|
551
|
+
return { kind: 'other', exitKinds: ['continue'] };
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
if (ts.isBlock(statement)) {
|
|
555
|
+
return { kind: 'other', exitKinds: getStatementsExitKinds(context, statement.statements) };
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
if (ts.isIfStatement(statement)) {
|
|
559
|
+
const thenExitKinds = getFlowStatementStructure(context, statement.thenStatement).exitKinds;
|
|
560
|
+
const elseExitKinds = statement.elseStatement
|
|
561
|
+
? getFlowStatementStructure(context, statement.elseStatement).exitKinds
|
|
562
|
+
: [];
|
|
563
|
+
const exitKinds = elseExitKinds.length > 0 ? mergeExitKinds(thenExitKinds, elseExitKinds) : [];
|
|
564
|
+
|
|
565
|
+
return {
|
|
566
|
+
kind: 'if',
|
|
567
|
+
condition: getFlowConditionStructure(context, statement.expression),
|
|
568
|
+
thenExitKinds,
|
|
569
|
+
elseExitKinds,
|
|
570
|
+
exitKinds,
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
if (
|
|
575
|
+
ts.isWhileStatement(statement) ||
|
|
576
|
+
ts.isDoStatement(statement) ||
|
|
577
|
+
ts.isForStatement(statement)
|
|
578
|
+
) {
|
|
579
|
+
const condition = ts.isForStatement(statement) ? statement.condition : statement.expression;
|
|
580
|
+
return {
|
|
581
|
+
kind: 'loop',
|
|
582
|
+
condition: condition ? getFlowConditionStructure(context, condition) : undefined,
|
|
583
|
+
exitKinds: [],
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
if (ts.isForOfStatement(statement) || ts.isForInStatement(statement)) {
|
|
588
|
+
return { kind: 'loop', exitKinds: [] };
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
if (ts.isSwitchStatement(statement)) {
|
|
592
|
+
return {
|
|
593
|
+
kind: 'switch',
|
|
594
|
+
isSwitchTrue: statement.expression.kind === ts.SyntaxKind.TrueKeyword,
|
|
595
|
+
caseConditions: statement.caseBlock.clauses.map((clause) =>
|
|
596
|
+
getSwitchClauseConditionStructure(context, statement, clause)
|
|
597
|
+
),
|
|
598
|
+
exitKinds: [],
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
if (ts.isTryStatement(statement)) {
|
|
603
|
+
const finallyExitKinds = statement.finallyBlock
|
|
604
|
+
? getStatementsExitKinds(context, statement.finallyBlock.statements)
|
|
605
|
+
: [];
|
|
606
|
+
|
|
607
|
+
return {
|
|
608
|
+
kind: 'try',
|
|
609
|
+
tryTerminalConditions: getFlowRegionStructure(
|
|
610
|
+
context,
|
|
611
|
+
statement.tryBlock,
|
|
612
|
+
statement.tryBlock.statements,
|
|
613
|
+
).terminalConditions,
|
|
614
|
+
catchExitKinds: statement.catchClause
|
|
615
|
+
? getStatementsExitKinds(context, statement.catchClause.block.statements)
|
|
616
|
+
: [],
|
|
617
|
+
exitKinds: finallyExitKinds,
|
|
618
|
+
hasCatch: !!statement.catchClause,
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
if (ts.isExpressionStatement(statement) && ts.isCallExpression(statement.expression)) {
|
|
623
|
+
return {
|
|
624
|
+
kind: 'expressionCall',
|
|
625
|
+
condition: getFlowConditionStructure(context, statement.expression),
|
|
626
|
+
exitKinds: [],
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
return { kind: 'other', exitKinds: [] };
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
function mergeExitKinds(
|
|
634
|
+
left: readonly FlowExitKind[],
|
|
635
|
+
right: readonly FlowExitKind[],
|
|
636
|
+
): readonly FlowExitKind[] {
|
|
637
|
+
if (left.length === 0 || right.length === 0) {
|
|
638
|
+
return [];
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
return [...new Set<FlowExitKind>([...left, ...right])];
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
function exitKindsSatisfyOptions(
|
|
645
|
+
exitKinds: readonly FlowExitKind[],
|
|
646
|
+
options: StatementAnalysisOptions,
|
|
647
|
+
): boolean {
|
|
648
|
+
return exitKinds.length > 0 &&
|
|
649
|
+
exitKinds.every((kind) =>
|
|
650
|
+
kind === 'returnThrow' ||
|
|
651
|
+
(kind === 'break' && !!options.treatBreakAsExit) ||
|
|
652
|
+
(kind === 'continue' && !!options.treatContinueAsExit)
|
|
653
|
+
);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
function getStatementOptionsKey(options: StatementAnalysisOptions): string {
|
|
657
|
+
return `break:${options.treatBreakAsExit ? '1' : '0'}|continue:${
|
|
658
|
+
options.treatContinueAsExit ? '1' : '0'
|
|
659
|
+
}`;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
function getSwitchClauseConditionStructure(
|
|
663
|
+
context: AnalysisContext,
|
|
664
|
+
statement: ts.SwitchStatement,
|
|
665
|
+
clause: ts.CaseOrDefaultClause,
|
|
666
|
+
): FlowConditionStructureFact | undefined {
|
|
667
|
+
if (statement.expression.kind === ts.SyntaxKind.TrueKeyword) {
|
|
668
|
+
return ts.isCaseClause(clause)
|
|
669
|
+
? getFlowConditionStructure(context, clause.expression)
|
|
670
|
+
: undefined;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
const discriminant = statement.expression;
|
|
674
|
+
const subjectExpression = ts.isTypeOfExpression(discriminant)
|
|
675
|
+
? discriminant.expression
|
|
676
|
+
: discriminant;
|
|
677
|
+
|
|
678
|
+
if (
|
|
679
|
+
(ts.isIdentifier(subjectExpression) ||
|
|
680
|
+
ts.isPropertyAccessExpression(subjectExpression) ||
|
|
681
|
+
ts.isElementAccessExpression(subjectExpression)) &&
|
|
682
|
+
(ts.isDefaultClause(clause) ||
|
|
683
|
+
(ts.isCaseClause(clause) && isSwitchCaseLiteral(clause.expression)))
|
|
684
|
+
) {
|
|
685
|
+
const kind = ts.isTypeOfExpression(discriminant) ? 'typeof' : 'truthy';
|
|
686
|
+
return {
|
|
687
|
+
kind: 'facts',
|
|
688
|
+
facts: [{
|
|
689
|
+
kind,
|
|
690
|
+
polarity: 'positive',
|
|
691
|
+
sourceNode: clause,
|
|
692
|
+
subjectExpression,
|
|
693
|
+
}],
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
return undefined;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
function parseConditionStructure(
|
|
701
|
+
context: AnalysisContext,
|
|
702
|
+
expression: ts.Expression,
|
|
703
|
+
): FlowConditionStructureFact {
|
|
704
|
+
if (ts.isParenthesizedExpression(expression)) {
|
|
705
|
+
return parseConditionStructure(context, expression.expression);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
if (
|
|
709
|
+
ts.isPrefixUnaryExpression(expression) && expression.operator === ts.SyntaxKind.ExclamationToken
|
|
710
|
+
) {
|
|
711
|
+
return invertConditionStructure(parseConditionStructure(context, expression.operand));
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
if (
|
|
715
|
+
ts.isBinaryExpression(expression) &&
|
|
716
|
+
expression.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken
|
|
717
|
+
) {
|
|
718
|
+
return {
|
|
719
|
+
kind: 'and',
|
|
720
|
+
left: parseConditionStructure(context, expression.left),
|
|
721
|
+
right: parseConditionStructure(context, expression.right),
|
|
722
|
+
rightExpression: expression.right,
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
const directFacts = parseDirectConditionFacts(context, expression);
|
|
727
|
+
return directFacts.length > 0 ? { kind: 'facts', facts: directFacts } : { kind: 'none' };
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
function getFallthroughConditionStructure(
|
|
731
|
+
context: AnalysisContext,
|
|
732
|
+
expression: ts.Expression,
|
|
733
|
+
): FlowConditionStructureFact {
|
|
734
|
+
if (ts.isParenthesizedExpression(expression)) {
|
|
735
|
+
return getFallthroughConditionStructure(context, expression.expression);
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
if (
|
|
739
|
+
ts.isPrefixUnaryExpression(expression) && expression.operator === ts.SyntaxKind.ExclamationToken
|
|
740
|
+
) {
|
|
741
|
+
return invertConditionStructure(getFallthroughConditionStructure(context, expression.operand));
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
if (
|
|
745
|
+
ts.isBinaryExpression(expression) &&
|
|
746
|
+
expression.operatorToken.kind === ts.SyntaxKind.BarBarToken
|
|
747
|
+
) {
|
|
748
|
+
return {
|
|
749
|
+
kind: 'and',
|
|
750
|
+
left: getFallthroughConditionStructure(context, expression.left),
|
|
751
|
+
right: getFallthroughConditionStructure(context, expression.right),
|
|
752
|
+
rightExpression: expression.right,
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
return getFlowConditionStructure(context, expression);
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
function invertConditionStructure(
|
|
760
|
+
structure: FlowConditionStructureFact,
|
|
761
|
+
): FlowConditionStructureFact {
|
|
762
|
+
if (structure.kind === 'none') {
|
|
763
|
+
return structure;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
if (structure.kind === 'and') {
|
|
767
|
+
return {
|
|
768
|
+
kind: 'and',
|
|
769
|
+
left: invertConditionStructure(structure.left),
|
|
770
|
+
right: invertConditionStructure(structure.right),
|
|
771
|
+
rightExpression: structure.rightExpression,
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
return {
|
|
776
|
+
kind: 'facts',
|
|
777
|
+
facts: structure.facts.map((fact) => ({
|
|
778
|
+
...fact,
|
|
779
|
+
polarity: fact.polarity === 'positive' ? 'negative' : 'positive',
|
|
780
|
+
})),
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
function parseDirectConditionFacts(
|
|
785
|
+
context: AnalysisContext,
|
|
786
|
+
expression: ts.Expression,
|
|
787
|
+
): readonly FlowConditionSyntaxFact[] {
|
|
788
|
+
if (ts.isCallExpression(expression)) {
|
|
789
|
+
const signature = context.checker.getResolvedSignature(expression);
|
|
790
|
+
const predicate = signature
|
|
791
|
+
? context.checker.getTypePredicateOfSignature(signature)
|
|
792
|
+
: undefined;
|
|
793
|
+
if (!predicate) {
|
|
794
|
+
return [];
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
if (predicate.parameterIndex !== undefined) {
|
|
798
|
+
const argument = expression.arguments[predicate.parameterIndex];
|
|
799
|
+
if (!argument) {
|
|
800
|
+
return [];
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
const kind = predicate.kind === ts.TypePredicateKind.AssertsIdentifier
|
|
804
|
+
? 'assertionCall'
|
|
805
|
+
: 'predicateCall';
|
|
806
|
+
return [{
|
|
807
|
+
kind,
|
|
808
|
+
polarity: 'positive',
|
|
809
|
+
sourceNode: expression,
|
|
810
|
+
subjectExpression: argument,
|
|
811
|
+
}];
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
if (
|
|
815
|
+
predicate.kind === ts.TypePredicateKind.AssertsThis ||
|
|
816
|
+
predicate.kind === ts.TypePredicateKind.This
|
|
817
|
+
) {
|
|
818
|
+
const callee = expression.expression;
|
|
819
|
+
const receiver = ts.isPropertyAccessExpression(callee) || ts.isElementAccessExpression(callee)
|
|
820
|
+
? callee.expression
|
|
821
|
+
: undefined;
|
|
822
|
+
return receiver
|
|
823
|
+
? [{
|
|
824
|
+
kind: 'assertionCall',
|
|
825
|
+
polarity: 'positive',
|
|
826
|
+
sourceNode: expression,
|
|
827
|
+
subjectExpression: receiver,
|
|
828
|
+
}]
|
|
829
|
+
: [];
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
if (
|
|
834
|
+
ts.isBinaryExpression(expression) &&
|
|
835
|
+
expression.operatorToken.kind === ts.SyntaxKind.InstanceOfKeyword
|
|
836
|
+
) {
|
|
837
|
+
return [{
|
|
838
|
+
kind: 'instanceof',
|
|
839
|
+
polarity: 'positive',
|
|
840
|
+
sourceNode: expression,
|
|
841
|
+
subjectExpression: expression.left,
|
|
842
|
+
}];
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
if (
|
|
846
|
+
ts.isBinaryExpression(expression) &&
|
|
847
|
+
(expression.operatorToken.kind === ts.SyntaxKind.EqualsEqualsEqualsToken ||
|
|
848
|
+
expression.operatorToken.kind === ts.SyntaxKind.ExclamationEqualsEqualsToken ||
|
|
849
|
+
expression.operatorToken.kind === ts.SyntaxKind.ExclamationEqualsToken) &&
|
|
850
|
+
(
|
|
851
|
+
(ts.isTypeOfExpression(expression.left) && ts.isStringLiteral(expression.right)) ||
|
|
852
|
+
(ts.isStringLiteral(expression.left) && ts.isTypeOfExpression(expression.right))
|
|
853
|
+
)
|
|
854
|
+
) {
|
|
855
|
+
return [{
|
|
856
|
+
kind: 'typeof',
|
|
857
|
+
polarity: 'positive',
|
|
858
|
+
sourceNode: expression,
|
|
859
|
+
subjectExpression: ts.isTypeOfExpression(expression.left)
|
|
860
|
+
? expression.left.expression
|
|
861
|
+
: (expression.right as ts.TypeOfExpression).expression,
|
|
862
|
+
}];
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
if (
|
|
866
|
+
ts.isBinaryExpression(expression) &&
|
|
867
|
+
expression.operatorToken.kind === ts.SyntaxKind.EqualsEqualsEqualsToken &&
|
|
868
|
+
(
|
|
869
|
+
(
|
|
870
|
+
(ts.isPropertyAccessExpression(expression.left) ||
|
|
871
|
+
ts.isElementAccessExpression(expression.left) ||
|
|
872
|
+
ts.isIdentifier(expression.left)) &&
|
|
873
|
+
isSwitchCaseLiteral(expression.right)
|
|
874
|
+
) ||
|
|
875
|
+
(
|
|
876
|
+
(ts.isPropertyAccessExpression(expression.right) ||
|
|
877
|
+
ts.isElementAccessExpression(expression.right) ||
|
|
878
|
+
ts.isIdentifier(expression.right)) &&
|
|
879
|
+
isSwitchCaseLiteral(expression.left)
|
|
880
|
+
)
|
|
881
|
+
)
|
|
882
|
+
) {
|
|
883
|
+
return [{
|
|
884
|
+
kind: 'discriminantLiteral',
|
|
885
|
+
polarity: 'positive',
|
|
886
|
+
sourceNode: expression,
|
|
887
|
+
subjectExpression: ts.isPropertyAccessExpression(expression.left) ||
|
|
888
|
+
ts.isElementAccessExpression(expression.left) ||
|
|
889
|
+
ts.isIdentifier(expression.left)
|
|
890
|
+
? expression.left
|
|
891
|
+
: expression.right,
|
|
892
|
+
}];
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
if (
|
|
896
|
+
ts.isBinaryExpression(expression) &&
|
|
897
|
+
expression.operatorToken.kind === ts.SyntaxKind.InKeyword &&
|
|
898
|
+
(ts.isStringLiteral(expression.left) || ts.isNumericLiteral(expression.left))
|
|
899
|
+
) {
|
|
900
|
+
return [{
|
|
901
|
+
kind: 'inProperty',
|
|
902
|
+
polarity: 'positive',
|
|
903
|
+
propertySegment: expression.left.text,
|
|
904
|
+
sourceNode: expression,
|
|
905
|
+
subjectExpression: expression.right,
|
|
906
|
+
}];
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
if (
|
|
910
|
+
ts.isBinaryExpression(expression) &&
|
|
911
|
+
(
|
|
912
|
+
expression.operatorToken.kind === ts.SyntaxKind.ExclamationEqualsEqualsToken ||
|
|
913
|
+
expression.operatorToken.kind === ts.SyntaxKind.ExclamationEqualsToken ||
|
|
914
|
+
expression.operatorToken.kind === ts.SyntaxKind.EqualsEqualsEqualsToken
|
|
915
|
+
)
|
|
916
|
+
) {
|
|
917
|
+
const leftIsUndefined = ts.isIdentifier(expression.left) &&
|
|
918
|
+
expression.left.text === 'undefined';
|
|
919
|
+
const rightIsUndefined = ts.isIdentifier(expression.right) &&
|
|
920
|
+
expression.right.text === 'undefined';
|
|
921
|
+
const leftIsNull = expression.left.kind === ts.SyntaxKind.NullKeyword;
|
|
922
|
+
const rightIsNull = expression.right.kind === ts.SyntaxKind.NullKeyword;
|
|
923
|
+
const subjectExpression = leftIsUndefined
|
|
924
|
+
? expression.right
|
|
925
|
+
: rightIsUndefined
|
|
926
|
+
? expression.left
|
|
927
|
+
: leftIsNull
|
|
928
|
+
? expression.right
|
|
929
|
+
: rightIsNull
|
|
930
|
+
? expression.left
|
|
931
|
+
: undefined;
|
|
932
|
+
return subjectExpression
|
|
933
|
+
? [{
|
|
934
|
+
kind: 'nonNull',
|
|
935
|
+
polarity: 'positive',
|
|
936
|
+
sourceNode: expression,
|
|
937
|
+
subjectExpression,
|
|
938
|
+
}]
|
|
939
|
+
: [];
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
if (
|
|
943
|
+
ts.isIdentifier(expression) || ts.isPropertyAccessExpression(expression) ||
|
|
944
|
+
ts.isElementAccessExpression(expression)
|
|
945
|
+
) {
|
|
946
|
+
return [{
|
|
947
|
+
kind: 'truthy',
|
|
948
|
+
polarity: 'positive',
|
|
949
|
+
sourceNode: expression,
|
|
950
|
+
subjectExpression: expression,
|
|
951
|
+
}];
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
return [];
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
function isSwitchCaseLiteral(expression: ts.Expression): boolean {
|
|
958
|
+
return ts.isStringLiteral(expression) ||
|
|
959
|
+
ts.isNumericLiteral(expression) ||
|
|
960
|
+
ts.isNoSubstitutionTemplateLiteral(expression) ||
|
|
961
|
+
expression.kind === ts.SyntaxKind.TrueKeyword ||
|
|
962
|
+
expression.kind === ts.SyntaxKind.FalseKeyword ||
|
|
963
|
+
expression.kind === ts.SyntaxKind.NullKeyword;
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
function getStatementsExitKinds(
|
|
967
|
+
context: AnalysisContext,
|
|
968
|
+
statements: readonly ts.Statement[],
|
|
969
|
+
): readonly FlowExitKind[] {
|
|
970
|
+
for (const child of statements) {
|
|
971
|
+
const childStructure = getFlowStatementStructure(context, child);
|
|
972
|
+
if (childStructure.exitKinds.length > 0) {
|
|
973
|
+
return childStructure.exitKinds;
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
return [];
|
|
978
|
+
}
|