@soundscript/soundscript 0.1.13 → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,798 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { SOUND_DIAGNOSTIC_CODES, SOUND_DIAGNOSTIC_MESSAGES } from '../engine/diagnostic_codes.js';
|
|
3
|
+
import { getNodeDiagnosticRange } from '../diagnostics.js';
|
|
4
|
+
var FieldInitializationState;
|
|
5
|
+
(function (FieldInitializationState) {
|
|
6
|
+
FieldInitializationState[FieldInitializationState["Uninitialized"] = 0] = "Uninitialized";
|
|
7
|
+
FieldInitializationState[FieldInitializationState["MaybeInitialized"] = 1] = "MaybeInitialized";
|
|
8
|
+
FieldInitializationState[FieldInitializationState["DefinitelyInitialized"] = 2] = "DefinitelyInitialized";
|
|
9
|
+
})(FieldInitializationState || (FieldInitializationState = {}));
|
|
10
|
+
var TrackedValueMask;
|
|
11
|
+
(function (TrackedValueMask) {
|
|
12
|
+
TrackedValueMask[TrackedValueMask["None"] = 0] = "None";
|
|
13
|
+
TrackedValueMask[TrackedValueMask["ThisAlias"] = 1] = "ThisAlias";
|
|
14
|
+
TrackedValueMask[TrackedValueMask["CapturedThisClosure"] = 2] = "CapturedThisClosure";
|
|
15
|
+
})(TrackedValueMask || (TrackedValueMask = {}));
|
|
16
|
+
function createLifecycleExample(info) {
|
|
17
|
+
if (info.hazardKind === 'receiver method dispatch' ||
|
|
18
|
+
info.hazardKind === 'receiver accessor dispatch') {
|
|
19
|
+
return `Write fields directly during construction, then call \`${info.memberName ?? 'the member'}\` from a post-construction method or factory step instead of from the constructor.`;
|
|
20
|
+
}
|
|
21
|
+
return 'Finish initialization first, then pass `this` or code that captures it to other routines only after construction completes.';
|
|
22
|
+
}
|
|
23
|
+
function createLifecycleNote(info) {
|
|
24
|
+
if (info.hazardKind === 'receiver method dispatch' ||
|
|
25
|
+
info.hazardKind === 'receiver accessor dispatch') {
|
|
26
|
+
const receiver = info.receiverKind ?? 'this';
|
|
27
|
+
return `This constructor dispatches through \`${receiver}.${info.memberName ?? 'member'}\` before construction completes.`;
|
|
28
|
+
}
|
|
29
|
+
if (info.hazardKind === 'captured closure call') {
|
|
30
|
+
return 'This constructor calls a closure that captures `this` before construction completes.';
|
|
31
|
+
}
|
|
32
|
+
if (info.hazardKind === 'tracked this argument escape') {
|
|
33
|
+
return 'This constructor passes `this` or a value that captures it into another call before construction completes.';
|
|
34
|
+
}
|
|
35
|
+
if (info.hazardKind === 'tracked this return') {
|
|
36
|
+
return 'This constructor returns `this` or a value that captures it before construction completes.';
|
|
37
|
+
}
|
|
38
|
+
if (info.hazardKind === 'tracked this throw') {
|
|
39
|
+
return 'This constructor throws `this` or a value that captures it before construction completes.';
|
|
40
|
+
}
|
|
41
|
+
return 'This constructor stores or forwards `this` before construction completes.';
|
|
42
|
+
}
|
|
43
|
+
function createLifecycleDiagnostic(info) {
|
|
44
|
+
const example = createLifecycleExample(info);
|
|
45
|
+
return {
|
|
46
|
+
source: 'sound',
|
|
47
|
+
code: SOUND_DIAGNOSTIC_CODES.constructionLifecycleViolation,
|
|
48
|
+
category: 'error',
|
|
49
|
+
message: SOUND_DIAGNOSTIC_MESSAGES.constructionLifecycleViolation,
|
|
50
|
+
metadata: {
|
|
51
|
+
rule: 'construction_lifecycle_violation',
|
|
52
|
+
primarySymbol: info.memberName,
|
|
53
|
+
fixability: 'local_rewrite',
|
|
54
|
+
invariant: 'Constructors and field initializers must finish establishing instance state before they dispatch through members or let `this` escape.',
|
|
55
|
+
replacementFamily: 'finish_initialization_before_dispatch',
|
|
56
|
+
evidence: [
|
|
57
|
+
{ label: 'hazardKind', value: info.hazardKind },
|
|
58
|
+
...(info.receiverKind ? [{ label: 'receiver', value: info.receiverKind }] : []),
|
|
59
|
+
...(info.memberName ? [{ label: 'memberName', value: info.memberName }] : []),
|
|
60
|
+
],
|
|
61
|
+
counterexample: 'Dispatching through instance members before construction completes can observe partially initialized state or overridden subclass behavior.',
|
|
62
|
+
example,
|
|
63
|
+
},
|
|
64
|
+
notes: [
|
|
65
|
+
createLifecycleNote(info),
|
|
66
|
+
`Example: ${example}`,
|
|
67
|
+
],
|
|
68
|
+
hint: 'Finish initialization before calling instance members or letting `this` escape.',
|
|
69
|
+
...getNodeDiagnosticRange(info.node),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function createFieldInitializationDiagnostic(info) {
|
|
73
|
+
const fieldName = info.fieldName ?? 'this field';
|
|
74
|
+
const example = `Assign \`${fieldName}\` on every path before reading it, or move the read after the initializing assignment.`;
|
|
75
|
+
return {
|
|
76
|
+
source: 'sound',
|
|
77
|
+
code: SOUND_DIAGNOSTIC_CODES.fieldReadBeforeInitialization,
|
|
78
|
+
category: 'error',
|
|
79
|
+
message: SOUND_DIAGNOSTIC_MESSAGES.fieldReadBeforeInitialization,
|
|
80
|
+
metadata: {
|
|
81
|
+
rule: 'field_read_before_initialization',
|
|
82
|
+
primarySymbol: info.fieldName,
|
|
83
|
+
fixability: 'local_rewrite',
|
|
84
|
+
invariant: 'Instance fields must be definitely initialized on every path before reads during construction or field initialization.',
|
|
85
|
+
replacementFamily: 'initialize_before_read',
|
|
86
|
+
evidence: [
|
|
87
|
+
...(info.fieldName ? [{ label: 'fieldName', value: info.fieldName }] : []),
|
|
88
|
+
{ label: 'accessKind', value: info.accessKind },
|
|
89
|
+
],
|
|
90
|
+
counterexample: 'A read before definite initialization can observe an uninitialized field or depend on constructor ordering that soundscript cannot prove safe.',
|
|
91
|
+
example,
|
|
92
|
+
},
|
|
93
|
+
notes: [
|
|
94
|
+
`The read of \`${fieldName}\` can happen before that field is definitely initialized on every path.`,
|
|
95
|
+
`Example: ${example}`,
|
|
96
|
+
],
|
|
97
|
+
hint: 'Initialize the field before reading it, or defer the read until after construction establishes the value.',
|
|
98
|
+
...getNodeDiagnosticRange(info.node),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function cloneState(state) {
|
|
102
|
+
return {
|
|
103
|
+
fieldStates: new Map(state.fieldStates),
|
|
104
|
+
trackedValues: new Map(state.trackedValues),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function mergeFieldState(left, right) {
|
|
108
|
+
if (left === right) {
|
|
109
|
+
return left;
|
|
110
|
+
}
|
|
111
|
+
if (left === FieldInitializationState.DefinitelyInitialized &&
|
|
112
|
+
right === FieldInitializationState.DefinitelyInitialized) {
|
|
113
|
+
return FieldInitializationState.DefinitelyInitialized;
|
|
114
|
+
}
|
|
115
|
+
if (left === FieldInitializationState.Uninitialized &&
|
|
116
|
+
right === FieldInitializationState.Uninitialized) {
|
|
117
|
+
return FieldInitializationState.Uninitialized;
|
|
118
|
+
}
|
|
119
|
+
return FieldInitializationState.MaybeInitialized;
|
|
120
|
+
}
|
|
121
|
+
function mergeStates(states) {
|
|
122
|
+
if (states.length === 0) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
const mergedFieldStates = new Map(states[0].fieldStates);
|
|
126
|
+
const mergedTrackedValues = new Map(states[0].trackedValues);
|
|
127
|
+
for (const state of states.slice(1)) {
|
|
128
|
+
for (const [fieldName, fieldState] of state.fieldStates) {
|
|
129
|
+
mergedFieldStates.set(fieldName, mergeFieldState(mergedFieldStates.get(fieldName) ?? FieldInitializationState.Uninitialized, fieldState));
|
|
130
|
+
}
|
|
131
|
+
for (const [symbolId, mask] of state.trackedValues) {
|
|
132
|
+
mergedTrackedValues.set(symbolId, (mergedTrackedValues.get(symbolId) ?? TrackedValueMask.None) | mask);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
fieldStates: mergedFieldStates,
|
|
137
|
+
trackedValues: mergedTrackedValues,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function getSimpleNameText(name) {
|
|
141
|
+
if (!name) {
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
if (ts.isIdentifier(name) ||
|
|
145
|
+
ts.isPrivateIdentifier(name) ||
|
|
146
|
+
ts.isStringLiteralLike(name) ||
|
|
147
|
+
ts.isNumericLiteral(name)) {
|
|
148
|
+
return name.text;
|
|
149
|
+
}
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
function hasStaticModifier(node) {
|
|
153
|
+
return ts.canHaveModifiers(node) &&
|
|
154
|
+
ts.getModifiers(node)?.some((modifier) => modifier.kind === ts.SyntaxKind.StaticKeyword) === true;
|
|
155
|
+
}
|
|
156
|
+
function isParameterProperty(parameter) {
|
|
157
|
+
if (!ts.isIdentifier(parameter.name)) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
const modifierFlags = ts.getCombinedModifierFlags(parameter);
|
|
161
|
+
return (modifierFlags & (ts.ModifierFlags.Public |
|
|
162
|
+
ts.ModifierFlags.Private |
|
|
163
|
+
ts.ModifierFlags.Protected |
|
|
164
|
+
ts.ModifierFlags.Readonly)) !== 0;
|
|
165
|
+
}
|
|
166
|
+
function collectClassLifecycleInfo(classLike) {
|
|
167
|
+
const fieldNames = new Set();
|
|
168
|
+
let constructorDeclaration;
|
|
169
|
+
for (const member of classLike.members) {
|
|
170
|
+
if (ts.isConstructorDeclaration(member)) {
|
|
171
|
+
constructorDeclaration = member;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (hasStaticModifier(member)) {
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if ((ts.isPropertyDeclaration(member) || ts.isAccessor(member)) &&
|
|
178
|
+
getSimpleNameText(member.name)) {
|
|
179
|
+
fieldNames.add(getSimpleNameText(member.name));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
for (const parameter of constructorDeclaration?.parameters ?? []) {
|
|
183
|
+
const parameterName = getSimpleNameText(parameter.name);
|
|
184
|
+
if (isParameterProperty(parameter) && parameterName) {
|
|
185
|
+
fieldNames.add(parameterName);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return {
|
|
189
|
+
fieldNames,
|
|
190
|
+
hasBaseClass: (classLike.heritageClauses ?? []).some((clause) => clause.token === ts.SyntaxKind.ExtendsKeyword && clause.types.length > 0),
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function createInitialState(classInfo) {
|
|
194
|
+
return {
|
|
195
|
+
fieldStates: new Map([...classInfo.fieldNames].map((fieldName) => [fieldName, FieldInitializationState.Uninitialized])),
|
|
196
|
+
trackedValues: new Map(),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function getTrackedMaskForSymbol(context, state, symbol) {
|
|
200
|
+
return symbol ? state.trackedValues.get(context.getSymbolId(symbol)) ?? TrackedValueMask.None : TrackedValueMask.None;
|
|
201
|
+
}
|
|
202
|
+
function setTrackedMaskForSymbol(context, state, symbol, mask) {
|
|
203
|
+
if (!symbol) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const symbolId = context.getSymbolId(symbol);
|
|
207
|
+
if (mask === TrackedValueMask.None) {
|
|
208
|
+
state.trackedValues.delete(symbolId);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
state.trackedValues.set(symbolId, mask);
|
|
212
|
+
}
|
|
213
|
+
function unwrapExpression(expression) {
|
|
214
|
+
let current = expression;
|
|
215
|
+
while (ts.isParenthesizedExpression(current) ||
|
|
216
|
+
ts.isNonNullExpression(current) ||
|
|
217
|
+
ts.isAsExpression(current) ||
|
|
218
|
+
ts.isSatisfiesExpression(current) ||
|
|
219
|
+
ts.isTypeAssertionExpression(current)) {
|
|
220
|
+
current = current.expression;
|
|
221
|
+
}
|
|
222
|
+
return current;
|
|
223
|
+
}
|
|
224
|
+
function functionCapturesTrackedThis(context, state, node) {
|
|
225
|
+
let captures = false;
|
|
226
|
+
function visit(current, allowThisKeyword) {
|
|
227
|
+
if (captures) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
if (current !== node && ts.isClassLike(current)) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (current !== node && ts.isFunctionLike(current)) {
|
|
234
|
+
if (ts.isArrowFunction(current)) {
|
|
235
|
+
visit(current.body, allowThisKeyword);
|
|
236
|
+
}
|
|
237
|
+
else if (ts.isFunctionDeclaration(current) ||
|
|
238
|
+
ts.isFunctionExpression(current) ||
|
|
239
|
+
ts.isMethodDeclaration(current) ||
|
|
240
|
+
ts.isConstructorDeclaration(current) ||
|
|
241
|
+
ts.isGetAccessorDeclaration(current) ||
|
|
242
|
+
ts.isSetAccessorDeclaration(current)) {
|
|
243
|
+
if (current.body) {
|
|
244
|
+
visit(current.body, false);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (allowThisKeyword && current.kind === ts.SyntaxKind.ThisKeyword) {
|
|
250
|
+
captures = true;
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
if (ts.isIdentifier(current)) {
|
|
254
|
+
const symbol = context.checker.getSymbolAtLocation(current);
|
|
255
|
+
if ((getTrackedMaskForSymbol(context, state, symbol) & TrackedValueMask.ThisAlias) !== 0) {
|
|
256
|
+
captures = true;
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
ts.forEachChild(current, (child) => visit(child, allowThisKeyword));
|
|
261
|
+
}
|
|
262
|
+
visit(node.body, ts.isArrowFunction(node));
|
|
263
|
+
return captures;
|
|
264
|
+
}
|
|
265
|
+
function classifyExpressionValueMask(context, state, expression) {
|
|
266
|
+
const current = unwrapExpression(expression);
|
|
267
|
+
if (current.kind === ts.SyntaxKind.ThisKeyword) {
|
|
268
|
+
return TrackedValueMask.ThisAlias;
|
|
269
|
+
}
|
|
270
|
+
if (ts.isIdentifier(current)) {
|
|
271
|
+
return getTrackedMaskForSymbol(context, state, context.checker.getSymbolAtLocation(current));
|
|
272
|
+
}
|
|
273
|
+
if (ts.isFunctionExpression(current) || ts.isArrowFunction(current)) {
|
|
274
|
+
return functionCapturesTrackedThis(context, state, current)
|
|
275
|
+
? TrackedValueMask.CapturedThisClosure
|
|
276
|
+
: TrackedValueMask.None;
|
|
277
|
+
}
|
|
278
|
+
return TrackedValueMask.None;
|
|
279
|
+
}
|
|
280
|
+
function expressionContainsTrackedValue(context, state, expression) {
|
|
281
|
+
const directMask = classifyExpressionValueMask(context, state, expression);
|
|
282
|
+
if (directMask !== TrackedValueMask.None) {
|
|
283
|
+
return directMask;
|
|
284
|
+
}
|
|
285
|
+
if (ts.isFunctionExpression(expression) ||
|
|
286
|
+
ts.isArrowFunction(expression) ||
|
|
287
|
+
ts.isClassExpression(expression)) {
|
|
288
|
+
return TrackedValueMask.None;
|
|
289
|
+
}
|
|
290
|
+
let result = TrackedValueMask.None;
|
|
291
|
+
ts.forEachChild(expression, (child) => {
|
|
292
|
+
if (result !== TrackedValueMask.None || !ts.isExpression(child)) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
result |= expressionContainsTrackedValue(context, state, child);
|
|
296
|
+
});
|
|
297
|
+
return result;
|
|
298
|
+
}
|
|
299
|
+
function getReceiverKind(context, state, expression) {
|
|
300
|
+
const current = unwrapExpression(expression);
|
|
301
|
+
if (current.kind === ts.SyntaxKind.ThisKeyword) {
|
|
302
|
+
return 'this';
|
|
303
|
+
}
|
|
304
|
+
if (current.kind === ts.SyntaxKind.SuperKeyword) {
|
|
305
|
+
return 'super';
|
|
306
|
+
}
|
|
307
|
+
if (ts.isIdentifier(current)) {
|
|
308
|
+
const symbol = context.checker.getSymbolAtLocation(current);
|
|
309
|
+
return (getTrackedMaskForSymbol(context, state, symbol) & TrackedValueMask.ThisAlias) !== 0
|
|
310
|
+
? 'this'
|
|
311
|
+
: undefined;
|
|
312
|
+
}
|
|
313
|
+
return undefined;
|
|
314
|
+
}
|
|
315
|
+
function getMemberSymbol(context, node) {
|
|
316
|
+
if (ts.isPropertyAccessExpression(node)) {
|
|
317
|
+
return context.checker.getSymbolAtLocation(node.name);
|
|
318
|
+
}
|
|
319
|
+
const memberName = node.argumentExpression && (ts.isStringLiteralLike(node.argumentExpression) || ts.isNumericLiteral(node.argumentExpression))
|
|
320
|
+
? node.argumentExpression.text
|
|
321
|
+
: undefined;
|
|
322
|
+
if (!memberName) {
|
|
323
|
+
return undefined;
|
|
324
|
+
}
|
|
325
|
+
return context.checker.getTypeAtLocation(node.expression).getProperty(memberName);
|
|
326
|
+
}
|
|
327
|
+
function getMemberName(node) {
|
|
328
|
+
return ts.isPropertyAccessExpression(node)
|
|
329
|
+
? getSimpleNameText(node.name)
|
|
330
|
+
: node.argumentExpression &&
|
|
331
|
+
(ts.isStringLiteralLike(node.argumentExpression) || ts.isNumericLiteral(node.argumentExpression))
|
|
332
|
+
? node.argumentExpression.text
|
|
333
|
+
: undefined;
|
|
334
|
+
}
|
|
335
|
+
function isInstanceMethodSymbol(symbol) {
|
|
336
|
+
if (!symbol) {
|
|
337
|
+
return false;
|
|
338
|
+
}
|
|
339
|
+
return (symbol.declarations ?? []).some((declaration) => !declaration.getSourceFile().isDeclarationFile &&
|
|
340
|
+
(ts.isMethodDeclaration(declaration) || ts.isMethodSignature(declaration)) &&
|
|
341
|
+
!hasStaticModifier(declaration));
|
|
342
|
+
}
|
|
343
|
+
function isInstanceAccessorSymbol(symbol) {
|
|
344
|
+
if (!symbol) {
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
return (symbol.declarations ?? []).some((declaration) => !declaration.getSourceFile().isDeclarationFile &&
|
|
348
|
+
(ts.isGetAccessorDeclaration(declaration) || ts.isSetAccessorDeclaration(declaration)) &&
|
|
349
|
+
!hasStaticModifier(declaration));
|
|
350
|
+
}
|
|
351
|
+
function getTrackedFieldName(classInfo, node) {
|
|
352
|
+
const memberName = ts.isPropertyAccessExpression(node)
|
|
353
|
+
? getSimpleNameText(node.name)
|
|
354
|
+
: node.argumentExpression &&
|
|
355
|
+
(ts.isStringLiteralLike(node.argumentExpression) || ts.isNumericLiteral(node.argumentExpression))
|
|
356
|
+
? node.argumentExpression.text
|
|
357
|
+
: undefined;
|
|
358
|
+
if (!memberName || !classInfo.fieldNames.has(memberName)) {
|
|
359
|
+
return undefined;
|
|
360
|
+
}
|
|
361
|
+
return memberName;
|
|
362
|
+
}
|
|
363
|
+
function isSimpleAssignmentOperator(token) {
|
|
364
|
+
return token === ts.SyntaxKind.EqualsToken;
|
|
365
|
+
}
|
|
366
|
+
function isAssignmentOperator(token) {
|
|
367
|
+
return token >= ts.SyntaxKind.FirstAssignment && token <= ts.SyntaxKind.LastAssignment;
|
|
368
|
+
}
|
|
369
|
+
function getFieldAccessMode(node) {
|
|
370
|
+
const parent = node.parent;
|
|
371
|
+
if (ts.isBinaryExpression(parent) && parent.left === node && isAssignmentOperator(parent.operatorToken.kind)) {
|
|
372
|
+
return isSimpleAssignmentOperator(parent.operatorToken.kind) ? 'write' : 'readwrite';
|
|
373
|
+
}
|
|
374
|
+
if ((ts.isPrefixUnaryExpression(parent) || ts.isPostfixUnaryExpression(parent)) &&
|
|
375
|
+
(parent.operator === ts.SyntaxKind.PlusPlusToken || parent.operator === ts.SyntaxKind.MinusMinusToken)) {
|
|
376
|
+
return 'readwrite';
|
|
377
|
+
}
|
|
378
|
+
return 'read';
|
|
379
|
+
}
|
|
380
|
+
function isDirectMethodCall(node) {
|
|
381
|
+
const parent = node.parent;
|
|
382
|
+
return (ts.isCallExpression(parent) || ts.isNewExpression(parent)) && parent.expression === node;
|
|
383
|
+
}
|
|
384
|
+
function getDirectSuperCallStatement(statement) {
|
|
385
|
+
if (!ts.isExpressionStatement(statement) || !ts.isCallExpression(statement.expression)) {
|
|
386
|
+
return undefined;
|
|
387
|
+
}
|
|
388
|
+
const callee = unwrapExpression(statement.expression.expression);
|
|
389
|
+
return callee.kind === ts.SyntaxKind.SuperKeyword ? statement.expression : undefined;
|
|
390
|
+
}
|
|
391
|
+
function pushDiagnostic(diagnostics, seen, diagnostic) {
|
|
392
|
+
const key = `${diagnostic.code}:${diagnostic.filePath}:${diagnostic.line}:${diagnostic.column}:` +
|
|
393
|
+
`${diagnostic.endLine}:${diagnostic.endColumn}`;
|
|
394
|
+
if (seen.has(key)) {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
seen.add(key);
|
|
398
|
+
diagnostics.push(diagnostic);
|
|
399
|
+
}
|
|
400
|
+
function analyzeExpression(context, classInfo, state, expression, diagnostics, seen) {
|
|
401
|
+
const current = unwrapExpression(expression);
|
|
402
|
+
if (ts.isFunctionExpression(current) || ts.isArrowFunction(current) || ts.isClassExpression(current)) {
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
if (ts.isCallExpression(current) || ts.isNewExpression(current)) {
|
|
406
|
+
const callee = current.expression;
|
|
407
|
+
const calleeMask = classifyExpressionValueMask(context, state, callee);
|
|
408
|
+
if ((calleeMask & TrackedValueMask.CapturedThisClosure) !== 0) {
|
|
409
|
+
pushDiagnostic(diagnostics, seen, createLifecycleDiagnostic({ node: callee, hazardKind: 'captured closure call' }));
|
|
410
|
+
}
|
|
411
|
+
if ((ts.isPropertyAccessExpression(callee) || ts.isElementAccessExpression(callee)) &&
|
|
412
|
+
(getReceiverKind(context, state, callee.expression) === 'this' ||
|
|
413
|
+
getReceiverKind(context, state, callee.expression) === 'super')) {
|
|
414
|
+
const receiverKind = getReceiverKind(context, state, callee.expression);
|
|
415
|
+
const memberSymbol = getMemberSymbol(context, callee);
|
|
416
|
+
if (isInstanceMethodSymbol(memberSymbol) || isInstanceAccessorSymbol(memberSymbol)) {
|
|
417
|
+
pushDiagnostic(diagnostics, seen, createLifecycleDiagnostic({
|
|
418
|
+
node: callee,
|
|
419
|
+
hazardKind: isInstanceAccessorSymbol(memberSymbol)
|
|
420
|
+
? 'receiver accessor dispatch'
|
|
421
|
+
: 'receiver method dispatch',
|
|
422
|
+
memberName: getMemberName(callee),
|
|
423
|
+
receiverKind,
|
|
424
|
+
}));
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
else if ((ts.isPropertyAccessExpression(callee) || ts.isElementAccessExpression(callee)) &&
|
|
428
|
+
(classifyExpressionValueMask(context, state, callee.expression) &
|
|
429
|
+
TrackedValueMask.CapturedThisClosure) !== 0) {
|
|
430
|
+
pushDiagnostic(diagnostics, seen, createLifecycleDiagnostic({
|
|
431
|
+
node: callee.expression,
|
|
432
|
+
hazardKind: 'tracked this alias escape',
|
|
433
|
+
}));
|
|
434
|
+
}
|
|
435
|
+
else {
|
|
436
|
+
analyzeExpression(context, classInfo, state, callee, diagnostics, seen);
|
|
437
|
+
}
|
|
438
|
+
for (const argument of current.arguments ?? []) {
|
|
439
|
+
analyzeExpression(context, classInfo, state, argument, diagnostics, seen);
|
|
440
|
+
if (expressionContainsTrackedValue(context, state, argument) !== TrackedValueMask.None) {
|
|
441
|
+
pushDiagnostic(diagnostics, seen, createLifecycleDiagnostic({ node: argument, hazardKind: 'tracked this argument escape' }));
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
if (ts.isBinaryExpression(current) && isAssignmentOperator(current.operatorToken.kind)) {
|
|
447
|
+
analyzeExpression(context, classInfo, state, current.right, diagnostics, seen);
|
|
448
|
+
const rightValueMask = classifyExpressionValueMask(context, state, current.right);
|
|
449
|
+
const rightContainsTrackedValue = expressionContainsTrackedValue(context, state, current.right);
|
|
450
|
+
if (ts.isIdentifier(current.left)) {
|
|
451
|
+
const leftSymbol = context.checker.getSymbolAtLocation(current.left);
|
|
452
|
+
if (rightValueMask !== TrackedValueMask.None) {
|
|
453
|
+
setTrackedMaskForSymbol(context, state, leftSymbol, rightValueMask);
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
setTrackedMaskForSymbol(context, state, leftSymbol, TrackedValueMask.None);
|
|
457
|
+
if (rightContainsTrackedValue !== TrackedValueMask.None) {
|
|
458
|
+
pushDiagnostic(diagnostics, seen, createLifecycleDiagnostic({ node: current.right, hazardKind: 'tracked this alias escape' }));
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
if (ts.isPropertyAccessExpression(current.left) || ts.isElementAccessExpression(current.left)) {
|
|
464
|
+
analyzePropertyAccess(context, classInfo, state, current.left, diagnostics, seen);
|
|
465
|
+
if (rightContainsTrackedValue !== TrackedValueMask.None) {
|
|
466
|
+
pushDiagnostic(diagnostics, seen, createLifecycleDiagnostic({ node: current.right, hazardKind: 'tracked this alias escape' }));
|
|
467
|
+
}
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
analyzeExpression(context, classInfo, state, current.left, diagnostics, seen);
|
|
471
|
+
if (rightContainsTrackedValue !== TrackedValueMask.None) {
|
|
472
|
+
pushDiagnostic(diagnostics, seen, createLifecycleDiagnostic({ node: current.right, hazardKind: 'tracked this alias escape' }));
|
|
473
|
+
}
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
if (ts.isPropertyAccessExpression(current) || ts.isElementAccessExpression(current)) {
|
|
477
|
+
analyzePropertyAccess(context, classInfo, state, current, diagnostics, seen);
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
if (ts.isConditionalExpression(current)) {
|
|
481
|
+
analyzeExpression(context, classInfo, state, current.condition, diagnostics, seen);
|
|
482
|
+
analyzeExpression(context, classInfo, state, current.whenTrue, diagnostics, seen);
|
|
483
|
+
analyzeExpression(context, classInfo, state, current.whenFalse, diagnostics, seen);
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
if (ts.isPrefixUnaryExpression(current) || ts.isPostfixUnaryExpression(current)) {
|
|
487
|
+
analyzeExpression(context, classInfo, state, current.operand, diagnostics, seen);
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
if (ts.isArrayLiteralExpression(current) || ts.isObjectLiteralExpression(current)) {
|
|
491
|
+
for (const child of current.getChildren(current.getSourceFile())) {
|
|
492
|
+
if (ts.isExpression(child)) {
|
|
493
|
+
analyzeExpression(context, classInfo, state, child, diagnostics, seen);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
ts.forEachChild(current, (child) => {
|
|
499
|
+
if (ts.isExpression(child)) {
|
|
500
|
+
analyzeExpression(context, classInfo, state, child, diagnostics, seen);
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
function analyzePropertyAccess(context, classInfo, state, node, diagnostics, seen) {
|
|
505
|
+
analyzeExpression(context, classInfo, state, node.expression, diagnostics, seen);
|
|
506
|
+
if (ts.isElementAccessExpression(node) && node.argumentExpression) {
|
|
507
|
+
analyzeExpression(context, classInfo, state, node.argumentExpression, diagnostics, seen);
|
|
508
|
+
}
|
|
509
|
+
const receiverKind = getReceiverKind(context, state, node.expression);
|
|
510
|
+
if (!receiverKind) {
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
const memberSymbol = getMemberSymbol(context, node);
|
|
514
|
+
if (isInstanceAccessorSymbol(memberSymbol)) {
|
|
515
|
+
pushDiagnostic(diagnostics, seen, createLifecycleDiagnostic({
|
|
516
|
+
node,
|
|
517
|
+
hazardKind: 'receiver accessor dispatch',
|
|
518
|
+
memberName: getMemberName(node),
|
|
519
|
+
receiverKind,
|
|
520
|
+
}));
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
if (isDirectMethodCall(node) && isInstanceMethodSymbol(memberSymbol)) {
|
|
524
|
+
pushDiagnostic(diagnostics, seen, createLifecycleDiagnostic({
|
|
525
|
+
node,
|
|
526
|
+
hazardKind: 'receiver method dispatch',
|
|
527
|
+
memberName: getMemberName(node),
|
|
528
|
+
receiverKind,
|
|
529
|
+
}));
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
if (receiverKind !== 'this') {
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
const fieldName = getTrackedFieldName(classInfo, node);
|
|
536
|
+
if (!fieldName) {
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
const accessMode = getFieldAccessMode(node);
|
|
540
|
+
if (accessMode !== 'write' &&
|
|
541
|
+
(state.fieldStates.get(fieldName) ?? FieldInitializationState.Uninitialized) !==
|
|
542
|
+
FieldInitializationState.DefinitelyInitialized) {
|
|
543
|
+
pushDiagnostic(diagnostics, seen, createFieldInitializationDiagnostic({
|
|
544
|
+
node,
|
|
545
|
+
fieldName,
|
|
546
|
+
accessKind: 'this property access',
|
|
547
|
+
}));
|
|
548
|
+
}
|
|
549
|
+
if (accessMode !== 'read') {
|
|
550
|
+
state.fieldStates.set(fieldName, FieldInitializationState.DefinitelyInitialized);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
function analyzeObjectBindingPatternFromThis(context, classInfo, state, declaration, diagnostics, seen) {
|
|
554
|
+
if (!declaration.initializer || !ts.isObjectBindingPattern(declaration.name)) {
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
const receiverKind = getReceiverKind(context, state, declaration.initializer);
|
|
558
|
+
if (receiverKind !== 'this' && receiverKind !== 'super') {
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
for (const element of declaration.name.elements) {
|
|
562
|
+
const memberName = getSimpleNameText(element.propertyName ?? element.name);
|
|
563
|
+
if (!memberName) {
|
|
564
|
+
continue;
|
|
565
|
+
}
|
|
566
|
+
const receiverType = context.checker.getTypeAtLocation(declaration.initializer);
|
|
567
|
+
const memberSymbol = receiverType.getProperty(memberName);
|
|
568
|
+
if (isInstanceAccessorSymbol(memberSymbol)) {
|
|
569
|
+
pushDiagnostic(diagnostics, seen, createLifecycleDiagnostic({
|
|
570
|
+
node: element,
|
|
571
|
+
hazardKind: 'receiver accessor dispatch',
|
|
572
|
+
memberName,
|
|
573
|
+
receiverKind,
|
|
574
|
+
}));
|
|
575
|
+
continue;
|
|
576
|
+
}
|
|
577
|
+
if (receiverKind === 'this' && classInfo.fieldNames.has(memberName)) {
|
|
578
|
+
const fieldState = state.fieldStates.get(memberName) ?? FieldInitializationState.Uninitialized;
|
|
579
|
+
if (fieldState !== FieldInitializationState.DefinitelyInitialized) {
|
|
580
|
+
pushDiagnostic(diagnostics, seen, createFieldInitializationDiagnostic({
|
|
581
|
+
node: element,
|
|
582
|
+
fieldName: memberName,
|
|
583
|
+
accessKind: 'object destructuring',
|
|
584
|
+
}));
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
function analyzeVariableDeclaration(context, classInfo, state, declaration, diagnostics, seen) {
|
|
590
|
+
if (!declaration.initializer) {
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
analyzeExpression(context, classInfo, state, declaration.initializer, diagnostics, seen);
|
|
594
|
+
analyzeObjectBindingPatternFromThis(context, classInfo, state, declaration, diagnostics, seen);
|
|
595
|
+
const directMask = classifyExpressionValueMask(context, state, declaration.initializer);
|
|
596
|
+
const containedMask = expressionContainsTrackedValue(context, state, declaration.initializer);
|
|
597
|
+
if (ts.isIdentifier(declaration.name)) {
|
|
598
|
+
const symbol = context.checker.getSymbolAtLocation(declaration.name);
|
|
599
|
+
if (directMask !== TrackedValueMask.None) {
|
|
600
|
+
setTrackedMaskForSymbol(context, state, symbol, directMask);
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
setTrackedMaskForSymbol(context, state, symbol, TrackedValueMask.None);
|
|
604
|
+
if (containedMask !== TrackedValueMask.None) {
|
|
605
|
+
pushDiagnostic(diagnostics, seen, createLifecycleDiagnostic({
|
|
606
|
+
node: declaration.initializer,
|
|
607
|
+
hazardKind: 'tracked this alias escape',
|
|
608
|
+
}));
|
|
609
|
+
}
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
if (containedMask !== TrackedValueMask.None) {
|
|
613
|
+
pushDiagnostic(diagnostics, seen, createLifecycleDiagnostic({
|
|
614
|
+
node: declaration.initializer,
|
|
615
|
+
hazardKind: 'tracked this alias escape',
|
|
616
|
+
}));
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
function analyzeStatement(context, classInfo, state, statement, diagnostics, seen) {
|
|
620
|
+
if (ts.isBlock(statement)) {
|
|
621
|
+
return analyzeStatements(context, classInfo, cloneState(state), statement.statements, diagnostics, seen);
|
|
622
|
+
}
|
|
623
|
+
if (ts.isVariableStatement(statement)) {
|
|
624
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
625
|
+
analyzeVariableDeclaration(context, classInfo, state, declaration, diagnostics, seen);
|
|
626
|
+
}
|
|
627
|
+
return state;
|
|
628
|
+
}
|
|
629
|
+
if (ts.isExpressionStatement(statement)) {
|
|
630
|
+
analyzeExpression(context, classInfo, state, statement.expression, diagnostics, seen);
|
|
631
|
+
return state;
|
|
632
|
+
}
|
|
633
|
+
if (ts.isReturnStatement(statement) || ts.isThrowStatement(statement)) {
|
|
634
|
+
if (statement.expression) {
|
|
635
|
+
analyzeExpression(context, classInfo, state, statement.expression, diagnostics, seen);
|
|
636
|
+
if (expressionContainsTrackedValue(context, state, statement.expression) !== TrackedValueMask.None) {
|
|
637
|
+
pushDiagnostic(diagnostics, seen, createLifecycleDiagnostic({
|
|
638
|
+
node: statement.expression,
|
|
639
|
+
hazardKind: ts.isReturnStatement(statement) ? 'tracked this return' : 'tracked this throw',
|
|
640
|
+
}));
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
return null;
|
|
644
|
+
}
|
|
645
|
+
if (ts.isIfStatement(statement)) {
|
|
646
|
+
analyzeExpression(context, classInfo, state, statement.expression, diagnostics, seen);
|
|
647
|
+
const thenState = analyzeStatement(context, classInfo, cloneState(state), statement.thenStatement, diagnostics, seen);
|
|
648
|
+
const elseState = statement.elseStatement
|
|
649
|
+
? analyzeStatement(context, classInfo, cloneState(state), statement.elseStatement, diagnostics, seen)
|
|
650
|
+
: cloneState(state);
|
|
651
|
+
return mergeStates([thenState, elseState].filter((value) => value !== null));
|
|
652
|
+
}
|
|
653
|
+
if (ts.isWhileStatement(statement)) {
|
|
654
|
+
analyzeExpression(context, classInfo, state, statement.expression, diagnostics, seen);
|
|
655
|
+
const bodyState = analyzeStatement(context, classInfo, cloneState(state), statement.statement, diagnostics, seen);
|
|
656
|
+
return mergeStates([state, bodyState].filter((value) => value !== null));
|
|
657
|
+
}
|
|
658
|
+
if (ts.isDoStatement(statement)) {
|
|
659
|
+
const bodyState = analyzeStatement(context, classInfo, cloneState(state), statement.statement, diagnostics, seen);
|
|
660
|
+
if (bodyState) {
|
|
661
|
+
analyzeExpression(context, classInfo, bodyState, statement.expression, diagnostics, seen);
|
|
662
|
+
}
|
|
663
|
+
return mergeStates([state, bodyState].filter((value) => value !== null));
|
|
664
|
+
}
|
|
665
|
+
if (ts.isForStatement(statement)) {
|
|
666
|
+
if (statement.initializer) {
|
|
667
|
+
if (ts.isVariableDeclarationList(statement.initializer)) {
|
|
668
|
+
for (const declaration of statement.initializer.declarations) {
|
|
669
|
+
analyzeVariableDeclaration(context, classInfo, state, declaration, diagnostics, seen);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
else {
|
|
673
|
+
analyzeExpression(context, classInfo, state, statement.initializer, diagnostics, seen);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
if (statement.condition) {
|
|
677
|
+
analyzeExpression(context, classInfo, state, statement.condition, diagnostics, seen);
|
|
678
|
+
}
|
|
679
|
+
const bodyState = analyzeStatement(context, classInfo, cloneState(state), statement.statement, diagnostics, seen);
|
|
680
|
+
if (bodyState && statement.incrementor) {
|
|
681
|
+
analyzeExpression(context, classInfo, bodyState, statement.incrementor, diagnostics, seen);
|
|
682
|
+
}
|
|
683
|
+
return mergeStates([state, bodyState].filter((value) => value !== null));
|
|
684
|
+
}
|
|
685
|
+
if (ts.isForOfStatement(statement) || ts.isForInStatement(statement)) {
|
|
686
|
+
analyzeExpression(context, classInfo, state, statement.expression, diagnostics, seen);
|
|
687
|
+
const bodyState = analyzeStatement(context, classInfo, cloneState(state), statement.statement, diagnostics, seen);
|
|
688
|
+
return mergeStates([state, bodyState].filter((value) => value !== null));
|
|
689
|
+
}
|
|
690
|
+
if (ts.isSwitchStatement(statement)) {
|
|
691
|
+
analyzeExpression(context, classInfo, state, statement.expression, diagnostics, seen);
|
|
692
|
+
const clauseStates = [];
|
|
693
|
+
for (const clause of statement.caseBlock.clauses) {
|
|
694
|
+
if (ts.isCaseClause(clause)) {
|
|
695
|
+
analyzeExpression(context, classInfo, state, clause.expression, diagnostics, seen);
|
|
696
|
+
}
|
|
697
|
+
const clauseState = analyzeStatements(context, classInfo, cloneState(state), clause.statements, diagnostics, seen);
|
|
698
|
+
if (clauseState) {
|
|
699
|
+
clauseStates.push(clauseState);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
clauseStates.push(state);
|
|
703
|
+
return mergeStates(clauseStates);
|
|
704
|
+
}
|
|
705
|
+
if (ts.isTryStatement(statement)) {
|
|
706
|
+
const tryState = analyzeStatement(context, classInfo, cloneState(state), statement.tryBlock, diagnostics, seen);
|
|
707
|
+
const catchState = statement.catchClause
|
|
708
|
+
? analyzeStatement(context, classInfo, cloneState(state), statement.catchClause.block, diagnostics, seen)
|
|
709
|
+
: null;
|
|
710
|
+
const mergedBeforeFinally = mergeStates([tryState, catchState].filter((value) => value !== null)) ?? cloneState(state);
|
|
711
|
+
return statement.finallyBlock
|
|
712
|
+
? analyzeStatement(context, classInfo, mergedBeforeFinally, statement.finallyBlock, diagnostics, seen)
|
|
713
|
+
: mergedBeforeFinally;
|
|
714
|
+
}
|
|
715
|
+
ts.forEachChild(statement, (child) => {
|
|
716
|
+
if (ts.isExpression(child)) {
|
|
717
|
+
analyzeExpression(context, classInfo, state, child, diagnostics, seen);
|
|
718
|
+
}
|
|
719
|
+
});
|
|
720
|
+
return state;
|
|
721
|
+
}
|
|
722
|
+
function analyzeStatements(context, classInfo, initialState, statements, diagnostics, seen) {
|
|
723
|
+
let currentState = initialState;
|
|
724
|
+
for (const statement of statements) {
|
|
725
|
+
if (context.isGeneratedNode(statement)) {
|
|
726
|
+
continue;
|
|
727
|
+
}
|
|
728
|
+
if (!currentState) {
|
|
729
|
+
return null;
|
|
730
|
+
}
|
|
731
|
+
currentState = analyzeStatement(context, classInfo, currentState, statement, diagnostics, seen);
|
|
732
|
+
}
|
|
733
|
+
return currentState;
|
|
734
|
+
}
|
|
735
|
+
function applyParameterPropertyInitialization(constructorDeclaration, state) {
|
|
736
|
+
for (const parameter of constructorDeclaration?.parameters ?? []) {
|
|
737
|
+
const parameterName = getSimpleNameText(parameter.name);
|
|
738
|
+
if (isParameterProperty(parameter) && parameterName) {
|
|
739
|
+
state.fieldStates.set(parameterName, FieldInitializationState.DefinitelyInitialized);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
function analyzeFieldInitializers(context, classInfo, classLike, state, diagnostics, seen) {
|
|
744
|
+
for (const member of classLike.members) {
|
|
745
|
+
if (!ts.isPropertyDeclaration(member) || hasStaticModifier(member) || !member.initializer) {
|
|
746
|
+
continue;
|
|
747
|
+
}
|
|
748
|
+
analyzeExpression(context, classInfo, state, member.initializer, diagnostics, seen);
|
|
749
|
+
const fieldName = getSimpleNameText(member.name);
|
|
750
|
+
if (fieldName) {
|
|
751
|
+
state.fieldStates.set(fieldName, FieldInitializationState.DefinitelyInitialized);
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
function analyzeClassLike(context, classLike, diagnostics, seen) {
|
|
756
|
+
const classInfo = collectClassLifecycleInfo(classLike);
|
|
757
|
+
const constructorDeclaration = classLike.members.find(ts.isConstructorDeclaration);
|
|
758
|
+
if (!classInfo.hasBaseClass) {
|
|
759
|
+
const state = createInitialState(classInfo);
|
|
760
|
+
analyzeFieldInitializers(context, classInfo, classLike, state, diagnostics, seen);
|
|
761
|
+
applyParameterPropertyInitialization(constructorDeclaration, state);
|
|
762
|
+
if (constructorDeclaration?.body) {
|
|
763
|
+
analyzeStatements(context, classInfo, state, constructorDeclaration.body.statements, diagnostics, seen);
|
|
764
|
+
}
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
const state = createInitialState(classInfo);
|
|
768
|
+
if (!constructorDeclaration?.body) {
|
|
769
|
+
analyzeFieldInitializers(context, classInfo, classLike, state, diagnostics, seen);
|
|
770
|
+
return;
|
|
771
|
+
}
|
|
772
|
+
const statements = constructorDeclaration.body.statements;
|
|
773
|
+
const superStatementIndex = statements.findIndex((statement) => getDirectSuperCallStatement(statement) !== undefined);
|
|
774
|
+
if (superStatementIndex === -1) {
|
|
775
|
+
return;
|
|
776
|
+
}
|
|
777
|
+
if (superStatementIndex > 0) {
|
|
778
|
+
analyzeStatements(context, classInfo, state, statements.slice(0, superStatementIndex + 1), diagnostics, seen);
|
|
779
|
+
}
|
|
780
|
+
else {
|
|
781
|
+
analyzeExpression(context, classInfo, state, getDirectSuperCallStatement(statements[superStatementIndex]), diagnostics, seen);
|
|
782
|
+
}
|
|
783
|
+
analyzeFieldInitializers(context, classInfo, classLike, state, diagnostics, seen);
|
|
784
|
+
applyParameterPropertyInitialization(constructorDeclaration, state);
|
|
785
|
+
analyzeStatements(context, classInfo, state, statements.slice(superStatementIndex + 1), diagnostics, seen);
|
|
786
|
+
}
|
|
787
|
+
export function runClassLifecycleRules(context) {
|
|
788
|
+
const diagnostics = [];
|
|
789
|
+
const seen = new Set();
|
|
790
|
+
context.forEachSourceFile((sourceFile) => {
|
|
791
|
+
context.traverse(sourceFile, (node) => {
|
|
792
|
+
if (ts.isClassDeclaration(node) || ts.isClassExpression(node)) {
|
|
793
|
+
analyzeClassLike(context, node, diagnostics, seen);
|
|
794
|
+
}
|
|
795
|
+
});
|
|
796
|
+
});
|
|
797
|
+
return diagnostics;
|
|
798
|
+
}
|