@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,206 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { deepValueClassDeclarationIsValid, resolveAliasedSymbol, typeNodeIsDeepSafe, } from '../../value_deep_safe.js';
|
|
3
|
+
import { SOUND_DIAGNOSTIC_CODES, SOUND_DIAGNOSTIC_MESSAGES } from '../engine/diagnostic_codes.js';
|
|
4
|
+
function createDiagnostic(sourceFile, node, message) {
|
|
5
|
+
const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
|
|
6
|
+
return {
|
|
7
|
+
source: 'sound',
|
|
8
|
+
code: SOUND_DIAGNOSTIC_CODES.invalidAnnotationTarget,
|
|
9
|
+
category: 'error',
|
|
10
|
+
message,
|
|
11
|
+
filePath: sourceFile.fileName,
|
|
12
|
+
line: line + 1,
|
|
13
|
+
column: character + 1,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function findValueAnnotation(context, declaration) {
|
|
17
|
+
return context.getAnnotationLookup(declaration.getSourceFile())
|
|
18
|
+
.getAttachedAnnotations(declaration)
|
|
19
|
+
.find((annotation) => annotation.name === 'value');
|
|
20
|
+
}
|
|
21
|
+
function isDeepValueAnnotation(annotation) {
|
|
22
|
+
const [argument] = annotation?.arguments ?? [];
|
|
23
|
+
return argument?.kind === 'named' &&
|
|
24
|
+
argument.name === 'deep' &&
|
|
25
|
+
argument.value.kind === 'boolean' &&
|
|
26
|
+
argument.value.value === true;
|
|
27
|
+
}
|
|
28
|
+
function hasModifier(node, kind) {
|
|
29
|
+
return ts.canHaveModifiers(node) &&
|
|
30
|
+
ts.getModifiers(node)?.some((modifier) => modifier.kind === kind) === true;
|
|
31
|
+
}
|
|
32
|
+
function symbolDeclaresValueClass(context, symbol) {
|
|
33
|
+
const resolved = resolveAliasedSymbol(context.checker, symbol);
|
|
34
|
+
return resolved.getDeclarations()?.some((declaration) => ts.isClassDeclaration(declaration) && !!findValueAnnotation(context, declaration)) === true;
|
|
35
|
+
}
|
|
36
|
+
function declarationIsDeepValueClass(context, declaration) {
|
|
37
|
+
const annotation = findValueAnnotation(context, declaration);
|
|
38
|
+
return !!annotation && isDeepValueAnnotation(annotation);
|
|
39
|
+
}
|
|
40
|
+
function declarationIsValidDeepValueClass(context, declaration) {
|
|
41
|
+
return deepValueClassDeclarationIsValid(declaration, {
|
|
42
|
+
checker: context.checker,
|
|
43
|
+
hasDeepValueAnnotation: (innerDeclaration) => declarationIsDeepValueClass(context, innerDeclaration),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function typeNodeExtendsValueClass(context, typeNode) {
|
|
47
|
+
const baseType = context.checker.getTypeAtLocation(typeNode);
|
|
48
|
+
const baseSymbol = baseType.aliasSymbol ?? baseType.getSymbol();
|
|
49
|
+
return !!baseSymbol && symbolDeclaresValueClass(context, baseSymbol);
|
|
50
|
+
}
|
|
51
|
+
function validateConstructorShape(context, sourceFile, declaration, fields, deep, diagnostics) {
|
|
52
|
+
const constructors = declaration.members.filter((member) => ts.isConstructorDeclaration(member));
|
|
53
|
+
if (fields.length === 0) {
|
|
54
|
+
if (constructors.length > 1) {
|
|
55
|
+
diagnostics.push(createDiagnostic(sourceFile, declaration, `${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value]\` classes may declare at most one constructor.`));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else if (constructors.length !== 1) {
|
|
59
|
+
diagnostics.push(createDiagnostic(sourceFile, declaration, `${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value]\` classes with fields must declare exactly one constructor.`));
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const [constructor] = constructors;
|
|
63
|
+
if (!constructor) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (fields.length === 0) {
|
|
67
|
+
if (constructor.parameters.length !== 0 || constructor.body?.statements.length) {
|
|
68
|
+
diagnostics.push(createDiagnostic(sourceFile, constructor, `${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} fieldless \`#[value]\` constructors must be empty.`));
|
|
69
|
+
}
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (constructor.parameters.length !== fields.length) {
|
|
73
|
+
diagnostics.push(createDiagnostic(sourceFile, constructor, `${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value]\` constructor parameters must match declared fields 1:1.`));
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
for (const parameter of constructor.parameters) {
|
|
77
|
+
if (!ts.isIdentifier(parameter.name) ||
|
|
78
|
+
parameter.dotDotDotToken ||
|
|
79
|
+
parameter.initializer ||
|
|
80
|
+
!parameter.type ||
|
|
81
|
+
hasModifier(parameter, ts.SyntaxKind.PublicKeyword) ||
|
|
82
|
+
hasModifier(parameter, ts.SyntaxKind.PrivateKeyword) ||
|
|
83
|
+
hasModifier(parameter, ts.SyntaxKind.ProtectedKeyword) ||
|
|
84
|
+
hasModifier(parameter, ts.SyntaxKind.ReadonlyKeyword)) {
|
|
85
|
+
diagnostics.push(createDiagnostic(sourceFile, parameter, `${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value]\` constructors only support plain identifier parameters with explicit types.`));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const statements = constructor.body?.statements ?? [];
|
|
89
|
+
if (statements.length !== fields.length) {
|
|
90
|
+
diagnostics.push(createDiagnostic(sourceFile, constructor, `${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value]\` constructors may only contain direct field assignments.`));
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
for (const [index, field] of fields.entries()) {
|
|
94
|
+
const parameter = constructor.parameters[index];
|
|
95
|
+
const statement = statements[index];
|
|
96
|
+
if (!parameter || !statement || !ts.isIdentifier(field.name) || !ts.isIdentifier(parameter.name)) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (!ts.isExpressionStatement(statement) || !ts.isBinaryExpression(statement.expression)) {
|
|
100
|
+
diagnostics.push(createDiagnostic(sourceFile, statement, `${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value]\` constructors may only contain direct \`this.field = param\` assignments.`));
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const assignment = statement.expression;
|
|
104
|
+
if (assignment.operatorToken.kind !== ts.SyntaxKind.FirstAssignment ||
|
|
105
|
+
!ts.isPropertyAccessExpression(assignment.left) ||
|
|
106
|
+
assignment.left.expression.kind !== ts.SyntaxKind.ThisKeyword ||
|
|
107
|
+
assignment.left.name.text !== field.name.text ||
|
|
108
|
+
!ts.isIdentifier(assignment.right) ||
|
|
109
|
+
assignment.right.text !== parameter.name.text) {
|
|
110
|
+
diagnostics.push(createDiagnostic(sourceFile, statement, `${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value]\` constructors must assign fields from same-name parameters in declaration order.`));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (deep) {
|
|
114
|
+
for (const field of fields) {
|
|
115
|
+
if (field.type && !typeNodeIsDeepSafe(field.type, {
|
|
116
|
+
checker: context.checker,
|
|
117
|
+
isDeepValueClassDeclaration: (declaration) => declarationIsValidDeepValueClass(context, declaration),
|
|
118
|
+
})) {
|
|
119
|
+
diagnostics.push(createDiagnostic(sourceFile, field, `${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value(deep: true)]\` fields must use recursively deep-safe types.`));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function validateValueClass(context, declaration, diagnostics) {
|
|
125
|
+
const sourceFile = declaration.getSourceFile();
|
|
126
|
+
const annotation = findValueAnnotation(context, declaration);
|
|
127
|
+
if (!annotation) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const deep = isDeepValueAnnotation(annotation);
|
|
131
|
+
if (!declaration.name) {
|
|
132
|
+
diagnostics.push(createDiagnostic(sourceFile, declaration, `${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value]\` classes must be named.`));
|
|
133
|
+
}
|
|
134
|
+
if (!ts.isSourceFile(declaration.parent)) {
|
|
135
|
+
diagnostics.push(createDiagnostic(sourceFile, declaration, `${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value]\` classes must be declared at module scope.`));
|
|
136
|
+
}
|
|
137
|
+
if (declaration.heritageClauses?.some((clause) => clause.token === ts.SyntaxKind.ExtendsKeyword)) {
|
|
138
|
+
diagnostics.push(createDiagnostic(sourceFile, declaration, `${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value]\` classes do not support inheritance in v1.`));
|
|
139
|
+
}
|
|
140
|
+
if (deep && (declaration.typeParameters?.length ?? 0) > 0) {
|
|
141
|
+
diagnostics.push(createDiagnostic(sourceFile, declaration, `${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value(deep: true)]\` classes may not be generic in v1.`));
|
|
142
|
+
}
|
|
143
|
+
const fields = [];
|
|
144
|
+
for (const member of declaration.members) {
|
|
145
|
+
if (hasModifier(member, ts.SyntaxKind.PrivateKeyword) ||
|
|
146
|
+
hasModifier(member, ts.SyntaxKind.ProtectedKeyword)) {
|
|
147
|
+
diagnostics.push(createDiagnostic(sourceFile, member, `${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value]\` classes do not support private or protected members in v1.`));
|
|
148
|
+
}
|
|
149
|
+
if (ts.isPropertyDeclaration(member)) {
|
|
150
|
+
fields.push(member);
|
|
151
|
+
if (!member.type ||
|
|
152
|
+
!ts.isIdentifier(member.name) ||
|
|
153
|
+
!!member.initializer ||
|
|
154
|
+
!!member.questionToken ||
|
|
155
|
+
hasModifier(member, ts.SyntaxKind.StaticKeyword) ||
|
|
156
|
+
!hasModifier(member, ts.SyntaxKind.ReadonlyKeyword)) {
|
|
157
|
+
diagnostics.push(createDiagnostic(sourceFile, member, `${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value]\` fields must be public readonly instance properties with explicit types and no initializers.`));
|
|
158
|
+
}
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (ts.isMethodDeclaration(member) ||
|
|
162
|
+
ts.isConstructorDeclaration(member)) {
|
|
163
|
+
if (ts.isMethodDeclaration(member) &&
|
|
164
|
+
(hasModifier(member, ts.SyntaxKind.StaticKeyword) ||
|
|
165
|
+
!ts.isIdentifier(member.name) ||
|
|
166
|
+
!!member.questionToken ||
|
|
167
|
+
!!member.asteriskToken ||
|
|
168
|
+
!member.body)) {
|
|
169
|
+
diagnostics.push(createDiagnostic(sourceFile, member, `${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value]\` methods must be ordinary public instance methods with identifier names and concrete bodies.`));
|
|
170
|
+
}
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
diagnostics.push(createDiagnostic(sourceFile, member, `${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value]\` classes only support readonly instance fields, constructors, and ordinary methods in v1.`));
|
|
174
|
+
}
|
|
175
|
+
validateConstructorShape(context, sourceFile, declaration, fields, deep, diagnostics);
|
|
176
|
+
}
|
|
177
|
+
function validateValueBaseExtension(context, declaration, diagnostics) {
|
|
178
|
+
const sourceFile = declaration.getSourceFile();
|
|
179
|
+
for (const clause of declaration.heritageClauses ?? []) {
|
|
180
|
+
if (clause.token !== ts.SyntaxKind.ExtendsKeyword) {
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
for (const type of clause.types) {
|
|
184
|
+
if (!typeNodeExtendsValueClass(context, type)) {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
diagnostics.push(createDiagnostic(sourceFile, type, `${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} classes may not extend \`#[value]\` classes in v1.`));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
export function runValueTypeRules(context) {
|
|
192
|
+
const diagnostics = [];
|
|
193
|
+
context.forEachSourceFile((sourceFile) => {
|
|
194
|
+
const visit = (node) => {
|
|
195
|
+
if (ts.isClassDeclaration(node) || ts.isClassExpression(node)) {
|
|
196
|
+
validateValueBaseExtension(context, node, diagnostics);
|
|
197
|
+
if (ts.isClassDeclaration(node) && findValueAnnotation(context, node)) {
|
|
198
|
+
validateValueClass(context, node, diagnostics);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
ts.forEachChild(node, visit);
|
|
202
|
+
};
|
|
203
|
+
visit(sourceFile);
|
|
204
|
+
});
|
|
205
|
+
return diagnostics;
|
|
206
|
+
}
|
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
|
|
3
|
+
import type { ParsedAnnotation } from '../../annotation_syntax.ts';
|
|
4
|
+
import {
|
|
5
|
+
deepValueClassDeclarationIsValid,
|
|
6
|
+
resolveAliasedSymbol,
|
|
7
|
+
typeNodeIsDeepSafe,
|
|
8
|
+
} from '../../value_deep_safe.ts';
|
|
9
|
+
import { SOUND_DIAGNOSTIC_CODES, SOUND_DIAGNOSTIC_MESSAGES } from '../engine/diagnostic_codes.ts';
|
|
10
|
+
import type { AnalysisContext } from '../engine/types.ts';
|
|
11
|
+
import type { SoundDiagnostic } from '../diagnostics.ts';
|
|
12
|
+
|
|
13
|
+
function createDiagnostic(
|
|
14
|
+
sourceFile: ts.SourceFile,
|
|
15
|
+
node: ts.Node,
|
|
16
|
+
message: string,
|
|
17
|
+
): SoundDiagnostic {
|
|
18
|
+
const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
|
|
19
|
+
return {
|
|
20
|
+
source: 'sound',
|
|
21
|
+
code: SOUND_DIAGNOSTIC_CODES.invalidAnnotationTarget,
|
|
22
|
+
category: 'error',
|
|
23
|
+
message,
|
|
24
|
+
filePath: sourceFile.fileName,
|
|
25
|
+
line: line + 1,
|
|
26
|
+
column: character + 1,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function findValueAnnotation(
|
|
31
|
+
context: AnalysisContext,
|
|
32
|
+
declaration: ts.ClassDeclaration,
|
|
33
|
+
): ParsedAnnotation | undefined {
|
|
34
|
+
return context.getAnnotationLookup(declaration.getSourceFile())
|
|
35
|
+
.getAttachedAnnotations(declaration)
|
|
36
|
+
.find((annotation) => annotation.name === 'value');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function isDeepValueAnnotation(annotation: ParsedAnnotation | undefined): boolean {
|
|
40
|
+
const [argument] = annotation?.arguments ?? [];
|
|
41
|
+
return argument?.kind === 'named' &&
|
|
42
|
+
argument.name === 'deep' &&
|
|
43
|
+
argument.value.kind === 'boolean' &&
|
|
44
|
+
argument.value.value === true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function hasModifier(node: ts.Node, kind: ts.SyntaxKind): boolean {
|
|
48
|
+
return ts.canHaveModifiers(node) &&
|
|
49
|
+
ts.getModifiers(node)?.some((modifier) => modifier.kind === kind) === true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function symbolDeclaresValueClass(
|
|
53
|
+
context: AnalysisContext,
|
|
54
|
+
symbol: ts.Symbol,
|
|
55
|
+
): boolean {
|
|
56
|
+
const resolved = resolveAliasedSymbol(context.checker, symbol);
|
|
57
|
+
return resolved.getDeclarations()?.some((declaration) =>
|
|
58
|
+
ts.isClassDeclaration(declaration) && !!findValueAnnotation(context, declaration)
|
|
59
|
+
) === true;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function declarationIsDeepValueClass(
|
|
63
|
+
context: AnalysisContext,
|
|
64
|
+
declaration: ts.ClassDeclaration,
|
|
65
|
+
): boolean {
|
|
66
|
+
const annotation = findValueAnnotation(context, declaration);
|
|
67
|
+
return !!annotation && isDeepValueAnnotation(annotation);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function declarationIsValidDeepValueClass(
|
|
71
|
+
context: AnalysisContext,
|
|
72
|
+
declaration: ts.ClassDeclaration,
|
|
73
|
+
): boolean {
|
|
74
|
+
return deepValueClassDeclarationIsValid(declaration, {
|
|
75
|
+
checker: context.checker,
|
|
76
|
+
hasDeepValueAnnotation: (innerDeclaration) => declarationIsDeepValueClass(context, innerDeclaration),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function typeNodeExtendsValueClass(
|
|
81
|
+
context: AnalysisContext,
|
|
82
|
+
typeNode: ts.ExpressionWithTypeArguments,
|
|
83
|
+
): boolean {
|
|
84
|
+
const baseType = context.checker.getTypeAtLocation(typeNode);
|
|
85
|
+
const baseSymbol = baseType.aliasSymbol ?? baseType.getSymbol();
|
|
86
|
+
return !!baseSymbol && symbolDeclaresValueClass(context, baseSymbol);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function validateConstructorShape(
|
|
90
|
+
context: AnalysisContext,
|
|
91
|
+
sourceFile: ts.SourceFile,
|
|
92
|
+
declaration: ts.ClassDeclaration,
|
|
93
|
+
fields: readonly ts.PropertyDeclaration[],
|
|
94
|
+
deep: boolean,
|
|
95
|
+
diagnostics: SoundDiagnostic[],
|
|
96
|
+
): void {
|
|
97
|
+
const constructors = declaration.members.filter((member) => ts.isConstructorDeclaration(member));
|
|
98
|
+
if (fields.length === 0) {
|
|
99
|
+
if (constructors.length > 1) {
|
|
100
|
+
diagnostics.push(
|
|
101
|
+
createDiagnostic(
|
|
102
|
+
sourceFile,
|
|
103
|
+
declaration,
|
|
104
|
+
`${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value]\` classes may declare at most one constructor.`,
|
|
105
|
+
),
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
} else if (constructors.length !== 1) {
|
|
109
|
+
diagnostics.push(
|
|
110
|
+
createDiagnostic(
|
|
111
|
+
sourceFile,
|
|
112
|
+
declaration,
|
|
113
|
+
`${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value]\` classes with fields must declare exactly one constructor.`,
|
|
114
|
+
),
|
|
115
|
+
);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const [constructor] = constructors;
|
|
120
|
+
if (!constructor) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (fields.length === 0) {
|
|
125
|
+
if (constructor.parameters.length !== 0 || constructor.body?.statements.length) {
|
|
126
|
+
diagnostics.push(
|
|
127
|
+
createDiagnostic(
|
|
128
|
+
sourceFile,
|
|
129
|
+
constructor,
|
|
130
|
+
`${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} fieldless \`#[value]\` constructors must be empty.`,
|
|
131
|
+
),
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (constructor.parameters.length !== fields.length) {
|
|
138
|
+
diagnostics.push(
|
|
139
|
+
createDiagnostic(
|
|
140
|
+
sourceFile,
|
|
141
|
+
constructor,
|
|
142
|
+
`${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value]\` constructor parameters must match declared fields 1:1.`,
|
|
143
|
+
),
|
|
144
|
+
);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
for (const parameter of constructor.parameters) {
|
|
149
|
+
if (
|
|
150
|
+
!ts.isIdentifier(parameter.name) ||
|
|
151
|
+
parameter.dotDotDotToken ||
|
|
152
|
+
parameter.initializer ||
|
|
153
|
+
!parameter.type ||
|
|
154
|
+
hasModifier(parameter, ts.SyntaxKind.PublicKeyword) ||
|
|
155
|
+
hasModifier(parameter, ts.SyntaxKind.PrivateKeyword) ||
|
|
156
|
+
hasModifier(parameter, ts.SyntaxKind.ProtectedKeyword) ||
|
|
157
|
+
hasModifier(parameter, ts.SyntaxKind.ReadonlyKeyword)
|
|
158
|
+
) {
|
|
159
|
+
diagnostics.push(
|
|
160
|
+
createDiagnostic(
|
|
161
|
+
sourceFile,
|
|
162
|
+
parameter,
|
|
163
|
+
`${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value]\` constructors only support plain identifier parameters with explicit types.`,
|
|
164
|
+
),
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const statements = constructor.body?.statements ?? [];
|
|
170
|
+
if (statements.length !== fields.length) {
|
|
171
|
+
diagnostics.push(
|
|
172
|
+
createDiagnostic(
|
|
173
|
+
sourceFile,
|
|
174
|
+
constructor,
|
|
175
|
+
`${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value]\` constructors may only contain direct field assignments.`,
|
|
176
|
+
),
|
|
177
|
+
);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
for (const [index, field] of fields.entries()) {
|
|
182
|
+
const parameter = constructor.parameters[index];
|
|
183
|
+
const statement = statements[index];
|
|
184
|
+
if (
|
|
185
|
+
!parameter || !statement || !ts.isIdentifier(field.name) || !ts.isIdentifier(parameter.name)
|
|
186
|
+
) {
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (!ts.isExpressionStatement(statement) || !ts.isBinaryExpression(statement.expression)) {
|
|
191
|
+
diagnostics.push(
|
|
192
|
+
createDiagnostic(
|
|
193
|
+
sourceFile,
|
|
194
|
+
statement,
|
|
195
|
+
`${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value]\` constructors may only contain direct \`this.field = param\` assignments.`,
|
|
196
|
+
),
|
|
197
|
+
);
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const assignment = statement.expression;
|
|
202
|
+
if (
|
|
203
|
+
assignment.operatorToken.kind !== ts.SyntaxKind.FirstAssignment ||
|
|
204
|
+
!ts.isPropertyAccessExpression(assignment.left) ||
|
|
205
|
+
assignment.left.expression.kind !== ts.SyntaxKind.ThisKeyword ||
|
|
206
|
+
assignment.left.name.text !== field.name.text ||
|
|
207
|
+
!ts.isIdentifier(assignment.right) ||
|
|
208
|
+
assignment.right.text !== parameter.name.text
|
|
209
|
+
) {
|
|
210
|
+
diagnostics.push(
|
|
211
|
+
createDiagnostic(
|
|
212
|
+
sourceFile,
|
|
213
|
+
statement,
|
|
214
|
+
`${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value]\` constructors must assign fields from same-name parameters in declaration order.`,
|
|
215
|
+
),
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (deep) {
|
|
221
|
+
for (const field of fields) {
|
|
222
|
+
if (field.type && !typeNodeIsDeepSafe(field.type, {
|
|
223
|
+
checker: context.checker,
|
|
224
|
+
isDeepValueClassDeclaration: (declaration) => declarationIsValidDeepValueClass(context, declaration),
|
|
225
|
+
})) {
|
|
226
|
+
diagnostics.push(
|
|
227
|
+
createDiagnostic(
|
|
228
|
+
sourceFile,
|
|
229
|
+
field,
|
|
230
|
+
`${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value(deep: true)]\` fields must use recursively deep-safe types.`,
|
|
231
|
+
),
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function validateValueClass(
|
|
239
|
+
context: AnalysisContext,
|
|
240
|
+
declaration: ts.ClassDeclaration,
|
|
241
|
+
diagnostics: SoundDiagnostic[],
|
|
242
|
+
): void {
|
|
243
|
+
const sourceFile = declaration.getSourceFile();
|
|
244
|
+
const annotation = findValueAnnotation(context, declaration);
|
|
245
|
+
if (!annotation) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const deep = isDeepValueAnnotation(annotation);
|
|
250
|
+
if (!declaration.name) {
|
|
251
|
+
diagnostics.push(
|
|
252
|
+
createDiagnostic(
|
|
253
|
+
sourceFile,
|
|
254
|
+
declaration,
|
|
255
|
+
`${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value]\` classes must be named.`,
|
|
256
|
+
),
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
if (!ts.isSourceFile(declaration.parent)) {
|
|
260
|
+
diagnostics.push(
|
|
261
|
+
createDiagnostic(
|
|
262
|
+
sourceFile,
|
|
263
|
+
declaration,
|
|
264
|
+
`${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value]\` classes must be declared at module scope.`,
|
|
265
|
+
),
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
if (
|
|
269
|
+
declaration.heritageClauses?.some((clause) => clause.token === ts.SyntaxKind.ExtendsKeyword)
|
|
270
|
+
) {
|
|
271
|
+
diagnostics.push(
|
|
272
|
+
createDiagnostic(
|
|
273
|
+
sourceFile,
|
|
274
|
+
declaration,
|
|
275
|
+
`${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value]\` classes do not support inheritance in v1.`,
|
|
276
|
+
),
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
if (deep && (declaration.typeParameters?.length ?? 0) > 0) {
|
|
280
|
+
diagnostics.push(
|
|
281
|
+
createDiagnostic(
|
|
282
|
+
sourceFile,
|
|
283
|
+
declaration,
|
|
284
|
+
`${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value(deep: true)]\` classes may not be generic in v1.`,
|
|
285
|
+
),
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const fields: ts.PropertyDeclaration[] = [];
|
|
290
|
+
for (const member of declaration.members) {
|
|
291
|
+
if (
|
|
292
|
+
hasModifier(member, ts.SyntaxKind.PrivateKeyword) ||
|
|
293
|
+
hasModifier(member, ts.SyntaxKind.ProtectedKeyword)
|
|
294
|
+
) {
|
|
295
|
+
diagnostics.push(
|
|
296
|
+
createDiagnostic(
|
|
297
|
+
sourceFile,
|
|
298
|
+
member,
|
|
299
|
+
`${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value]\` classes do not support private or protected members in v1.`,
|
|
300
|
+
),
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
if (ts.isPropertyDeclaration(member)) {
|
|
305
|
+
fields.push(member);
|
|
306
|
+
if (
|
|
307
|
+
!member.type ||
|
|
308
|
+
!ts.isIdentifier(member.name) ||
|
|
309
|
+
!!member.initializer ||
|
|
310
|
+
!!member.questionToken ||
|
|
311
|
+
hasModifier(member, ts.SyntaxKind.StaticKeyword) ||
|
|
312
|
+
!hasModifier(member, ts.SyntaxKind.ReadonlyKeyword)
|
|
313
|
+
) {
|
|
314
|
+
diagnostics.push(
|
|
315
|
+
createDiagnostic(
|
|
316
|
+
sourceFile,
|
|
317
|
+
member,
|
|
318
|
+
`${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value]\` fields must be public readonly instance properties with explicit types and no initializers.`,
|
|
319
|
+
),
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (
|
|
326
|
+
ts.isMethodDeclaration(member) ||
|
|
327
|
+
ts.isConstructorDeclaration(member)
|
|
328
|
+
) {
|
|
329
|
+
if (
|
|
330
|
+
ts.isMethodDeclaration(member) &&
|
|
331
|
+
(
|
|
332
|
+
hasModifier(member, ts.SyntaxKind.StaticKeyword) ||
|
|
333
|
+
!ts.isIdentifier(member.name) ||
|
|
334
|
+
!!member.questionToken ||
|
|
335
|
+
!!member.asteriskToken ||
|
|
336
|
+
!member.body
|
|
337
|
+
)
|
|
338
|
+
) {
|
|
339
|
+
diagnostics.push(
|
|
340
|
+
createDiagnostic(
|
|
341
|
+
sourceFile,
|
|
342
|
+
member,
|
|
343
|
+
`${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value]\` methods must be ordinary public instance methods with identifier names and concrete bodies.`,
|
|
344
|
+
),
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
diagnostics.push(
|
|
351
|
+
createDiagnostic(
|
|
352
|
+
sourceFile,
|
|
353
|
+
member,
|
|
354
|
+
`${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} \`#[value]\` classes only support readonly instance fields, constructors, and ordinary methods in v1.`,
|
|
355
|
+
),
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
validateConstructorShape(context, sourceFile, declaration, fields, deep, diagnostics);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function validateValueBaseExtension(
|
|
363
|
+
context: AnalysisContext,
|
|
364
|
+
declaration: ts.ClassLikeDeclaration,
|
|
365
|
+
diagnostics: SoundDiagnostic[],
|
|
366
|
+
): void {
|
|
367
|
+
const sourceFile = declaration.getSourceFile();
|
|
368
|
+
|
|
369
|
+
for (const clause of declaration.heritageClauses ?? []) {
|
|
370
|
+
if (clause.token !== ts.SyntaxKind.ExtendsKeyword) {
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
for (const type of clause.types) {
|
|
375
|
+
if (!typeNodeExtendsValueClass(context, type)) {
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
diagnostics.push(
|
|
380
|
+
createDiagnostic(
|
|
381
|
+
sourceFile,
|
|
382
|
+
type,
|
|
383
|
+
`${SOUND_DIAGNOSTIC_MESSAGES.invalidAnnotationTarget} classes may not extend \`#[value]\` classes in v1.`,
|
|
384
|
+
),
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
export function runValueTypeRules(context: AnalysisContext): SoundDiagnostic[] {
|
|
391
|
+
const diagnostics: SoundDiagnostic[] = [];
|
|
392
|
+
|
|
393
|
+
context.forEachSourceFile((sourceFile) => {
|
|
394
|
+
const visit = (node: ts.Node): void => {
|
|
395
|
+
if (ts.isClassDeclaration(node) || ts.isClassExpression(node)) {
|
|
396
|
+
validateValueBaseExtension(context, node, diagnostics);
|
|
397
|
+
if (ts.isClassDeclaration(node) && findValueAnnotation(context, node)) {
|
|
398
|
+
validateValueClass(context, node, diagnostics);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
ts.forEachChild(node, visit);
|
|
402
|
+
};
|
|
403
|
+
visit(sourceFile);
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
return diagnostics;
|
|
407
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const CHECKER_TIMING_ENV_VAR = 'SOUNDSCRIPT_CHECKER_TIMING';
|
|
2
|
+
const DEFAULT_CHECKER_TIMING_THRESHOLD_MS = 25;
|
|
3
|
+
function getTimingEnvValue() {
|
|
4
|
+
if (typeof process !== 'undefined' && typeof process.env === 'object') {
|
|
5
|
+
const processValue = process.env[CHECKER_TIMING_ENV_VAR];
|
|
6
|
+
if (typeof processValue === 'string') {
|
|
7
|
+
return processValue;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const maybeDeno = globalThis;
|
|
11
|
+
return maybeDeno.Deno?.env?.get(CHECKER_TIMING_ENV_VAR);
|
|
12
|
+
}
|
|
13
|
+
export function isCheckerTimingEnabled(rawValue = getTimingEnvValue()) {
|
|
14
|
+
return rawValue === '1' || rawValue === 'true';
|
|
15
|
+
}
|
|
16
|
+
function formatMetadata(metadata) {
|
|
17
|
+
return Object.entries(metadata)
|
|
18
|
+
.filter(([, value]) => value !== undefined)
|
|
19
|
+
.map(([key, value]) => `${key}=${String(value)}`)
|
|
20
|
+
.join(' ');
|
|
21
|
+
}
|
|
22
|
+
export function logCheckerTiming(operation, durationMs, metadata = {}, options = {}) {
|
|
23
|
+
const enabled = options.enabled ?? isCheckerTimingEnabled();
|
|
24
|
+
if (!enabled) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const thresholdMs = options.thresholdMs ?? DEFAULT_CHECKER_TIMING_THRESHOLD_MS;
|
|
28
|
+
if (!options.always && durationMs < thresholdMs) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const metadataText = formatMetadata(metadata);
|
|
32
|
+
const prefix = `[soundscript:checker] ${operation} ${durationMs.toFixed(1)}ms`;
|
|
33
|
+
console.error(metadataText.length > 0 ? `${prefix} ${metadataText}` : prefix);
|
|
34
|
+
}
|
|
35
|
+
export function measureCheckerTiming(operation, metadata, fn, options = {}) {
|
|
36
|
+
const start = performance.now();
|
|
37
|
+
try {
|
|
38
|
+
return fn();
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
logCheckerTiming(operation, performance.now() - start, metadata, options);
|
|
42
|
+
}
|
|
43
|
+
}
|