@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,176 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { createAnnotationLookup } from '../annotation_syntax.js';
|
|
3
|
+
const MACRO_API_SPECIFIERS = new Set(['sts:macros', '@soundscript/macros']);
|
|
4
|
+
function blankPreservingLines(text) {
|
|
5
|
+
return text.replace(/[^\r\n]/gu, ' ');
|
|
6
|
+
}
|
|
7
|
+
function macroFactoryAnnotationForNode(sourceFile, node) {
|
|
8
|
+
const block = createAnnotationLookup(sourceFile).getAttachedAnnotationBlock(node);
|
|
9
|
+
const annotation = block?.annotations.find((entry) => entry.name === 'macro');
|
|
10
|
+
const formValue = annotation?.arguments?.[0]?.value;
|
|
11
|
+
if (!block ||
|
|
12
|
+
!annotation ||
|
|
13
|
+
annotation.arguments?.length !== 1 ||
|
|
14
|
+
annotation.arguments[0]?.kind !== 'positional' ||
|
|
15
|
+
!formValue ||
|
|
16
|
+
formValue.kind !== 'identifier' ||
|
|
17
|
+
(formValue.name !== 'call' && formValue.name !== 'decl' && formValue.name !== 'tag')) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
form: formValue.name,
|
|
22
|
+
span: {
|
|
23
|
+
fileName: sourceFile.fileName,
|
|
24
|
+
start: block.range.start,
|
|
25
|
+
end: block.range.end,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function getFunctionDeclarationExportName(node) {
|
|
30
|
+
if (!ts.isFunctionDeclaration(node)) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
const modifiers = ts.canHaveModifiers(node) ? ts.getModifiers(node) : undefined;
|
|
34
|
+
const isExported = !!modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword);
|
|
35
|
+
if (!isExported) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
const isDefault = !!modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword);
|
|
39
|
+
if (isDefault) {
|
|
40
|
+
return 'default';
|
|
41
|
+
}
|
|
42
|
+
return node.name?.text;
|
|
43
|
+
}
|
|
44
|
+
function exportedDeclarationNames(statement) {
|
|
45
|
+
const modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) : undefined;
|
|
46
|
+
const isExported = !!modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword);
|
|
47
|
+
if (!isExported) {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
const isDefault = !!modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword);
|
|
51
|
+
if (isDefault) {
|
|
52
|
+
return ['default'];
|
|
53
|
+
}
|
|
54
|
+
if ((ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement) ||
|
|
55
|
+
ts.isInterfaceDeclaration(statement) || ts.isTypeAliasDeclaration(statement) ||
|
|
56
|
+
ts.isEnumDeclaration(statement)) &&
|
|
57
|
+
statement.name) {
|
|
58
|
+
return [statement.name.text];
|
|
59
|
+
}
|
|
60
|
+
if (ts.isVariableStatement(statement)) {
|
|
61
|
+
return statement.declarationList.declarations.flatMap((declaration) => ts.isIdentifier(declaration.name) ? [declaration.name.text] : []);
|
|
62
|
+
}
|
|
63
|
+
if (ts.isExportAssignment(statement) && !statement.isExportEquals) {
|
|
64
|
+
return ['default'];
|
|
65
|
+
}
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
export function sourceTextLooksLikeMacroModule(sourceText) {
|
|
69
|
+
return [...MACRO_API_SPECIFIERS].some((specifier) => sourceText.includes(specifier));
|
|
70
|
+
}
|
|
71
|
+
export function macroSiteKindForFactoryForm(form) {
|
|
72
|
+
switch (form) {
|
|
73
|
+
case 'call':
|
|
74
|
+
return 'call';
|
|
75
|
+
case 'tag':
|
|
76
|
+
return 'tag';
|
|
77
|
+
case 'decl':
|
|
78
|
+
return 'annotation';
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export function scanMacroFactoryExports(fileName, sourceText) {
|
|
82
|
+
const sourceFile = ts.createSourceFile(fileName, sourceText, ts.ScriptTarget.Latest, true, /\.(?:[cm]?tsx|jsx|sts)$/iu.test(fileName) ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
83
|
+
const exports = new Map();
|
|
84
|
+
for (const statement of sourceFile.statements) {
|
|
85
|
+
const exportName = getFunctionDeclarationExportName(statement);
|
|
86
|
+
if (!exportName || !ts.isFunctionDeclaration(statement)) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const annotation = macroFactoryAnnotationForNode(sourceFile, statement);
|
|
90
|
+
if (!annotation) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
exports.set(exportName, {
|
|
94
|
+
exportName,
|
|
95
|
+
form: annotation.form,
|
|
96
|
+
span: {
|
|
97
|
+
fileName,
|
|
98
|
+
start: annotation.span.start,
|
|
99
|
+
end: statement.getEnd(),
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return exports;
|
|
104
|
+
}
|
|
105
|
+
export function usesLegacyDefineMacroAuthoring(sourceText) {
|
|
106
|
+
return /\bdefineMacro\s*\(/u.test(sourceText) ||
|
|
107
|
+
/from ['"]@soundscript\/macros['"]/u.test(sourceText) ||
|
|
108
|
+
/from ['"]sts:macros['"][^]*\bdefineMacro\b/u.test(sourceText);
|
|
109
|
+
}
|
|
110
|
+
export function stripMacroFactoryAuthoringFromText(fileName, sourceText) {
|
|
111
|
+
const sourceFile = ts.createSourceFile(fileName, sourceText, ts.ScriptTarget.Latest, true, /\.(?:[cm]?tsx|jsx|sts)$/iu.test(fileName) ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
112
|
+
const spansToBlank = [];
|
|
113
|
+
const strippedMacroExportNames = [];
|
|
114
|
+
for (const statement of sourceFile.statements) {
|
|
115
|
+
if (ts.isImportDeclaration(statement) &&
|
|
116
|
+
ts.isStringLiteral(statement.moduleSpecifier) &&
|
|
117
|
+
MACRO_API_SPECIFIERS.has(statement.moduleSpecifier.text)) {
|
|
118
|
+
spansToBlank.push({
|
|
119
|
+
start: statement.getFullStart(),
|
|
120
|
+
end: statement.getEnd(),
|
|
121
|
+
});
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const exportName = getFunctionDeclarationExportName(statement);
|
|
125
|
+
if (!exportName || !ts.isFunctionDeclaration(statement)) {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const annotation = macroFactoryAnnotationForNode(sourceFile, statement);
|
|
129
|
+
if (!annotation) {
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
spansToBlank.push({
|
|
133
|
+
start: annotation.span.start,
|
|
134
|
+
end: statement.getEnd(),
|
|
135
|
+
});
|
|
136
|
+
strippedMacroExportNames.push(exportName);
|
|
137
|
+
}
|
|
138
|
+
if (spansToBlank.length === 0) {
|
|
139
|
+
return sourceText;
|
|
140
|
+
}
|
|
141
|
+
const originalWasModule = ts.isExternalModule(sourceFile);
|
|
142
|
+
let stripped = '';
|
|
143
|
+
let cursor = 0;
|
|
144
|
+
for (const span of spansToBlank.sort((left, right) => left.start - right.start)) {
|
|
145
|
+
if (span.start < cursor) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
stripped += sourceText.slice(cursor, span.start);
|
|
149
|
+
stripped += blankPreservingLines(sourceText.slice(span.start, span.end));
|
|
150
|
+
cursor = span.end;
|
|
151
|
+
}
|
|
152
|
+
stripped += sourceText.slice(cursor);
|
|
153
|
+
const strippedSourceFile = ts.createSourceFile(fileName, stripped, ts.ScriptTarget.Latest, true, /\.(?:[cm]?tsx|jsx|sts)$/iu.test(fileName) ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
154
|
+
const survivingExportNames = new Set(strippedSourceFile.statements.flatMap((statement) => exportedDeclarationNames(statement)));
|
|
155
|
+
const missingExportNames = strippedMacroExportNames.filter((exportName) => !survivingExportNames.has(exportName));
|
|
156
|
+
if (missingExportNames.length > 0) {
|
|
157
|
+
const namedExportNames = missingExportNames.filter((exportName) => exportName !== 'default');
|
|
158
|
+
const missingDefaultExport = missingExportNames.includes('default');
|
|
159
|
+
const placeholderStatements = [
|
|
160
|
+
...namedExportNames.map((exportName) => `export declare const ${exportName}: unknown;`),
|
|
161
|
+
...(missingDefaultExport
|
|
162
|
+
? [
|
|
163
|
+
'declare const __soundscript_default_macro_export: unknown;',
|
|
164
|
+
'export default __soundscript_default_macro_export;',
|
|
165
|
+
]
|
|
166
|
+
: []),
|
|
167
|
+
];
|
|
168
|
+
return `${stripped}\n/* soundscript:macros */\n${placeholderStatements.join('\n')}\n`;
|
|
169
|
+
}
|
|
170
|
+
if (!originalWasModule) {
|
|
171
|
+
return stripped;
|
|
172
|
+
}
|
|
173
|
+
return ts.isExternalModule(strippedSourceFile)
|
|
174
|
+
? `${stripped}\n/* soundscript:macros */\n`
|
|
175
|
+
: `${stripped}\n/* soundscript:macros */\nexport {};\n`;
|
|
176
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
|
|
3
|
+
import { createAnnotationLookup } from '../annotation_syntax.ts';
|
|
4
|
+
import type { SourceSpan } from './macro_types.ts';
|
|
5
|
+
|
|
6
|
+
export type MacroFactoryForm = 'call' | 'decl' | 'tag';
|
|
7
|
+
export type ImportedMacroSiteKind = 'annotation' | 'call' | 'tag';
|
|
8
|
+
|
|
9
|
+
export interface ScannedMacroFactoryExport {
|
|
10
|
+
readonly exportName: string;
|
|
11
|
+
readonly form: MacroFactoryForm;
|
|
12
|
+
readonly span: SourceSpan;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const MACRO_API_SPECIFIERS = new Set(['sts:macros', '@soundscript/macros']);
|
|
16
|
+
function blankPreservingLines(text: string): string {
|
|
17
|
+
return text.replace(/[^\r\n]/gu, ' ');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function macroFactoryAnnotationForNode(
|
|
21
|
+
sourceFile: ts.SourceFile,
|
|
22
|
+
node: ts.Node,
|
|
23
|
+
): { form: MacroFactoryForm; span: SourceSpan } | null {
|
|
24
|
+
const block = createAnnotationLookup(sourceFile).getAttachedAnnotationBlock(node);
|
|
25
|
+
const annotation = block?.annotations.find((entry) => entry.name === 'macro');
|
|
26
|
+
const formValue = annotation?.arguments?.[0]?.value;
|
|
27
|
+
if (
|
|
28
|
+
!block ||
|
|
29
|
+
!annotation ||
|
|
30
|
+
annotation.arguments?.length !== 1 ||
|
|
31
|
+
annotation.arguments[0]?.kind !== 'positional' ||
|
|
32
|
+
!formValue ||
|
|
33
|
+
formValue.kind !== 'identifier' ||
|
|
34
|
+
(formValue.name !== 'call' && formValue.name !== 'decl' && formValue.name !== 'tag')
|
|
35
|
+
) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
form: formValue.name as MacroFactoryForm,
|
|
41
|
+
span: {
|
|
42
|
+
fileName: sourceFile.fileName,
|
|
43
|
+
start: block.range.start,
|
|
44
|
+
end: block.range.end,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function getFunctionDeclarationExportName(
|
|
50
|
+
node: ts.Statement,
|
|
51
|
+
): 'default' | string | undefined {
|
|
52
|
+
if (!ts.isFunctionDeclaration(node)) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const modifiers = ts.canHaveModifiers(node) ? ts.getModifiers(node) : undefined;
|
|
57
|
+
const isExported = !!modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword);
|
|
58
|
+
if (!isExported) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const isDefault = !!modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword);
|
|
63
|
+
if (isDefault) {
|
|
64
|
+
return 'default';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return node.name?.text;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function exportedDeclarationNames(statement: ts.Statement): readonly string[] {
|
|
71
|
+
const modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) : undefined;
|
|
72
|
+
const isExported = !!modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword);
|
|
73
|
+
if (!isExported) {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const isDefault = !!modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword);
|
|
78
|
+
if (isDefault) {
|
|
79
|
+
return ['default'];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (
|
|
83
|
+
(ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement) ||
|
|
84
|
+
ts.isInterfaceDeclaration(statement) || ts.isTypeAliasDeclaration(statement) ||
|
|
85
|
+
ts.isEnumDeclaration(statement)) &&
|
|
86
|
+
statement.name
|
|
87
|
+
) {
|
|
88
|
+
return [statement.name.text];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (ts.isVariableStatement(statement)) {
|
|
92
|
+
return statement.declarationList.declarations.flatMap((declaration) =>
|
|
93
|
+
ts.isIdentifier(declaration.name) ? [declaration.name.text] : []
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (ts.isExportAssignment(statement) && !statement.isExportEquals) {
|
|
98
|
+
return ['default'];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function sourceTextLooksLikeMacroModule(sourceText: string): boolean {
|
|
105
|
+
return [...MACRO_API_SPECIFIERS].some((specifier) => sourceText.includes(specifier));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function macroSiteKindForFactoryForm(form: MacroFactoryForm): ImportedMacroSiteKind {
|
|
109
|
+
switch (form) {
|
|
110
|
+
case 'call':
|
|
111
|
+
return 'call';
|
|
112
|
+
case 'tag':
|
|
113
|
+
return 'tag';
|
|
114
|
+
case 'decl':
|
|
115
|
+
return 'annotation';
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function scanMacroFactoryExports(
|
|
120
|
+
fileName: string,
|
|
121
|
+
sourceText: string,
|
|
122
|
+
): ReadonlyMap<string, ScannedMacroFactoryExport> {
|
|
123
|
+
const sourceFile = ts.createSourceFile(
|
|
124
|
+
fileName,
|
|
125
|
+
sourceText,
|
|
126
|
+
ts.ScriptTarget.Latest,
|
|
127
|
+
true,
|
|
128
|
+
/\.(?:[cm]?tsx|jsx|sts)$/iu.test(fileName) ? ts.ScriptKind.TSX : ts.ScriptKind.TS,
|
|
129
|
+
);
|
|
130
|
+
const exports = new Map<string, ScannedMacroFactoryExport>();
|
|
131
|
+
|
|
132
|
+
for (const statement of sourceFile.statements) {
|
|
133
|
+
const exportName = getFunctionDeclarationExportName(statement);
|
|
134
|
+
if (!exportName || !ts.isFunctionDeclaration(statement)) {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const annotation = macroFactoryAnnotationForNode(sourceFile, statement);
|
|
139
|
+
if (!annotation) {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
exports.set(exportName, {
|
|
144
|
+
exportName,
|
|
145
|
+
form: annotation.form,
|
|
146
|
+
span: {
|
|
147
|
+
fileName,
|
|
148
|
+
start: annotation.span.start,
|
|
149
|
+
end: statement.getEnd(),
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return exports;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function usesLegacyDefineMacroAuthoring(sourceText: string): boolean {
|
|
158
|
+
return /\bdefineMacro\s*\(/u.test(sourceText) ||
|
|
159
|
+
/from ['"]@soundscript\/macros['"]/u.test(sourceText) ||
|
|
160
|
+
/from ['"]sts:macros['"][^]*\bdefineMacro\b/u.test(sourceText);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function stripMacroFactoryAuthoringFromText(
|
|
164
|
+
fileName: string,
|
|
165
|
+
sourceText: string,
|
|
166
|
+
): string {
|
|
167
|
+
const sourceFile = ts.createSourceFile(
|
|
168
|
+
fileName,
|
|
169
|
+
sourceText,
|
|
170
|
+
ts.ScriptTarget.Latest,
|
|
171
|
+
true,
|
|
172
|
+
/\.(?:[cm]?tsx|jsx|sts)$/iu.test(fileName) ? ts.ScriptKind.TSX : ts.ScriptKind.TS,
|
|
173
|
+
);
|
|
174
|
+
const spansToBlank: Array<{ start: number; end: number }> = [];
|
|
175
|
+
const strippedMacroExportNames: string[] = [];
|
|
176
|
+
|
|
177
|
+
for (const statement of sourceFile.statements) {
|
|
178
|
+
if (
|
|
179
|
+
ts.isImportDeclaration(statement) &&
|
|
180
|
+
ts.isStringLiteral(statement.moduleSpecifier) &&
|
|
181
|
+
MACRO_API_SPECIFIERS.has(statement.moduleSpecifier.text)
|
|
182
|
+
) {
|
|
183
|
+
spansToBlank.push({
|
|
184
|
+
start: statement.getFullStart(),
|
|
185
|
+
end: statement.getEnd(),
|
|
186
|
+
});
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const exportName = getFunctionDeclarationExportName(statement);
|
|
191
|
+
if (!exportName || !ts.isFunctionDeclaration(statement)) {
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const annotation = macroFactoryAnnotationForNode(sourceFile, statement);
|
|
196
|
+
if (!annotation) {
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
spansToBlank.push({
|
|
201
|
+
start: annotation.span.start,
|
|
202
|
+
end: statement.getEnd(),
|
|
203
|
+
});
|
|
204
|
+
strippedMacroExportNames.push(exportName);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (spansToBlank.length === 0) {
|
|
208
|
+
return sourceText;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const originalWasModule = ts.isExternalModule(sourceFile);
|
|
212
|
+
|
|
213
|
+
let stripped = '';
|
|
214
|
+
let cursor = 0;
|
|
215
|
+
for (const span of spansToBlank.sort((left, right) => left.start - right.start)) {
|
|
216
|
+
if (span.start < cursor) {
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
stripped += sourceText.slice(cursor, span.start);
|
|
221
|
+
stripped += blankPreservingLines(sourceText.slice(span.start, span.end));
|
|
222
|
+
cursor = span.end;
|
|
223
|
+
}
|
|
224
|
+
stripped += sourceText.slice(cursor);
|
|
225
|
+
|
|
226
|
+
const strippedSourceFile = ts.createSourceFile(
|
|
227
|
+
fileName,
|
|
228
|
+
stripped,
|
|
229
|
+
ts.ScriptTarget.Latest,
|
|
230
|
+
true,
|
|
231
|
+
/\.(?:[cm]?tsx|jsx|sts)$/iu.test(fileName) ? ts.ScriptKind.TSX : ts.ScriptKind.TS,
|
|
232
|
+
);
|
|
233
|
+
const survivingExportNames = new Set(
|
|
234
|
+
strippedSourceFile.statements.flatMap((statement) => exportedDeclarationNames(statement)),
|
|
235
|
+
);
|
|
236
|
+
const missingExportNames = strippedMacroExportNames.filter((exportName) =>
|
|
237
|
+
!survivingExportNames.has(exportName)
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
if (missingExportNames.length > 0) {
|
|
241
|
+
const namedExportNames = missingExportNames.filter((exportName) => exportName !== 'default');
|
|
242
|
+
const missingDefaultExport = missingExportNames.includes('default');
|
|
243
|
+
const placeholderStatements = [
|
|
244
|
+
...namedExportNames.map((exportName) => `export declare const ${exportName}: unknown;`),
|
|
245
|
+
...(missingDefaultExport
|
|
246
|
+
? [
|
|
247
|
+
'declare const __soundscript_default_macro_export: unknown;',
|
|
248
|
+
'export default __soundscript_default_macro_export;',
|
|
249
|
+
]
|
|
250
|
+
: []),
|
|
251
|
+
];
|
|
252
|
+
return `${stripped}\n/* soundscript:macros */\n${
|
|
253
|
+
placeholderStatements.join('\n')
|
|
254
|
+
}\n`;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (!originalWasModule) {
|
|
258
|
+
return stripped;
|
|
259
|
+
}
|
|
260
|
+
return ts.isExternalModule(strippedSourceFile)
|
|
261
|
+
? `${stripped}\n/* soundscript:macros */\n`
|
|
262
|
+
: `${stripped}\n/* soundscript:macros */\nexport {};\n`;
|
|
263
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
// Internal TypeScript host parsing and synthesis helpers.
|
|
3
|
+
// Macro authors should depend on macro_api.ts instead of this module.
|
|
4
|
+
function getFragmentScriptKind(fileName) {
|
|
5
|
+
const lowered = fileName.toLowerCase();
|
|
6
|
+
if (lowered.endsWith('.sts') || lowered.endsWith('.tsx') || lowered.endsWith('.jsx')) {
|
|
7
|
+
return ts.ScriptKind.TSX;
|
|
8
|
+
}
|
|
9
|
+
if (lowered.endsWith('.js') || lowered.endsWith('.mjs') || lowered.endsWith('.cjs')) {
|
|
10
|
+
return ts.ScriptKind.JS;
|
|
11
|
+
}
|
|
12
|
+
return ts.ScriptKind.TS;
|
|
13
|
+
}
|
|
14
|
+
function createFragmentSourceFile(hostFileName, suffix, text) {
|
|
15
|
+
const match = /(\.[^.]+)$/u.exec(hostFileName);
|
|
16
|
+
const extension = match ? match[1] : '.ts';
|
|
17
|
+
const fragmentFileName = `/virtual/${suffix}${extension === '.sts' ? '.tsx' : extension}`;
|
|
18
|
+
return ts.createSourceFile(fragmentFileName, text, ts.ScriptTarget.Latest, true, getFragmentScriptKind(hostFileName));
|
|
19
|
+
}
|
|
20
|
+
export function synthesizeHostNode(node) {
|
|
21
|
+
ts.setTextRange(node, { pos: -1, end: -1 });
|
|
22
|
+
ts.setOriginalNode(node, undefined);
|
|
23
|
+
ts.forEachChild(node, (child) => {
|
|
24
|
+
synthesizeHostNode(child);
|
|
25
|
+
});
|
|
26
|
+
return node;
|
|
27
|
+
}
|
|
28
|
+
function ensureNoParseDiagnostics(sourceFile, message) {
|
|
29
|
+
const parseDiagnostics = sourceFile.parseDiagnostics ?? [];
|
|
30
|
+
if (parseDiagnostics.length > 0) {
|
|
31
|
+
throw new Error(message);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function parseHostExpression(hostFileName, code, message) {
|
|
35
|
+
const sourceFile = createFragmentSourceFile(hostFileName, 'macro_expr', `const __macro_expr = (${code});`);
|
|
36
|
+
ensureNoParseDiagnostics(sourceFile, message);
|
|
37
|
+
if (sourceFile.statements.length !== 1) {
|
|
38
|
+
throw new Error(message);
|
|
39
|
+
}
|
|
40
|
+
const [statement] = sourceFile.statements;
|
|
41
|
+
if (!statement ||
|
|
42
|
+
!ts.isVariableStatement(statement) ||
|
|
43
|
+
statement.declarationList.declarations.length !== 1) {
|
|
44
|
+
throw new Error(message);
|
|
45
|
+
}
|
|
46
|
+
const [declaration] = statement.declarationList.declarations;
|
|
47
|
+
if (!declaration?.initializer ||
|
|
48
|
+
!ts.isParenthesizedExpression(declaration.initializer)) {
|
|
49
|
+
throw new Error(message);
|
|
50
|
+
}
|
|
51
|
+
return declaration.initializer.expression;
|
|
52
|
+
}
|
|
53
|
+
export function parseHostStatements(hostFileName, suffix, code, message) {
|
|
54
|
+
const sourceFile = createFragmentSourceFile(hostFileName, suffix, code);
|
|
55
|
+
ensureNoParseDiagnostics(sourceFile, message);
|
|
56
|
+
return [...sourceFile.statements];
|
|
57
|
+
}
|
|
58
|
+
export function parseSingleHostStatement(hostFileName, suffix, code, message) {
|
|
59
|
+
const statements = parseHostStatements(hostFileName, suffix, code, message);
|
|
60
|
+
if (statements.length !== 1) {
|
|
61
|
+
throw new Error(message);
|
|
62
|
+
}
|
|
63
|
+
return statements[0];
|
|
64
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
|
|
3
|
+
// Internal TypeScript host parsing and synthesis helpers.
|
|
4
|
+
// Macro authors should depend on macro_api.ts instead of this module.
|
|
5
|
+
|
|
6
|
+
function getFragmentScriptKind(fileName: string): ts.ScriptKind {
|
|
7
|
+
const lowered = fileName.toLowerCase();
|
|
8
|
+
if (lowered.endsWith('.sts') || lowered.endsWith('.tsx') || lowered.endsWith('.jsx')) {
|
|
9
|
+
return ts.ScriptKind.TSX;
|
|
10
|
+
}
|
|
11
|
+
if (lowered.endsWith('.js') || lowered.endsWith('.mjs') || lowered.endsWith('.cjs')) {
|
|
12
|
+
return ts.ScriptKind.JS;
|
|
13
|
+
}
|
|
14
|
+
return ts.ScriptKind.TS;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function createFragmentSourceFile(
|
|
18
|
+
hostFileName: string,
|
|
19
|
+
suffix: string,
|
|
20
|
+
text: string,
|
|
21
|
+
): ts.SourceFile {
|
|
22
|
+
const match = /(\.[^.]+)$/u.exec(hostFileName);
|
|
23
|
+
const extension = match ? match[1] : '.ts';
|
|
24
|
+
const fragmentFileName = `/virtual/${suffix}${extension === '.sts' ? '.tsx' : extension}`;
|
|
25
|
+
return ts.createSourceFile(
|
|
26
|
+
fragmentFileName,
|
|
27
|
+
text,
|
|
28
|
+
ts.ScriptTarget.Latest,
|
|
29
|
+
true,
|
|
30
|
+
getFragmentScriptKind(hostFileName),
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function synthesizeHostNode<T extends ts.Node>(node: T): T {
|
|
35
|
+
ts.setTextRange(node, { pos: -1, end: -1 });
|
|
36
|
+
ts.setOriginalNode(node, undefined);
|
|
37
|
+
ts.forEachChild(node, (child) => {
|
|
38
|
+
synthesizeHostNode(child);
|
|
39
|
+
});
|
|
40
|
+
return node;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function ensureNoParseDiagnostics(sourceFile: ts.SourceFile, message: string): void {
|
|
44
|
+
const parseDiagnostics = (sourceFile as ts.SourceFile & {
|
|
45
|
+
parseDiagnostics?: readonly ts.Diagnostic[];
|
|
46
|
+
}).parseDiagnostics ?? [];
|
|
47
|
+
if (parseDiagnostics.length > 0) {
|
|
48
|
+
throw new Error(message);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function parseHostExpression(
|
|
53
|
+
hostFileName: string,
|
|
54
|
+
code: string,
|
|
55
|
+
message: string,
|
|
56
|
+
): ts.Expression {
|
|
57
|
+
const sourceFile = createFragmentSourceFile(
|
|
58
|
+
hostFileName,
|
|
59
|
+
'macro_expr',
|
|
60
|
+
`const __macro_expr = (${code});`,
|
|
61
|
+
);
|
|
62
|
+
ensureNoParseDiagnostics(sourceFile, message);
|
|
63
|
+
if (sourceFile.statements.length !== 1) {
|
|
64
|
+
throw new Error(message);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const [statement] = sourceFile.statements;
|
|
68
|
+
if (
|
|
69
|
+
!statement ||
|
|
70
|
+
!ts.isVariableStatement(statement) ||
|
|
71
|
+
statement.declarationList.declarations.length !== 1
|
|
72
|
+
) {
|
|
73
|
+
throw new Error(message);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const [declaration] = statement.declarationList.declarations;
|
|
77
|
+
if (
|
|
78
|
+
!declaration?.initializer ||
|
|
79
|
+
!ts.isParenthesizedExpression(declaration.initializer)
|
|
80
|
+
) {
|
|
81
|
+
throw new Error(message);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return declaration.initializer.expression;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function parseHostStatements(
|
|
88
|
+
hostFileName: string,
|
|
89
|
+
suffix: string,
|
|
90
|
+
code: string,
|
|
91
|
+
message: string,
|
|
92
|
+
): readonly ts.Statement[] {
|
|
93
|
+
const sourceFile = createFragmentSourceFile(hostFileName, suffix, code);
|
|
94
|
+
ensureNoParseDiagnostics(sourceFile, message);
|
|
95
|
+
return [...sourceFile.statements];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function parseSingleHostStatement(
|
|
99
|
+
hostFileName: string,
|
|
100
|
+
suffix: string,
|
|
101
|
+
code: string,
|
|
102
|
+
message: string,
|
|
103
|
+
): ts.Statement {
|
|
104
|
+
const statements = parseHostStatements(hostFileName, suffix, code, message);
|
|
105
|
+
if (statements.length !== 1) {
|
|
106
|
+
throw new Error(message);
|
|
107
|
+
}
|
|
108
|
+
return statements[0]!;
|
|
109
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function buildMacroPlaceholderIndex(preparedFiles) {
|
|
2
|
+
const entries = preparedFiles.flatMap((preparedFile) => preparedFile.rewriteResult.replacements.flatMap((replacement) => {
|
|
3
|
+
const invocation = preparedFile.rewriteResult.macrosById.get(replacement.id);
|
|
4
|
+
if (!invocation) {
|
|
5
|
+
return [];
|
|
6
|
+
}
|
|
7
|
+
return [{
|
|
8
|
+
fileName: replacement.originalSpan.fileName,
|
|
9
|
+
id: replacement.id,
|
|
10
|
+
invocation,
|
|
11
|
+
preparedFile,
|
|
12
|
+
replacement,
|
|
13
|
+
}];
|
|
14
|
+
}));
|
|
15
|
+
const byFileAndId = new Map();
|
|
16
|
+
for (const entry of entries) {
|
|
17
|
+
byFileAndId.set(`${entry.fileName}:${entry.id}`, entry);
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
entries() {
|
|
21
|
+
return entries;
|
|
22
|
+
},
|
|
23
|
+
get(fileName, id) {
|
|
24
|
+
return byFileAndId.get(`${fileName}:${id}`);
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { MacroReplacement, ParsedMacroInvocation } from './macro_types.ts';
|
|
2
|
+
import type { PreparedSourceFile } from './project_frontend.ts';
|
|
3
|
+
|
|
4
|
+
export interface IndexedMacroPlaceholder {
|
|
5
|
+
fileName: string;
|
|
6
|
+
id: number;
|
|
7
|
+
invocation: ParsedMacroInvocation;
|
|
8
|
+
preparedFile: PreparedSourceFile;
|
|
9
|
+
replacement: MacroReplacement;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface MacroPlaceholderIndex {
|
|
13
|
+
entries(): readonly IndexedMacroPlaceholder[];
|
|
14
|
+
get(fileName: string, id: number): IndexedMacroPlaceholder | undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function buildMacroPlaceholderIndex(
|
|
18
|
+
preparedFiles: readonly PreparedSourceFile[],
|
|
19
|
+
): MacroPlaceholderIndex {
|
|
20
|
+
const entries = preparedFiles.flatMap((preparedFile) =>
|
|
21
|
+
preparedFile.rewriteResult.replacements.flatMap((replacement) => {
|
|
22
|
+
const invocation = preparedFile.rewriteResult.macrosById.get(replacement.id);
|
|
23
|
+
if (!invocation) {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return [{
|
|
28
|
+
fileName: replacement.originalSpan.fileName,
|
|
29
|
+
id: replacement.id,
|
|
30
|
+
invocation,
|
|
31
|
+
preparedFile,
|
|
32
|
+
replacement,
|
|
33
|
+
}];
|
|
34
|
+
})
|
|
35
|
+
);
|
|
36
|
+
const byFileAndId = new Map<string, IndexedMacroPlaceholder>();
|
|
37
|
+
|
|
38
|
+
for (const entry of entries) {
|
|
39
|
+
byFileAndId.set(`${entry.fileName}:${entry.id}`, entry);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
entries(): readonly IndexedMacroPlaceholder[] {
|
|
44
|
+
return entries;
|
|
45
|
+
},
|
|
46
|
+
get(fileName: string, id: number): IndexedMacroPlaceholder | undefined {
|
|
47
|
+
return byFileAndId.get(`${fileName}:${id}`);
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|