@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,1722 @@
|
|
|
1
|
+
import type { RuntimeBackend, RuntimeHost, RuntimeTarget } from '../config.ts';
|
|
2
|
+
import type {
|
|
3
|
+
CanonicalFailureInfo,
|
|
4
|
+
MacroDependencySet,
|
|
5
|
+
CanonicalResultCarrierInfo,
|
|
6
|
+
CanonicalResultInfo,
|
|
7
|
+
MacroFiniteCase,
|
|
8
|
+
MacroFunctionContext,
|
|
9
|
+
MacroTryCarrierInfo,
|
|
10
|
+
MacroType,
|
|
11
|
+
} from './macro_semantic_types.ts';
|
|
12
|
+
import type { SourceSpan } from './macro_types.ts';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Public macro authoring surface.
|
|
16
|
+
*
|
|
17
|
+
* Macro authors should depend on this module, not on frontend implementation modules such as
|
|
18
|
+
* `macro_syntax_internal.ts` or `macro_host_ast_internal.ts`.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export type MacroInvocationForm =
|
|
22
|
+
| 'block'
|
|
23
|
+
| 'arglist'
|
|
24
|
+
| 'decl'
|
|
25
|
+
| 'arglist_decl';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Declaration-position macros may currently target only module-scope declarations of these kinds.
|
|
29
|
+
*/
|
|
30
|
+
export type MacroDeclarationKind = 'class' | 'function' | 'interface' | 'typeAlias';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* `replace` fully replaces the annotated declaration.
|
|
34
|
+
*
|
|
35
|
+
* `augment` preserves the original declaration unchanged and appends generated sibling statements
|
|
36
|
+
* immediately after it.
|
|
37
|
+
*/
|
|
38
|
+
export type MacroDeclarationExpansionMode = 'augment' | 'replace';
|
|
39
|
+
|
|
40
|
+
export type MacroBinaryOperator =
|
|
41
|
+
| '&'
|
|
42
|
+
| '<'
|
|
43
|
+
| '+'
|
|
44
|
+
| '='
|
|
45
|
+
| '!=='
|
|
46
|
+
| '==='
|
|
47
|
+
| '|';
|
|
48
|
+
|
|
49
|
+
export type MacroUnaryOperator = '!';
|
|
50
|
+
|
|
51
|
+
export type MacroModifierName =
|
|
52
|
+
| 'async'
|
|
53
|
+
| 'default'
|
|
54
|
+
| 'export'
|
|
55
|
+
| 'private'
|
|
56
|
+
| 'protected'
|
|
57
|
+
| 'public'
|
|
58
|
+
| 'readonly'
|
|
59
|
+
| 'static';
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Macro expansion results are intentionally opaque at the public API layer.
|
|
63
|
+
*
|
|
64
|
+
* Macro authors can construct these through `ctx.output` / `ctx.controlFlow`, but they should not
|
|
65
|
+
* depend on backend-specific payload details.
|
|
66
|
+
*/
|
|
67
|
+
export interface MacroExprOutput {
|
|
68
|
+
readonly kind: 'expr';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface MacroStmtOutput {
|
|
72
|
+
readonly kind: 'stmt';
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export type MacroStmtListOutput = MacroStmtOutput;
|
|
76
|
+
|
|
77
|
+
export interface MacroValueRewriteOutput {
|
|
78
|
+
readonly kind: 'value_rewrite';
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface MacroScopeExitOutput {
|
|
82
|
+
readonly kind: 'scope_exit';
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export type MacroOutput =
|
|
86
|
+
| MacroExprOutput
|
|
87
|
+
| MacroStmtOutput
|
|
88
|
+
| MacroValueRewriteOutput
|
|
89
|
+
| MacroScopeExitOutput;
|
|
90
|
+
|
|
91
|
+
export interface MacroArgumentView extends ExprSyntax {
|
|
92
|
+
readonly index: number;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface MacroInvocationView {
|
|
96
|
+
/**
|
|
97
|
+
* Normalized invocation shape.
|
|
98
|
+
*
|
|
99
|
+
* Expression operands are always exposed through `args`, regardless of whether they were written
|
|
100
|
+
* as `#foo value`, `#foo(value)`, or `#foo(a) b`.
|
|
101
|
+
*
|
|
102
|
+
* Trailing statement blocks and declaration operands are kept separate from `args`, so an
|
|
103
|
+
* invocation can be modeled as:
|
|
104
|
+
* - `args`
|
|
105
|
+
* - optional trailing `block`
|
|
106
|
+
* - optional trailing `declaration`
|
|
107
|
+
*/
|
|
108
|
+
readonly args: readonly MacroArgumentView[];
|
|
109
|
+
readonly form: MacroInvocationForm;
|
|
110
|
+
readonly hasBlock: boolean;
|
|
111
|
+
readonly name: string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export type MacroAnnotationValue =
|
|
115
|
+
| {
|
|
116
|
+
readonly kind: 'array';
|
|
117
|
+
readonly text: string;
|
|
118
|
+
readonly elements: readonly MacroAnnotationValue[];
|
|
119
|
+
}
|
|
120
|
+
| {
|
|
121
|
+
readonly kind: 'boolean';
|
|
122
|
+
readonly text: string;
|
|
123
|
+
readonly value: boolean;
|
|
124
|
+
}
|
|
125
|
+
| {
|
|
126
|
+
readonly kind: 'identifier';
|
|
127
|
+
readonly text: string;
|
|
128
|
+
readonly name: string;
|
|
129
|
+
}
|
|
130
|
+
| {
|
|
131
|
+
readonly kind: 'number';
|
|
132
|
+
readonly text: string;
|
|
133
|
+
readonly value: number;
|
|
134
|
+
}
|
|
135
|
+
| {
|
|
136
|
+
readonly kind: 'object';
|
|
137
|
+
readonly text: string;
|
|
138
|
+
readonly properties: readonly {
|
|
139
|
+
readonly name: string;
|
|
140
|
+
readonly text: string;
|
|
141
|
+
readonly value: MacroAnnotationValue;
|
|
142
|
+
}[];
|
|
143
|
+
}
|
|
144
|
+
| {
|
|
145
|
+
readonly kind: 'string';
|
|
146
|
+
readonly text: string;
|
|
147
|
+
readonly value: string;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export type MacroAnnotationArgument =
|
|
151
|
+
| {
|
|
152
|
+
readonly kind: 'named';
|
|
153
|
+
readonly name: string;
|
|
154
|
+
readonly text: string;
|
|
155
|
+
readonly value: MacroAnnotationValue;
|
|
156
|
+
}
|
|
157
|
+
| {
|
|
158
|
+
readonly kind: 'positional';
|
|
159
|
+
readonly text: string;
|
|
160
|
+
readonly value: MacroAnnotationValue;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
export interface MacroAnnotation {
|
|
164
|
+
readonly arguments?: readonly MacroAnnotationArgument[];
|
|
165
|
+
readonly argumentsText?: string;
|
|
166
|
+
readonly name: string;
|
|
167
|
+
readonly text: string;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export interface ExprSyntax extends MacroSyntaxNode {
|
|
171
|
+
asArrayLiteral(): MacroArrayLiteralExprSyntax | null;
|
|
172
|
+
asBinary(): MacroBinaryExprPattern | null;
|
|
173
|
+
asCall(): MacroCallExprPattern | null;
|
|
174
|
+
asConditional(): MacroConditionalExprPattern | null;
|
|
175
|
+
asFunction(): MacroFunctionExprSyntax | null;
|
|
176
|
+
asIdentifier(): string | null;
|
|
177
|
+
asInvocation(): InvocationSyntax | null;
|
|
178
|
+
asJsxElement(): MacroJsxElementSyntax | null;
|
|
179
|
+
asJsxFragment(): MacroJsxFragmentSyntax | null;
|
|
180
|
+
asPropertyAccess(): MacroPropertyAccessPattern | null;
|
|
181
|
+
containsCallNamed(name: string): boolean;
|
|
182
|
+
isBooleanLiteral(value: boolean): boolean;
|
|
183
|
+
isNullLiteral(): boolean;
|
|
184
|
+
readonly kind: 'expr';
|
|
185
|
+
replaceThis(replacement: ExprSyntax): ExprSyntax;
|
|
186
|
+
rewrite(options: MacroSyntaxRewriteOptions): ExprSyntax;
|
|
187
|
+
text(): string;
|
|
188
|
+
thisMemberReferences(): readonly string[];
|
|
189
|
+
unparenthesized(): ExprSyntax;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export interface MacroIdentifierExprSyntax extends ExprSyntax {
|
|
193
|
+
asIdentifier(): string;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export interface MacroCallExprSyntax extends ExprSyntax {
|
|
197
|
+
asCall(): MacroCallExprPattern;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export interface MacroArrayLiteralElementSyntax extends MacroSyntaxNode {
|
|
201
|
+
expression(): ExprSyntax | null;
|
|
202
|
+
readonly isSpread: boolean;
|
|
203
|
+
readonly kind: 'array_element' | 'array_elision';
|
|
204
|
+
text(): string;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export interface MacroArrayLiteralExprSyntax extends ExprSyntax {
|
|
208
|
+
asArrayLiteral(): MacroArrayLiteralExprSyntax;
|
|
209
|
+
readonly elements: readonly MacroArrayLiteralElementSyntax[];
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export interface StmtSyntax extends MacroSyntaxNode {
|
|
213
|
+
readonly kind: 'stmt';
|
|
214
|
+
text(): string;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export interface BlockSyntax extends MacroSyntaxNode {
|
|
218
|
+
containsCallNamed(name: string): boolean;
|
|
219
|
+
readonly kind: 'block';
|
|
220
|
+
replaceThis(replacement: ExprSyntax): BlockSyntax;
|
|
221
|
+
rewrite(options: MacroSyntaxRewriteOptions): BlockSyntax;
|
|
222
|
+
readonly statements: readonly StmtSyntax[];
|
|
223
|
+
text(): string;
|
|
224
|
+
thisMemberReferences(): readonly string[];
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export interface MacroSyntaxRewriteOptions {
|
|
228
|
+
readonly replaceCallNamed?: Readonly<Record<string, ExprSyntax>>;
|
|
229
|
+
readonly replaceThisMemberWriteNamed?: Readonly<Record<string, ExprSyntax>>;
|
|
230
|
+
readonly replaceThisWith?: ExprSyntax;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export interface DeclSyntax extends MacroSyntaxNode {
|
|
234
|
+
readonly declarationKind: MacroDeclarationKind;
|
|
235
|
+
readonly kind: 'decl';
|
|
236
|
+
readonly name: string | null;
|
|
237
|
+
asClass(): MacroClassDeclSyntax | null;
|
|
238
|
+
asFunction(): MacroFunctionDeclSyntax | null;
|
|
239
|
+
asInterface(): MacroInterfaceDeclSyntax | null;
|
|
240
|
+
asTypeAlias(): MacroTypeAliasDeclSyntax | null;
|
|
241
|
+
text(): string;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export interface JsxSyntax extends MacroSyntaxNode {
|
|
245
|
+
text(): string;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export interface MacroParameterSyntax extends MacroSyntaxNode {
|
|
249
|
+
bindingIdentifiers(): readonly MacroBindingIdentifierSyntax[];
|
|
250
|
+
explicitType(): TypeSyntax | null;
|
|
251
|
+
hasDefault(): boolean;
|
|
252
|
+
hasExplicitType(): boolean;
|
|
253
|
+
isRest(): boolean;
|
|
254
|
+
readonly kind: 'parameter';
|
|
255
|
+
readonly name: string | null;
|
|
256
|
+
text(): string;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export interface TypeSyntax extends MacroSyntaxNode {
|
|
260
|
+
asLiteral(): MacroLiteralTypeSyntax | null;
|
|
261
|
+
asObjectLiteral(): MacroObjectTypeSyntax | null;
|
|
262
|
+
asUnion(): MacroUnionTypeSyntax | null;
|
|
263
|
+
readonly kind: 'type';
|
|
264
|
+
text(): string;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export interface MacroLiteralTypeSyntax extends TypeSyntax {
|
|
268
|
+
asLiteral(): MacroLiteralTypeSyntax;
|
|
269
|
+
readonly literalKind: 'boolean' | 'number' | 'string';
|
|
270
|
+
readonly value: boolean | number | string;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export interface MacroTypeParameterSyntax extends MacroSyntaxNode {
|
|
274
|
+
constraint(): TypeSyntax | null;
|
|
275
|
+
defaultType(): TypeSyntax | null;
|
|
276
|
+
readonly kind: 'type_parameter';
|
|
277
|
+
readonly name: string;
|
|
278
|
+
text(): string;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export interface MacroObjectTypeMemberSyntax extends MacroSyntaxNode {
|
|
282
|
+
explicitType(): TypeSyntax | null;
|
|
283
|
+
hasExplicitType(): boolean;
|
|
284
|
+
isOptional(): boolean;
|
|
285
|
+
readonly kind: 'type_member';
|
|
286
|
+
readonly memberKind:
|
|
287
|
+
| 'call_signature'
|
|
288
|
+
| 'construct_signature'
|
|
289
|
+
| 'index_signature'
|
|
290
|
+
| 'method_signature'
|
|
291
|
+
| 'property_signature';
|
|
292
|
+
readonly name: string | null;
|
|
293
|
+
text(): string;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export interface MacroObjectTypeSyntax extends TypeSyntax {
|
|
297
|
+
asObjectLiteral(): MacroObjectTypeSyntax;
|
|
298
|
+
readonly members: readonly MacroObjectTypeMemberSyntax[];
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export interface MacroUnionTypeSyntax extends TypeSyntax {
|
|
302
|
+
asUnion(): MacroUnionTypeSyntax;
|
|
303
|
+
readonly members: readonly TypeSyntax[];
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export interface MacroBindingIdentifierSyntax extends MacroSyntaxNode {
|
|
307
|
+
readonly kind: 'binding_identifier';
|
|
308
|
+
readonly name: string;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export interface MacroClassMemberSyntax extends MacroSyntaxNode {
|
|
312
|
+
readonly kind: 'class_member';
|
|
313
|
+
readonly memberKind: 'constructor' | 'field' | 'getter' | 'method' | 'setter';
|
|
314
|
+
readonly name: string | null;
|
|
315
|
+
hasModifier(name: MacroModifierName): boolean;
|
|
316
|
+
text(): string;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export interface MacroClassFieldSyntax extends MacroClassMemberSyntax {
|
|
320
|
+
explicitType(): TypeSyntax | null;
|
|
321
|
+
hasExplicitType(): boolean;
|
|
322
|
+
isOptional(): boolean;
|
|
323
|
+
readonly memberKind: 'field';
|
|
324
|
+
initializer(): ExprSyntax | null;
|
|
325
|
+
withInitializer(initializer: ExprSyntax | null): MacroClassFieldSyntax;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export interface MacroClassMethodSyntax extends MacroClassMemberSyntax {
|
|
329
|
+
readonly memberKind: 'getter' | 'method' | 'setter';
|
|
330
|
+
readonly parameters: readonly MacroParameterSyntax[];
|
|
331
|
+
body(): BlockSyntax | null;
|
|
332
|
+
returnedExpr(): ExprSyntax | null;
|
|
333
|
+
returnedJsx(): MacroJsxElementSyntax | null;
|
|
334
|
+
withBody(body: BlockSyntax): MacroClassMethodSyntax;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export interface MacroClassConstructorSyntax extends MacroClassMemberSyntax {
|
|
338
|
+
readonly memberKind: 'constructor';
|
|
339
|
+
readonly parameters: readonly MacroParameterSyntax[];
|
|
340
|
+
body(): BlockSyntax | null;
|
|
341
|
+
withBody(body: BlockSyntax): MacroClassConstructorSyntax;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export type MacroAnyClassMemberSyntax =
|
|
345
|
+
| MacroClassConstructorSyntax
|
|
346
|
+
| MacroClassFieldSyntax
|
|
347
|
+
| MacroClassMethodSyntax;
|
|
348
|
+
|
|
349
|
+
export interface MacroClassDeclSyntax extends DeclSyntax {
|
|
350
|
+
readonly declarationKind: 'class';
|
|
351
|
+
hasModifier(name: MacroModifierName): boolean;
|
|
352
|
+
member(name: string): MacroAnyClassMemberSyntax | null;
|
|
353
|
+
members(): readonly MacroAnyClassMemberSyntax[];
|
|
354
|
+
resolveThisDependencies(
|
|
355
|
+
node: ExprSyntax | BlockSyntax,
|
|
356
|
+
rootMemberNames: readonly string[],
|
|
357
|
+
): readonly string[];
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export interface MacroFunctionDeclSyntax extends DeclSyntax {
|
|
361
|
+
readonly declarationKind: 'function';
|
|
362
|
+
hasModifier(name: MacroModifierName): boolean;
|
|
363
|
+
readonly parameters: readonly MacroParameterSyntax[];
|
|
364
|
+
body(): BlockSyntax | null;
|
|
365
|
+
returnedExpr(): ExprSyntax | null;
|
|
366
|
+
returnedJsx(): MacroJsxElementSyntax | null;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export interface MacroInterfaceDeclSyntax extends DeclSyntax {
|
|
370
|
+
readonly declarationKind: 'interface';
|
|
371
|
+
readonly extendsTypes: readonly TypeSyntax[];
|
|
372
|
+
hasModifier(name: MacroModifierName): boolean;
|
|
373
|
+
readonly members: readonly MacroObjectTypeMemberSyntax[];
|
|
374
|
+
readonly typeParameters: readonly MacroTypeParameterSyntax[];
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
export interface MacroTypeAliasDeclSyntax extends DeclSyntax {
|
|
378
|
+
readonly declarationKind: 'typeAlias';
|
|
379
|
+
hasModifier(name: MacroModifierName): boolean;
|
|
380
|
+
readonly type: TypeSyntax;
|
|
381
|
+
readonly typeParameters: readonly MacroTypeParameterSyntax[];
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
export interface MacroPropertyAccessPattern {
|
|
385
|
+
readonly name: string;
|
|
386
|
+
readonly object: ExprSyntax;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
export interface MacroCallExprPattern {
|
|
390
|
+
readonly args: readonly ExprSyntax[];
|
|
391
|
+
readonly callee: ExprSyntax;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
export interface MacroBinaryExprPattern {
|
|
395
|
+
readonly left: ExprSyntax;
|
|
396
|
+
readonly operator: string;
|
|
397
|
+
readonly right: ExprSyntax;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
export interface MacroConditionalExprPattern {
|
|
401
|
+
readonly condition: ExprSyntax;
|
|
402
|
+
readonly whenFalse: ExprSyntax;
|
|
403
|
+
readonly whenTrue: ExprSyntax;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export interface MacroFunctionExprSyntax extends ExprSyntax {
|
|
407
|
+
readonly functionKind: 'arrow' | 'function';
|
|
408
|
+
hasAsyncModifier(): boolean;
|
|
409
|
+
readonly parameters: readonly MacroParameterSyntax[];
|
|
410
|
+
body(): BlockSyntax | null;
|
|
411
|
+
returnedExpr(): ExprSyntax | null;
|
|
412
|
+
returnedJsx(): MacroJsxElementSyntax | null;
|
|
413
|
+
typeParameterCount(): number;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
export interface MacroJsxAttributeSyntax extends MacroSyntaxNode {
|
|
417
|
+
readonly kind: 'jsx_attribute';
|
|
418
|
+
readonly name: string;
|
|
419
|
+
expression(): ExprSyntax | null;
|
|
420
|
+
stringValue(): string | null;
|
|
421
|
+
text(): string;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
export interface MacroJsxSpreadAttributeSyntax extends MacroSyntaxNode {
|
|
425
|
+
readonly kind: 'jsx_spread_attribute';
|
|
426
|
+
expression(): ExprSyntax;
|
|
427
|
+
text(): string;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
export type MacroAnyJsxAttributeSyntax =
|
|
431
|
+
| MacroJsxAttributeSyntax
|
|
432
|
+
| MacroJsxSpreadAttributeSyntax;
|
|
433
|
+
|
|
434
|
+
export interface MacroJsxTextSyntax extends JsxSyntax {
|
|
435
|
+
readonly kind: 'jsx_text';
|
|
436
|
+
readonly value: string;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
export interface MacroJsxExpressionSyntax extends JsxSyntax {
|
|
440
|
+
readonly kind: 'jsx_expr';
|
|
441
|
+
expression(): ExprSyntax | null;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
export interface MacroJsxElementSyntax extends JsxSyntax {
|
|
445
|
+
readonly kind: 'jsx_element';
|
|
446
|
+
readonly selfClosing: boolean;
|
|
447
|
+
readonly tagName: string | null;
|
|
448
|
+
attribute(name: string): MacroAnyJsxAttributeSyntax | null;
|
|
449
|
+
attributes(): readonly MacroAnyJsxAttributeSyntax[];
|
|
450
|
+
children(): readonly MacroAnyJsxChildSyntax[];
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
export interface MacroJsxFragmentSyntax extends JsxSyntax {
|
|
454
|
+
readonly kind: 'jsx_fragment';
|
|
455
|
+
children(): readonly MacroAnyJsxChildSyntax[];
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
export type MacroAnyJsxChildSyntax =
|
|
459
|
+
| MacroJsxElementSyntax
|
|
460
|
+
| MacroJsxFragmentSyntax
|
|
461
|
+
| MacroJsxExpressionSyntax
|
|
462
|
+
| MacroJsxTextSyntax;
|
|
463
|
+
|
|
464
|
+
export interface InvocationSyntax extends MacroSyntaxNode {
|
|
465
|
+
readonly args: readonly MacroArgumentView[];
|
|
466
|
+
readonly block: BlockSyntax | null;
|
|
467
|
+
readonly declaration: DeclSyntax | null;
|
|
468
|
+
readonly form: MacroInvocationForm;
|
|
469
|
+
readonly hasBlock: boolean;
|
|
470
|
+
readonly kind: 'invocation';
|
|
471
|
+
readonly name: string;
|
|
472
|
+
text(): string;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
export interface MacroAnalysisRegion {
|
|
476
|
+
readonly prefixText: string;
|
|
477
|
+
readonly sourceSpan: SourceSpan;
|
|
478
|
+
readonly suffixText: string;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
export interface MacroTemplateQuasi {
|
|
482
|
+
readonly span: SourceSpan;
|
|
483
|
+
readonly text: string;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
export type MacroTemplateExpression = ExprSyntax;
|
|
487
|
+
|
|
488
|
+
export interface MacroTemplateOperand extends MacroSyntaxNode {
|
|
489
|
+
readonly expressions: readonly MacroTemplateExpression[];
|
|
490
|
+
readonly kind: 'template';
|
|
491
|
+
readonly quasis: readonly MacroTemplateQuasi[];
|
|
492
|
+
readonly span: SourceSpan;
|
|
493
|
+
text(): string;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
export type MacroSignatureOperandKind = 'expr' | 'template' | 'block' | 'decl';
|
|
497
|
+
|
|
498
|
+
export type MacroSignatureOperandRefinementKind =
|
|
499
|
+
| 'array_literal'
|
|
500
|
+
| 'call'
|
|
501
|
+
| 'class_decl'
|
|
502
|
+
| 'function'
|
|
503
|
+
| 'function_decl'
|
|
504
|
+
| 'interface_decl'
|
|
505
|
+
| 'type_alias_decl'
|
|
506
|
+
| 'identifier';
|
|
507
|
+
|
|
508
|
+
export interface MacroSignatureOperandRefinement {
|
|
509
|
+
readonly displayText: string;
|
|
510
|
+
readonly kind: MacroSignatureOperandRefinementKind;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
export type MacroSignatureRefinedValue<Kind extends MacroSignatureOperandRefinementKind> =
|
|
514
|
+
Kind extends 'array_literal' ? MacroArrayLiteralExprSyntax
|
|
515
|
+
: Kind extends 'call' ? MacroCallExprSyntax
|
|
516
|
+
: Kind extends 'class_decl' ? MacroClassDeclSyntax
|
|
517
|
+
: Kind extends 'function' ? MacroFunctionExprSyntax
|
|
518
|
+
: Kind extends 'function_decl' ? MacroFunctionDeclSyntax
|
|
519
|
+
: Kind extends 'interface_decl' ? MacroInterfaceDeclSyntax
|
|
520
|
+
: Kind extends 'type_alias_decl' ? MacroTypeAliasDeclSyntax
|
|
521
|
+
: MacroIdentifierExprSyntax;
|
|
522
|
+
|
|
523
|
+
export type MacroSignatureOperandBaseValue<Kind extends MacroSignatureOperandKind> = Kind extends
|
|
524
|
+
'expr' ? ExprSyntax
|
|
525
|
+
: Kind extends 'template' ? MacroTemplateOperand
|
|
526
|
+
: Kind extends 'block' ? BlockSyntax
|
|
527
|
+
: DeclSyntax;
|
|
528
|
+
|
|
529
|
+
export interface MacroSignatureOperand<
|
|
530
|
+
Kind extends MacroSignatureOperandKind = MacroSignatureOperandKind,
|
|
531
|
+
Name extends string = string,
|
|
532
|
+
Optional extends boolean = boolean,
|
|
533
|
+
Value extends MacroDecodedSignatureValue = MacroSignatureOperandBaseValue<Kind>,
|
|
534
|
+
> {
|
|
535
|
+
readonly description?: string;
|
|
536
|
+
readonly kind: Kind;
|
|
537
|
+
readonly name: Name;
|
|
538
|
+
readonly optional: Optional;
|
|
539
|
+
readonly refinement?: MacroSignatureOperandRefinement;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
export interface MacroSignatureCase<
|
|
543
|
+
CaseName extends string | null = string | null,
|
|
544
|
+
Operands extends readonly MacroSignatureOperand[] = readonly MacroSignatureOperand[],
|
|
545
|
+
> {
|
|
546
|
+
readonly caseName: CaseName;
|
|
547
|
+
readonly operands: Operands;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
export interface MacroSignature<
|
|
551
|
+
Cases extends readonly MacroSignatureCase[] = readonly MacroSignatureCase[],
|
|
552
|
+
> {
|
|
553
|
+
readonly cases: Cases;
|
|
554
|
+
readonly validators?: readonly MacroSignatureValidator[];
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
export type MacroDecodedSignatureValue =
|
|
558
|
+
| BlockSyntax
|
|
559
|
+
| DeclSyntax
|
|
560
|
+
| ExprSyntax
|
|
561
|
+
| MacroTemplateOperand
|
|
562
|
+
| null;
|
|
563
|
+
|
|
564
|
+
type MacroSignatureOperandDecodedValue<Operand extends MacroSignatureOperand> = Operand extends
|
|
565
|
+
MacroSignatureOperand<any, any, infer Optional, infer Value>
|
|
566
|
+
? Optional extends true ? Value | null : Value
|
|
567
|
+
: never;
|
|
568
|
+
|
|
569
|
+
type MacroSignatureArgsFromOperands<Operands extends readonly MacroSignatureOperand[]> = Readonly<
|
|
570
|
+
{
|
|
571
|
+
[Operand in Operands[number] as Operand['name']]: MacroSignatureOperandDecodedValue<Operand>;
|
|
572
|
+
}
|
|
573
|
+
>;
|
|
574
|
+
|
|
575
|
+
export interface MacroDecodedSignatureCase<
|
|
576
|
+
Case extends MacroSignatureCase = MacroSignatureCase,
|
|
577
|
+
> {
|
|
578
|
+
readonly args: MacroSignatureArgsFromOperands<Case['operands']>;
|
|
579
|
+
readonly caseName: Case['caseName'];
|
|
580
|
+
readonly signatureCase: Case;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
export type MacroDecodedSignature<Signature extends MacroSignature> = MacroDecodedSignatureCase<
|
|
584
|
+
Signature['cases'][number]
|
|
585
|
+
>;
|
|
586
|
+
|
|
587
|
+
export type MacroSignatureValidator<
|
|
588
|
+
Signature extends MacroSignature = MacroSignature,
|
|
589
|
+
> = (ctx: MacroContext, signature: MacroDecodedSignature<Signature>) => void;
|
|
590
|
+
|
|
591
|
+
export interface MacroSyntaxAccess {
|
|
592
|
+
annotations(node: MacroSyntaxNode): readonly MacroAnnotation[];
|
|
593
|
+
arg(index: number): ExprSyntax;
|
|
594
|
+
args(): readonly MacroArgumentView[];
|
|
595
|
+
block(): BlockSyntax;
|
|
596
|
+
declaration(): DeclSyntax;
|
|
597
|
+
primaryExpr(): ExprSyntax;
|
|
598
|
+
root(): InvocationSyntax;
|
|
599
|
+
template(index: number): MacroTemplateOperand | null;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
export interface MacroQuoteFactory {
|
|
603
|
+
readonly block: (
|
|
604
|
+
strings: TemplateStringsArray,
|
|
605
|
+
...values: readonly MacroQuoteValue[]
|
|
606
|
+
) => BlockSyntax;
|
|
607
|
+
readonly classMembers: (
|
|
608
|
+
strings: TemplateStringsArray,
|
|
609
|
+
...values: readonly MacroQuoteValue[]
|
|
610
|
+
) => readonly MacroAnyClassMemberSyntax[];
|
|
611
|
+
readonly decl: (
|
|
612
|
+
strings: TemplateStringsArray,
|
|
613
|
+
...values: readonly MacroQuoteValue[]
|
|
614
|
+
) => DeclSyntax;
|
|
615
|
+
readonly expr: (
|
|
616
|
+
strings: TemplateStringsArray,
|
|
617
|
+
...values: readonly MacroQuoteValue[]
|
|
618
|
+
) => ExprSyntax;
|
|
619
|
+
readonly stmt: (
|
|
620
|
+
strings: TemplateStringsArray,
|
|
621
|
+
...values: readonly MacroQuoteValue[]
|
|
622
|
+
) => StmtSyntax;
|
|
623
|
+
readonly stmts: (
|
|
624
|
+
strings: TemplateStringsArray,
|
|
625
|
+
...values: readonly MacroQuoteValue[]
|
|
626
|
+
) => readonly StmtSyntax[];
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
export interface MacroFieldBuildOptions {
|
|
630
|
+
readonly initializer?: ExprSyntax | null;
|
|
631
|
+
readonly modifiers?: readonly MacroModifierName[];
|
|
632
|
+
readonly name: string;
|
|
633
|
+
readonly type?: string;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
export interface MacroParameterBuildOptions {
|
|
637
|
+
readonly name: string;
|
|
638
|
+
readonly type?: string;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
export interface MacroMethodBuildOptions {
|
|
642
|
+
readonly body: BlockSyntax;
|
|
643
|
+
readonly modifiers?: readonly MacroModifierName[];
|
|
644
|
+
readonly name: string;
|
|
645
|
+
readonly parameters?: readonly (string | MacroParameterBuildOptions)[];
|
|
646
|
+
readonly returnType?: string;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
export interface MacroSetterBuildOptions {
|
|
650
|
+
readonly body: BlockSyntax;
|
|
651
|
+
readonly modifiers?: readonly MacroModifierName[];
|
|
652
|
+
readonly name: string;
|
|
653
|
+
readonly parameter: string | MacroParameterBuildOptions;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
export interface MacroFunctionBuildOptions {
|
|
657
|
+
readonly body: BlockSyntax;
|
|
658
|
+
readonly modifiers?: readonly MacroModifierName[];
|
|
659
|
+
readonly name: string;
|
|
660
|
+
readonly parameters?: readonly (string | MacroParameterBuildOptions)[];
|
|
661
|
+
readonly returnType?: string;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
export interface MacroIfBuildOptions {
|
|
665
|
+
readonly condition: ExprSyntax;
|
|
666
|
+
readonly elseStatements?: readonly StmtSyntax[];
|
|
667
|
+
readonly thenStatements: readonly StmtSyntax[];
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
export interface MacroForInitializerBuildOptions {
|
|
671
|
+
readonly kind: 'const' | 'let';
|
|
672
|
+
readonly name: string;
|
|
673
|
+
readonly value: ExprSyntax;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
export interface MacroForBuildOptions {
|
|
677
|
+
readonly condition?: ExprSyntax;
|
|
678
|
+
readonly increment?: ExprSyntax;
|
|
679
|
+
readonly initializer?: ExprSyntax | MacroForInitializerBuildOptions;
|
|
680
|
+
readonly statements: readonly StmtSyntax[];
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
export interface MacroObjectPropertyBuildOptions {
|
|
684
|
+
readonly kind: 'property';
|
|
685
|
+
readonly name: string;
|
|
686
|
+
readonly value: ExprSyntax;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
export interface MacroObjectMethodBuildOptions {
|
|
690
|
+
readonly body: BlockSyntax;
|
|
691
|
+
readonly kind: 'method';
|
|
692
|
+
readonly name: string;
|
|
693
|
+
readonly parameters?: readonly (string | MacroParameterBuildOptions)[];
|
|
694
|
+
readonly returnType?: string;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
export type MacroObjectMemberBuildOptions =
|
|
698
|
+
| MacroObjectMethodBuildOptions
|
|
699
|
+
| MacroObjectPropertyBuildOptions;
|
|
700
|
+
|
|
701
|
+
export interface MacroBuildFactory {
|
|
702
|
+
assign(target: ExprSyntax, value: ExprSyntax): ExprSyntax;
|
|
703
|
+
arrowFunction(
|
|
704
|
+
parameters: readonly (string | MacroParameterBuildOptions)[],
|
|
705
|
+
body: BlockSyntax | ExprSyntax,
|
|
706
|
+
): ExprSyntax;
|
|
707
|
+
binary(left: ExprSyntax, operator: MacroBinaryOperator, right: ExprSyntax): ExprSyntax;
|
|
708
|
+
block(statements: readonly StmtSyntax[]): BlockSyntax;
|
|
709
|
+
booleanLiteral(value: boolean): ExprSyntax;
|
|
710
|
+
call(callee: ExprSyntax, args: readonly ExprSyntax[]): ExprSyntax;
|
|
711
|
+
constDecl(name: string, initializer: ExprSyntax): StmtSyntax;
|
|
712
|
+
element(object: ExprSyntax, index: ExprSyntax): ExprSyntax;
|
|
713
|
+
exprStmt(expression: ExprSyntax): StmtSyntax;
|
|
714
|
+
field(options: MacroFieldBuildOptions): MacroClassFieldSyntax;
|
|
715
|
+
forStmt(options: MacroForBuildOptions): StmtSyntax;
|
|
716
|
+
identifier(name: string): ExprSyntax;
|
|
717
|
+
ifStmt(options: MacroIfBuildOptions): StmtSyntax;
|
|
718
|
+
functionDecl(options: MacroFunctionBuildOptions): MacroFunctionDeclSyntax;
|
|
719
|
+
getter(options: Omit<MacroMethodBuildOptions, 'parameters'>): MacroClassMethodSyntax;
|
|
720
|
+
letDecl(name: string, initializer: ExprSyntax): StmtSyntax;
|
|
721
|
+
method(options: MacroMethodBuildOptions): MacroClassMethodSyntax;
|
|
722
|
+
newExpr(callee: ExprSyntax, args: readonly ExprSyntax[]): ExprSyntax;
|
|
723
|
+
nullLiteral(): ExprSyntax;
|
|
724
|
+
numberLiteral(value: number): ExprSyntax;
|
|
725
|
+
objectLiteral(members: readonly MacroObjectMemberBuildOptions[]): ExprSyntax;
|
|
726
|
+
optionalMethodCall(receiver: ExprSyntax, name: string, args: readonly ExprSyntax[]): ExprSyntax;
|
|
727
|
+
property(object: ExprSyntax, name: string): ExprSyntax;
|
|
728
|
+
returnStmt(expression?: ExprSyntax): StmtSyntax;
|
|
729
|
+
setter(options: MacroSetterBuildOptions): MacroClassMethodSyntax;
|
|
730
|
+
stringLiteral(value: string): ExprSyntax;
|
|
731
|
+
thisExpr(): ExprSyntax;
|
|
732
|
+
throwStmt(expression: ExprSyntax): StmtSyntax;
|
|
733
|
+
unary(operator: MacroUnaryOperator, value: ExprSyntax): ExprSyntax;
|
|
734
|
+
updateClass(
|
|
735
|
+
base: MacroClassDeclSyntax,
|
|
736
|
+
members: readonly MacroAnyClassMemberSyntax[],
|
|
737
|
+
): MacroClassDeclSyntax;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
export interface MacroOutputFactory {
|
|
741
|
+
expr(node: ExprSyntax): MacroExprOutput;
|
|
742
|
+
stmt(node: StmtSyntax | DeclSyntax): MacroStmtOutput;
|
|
743
|
+
stmts(nodes: readonly (StmtSyntax | DeclSyntax)[]): MacroStmtListOutput;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
export interface MacroRuntimeAccess {
|
|
747
|
+
readonly backend: RuntimeBackend;
|
|
748
|
+
readonly host: RuntimeHost;
|
|
749
|
+
readonly target: RuntimeTarget;
|
|
750
|
+
default(specifier: string): ExprSyntax;
|
|
751
|
+
externs(): readonly string[];
|
|
752
|
+
named(specifier: string, exportName: string): ExprSyntax;
|
|
753
|
+
namespace(specifier: string): ExprSyntax;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
export interface MacroHostPathOptions {
|
|
757
|
+
readonly base?: 'macro' | 'project';
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
export interface MacroHostEnvAccess {
|
|
761
|
+
get(name: string): string | undefined;
|
|
762
|
+
require(name: string): string;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
export interface MacroHostFsAccess {
|
|
766
|
+
exists(path: string, options?: MacroHostPathOptions): boolean;
|
|
767
|
+
readBytes(path: string, options?: MacroHostPathOptions): Uint8Array;
|
|
768
|
+
readText(path: string, options?: MacroHostPathOptions): string;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
export interface MacroHostAccess {
|
|
772
|
+
readonly env: MacroHostEnvAccess;
|
|
773
|
+
readonly fs: MacroHostFsAccess;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
export type MacroReflectedFieldOriginKind =
|
|
777
|
+
| 'classField'
|
|
778
|
+
| 'interfaceProperty'
|
|
779
|
+
| 'typeLiteralProperty';
|
|
780
|
+
|
|
781
|
+
export type MacroReflectedPrimitiveKind = 'bigint' | 'boolean' | 'number' | 'string';
|
|
782
|
+
|
|
783
|
+
export type MacroReflectedTypeShape =
|
|
784
|
+
| {
|
|
785
|
+
readonly element: MacroReflectedTypeShape;
|
|
786
|
+
readonly kind: 'array';
|
|
787
|
+
readonly readonly: boolean;
|
|
788
|
+
readonly text: string;
|
|
789
|
+
}
|
|
790
|
+
| {
|
|
791
|
+
readonly fields: readonly MacroReflectedFieldShape[];
|
|
792
|
+
readonly kind: 'object';
|
|
793
|
+
readonly text: string;
|
|
794
|
+
}
|
|
795
|
+
| {
|
|
796
|
+
readonly err: MacroReflectedTypeShape;
|
|
797
|
+
readonly kind: 'result';
|
|
798
|
+
readonly ok: MacroReflectedTypeShape;
|
|
799
|
+
readonly text: string;
|
|
800
|
+
}
|
|
801
|
+
| {
|
|
802
|
+
readonly kind: 'option';
|
|
803
|
+
readonly text: string;
|
|
804
|
+
readonly value: MacroReflectedTypeShape;
|
|
805
|
+
}
|
|
806
|
+
| {
|
|
807
|
+
readonly kind: 'primitive';
|
|
808
|
+
readonly primitiveKind: MacroReflectedPrimitiveKind;
|
|
809
|
+
readonly text: string;
|
|
810
|
+
}
|
|
811
|
+
| {
|
|
812
|
+
readonly kind: 'literal';
|
|
813
|
+
readonly literalKind: 'boolean' | 'number' | 'string';
|
|
814
|
+
readonly text: string;
|
|
815
|
+
readonly value: boolean | number | string;
|
|
816
|
+
}
|
|
817
|
+
| {
|
|
818
|
+
readonly kind: 'named';
|
|
819
|
+
readonly name: string;
|
|
820
|
+
readonly text: string;
|
|
821
|
+
readonly typeArguments: readonly MacroReflectedTypeShape[];
|
|
822
|
+
}
|
|
823
|
+
| {
|
|
824
|
+
readonly elements: readonly MacroReflectedTypeShape[];
|
|
825
|
+
readonly kind: 'tuple';
|
|
826
|
+
readonly readonly: boolean;
|
|
827
|
+
readonly text: string;
|
|
828
|
+
}
|
|
829
|
+
| {
|
|
830
|
+
readonly kind: 'union';
|
|
831
|
+
readonly members: readonly MacroReflectedTypeShape[];
|
|
832
|
+
readonly text: string;
|
|
833
|
+
}
|
|
834
|
+
| {
|
|
835
|
+
readonly kind: 'unsupported';
|
|
836
|
+
readonly text: string;
|
|
837
|
+
};
|
|
838
|
+
|
|
839
|
+
export interface MacroReflectedFieldShape {
|
|
840
|
+
readonly annotations: readonly MacroAnnotation[];
|
|
841
|
+
readonly name: string;
|
|
842
|
+
readonly node: MacroSyntaxNode;
|
|
843
|
+
readonly optional: boolean;
|
|
844
|
+
readonly originKind: MacroReflectedFieldOriginKind;
|
|
845
|
+
readonly text: string;
|
|
846
|
+
readonly type: MacroReflectedTypeShape | null;
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
export interface MacroReflectedDiscriminant {
|
|
850
|
+
readonly name: string;
|
|
851
|
+
readonly tag: string;
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
export interface MacroReflectedDiscriminatedUnionVariant {
|
|
855
|
+
readonly discriminants: readonly MacroReflectedDiscriminant[];
|
|
856
|
+
readonly fields: readonly MacroReflectedFieldShape[];
|
|
857
|
+
readonly node: MacroSyntaxNode;
|
|
858
|
+
readonly text: string;
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
export type MacroReflectedDeclarationShape =
|
|
862
|
+
| {
|
|
863
|
+
readonly declarationKind: 'class' | 'interface' | 'typeAlias';
|
|
864
|
+
readonly fields: readonly MacroReflectedFieldShape[];
|
|
865
|
+
readonly kind: 'objectLike';
|
|
866
|
+
readonly name: string | null;
|
|
867
|
+
readonly node: DeclSyntax;
|
|
868
|
+
readonly text: string;
|
|
869
|
+
}
|
|
870
|
+
| {
|
|
871
|
+
readonly commonDiscriminantNames: readonly string[];
|
|
872
|
+
readonly kind: 'discriminatedUnion';
|
|
873
|
+
readonly name: string | null;
|
|
874
|
+
readonly node: MacroTypeAliasDeclSyntax;
|
|
875
|
+
readonly text: string;
|
|
876
|
+
readonly variants: readonly MacroReflectedDiscriminatedUnionVariant[];
|
|
877
|
+
}
|
|
878
|
+
| {
|
|
879
|
+
readonly kind: 'unsupported';
|
|
880
|
+
readonly node: DeclSyntax;
|
|
881
|
+
readonly reason: 'notDiscriminatedUnion' | 'notObjectLike' | 'unsupportedDeclarationKind';
|
|
882
|
+
readonly text: string;
|
|
883
|
+
};
|
|
884
|
+
|
|
885
|
+
export interface MacroReflectionAccess {
|
|
886
|
+
declarationShape(declaration: DeclSyntax): MacroReflectedDeclarationShape;
|
|
887
|
+
typeShape(type: TypeSyntax): MacroReflectedTypeShape;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
export interface MacroContext {
|
|
891
|
+
readonly build: MacroBuildFactory;
|
|
892
|
+
readonly controlFlow: MacroControlFlow;
|
|
893
|
+
readonly fresh: MacroFresh;
|
|
894
|
+
readonly host: MacroHostAccess;
|
|
895
|
+
readonly invocation: MacroInvocationView;
|
|
896
|
+
readonly kind: 'expr' | 'stmt';
|
|
897
|
+
readonly name: string;
|
|
898
|
+
readonly output: MacroOutputFactory;
|
|
899
|
+
readonly quote: MacroQuoteFactory;
|
|
900
|
+
readonly reflect: MacroReflectionAccess;
|
|
901
|
+
readonly runtime: MacroRuntimeAccess;
|
|
902
|
+
readonly semantics: MacroSemanticsView;
|
|
903
|
+
readonly syntax: MacroSyntaxAccess;
|
|
904
|
+
blockSpan(): SourceSpan | null;
|
|
905
|
+
declarationSpan(): SourceSpan | null;
|
|
906
|
+
error(message: string, node?: MacroSyntaxNode): never;
|
|
907
|
+
hasBlock(): boolean;
|
|
908
|
+
invocationSpan(): SourceSpan;
|
|
909
|
+
location(): { readonly column: number; readonly filePath: string; readonly line: number };
|
|
910
|
+
parsedSyntax(): MacroSyntaxNode | null;
|
|
911
|
+
sourceText(): string;
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
export interface MacroSemanticsView {
|
|
915
|
+
argExpanded(index: number): ExprSyntax | null;
|
|
916
|
+
argType(index: number): MacroType | null;
|
|
917
|
+
awaitedType(type: MacroType): MacroType;
|
|
918
|
+
classDeclarationOfType(type: TypeSyntax): MacroClassDeclSyntax | null;
|
|
919
|
+
classifyCanonicalFailureType(type: MacroType): CanonicalFailureInfo | null;
|
|
920
|
+
classifyCanonicalResultCarrierType(type: MacroType): CanonicalResultCarrierInfo | null;
|
|
921
|
+
classifyCanonicalResultType(type: MacroType): CanonicalResultInfo | null;
|
|
922
|
+
classifyTryCarrierType(type: MacroType): MacroTryCarrierInfo | null;
|
|
923
|
+
exprType(expr: ExprSyntax): MacroType | null;
|
|
924
|
+
enclosingFunction(): MacroFunctionContext | null;
|
|
925
|
+
enclosingFunctionCanonicalResult(): CanonicalResultInfo | null;
|
|
926
|
+
finiteCases(type: MacroType): readonly MacroFiniteCase[] | null;
|
|
927
|
+
isAssignable(from: MacroType, to: MacroType): boolean;
|
|
928
|
+
localDeclarationHasAnnotation(
|
|
929
|
+
name: string,
|
|
930
|
+
annotationName: string,
|
|
931
|
+
node?: MacroSyntaxNode,
|
|
932
|
+
): boolean;
|
|
933
|
+
nullType(): MacroType;
|
|
934
|
+
parameterType(parameter: MacroParameterSyntax): MacroType | null;
|
|
935
|
+
primaryExprEnclosingFunction(): MacroFunctionContext | null;
|
|
936
|
+
primaryExprEnclosingFunctionCanonicalResult(): CanonicalResultInfo | null;
|
|
937
|
+
primaryExprExpanded(): ExprSyntax | null;
|
|
938
|
+
primaryExprPrelude(): readonly StmtSyntax[] | null;
|
|
939
|
+
primaryExprCanonicalResultCarrier(): CanonicalResultCarrierInfo | null;
|
|
940
|
+
primaryExprCanonicalResult(): CanonicalResultInfo | null;
|
|
941
|
+
primaryExprContainsMacroInvocations(): boolean;
|
|
942
|
+
primaryExprTryCarrier(): MacroTryCarrierInfo | null;
|
|
943
|
+
primaryExprType(): MacroType | null;
|
|
944
|
+
readSet(node: ExprSyntax | BlockSyntax): MacroDependencySet;
|
|
945
|
+
undefinedType(): MacroType;
|
|
946
|
+
valueBindingCallableInScope(name: string, node?: MacroSyntaxNode): boolean;
|
|
947
|
+
valueBindingInScope(name: string, node?: MacroSyntaxNode): boolean;
|
|
948
|
+
writeSet(node: ExprSyntax | BlockSyntax): MacroDependencySet;
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
export type MacroPlacement =
|
|
952
|
+
| { readonly kind: 'statement-region' }
|
|
953
|
+
| { readonly kind: 'unsupported'; readonly reason: 'multi-declaration' | 'unsupported-site' };
|
|
954
|
+
|
|
955
|
+
export interface MacroFresh {
|
|
956
|
+
binding(hint: string): string;
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
export interface MacroControlFlow {
|
|
960
|
+
deferCleanup(cleanup: BlockSyntax | readonly StmtSyntax[]): MacroScopeExitOutput;
|
|
961
|
+
freshBinding(hint: string): string;
|
|
962
|
+
placement(): MacroPlacement;
|
|
963
|
+
rewriteWithValue(
|
|
964
|
+
preludeStatements: readonly StmtSyntax[],
|
|
965
|
+
replacementExpr: ExprSyntax,
|
|
966
|
+
): MacroValueRewriteOutput;
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
export type MacroExpand<
|
|
970
|
+
Signature extends MacroSignature | undefined = undefined,
|
|
971
|
+
> = (
|
|
972
|
+
ctx: MacroContext,
|
|
973
|
+
signature: Signature extends MacroSignature ? MacroDecodedSignature<Signature> : null,
|
|
974
|
+
) => MacroOutput;
|
|
975
|
+
|
|
976
|
+
export interface MacroSyntaxNode {
|
|
977
|
+
readonly data?: unknown;
|
|
978
|
+
readonly kind: string;
|
|
979
|
+
readonly span: SourceSpan;
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
export type MacroQuoteValue =
|
|
983
|
+
| MacroSyntaxNode
|
|
984
|
+
| readonly MacroSyntaxNode[]
|
|
985
|
+
| string
|
|
986
|
+
| number
|
|
987
|
+
| boolean
|
|
988
|
+
| bigint
|
|
989
|
+
| null
|
|
990
|
+
| undefined;
|
|
991
|
+
|
|
992
|
+
export interface MacroFormatContext {
|
|
993
|
+
formatBlock(text: string): string;
|
|
994
|
+
formatExpression(text: string): string;
|
|
995
|
+
readonly node: MacroSyntaxNode;
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
export interface MacroHoverContext {
|
|
999
|
+
readonly node: MacroSyntaxNode;
|
|
1000
|
+
readonly offset: number;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
export interface MacroPositionHoverContext {
|
|
1004
|
+
readonly macro: MacroContext;
|
|
1005
|
+
readonly node: MacroSyntaxNode;
|
|
1006
|
+
readonly offset: number;
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
export interface MacroAnalysisContext {
|
|
1010
|
+
readonly macro: MacroContext;
|
|
1011
|
+
readonly node: MacroSyntaxNode;
|
|
1012
|
+
readonly offset: number;
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
export interface MacroHoverResult {
|
|
1016
|
+
readonly contents: string;
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
export interface MacroCompletionContext {
|
|
1020
|
+
readonly node: MacroSyntaxNode;
|
|
1021
|
+
readonly offset: number;
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
export interface MacroCompletionItem {
|
|
1025
|
+
readonly detail?: string;
|
|
1026
|
+
readonly label: string;
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
export interface MacroBindingOccurrence {
|
|
1030
|
+
readonly bindingId: string;
|
|
1031
|
+
readonly kind: 'declaration' | 'reference';
|
|
1032
|
+
readonly name: string;
|
|
1033
|
+
readonly span: SourceSpan;
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
export interface MacroBindingsContext {
|
|
1037
|
+
readonly node: MacroSyntaxNode;
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
export interface MacroSemanticToken {
|
|
1041
|
+
readonly modifiers?: readonly string[];
|
|
1042
|
+
readonly span: SourceSpan;
|
|
1043
|
+
readonly type: string;
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
export interface MacroSemanticTokensContext {
|
|
1047
|
+
readonly node: MacroSyntaxNode;
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
export interface MacroEmbeddedFragment {
|
|
1051
|
+
readonly bindings?: readonly MacroBindingOccurrence[];
|
|
1052
|
+
readonly completions?: (sourcePosition: number) => readonly MacroCompletionItem[];
|
|
1053
|
+
readonly format?: (ctx: Pick<MacroFormatContext, 'formatBlock' | 'formatExpression'>) => string;
|
|
1054
|
+
readonly hover?: (sourcePosition: number) => MacroHoverResult | null;
|
|
1055
|
+
readonly language: string;
|
|
1056
|
+
readonly semanticTokens?: readonly MacroSemanticToken[];
|
|
1057
|
+
readonly span: SourceSpan;
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
export interface MacroDefinitionCapabilities<
|
|
1061
|
+
Signature extends MacroSignature | undefined = MacroSignature | undefined,
|
|
1062
|
+
> {
|
|
1063
|
+
readonly analysisRegion?: (ctx: MacroAnalysisContext) => MacroAnalysisRegion | null;
|
|
1064
|
+
readonly bindings?: (ctx: MacroBindingsContext) => readonly MacroBindingOccurrence[];
|
|
1065
|
+
readonly completions?: (ctx: MacroCompletionContext) => readonly MacroCompletionItem[];
|
|
1066
|
+
/** Narrows which module-scope declaration kinds a `// #[macro(decl)]` factory accepts. */
|
|
1067
|
+
readonly declarationKinds?: readonly MacroDeclarationKind[];
|
|
1068
|
+
/** Controls whether a declaration macro replaces the declaration or preserves it and appends siblings. */
|
|
1069
|
+
readonly expansionMode?: MacroDeclarationExpansionMode;
|
|
1070
|
+
readonly expand: MacroExpand<Signature>;
|
|
1071
|
+
readonly format?: (ctx: MacroFormatContext) => string;
|
|
1072
|
+
readonly fragments?: (ctx: MacroContext) => readonly MacroEmbeddedFragment[];
|
|
1073
|
+
readonly hover?: (ctx: MacroHoverContext) => MacroHoverResult | null;
|
|
1074
|
+
readonly positionHover?: (ctx: MacroPositionHoverContext) => MacroHoverResult | null;
|
|
1075
|
+
readonly parse?: (ctx: MacroContext) => MacroSyntaxNode;
|
|
1076
|
+
readonly semanticTokens?: (ctx: MacroSemanticTokensContext) => readonly MacroSemanticToken[];
|
|
1077
|
+
readonly signature?: Signature;
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
export interface MacroDefinition<
|
|
1081
|
+
Signature extends MacroSignature | undefined = MacroSignature | undefined,
|
|
1082
|
+
> {
|
|
1083
|
+
readonly analysisRegion?: MacroDefinitionCapabilities<Signature>['analysisRegion'];
|
|
1084
|
+
readonly bindings?: MacroDefinitionCapabilities<Signature>['bindings'];
|
|
1085
|
+
readonly completions?: MacroDefinitionCapabilities<Signature>['completions'];
|
|
1086
|
+
/** Narrows which module-scope declaration kinds a `// #[macro(decl)]` factory accepts. */
|
|
1087
|
+
readonly declarationKinds?: MacroDefinitionCapabilities<Signature>['declarationKinds'];
|
|
1088
|
+
/** Controls whether a declaration macro replaces the declaration or preserves it and appends siblings. */
|
|
1089
|
+
readonly expansionMode?: MacroDefinitionCapabilities<Signature>['expansionMode'];
|
|
1090
|
+
readonly expand: MacroExpand<Signature>;
|
|
1091
|
+
readonly format?: MacroDefinitionCapabilities<Signature>['format'];
|
|
1092
|
+
readonly fragments?: MacroDefinitionCapabilities<Signature>['fragments'];
|
|
1093
|
+
readonly hover?: MacroDefinitionCapabilities<Signature>['hover'];
|
|
1094
|
+
readonly positionHover?: MacroDefinitionCapabilities<Signature>['positionHover'];
|
|
1095
|
+
readonly parse?: MacroDefinitionCapabilities<Signature>['parse'];
|
|
1096
|
+
readonly semanticTokens?: MacroDefinitionCapabilities<Signature>['semanticTokens'];
|
|
1097
|
+
readonly signature?: MacroDefinitionCapabilities<Signature>['signature'];
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
function createMacroSignatureOperand<
|
|
1101
|
+
Kind extends MacroSignatureOperandKind,
|
|
1102
|
+
Name extends string,
|
|
1103
|
+
>(
|
|
1104
|
+
kind: Kind,
|
|
1105
|
+
name: Name,
|
|
1106
|
+
options: {
|
|
1107
|
+
description?: string;
|
|
1108
|
+
optional?: boolean;
|
|
1109
|
+
refinement?: MacroSignatureOperandRefinement;
|
|
1110
|
+
} = {},
|
|
1111
|
+
): MacroSignatureOperand<
|
|
1112
|
+
Kind,
|
|
1113
|
+
Name,
|
|
1114
|
+
false,
|
|
1115
|
+
MacroSignatureOperandBaseValue<Kind>
|
|
1116
|
+
> {
|
|
1117
|
+
return {
|
|
1118
|
+
description: options.description,
|
|
1119
|
+
kind,
|
|
1120
|
+
name,
|
|
1121
|
+
optional: (options.optional ?? false) as false,
|
|
1122
|
+
refinement: options.refinement,
|
|
1123
|
+
};
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
function createMacroSignatureCase<
|
|
1127
|
+
CaseName extends string | null,
|
|
1128
|
+
const Operands extends readonly MacroSignatureOperand[],
|
|
1129
|
+
>(
|
|
1130
|
+
caseName: CaseName,
|
|
1131
|
+
operands: Operands,
|
|
1132
|
+
): MacroSignatureCase<CaseName, Operands> {
|
|
1133
|
+
let sawOptional = false;
|
|
1134
|
+
let sawTerminal = false;
|
|
1135
|
+
operands.forEach((operand, index) => {
|
|
1136
|
+
const isTerminal = operand.kind === 'block' || operand.kind === 'decl';
|
|
1137
|
+
if (sawTerminal) {
|
|
1138
|
+
throw new Error(
|
|
1139
|
+
'Macro signatures cannot place operands after a block or declaration operand.',
|
|
1140
|
+
);
|
|
1141
|
+
}
|
|
1142
|
+
if (isTerminal && index !== operands.length - 1) {
|
|
1143
|
+
throw new Error(
|
|
1144
|
+
'Macro block and declaration operands must be the final operand in a signature case.',
|
|
1145
|
+
);
|
|
1146
|
+
}
|
|
1147
|
+
if (sawOptional && !operand.optional) {
|
|
1148
|
+
throw new Error(
|
|
1149
|
+
'Macro signature optional operands must appear at the end of a signature case.',
|
|
1150
|
+
);
|
|
1151
|
+
}
|
|
1152
|
+
if (operand.optional) {
|
|
1153
|
+
sawOptional = true;
|
|
1154
|
+
}
|
|
1155
|
+
if (isTerminal) {
|
|
1156
|
+
sawTerminal = true;
|
|
1157
|
+
}
|
|
1158
|
+
});
|
|
1159
|
+
return {
|
|
1160
|
+
caseName,
|
|
1161
|
+
operands: [...operands] as Operands,
|
|
1162
|
+
};
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
type MacroSignatureCaseCandidates =
|
|
1166
|
+
| MacroSignature
|
|
1167
|
+
| MacroSignatureCase;
|
|
1168
|
+
|
|
1169
|
+
type MacroSignatureCasesForCandidate<Candidate> = Candidate extends MacroSignature<infer Cases>
|
|
1170
|
+
? Cases
|
|
1171
|
+
: Candidate extends MacroSignatureCase ? readonly [Candidate]
|
|
1172
|
+
: never;
|
|
1173
|
+
|
|
1174
|
+
type NormalizeMacroSignatureCases<Candidates extends readonly unknown[]> = Candidates extends
|
|
1175
|
+
readonly [infer First, ...infer Rest]
|
|
1176
|
+
? [...MacroSignatureCasesForCandidate<First>, ...NormalizeMacroSignatureCases<Rest>]
|
|
1177
|
+
: [];
|
|
1178
|
+
|
|
1179
|
+
function normalizeMacroSignatureCases<
|
|
1180
|
+
const Candidates extends readonly MacroSignatureCaseCandidates[],
|
|
1181
|
+
>(
|
|
1182
|
+
cases: Candidates,
|
|
1183
|
+
): NormalizeMacroSignatureCases<Candidates> {
|
|
1184
|
+
return cases.flatMap((candidate) =>
|
|
1185
|
+
'cases' in candidate ? candidate.cases : [candidate]
|
|
1186
|
+
) as NormalizeMacroSignatureCases<Candidates>;
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
function formatMacroSignatureOperand(operand: MacroSignatureOperand): string {
|
|
1190
|
+
const required = formatRequiredMacroSignatureOperand(operand);
|
|
1191
|
+
return operand.optional ? `[${required}]` : required;
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
function formatRequiredMacroSignatureOperand(operand: MacroSignatureOperand): string {
|
|
1195
|
+
return operand.refinement?.displayText ?? (() => {
|
|
1196
|
+
switch (operand.kind) {
|
|
1197
|
+
case 'expr':
|
|
1198
|
+
return `<${operand.name}>`;
|
|
1199
|
+
case 'template':
|
|
1200
|
+
return '`...`';
|
|
1201
|
+
case 'block':
|
|
1202
|
+
return '{ ... }';
|
|
1203
|
+
case 'decl':
|
|
1204
|
+
return '<declaration>';
|
|
1205
|
+
}
|
|
1206
|
+
})();
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
function formatMacroSignatureCaseExample(
|
|
1210
|
+
macroName: string,
|
|
1211
|
+
signatureCase: MacroSignatureCase,
|
|
1212
|
+
): string {
|
|
1213
|
+
return formatMacroSignatureCaseExamples(macroName, signatureCase).at(-1) ?? `${macroName}()`;
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
function formatMacroSignatureCaseExamples(
|
|
1217
|
+
macroName: string,
|
|
1218
|
+
signatureCase: MacroSignatureCase,
|
|
1219
|
+
): readonly string[] {
|
|
1220
|
+
const exprOperands = signatureCase.operands.filter((operand) =>
|
|
1221
|
+
operand.kind === 'expr' || operand.kind === 'template'
|
|
1222
|
+
);
|
|
1223
|
+
const terminalOperand =
|
|
1224
|
+
signatureCase.operands.find((operand) => operand.kind === 'block' || operand.kind === 'decl') ??
|
|
1225
|
+
null;
|
|
1226
|
+
const requiredExprCount = exprOperands.filter((operand) => !operand.optional).length;
|
|
1227
|
+
const variants: string[] = [];
|
|
1228
|
+
|
|
1229
|
+
for (let exprCount = requiredExprCount; exprCount <= exprOperands.length; exprCount += 1) {
|
|
1230
|
+
const includedExprOperands = exprOperands.slice(0, exprCount);
|
|
1231
|
+
const templateOnly = !terminalOperand &&
|
|
1232
|
+
includedExprOperands.length === 1 &&
|
|
1233
|
+
exprOperands.length === 1 &&
|
|
1234
|
+
includedExprOperands[0]?.kind === 'template';
|
|
1235
|
+
const formattedArgs = includedExprOperands.map(formatRequiredMacroSignatureOperand);
|
|
1236
|
+
let invocation = templateOnly
|
|
1237
|
+
? `${macroName}${formatRequiredMacroSignatureOperand(includedExprOperands[0]!)}`
|
|
1238
|
+
: `${macroName}(${formattedArgs.join(', ')})`;
|
|
1239
|
+
|
|
1240
|
+
if (terminalOperand?.kind === 'block') {
|
|
1241
|
+
invocation = `${macroName}(${[...formattedArgs, '() => { ... }'].join(', ')})`;
|
|
1242
|
+
} else if (terminalOperand?.kind === 'decl') {
|
|
1243
|
+
invocation = includedExprOperands.length === 0
|
|
1244
|
+
? `// #[${macroName}] <declaration>`
|
|
1245
|
+
: `${macroName}(${formattedArgs.join(', ')}) <declaration>`;
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
variants.push(invocation);
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
return variants;
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
export function formatMacroSignatureExamples(
|
|
1255
|
+
signature: MacroSignature,
|
|
1256
|
+
macroName: string,
|
|
1257
|
+
): readonly string[] {
|
|
1258
|
+
return signature.cases.map((signatureCase) =>
|
|
1259
|
+
formatMacroSignatureCaseExample(macroName, signatureCase)
|
|
1260
|
+
);
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
export function formatMacroSignature(signature: MacroSignature, macroName: string): string {
|
|
1264
|
+
return signature.cases
|
|
1265
|
+
.flatMap((signatureCase) => formatMacroSignatureCaseExamples(macroName, signatureCase))
|
|
1266
|
+
.join('; ');
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
function refineMacroSignatureOperandValue<const Operand extends MacroSignatureOperand>(
|
|
1270
|
+
operand: Operand,
|
|
1271
|
+
value: MacroDecodedSignatureValue,
|
|
1272
|
+
): MacroSignatureOperandDecodedValue<Operand> | null {
|
|
1273
|
+
if (value === null || !operand.refinement) {
|
|
1274
|
+
return value as MacroSignatureOperandDecodedValue<Operand>;
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
switch (operand.refinement.kind) {
|
|
1278
|
+
case 'array_literal':
|
|
1279
|
+
return value.kind === 'expr'
|
|
1280
|
+
? value.asArrayLiteral() as
|
|
1281
|
+
| MacroSignatureOperandDecodedValue<
|
|
1282
|
+
Operand
|
|
1283
|
+
>
|
|
1284
|
+
| null
|
|
1285
|
+
: null;
|
|
1286
|
+
case 'call':
|
|
1287
|
+
return value.kind === 'expr' && value.asCall() !== null
|
|
1288
|
+
? value as MacroSignatureOperandDecodedValue<Operand>
|
|
1289
|
+
: null;
|
|
1290
|
+
case 'class_decl':
|
|
1291
|
+
return value.kind === 'decl'
|
|
1292
|
+
? value.asClass() as MacroSignatureOperandDecodedValue<Operand> | null
|
|
1293
|
+
: null;
|
|
1294
|
+
case 'function':
|
|
1295
|
+
return value.kind === 'expr'
|
|
1296
|
+
? value.asFunction() as
|
|
1297
|
+
| MacroSignatureOperandDecodedValue<
|
|
1298
|
+
Operand
|
|
1299
|
+
>
|
|
1300
|
+
| null
|
|
1301
|
+
: null;
|
|
1302
|
+
case 'function_decl':
|
|
1303
|
+
return value.kind === 'decl'
|
|
1304
|
+
? value.asFunction() as MacroSignatureOperandDecodedValue<Operand> | null
|
|
1305
|
+
: null;
|
|
1306
|
+
case 'interface_decl':
|
|
1307
|
+
return value.kind === 'decl'
|
|
1308
|
+
? value.asInterface() as MacroSignatureOperandDecodedValue<Operand> | null
|
|
1309
|
+
: null;
|
|
1310
|
+
case 'type_alias_decl':
|
|
1311
|
+
return value.kind === 'decl'
|
|
1312
|
+
? value.asTypeAlias() as MacroSignatureOperandDecodedValue<Operand> | null
|
|
1313
|
+
: null;
|
|
1314
|
+
case 'identifier':
|
|
1315
|
+
return value.kind === 'expr' && value.asIdentifier() !== null
|
|
1316
|
+
? value as MacroSignatureOperandDecodedValue<Operand>
|
|
1317
|
+
: null;
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
function tryReadMacroSignatureCase<const Case extends MacroSignatureCase>(
|
|
1322
|
+
signatureCase: Case,
|
|
1323
|
+
ctx: Pick<MacroContext, 'declarationSpan' | 'hasBlock' | 'invocation' | 'syntax'>,
|
|
1324
|
+
): MacroDecodedSignatureCase<Case> | null {
|
|
1325
|
+
const args: Record<string, MacroDecodedSignatureValue> = {};
|
|
1326
|
+
let exprIndex = 0;
|
|
1327
|
+
const argCount = ctx.invocation.args.length;
|
|
1328
|
+
const declarationSpan = ctx.declarationSpan();
|
|
1329
|
+
const hasBlock = ctx.hasBlock();
|
|
1330
|
+
|
|
1331
|
+
for (const operand of signatureCase.operands) {
|
|
1332
|
+
switch (operand.kind) {
|
|
1333
|
+
case 'expr': {
|
|
1334
|
+
if (exprIndex >= argCount) {
|
|
1335
|
+
if (operand.optional) {
|
|
1336
|
+
args[operand.name] = null;
|
|
1337
|
+
break;
|
|
1338
|
+
}
|
|
1339
|
+
return null;
|
|
1340
|
+
}
|
|
1341
|
+
const value = refineMacroSignatureOperandValue(operand, ctx.syntax.arg(exprIndex));
|
|
1342
|
+
if (value === null) {
|
|
1343
|
+
return null;
|
|
1344
|
+
}
|
|
1345
|
+
args[operand.name] = value;
|
|
1346
|
+
exprIndex += 1;
|
|
1347
|
+
break;
|
|
1348
|
+
}
|
|
1349
|
+
case 'template': {
|
|
1350
|
+
if (exprIndex >= argCount) {
|
|
1351
|
+
if (operand.optional) {
|
|
1352
|
+
args[operand.name] = null;
|
|
1353
|
+
break;
|
|
1354
|
+
}
|
|
1355
|
+
return null;
|
|
1356
|
+
}
|
|
1357
|
+
const template = ctx.syntax.template(exprIndex);
|
|
1358
|
+
if (!template) {
|
|
1359
|
+
return null;
|
|
1360
|
+
}
|
|
1361
|
+
const value = refineMacroSignatureOperandValue(operand, template);
|
|
1362
|
+
if (value === null) {
|
|
1363
|
+
return null;
|
|
1364
|
+
}
|
|
1365
|
+
args[operand.name] = value;
|
|
1366
|
+
exprIndex += 1;
|
|
1367
|
+
break;
|
|
1368
|
+
}
|
|
1369
|
+
case 'block': {
|
|
1370
|
+
if (!hasBlock) {
|
|
1371
|
+
if (operand.optional) {
|
|
1372
|
+
args[operand.name] = null;
|
|
1373
|
+
break;
|
|
1374
|
+
}
|
|
1375
|
+
return null;
|
|
1376
|
+
}
|
|
1377
|
+
if (declarationSpan) {
|
|
1378
|
+
return null;
|
|
1379
|
+
}
|
|
1380
|
+
const value = refineMacroSignatureOperandValue(operand, ctx.syntax.block());
|
|
1381
|
+
if (value === null) {
|
|
1382
|
+
return null;
|
|
1383
|
+
}
|
|
1384
|
+
args[operand.name] = value;
|
|
1385
|
+
break;
|
|
1386
|
+
}
|
|
1387
|
+
case 'decl': {
|
|
1388
|
+
if (!declarationSpan) {
|
|
1389
|
+
if (operand.optional) {
|
|
1390
|
+
args[operand.name] = null;
|
|
1391
|
+
break;
|
|
1392
|
+
}
|
|
1393
|
+
return null;
|
|
1394
|
+
}
|
|
1395
|
+
if (hasBlock) {
|
|
1396
|
+
return null;
|
|
1397
|
+
}
|
|
1398
|
+
const value = refineMacroSignatureOperandValue(operand, ctx.syntax.declaration());
|
|
1399
|
+
if (value === null) {
|
|
1400
|
+
return null;
|
|
1401
|
+
}
|
|
1402
|
+
args[operand.name] = value;
|
|
1403
|
+
break;
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1408
|
+
if (exprIndex !== argCount) {
|
|
1409
|
+
return null;
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
const expectsBlock = signatureCase.operands.some((operand) => operand.kind === 'block');
|
|
1413
|
+
const expectsDecl = signatureCase.operands.some((operand) => operand.kind === 'decl');
|
|
1414
|
+
if (hasBlock && !expectsBlock) {
|
|
1415
|
+
return null;
|
|
1416
|
+
}
|
|
1417
|
+
if (declarationSpan && !expectsDecl) {
|
|
1418
|
+
return null;
|
|
1419
|
+
}
|
|
1420
|
+
if (
|
|
1421
|
+
!hasBlock && expectsBlock && !signatureCase.operands.find((operand) => operand.kind === 'block')
|
|
1422
|
+
?.optional
|
|
1423
|
+
) {
|
|
1424
|
+
return null;
|
|
1425
|
+
}
|
|
1426
|
+
if (
|
|
1427
|
+
!declarationSpan && expectsDecl &&
|
|
1428
|
+
!signatureCase.operands.find((operand) => operand.kind === 'decl')?.optional
|
|
1429
|
+
) {
|
|
1430
|
+
return null;
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
return {
|
|
1434
|
+
args: args as MacroSignatureArgsFromOperands<Case['operands']>,
|
|
1435
|
+
caseName: signatureCase.caseName,
|
|
1436
|
+
signatureCase,
|
|
1437
|
+
};
|
|
1438
|
+
}
|
|
1439
|
+
|
|
1440
|
+
export function tryReadMacroSignature<const Signature extends MacroSignature>(
|
|
1441
|
+
signature: Signature,
|
|
1442
|
+
ctx: Pick<
|
|
1443
|
+
MacroContext,
|
|
1444
|
+
'declarationSpan' | 'hasBlock' | 'invocation' | 'syntax'
|
|
1445
|
+
>,
|
|
1446
|
+
): MacroDecodedSignature<Signature> | null {
|
|
1447
|
+
for (const signatureCase of signature.cases) {
|
|
1448
|
+
const decoded = tryReadMacroSignatureCase(signatureCase, ctx);
|
|
1449
|
+
if (decoded) {
|
|
1450
|
+
return decoded as MacroDecodedSignature<Signature>;
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
return null;
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
export function readMacroSignature<const Signature extends MacroSignature>(
|
|
1457
|
+
signature: Signature,
|
|
1458
|
+
ctx: Pick<
|
|
1459
|
+
MacroContext,
|
|
1460
|
+
'declarationSpan' | 'error' | 'hasBlock' | 'invocation' | 'name' | 'syntax'
|
|
1461
|
+
>,
|
|
1462
|
+
): MacroDecodedSignature<Signature> {
|
|
1463
|
+
const decoded = tryReadMacroSignature(signature, ctx);
|
|
1464
|
+
if (decoded) {
|
|
1465
|
+
return decoded;
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
ctx.error(`${ctx.name} only supports: ${formatMacroSignature(signature, ctx.name)}.`);
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
function macroSignatureBlock<const Name extends string>(
|
|
1472
|
+
name: Name,
|
|
1473
|
+
options: { description?: string } = {},
|
|
1474
|
+
): MacroSignatureOperand<'block', Name, false, BlockSyntax> {
|
|
1475
|
+
return createMacroSignatureOperand('block', name, options);
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
function macroSignatureCase<const Operands extends readonly MacroSignatureOperand[]>(
|
|
1479
|
+
...operands: Operands
|
|
1480
|
+
): MacroSignatureCase<null, Operands>;
|
|
1481
|
+
function macroSignatureCase<
|
|
1482
|
+
const CaseName extends string,
|
|
1483
|
+
const Operands extends readonly MacroSignatureOperand[],
|
|
1484
|
+
>(
|
|
1485
|
+
caseName: CaseName,
|
|
1486
|
+
...operands: Operands
|
|
1487
|
+
): MacroSignatureCase<CaseName, Operands>;
|
|
1488
|
+
function macroSignatureCase(
|
|
1489
|
+
...operandsOrCaseName:
|
|
1490
|
+
| readonly [string, ...MacroSignatureOperand[]]
|
|
1491
|
+
| readonly MacroSignatureOperand[]
|
|
1492
|
+
): MacroSignatureCase {
|
|
1493
|
+
if (typeof operandsOrCaseName[0] === 'string') {
|
|
1494
|
+
const [caseName, ...operands] = operandsOrCaseName as readonly [
|
|
1495
|
+
string,
|
|
1496
|
+
...MacroSignatureOperand[],
|
|
1497
|
+
];
|
|
1498
|
+
return createMacroSignatureCase(caseName, operands);
|
|
1499
|
+
}
|
|
1500
|
+
return createMacroSignatureCase(null, operandsOrCaseName as readonly MacroSignatureOperand[]);
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
function macroSignatureDecl<const Name extends string>(
|
|
1504
|
+
name: Name,
|
|
1505
|
+
options: { description?: string } = {},
|
|
1506
|
+
): MacroSignatureOperand<'decl', Name, false, DeclSyntax> {
|
|
1507
|
+
return createMacroSignatureOperand('decl', name, options);
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
function macroSignatureExpr<const Name extends string>(
|
|
1511
|
+
name: Name,
|
|
1512
|
+
options: { description?: string } = {},
|
|
1513
|
+
): MacroSignatureOperand<'expr', Name, false, ExprSyntax> {
|
|
1514
|
+
return createMacroSignatureOperand('expr', name, options);
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
function createRefinedMacroSignatureOperand<
|
|
1518
|
+
Kind extends MacroSignatureOperandKind,
|
|
1519
|
+
Name extends string,
|
|
1520
|
+
Refinement extends MacroSignatureOperandRefinementKind,
|
|
1521
|
+
>(
|
|
1522
|
+
kind: Kind,
|
|
1523
|
+
name: Name,
|
|
1524
|
+
refinement: { displayText: string; kind: Refinement },
|
|
1525
|
+
options: { description?: string } = {},
|
|
1526
|
+
): MacroSignatureOperand<
|
|
1527
|
+
Kind,
|
|
1528
|
+
Name,
|
|
1529
|
+
false,
|
|
1530
|
+
MacroSignatureRefinedValue<Refinement>
|
|
1531
|
+
> {
|
|
1532
|
+
return createMacroSignatureOperand(kind, name, {
|
|
1533
|
+
...options,
|
|
1534
|
+
refinement,
|
|
1535
|
+
}) as MacroSignatureOperand<
|
|
1536
|
+
Kind,
|
|
1537
|
+
Name,
|
|
1538
|
+
false,
|
|
1539
|
+
MacroSignatureRefinedValue<Refinement>
|
|
1540
|
+
>;
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1543
|
+
function macroSignatureArrayLiteral<const Name extends string>(
|
|
1544
|
+
name: Name,
|
|
1545
|
+
options: { description?: string } = {},
|
|
1546
|
+
): MacroSignatureOperand<'expr', Name, false, MacroArrayLiteralExprSyntax> {
|
|
1547
|
+
return createRefinedMacroSignatureOperand(
|
|
1548
|
+
'expr',
|
|
1549
|
+
name,
|
|
1550
|
+
{ displayText: '[ ... ]', kind: 'array_literal' },
|
|
1551
|
+
options,
|
|
1552
|
+
);
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
function macroSignatureCall<const Name extends string>(
|
|
1556
|
+
name: Name,
|
|
1557
|
+
options: { description?: string } = {},
|
|
1558
|
+
): MacroSignatureOperand<'expr', Name, false, MacroCallExprSyntax> {
|
|
1559
|
+
return createRefinedMacroSignatureOperand(
|
|
1560
|
+
'expr',
|
|
1561
|
+
name,
|
|
1562
|
+
{ displayText: '<call>(...)', kind: 'call' },
|
|
1563
|
+
options,
|
|
1564
|
+
);
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
function macroSignatureFunctionExpr<const Name extends string>(
|
|
1568
|
+
name: Name,
|
|
1569
|
+
options: { description?: string } = {},
|
|
1570
|
+
): MacroSignatureOperand<'expr', Name, false, MacroFunctionExprSyntax> {
|
|
1571
|
+
return createRefinedMacroSignatureOperand(
|
|
1572
|
+
'expr',
|
|
1573
|
+
name,
|
|
1574
|
+
{ displayText: '(() => ...)', kind: 'function' },
|
|
1575
|
+
options,
|
|
1576
|
+
);
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
function macroSignatureIdentifier<const Name extends string>(
|
|
1580
|
+
name: Name,
|
|
1581
|
+
options: { description?: string } = {},
|
|
1582
|
+
): MacroSignatureOperand<'expr', Name, false, MacroIdentifierExprSyntax> {
|
|
1583
|
+
return createRefinedMacroSignatureOperand(
|
|
1584
|
+
'expr',
|
|
1585
|
+
name,
|
|
1586
|
+
{ displayText: '<identifier>', kind: 'identifier' },
|
|
1587
|
+
options,
|
|
1588
|
+
);
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
function macroSignatureOf<const Operands extends readonly MacroSignatureOperand[]>(
|
|
1592
|
+
...operands: Operands
|
|
1593
|
+
): MacroSignature<readonly [MacroSignatureCase<null, Operands>]> {
|
|
1594
|
+
return {
|
|
1595
|
+
cases: [createMacroSignatureCase(null, operands)],
|
|
1596
|
+
};
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
function macroSignatureOneOf<const Cases extends readonly MacroSignatureCaseCandidates[]>(
|
|
1600
|
+
...cases: Cases
|
|
1601
|
+
): MacroSignature<NormalizeMacroSignatureCases<Cases>> {
|
|
1602
|
+
return {
|
|
1603
|
+
cases: normalizeMacroSignatureCases(cases),
|
|
1604
|
+
};
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
function macroSignatureOptional<const Operand extends MacroSignatureOperand>(
|
|
1608
|
+
operand: Operand,
|
|
1609
|
+
): MacroSignatureOperand<
|
|
1610
|
+
Operand['kind'],
|
|
1611
|
+
Operand['name'],
|
|
1612
|
+
true,
|
|
1613
|
+
MacroSignatureOperandDecodedValue<Operand> extends infer Value
|
|
1614
|
+
? Exclude<Value, null> & MacroDecodedSignatureValue
|
|
1615
|
+
: never
|
|
1616
|
+
> {
|
|
1617
|
+
return {
|
|
1618
|
+
...operand,
|
|
1619
|
+
optional: true,
|
|
1620
|
+
} as MacroSignatureOperand<
|
|
1621
|
+
Operand['kind'],
|
|
1622
|
+
Operand['name'],
|
|
1623
|
+
true,
|
|
1624
|
+
MacroSignatureOperandDecodedValue<Operand> extends infer Value
|
|
1625
|
+
? Exclude<Value, null> & MacroDecodedSignatureValue
|
|
1626
|
+
: never
|
|
1627
|
+
>;
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1630
|
+
function macroSignatureSignature<const Operands extends readonly MacroSignatureOperand[]>(
|
|
1631
|
+
...operands: Operands
|
|
1632
|
+
): MacroSignature<readonly [MacroSignatureCase<null, Operands>]> {
|
|
1633
|
+
return {
|
|
1634
|
+
cases: [createMacroSignatureCase(null, operands)],
|
|
1635
|
+
};
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
function macroSignatureTemplate<const Name extends string>(
|
|
1639
|
+
name: Name,
|
|
1640
|
+
options: { description?: string } = {},
|
|
1641
|
+
): MacroSignatureOperand<'template', Name, false, MacroTemplateOperand> {
|
|
1642
|
+
return createMacroSignatureOperand('template', name, options);
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1645
|
+
function macroSignatureClassDecl<const Name extends string>(
|
|
1646
|
+
name: Name,
|
|
1647
|
+
options: { description?: string } = {},
|
|
1648
|
+
): MacroSignatureOperand<'decl', Name, false, MacroClassDeclSyntax> {
|
|
1649
|
+
return createRefinedMacroSignatureOperand(
|
|
1650
|
+
'decl',
|
|
1651
|
+
name,
|
|
1652
|
+
{ displayText: 'class { ... }', kind: 'class_decl' },
|
|
1653
|
+
options,
|
|
1654
|
+
);
|
|
1655
|
+
}
|
|
1656
|
+
|
|
1657
|
+
function macroSignatureFunctionDecl<const Name extends string>(
|
|
1658
|
+
name: Name,
|
|
1659
|
+
options: { description?: string } = {},
|
|
1660
|
+
): MacroSignatureOperand<'decl', Name, false, MacroFunctionDeclSyntax> {
|
|
1661
|
+
return createRefinedMacroSignatureOperand(
|
|
1662
|
+
'decl',
|
|
1663
|
+
name,
|
|
1664
|
+
{ displayText: 'function ...', kind: 'function_decl' },
|
|
1665
|
+
options,
|
|
1666
|
+
);
|
|
1667
|
+
}
|
|
1668
|
+
|
|
1669
|
+
function macroSignatureInterfaceDecl<const Name extends string>(
|
|
1670
|
+
name: Name,
|
|
1671
|
+
options: { description?: string } = {},
|
|
1672
|
+
): MacroSignatureOperand<'decl', Name, false, MacroInterfaceDeclSyntax> {
|
|
1673
|
+
return createRefinedMacroSignatureOperand(
|
|
1674
|
+
'decl',
|
|
1675
|
+
name,
|
|
1676
|
+
{ displayText: 'interface ...', kind: 'interface_decl' },
|
|
1677
|
+
options,
|
|
1678
|
+
);
|
|
1679
|
+
}
|
|
1680
|
+
|
|
1681
|
+
function macroSignatureTypeAliasDecl<const Name extends string>(
|
|
1682
|
+
name: Name,
|
|
1683
|
+
options: { description?: string } = {},
|
|
1684
|
+
): MacroSignatureOperand<'decl', Name, false, MacroTypeAliasDeclSyntax> {
|
|
1685
|
+
return createRefinedMacroSignatureOperand(
|
|
1686
|
+
'decl',
|
|
1687
|
+
name,
|
|
1688
|
+
{ displayText: 'type ... = ...', kind: 'type_alias_decl' },
|
|
1689
|
+
options,
|
|
1690
|
+
);
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
function macroSignatureRefine<const Signature extends MacroSignature>(
|
|
1694
|
+
signature: Signature,
|
|
1695
|
+
validator: MacroSignatureValidator<Signature>,
|
|
1696
|
+
): Signature {
|
|
1697
|
+
return {
|
|
1698
|
+
...signature,
|
|
1699
|
+
validators: [...(signature.validators ?? []), validator as MacroSignatureValidator],
|
|
1700
|
+
} as Signature;
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
export const macroSignature = {
|
|
1704
|
+
arrayLiteral: macroSignatureArrayLiteral,
|
|
1705
|
+
block: macroSignatureBlock,
|
|
1706
|
+
case: macroSignatureCase,
|
|
1707
|
+
call: macroSignatureCall,
|
|
1708
|
+
classDecl: macroSignatureClassDecl,
|
|
1709
|
+
decl: macroSignatureDecl,
|
|
1710
|
+
expr: macroSignatureExpr,
|
|
1711
|
+
functionDecl: macroSignatureFunctionDecl,
|
|
1712
|
+
functionExpr: macroSignatureFunctionExpr,
|
|
1713
|
+
identifier: macroSignatureIdentifier,
|
|
1714
|
+
interfaceDecl: macroSignatureInterfaceDecl,
|
|
1715
|
+
of: macroSignatureOf,
|
|
1716
|
+
oneOf: macroSignatureOneOf,
|
|
1717
|
+
optional: macroSignatureOptional,
|
|
1718
|
+
refine: macroSignatureRefine,
|
|
1719
|
+
signature: macroSignatureSignature,
|
|
1720
|
+
template: macroSignatureTemplate,
|
|
1721
|
+
typeAliasDecl: macroSignatureTypeAliasDecl,
|
|
1722
|
+
} as const;
|