@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,1386 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
getBundledExternRootNames,
|
|
5
|
+
withBundledRuntimeExterns,
|
|
6
|
+
} from '../bundled/runtime_externs.ts';
|
|
7
|
+
import { normalizeRuntimeContext } from '../config.ts';
|
|
8
|
+
import { hasErrorDiagnostics, type MergedDiagnostic } from '../checker/diagnostics.ts';
|
|
9
|
+
import { measureCheckerTiming } from '../checker/timing.ts';
|
|
10
|
+
import { builtinRuntimeImportSpecifier } from '../soundscript_runtime_specifiers.ts';
|
|
11
|
+
import type { MacroDefinition } from './macro_api.ts';
|
|
12
|
+
import { getLoadedMacroDefinitionMetadata, getMacroFactoryMetadata } from './macro_api_internal.ts';
|
|
13
|
+
import { withMacroApiModuleResolution } from './macro_api_module_support.ts';
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
CSS_STDLIB_MODULE_SPECIFIER,
|
|
17
|
+
DEBUG_STDLIB_MODULE_SPECIFIER,
|
|
18
|
+
DERIVE_STDLIB_MODULE_SPECIFIER,
|
|
19
|
+
GRAPHQL_STDLIB_MODULE_SPECIFIER,
|
|
20
|
+
HKT_STDLIB_MODULE_SPECIFIER,
|
|
21
|
+
MATCH_STDLIB_MODULE_SPECIFIER,
|
|
22
|
+
RESULT_STDLIB_MODULE_SPECIFIER,
|
|
23
|
+
SQL_STDLIB_MODULE_SPECIFIER,
|
|
24
|
+
STDLIB_MODULE_SPECIFIER,
|
|
25
|
+
THUNK_STDLIB_MODULE_SPECIFIER,
|
|
26
|
+
TYPECLASSES_STDLIB_MODULE_SPECIFIER,
|
|
27
|
+
withStdPackageModuleResolution,
|
|
28
|
+
} from './std_package_support.ts';
|
|
29
|
+
import {
|
|
30
|
+
assert as assertMacro,
|
|
31
|
+
css,
|
|
32
|
+
Defer,
|
|
33
|
+
Do,
|
|
34
|
+
graphql,
|
|
35
|
+
hkt as hktMacro,
|
|
36
|
+
lazy,
|
|
37
|
+
log,
|
|
38
|
+
Match,
|
|
39
|
+
memo,
|
|
40
|
+
sql,
|
|
41
|
+
todo,
|
|
42
|
+
Try,
|
|
43
|
+
unreachable,
|
|
44
|
+
} from './builtin_macros.ts';
|
|
45
|
+
import {
|
|
46
|
+
codec as codecMacro,
|
|
47
|
+
decode as decodeMacro,
|
|
48
|
+
encode as encodeMacro,
|
|
49
|
+
eq as eqMacro,
|
|
50
|
+
hash as hashMacro,
|
|
51
|
+
tagged as taggedMacro,
|
|
52
|
+
} from './derive_macros.ts';
|
|
53
|
+
import { MacroError } from './macro_errors.ts';
|
|
54
|
+
import {
|
|
55
|
+
collectNamedMacroDefinitions,
|
|
56
|
+
collectNamedMacroExports,
|
|
57
|
+
type LoadedNamedMacroExports,
|
|
58
|
+
} from './macro_loader.ts';
|
|
59
|
+
import type { IndexedMacroPlaceholder } from './macro_index.ts';
|
|
60
|
+
import {
|
|
61
|
+
createProjectMacroEnvironment,
|
|
62
|
+
type ProjectMacroEnvironment,
|
|
63
|
+
} from './project_macro_support.ts';
|
|
64
|
+
import {
|
|
65
|
+
clearPreparedCompilerHostReuseState,
|
|
66
|
+
createPreparedProgram,
|
|
67
|
+
type CreatePreparedProgramOptions,
|
|
68
|
+
getLineAndCharacterOfPosition,
|
|
69
|
+
type ImportedMacroSiteKind,
|
|
70
|
+
mapProgramRangeToSource,
|
|
71
|
+
type PreparedProgram,
|
|
72
|
+
type PreparedSourceFile,
|
|
73
|
+
toSourceFileName,
|
|
74
|
+
} from './project_frontend.ts';
|
|
75
|
+
import {
|
|
76
|
+
buildRewriteStageFromTexts,
|
|
77
|
+
normalizeErrorBoundariesInProgram,
|
|
78
|
+
} from './error_normalization.ts';
|
|
79
|
+
import {
|
|
80
|
+
type AbstractNumericFamilyArithmetic,
|
|
81
|
+
collectAbstractNumericFamilyArithmeticInProgram,
|
|
82
|
+
collectMixedMachineNumericArithmeticInProgram,
|
|
83
|
+
collectSortCallsWithoutComparatorInProgram,
|
|
84
|
+
type MixedMachineNumericArithmetic,
|
|
85
|
+
normalizeMachineNumericSemanticsInProgram,
|
|
86
|
+
type NumericLoweringTarget,
|
|
87
|
+
type SortCallWithoutComparator,
|
|
88
|
+
} from './numeric_normalization.ts';
|
|
89
|
+
import {
|
|
90
|
+
MACRO_EXPANSION_END_MARKER_PREFIX,
|
|
91
|
+
MACRO_EXPANSION_START_MARKER_PREFIX,
|
|
92
|
+
} from './macro_expander.ts';
|
|
93
|
+
|
|
94
|
+
export interface BuiltinExpandedProgram {
|
|
95
|
+
analysisPreparedProgram: PreparedProgram;
|
|
96
|
+
diagnosticPreparedFiles: ReadonlyMap<string, PreparedSourceFile>;
|
|
97
|
+
dispose(): void;
|
|
98
|
+
frontendDiagnostics(): readonly MergedDiagnostic[];
|
|
99
|
+
macroEnvironment: ProjectMacroEnvironment;
|
|
100
|
+
preparedProgram: PreparedProgram;
|
|
101
|
+
program: ts.Program;
|
|
102
|
+
tsDiagnosticPrograms: readonly BuiltinExpandedTsDiagnosticProgram[];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface BuiltinExpandedTsDiagnosticProgram {
|
|
106
|
+
filePaths?: readonly string[];
|
|
107
|
+
program: ts.Program;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface CreateBuiltinExpandedProgramOptions extends CreatePreparedProgramOptions {
|
|
111
|
+
allowSupplementalDiagnosticPrograms?: boolean;
|
|
112
|
+
numericLoweringTarget?: NumericLoweringTarget;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const NUMERIC_NORMALIZATION_MAX_PASSES = 8;
|
|
116
|
+
|
|
117
|
+
function repairBuiltinMacroModuleSpecifiers(text: string): string {
|
|
118
|
+
return text;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function withBuiltinRuntimeSpecifierAliases<T>(
|
|
122
|
+
entries: Iterable<readonly [string, T]>,
|
|
123
|
+
): Map<string, T> {
|
|
124
|
+
const aliased = new Map<string, T>();
|
|
125
|
+
for (const [specifier, value] of entries) {
|
|
126
|
+
aliased.set(specifier, value);
|
|
127
|
+
const runtimeSpecifier = builtinRuntimeImportSpecifier(specifier);
|
|
128
|
+
if (runtimeSpecifier) {
|
|
129
|
+
aliased.set(runtimeSpecifier, value);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return aliased;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function createMixedMachineNumericDiagnostic(
|
|
136
|
+
diagnostic: MixedMachineNumericArithmetic,
|
|
137
|
+
preparedFile: PreparedSourceFile | undefined,
|
|
138
|
+
fallbackSourceText: string,
|
|
139
|
+
): MergedDiagnostic {
|
|
140
|
+
const mappedRange = preparedFile
|
|
141
|
+
? mapProgramRangeToSource(preparedFile, diagnostic.start, diagnostic.end)
|
|
142
|
+
: {
|
|
143
|
+
intersectsReplacement: false,
|
|
144
|
+
start: diagnostic.start,
|
|
145
|
+
end: diagnostic.end,
|
|
146
|
+
};
|
|
147
|
+
const sourceText = preparedFile?.originalText ?? fallbackSourceText;
|
|
148
|
+
let rangeStart = mappedRange.start;
|
|
149
|
+
let rangeEnd = mappedRange.end;
|
|
150
|
+
const exactMatchIndexes: number[] = [];
|
|
151
|
+
let searchFrom = 0;
|
|
152
|
+
while (searchFrom <= sourceText.length) {
|
|
153
|
+
const exactMatchIndex = sourceText.indexOf(diagnostic.expressionText, searchFrom);
|
|
154
|
+
if (exactMatchIndex === -1) {
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
exactMatchIndexes.push(exactMatchIndex);
|
|
158
|
+
searchFrom = exactMatchIndex + 1;
|
|
159
|
+
}
|
|
160
|
+
const inMappedRange = exactMatchIndexes.find((index) =>
|
|
161
|
+
index >= mappedRange.start && index < mappedRange.end
|
|
162
|
+
);
|
|
163
|
+
const refinedIndex = inMappedRange ??
|
|
164
|
+
(exactMatchIndexes.length === 1 ? exactMatchIndexes[0] : undefined);
|
|
165
|
+
if (refinedIndex !== undefined) {
|
|
166
|
+
rangeStart = refinedIndex;
|
|
167
|
+
rangeEnd = refinedIndex + diagnostic.expressionText.length;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const start = getLineAndCharacterOfPosition(sourceText, rangeStart);
|
|
171
|
+
const end = getLineAndCharacterOfPosition(sourceText, rangeEnd);
|
|
172
|
+
return {
|
|
173
|
+
source: 'cli',
|
|
174
|
+
code: 'SOUNDSCRIPT_NUMERIC_MIXED_LEAF',
|
|
175
|
+
category: 'error',
|
|
176
|
+
message:
|
|
177
|
+
`Mixed machine numeric arithmetic between \`${diagnostic.leftLeaf}\` and \`${diagnostic.rightLeaf}\` requires explicit coercion.`,
|
|
178
|
+
hint: 'Coerce one side explicitly before applying this operator.',
|
|
179
|
+
filePath: toSourceFileName(diagnostic.fileName),
|
|
180
|
+
line: start.line + 1,
|
|
181
|
+
column: start.character + 1,
|
|
182
|
+
endLine: end.line + 1,
|
|
183
|
+
endColumn: end.character + 1,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function createAbstractNumericFamilyDiagnostic(
|
|
188
|
+
diagnostic: AbstractNumericFamilyArithmetic,
|
|
189
|
+
preparedFile: PreparedSourceFile | undefined,
|
|
190
|
+
fallbackSourceText: string,
|
|
191
|
+
): MergedDiagnostic {
|
|
192
|
+
const mappedRange = preparedFile
|
|
193
|
+
? mapProgramRangeToSource(preparedFile, diagnostic.start, diagnostic.end)
|
|
194
|
+
: {
|
|
195
|
+
intersectsReplacement: false,
|
|
196
|
+
start: diagnostic.start,
|
|
197
|
+
end: diagnostic.end,
|
|
198
|
+
};
|
|
199
|
+
const sourceText = preparedFile?.originalText ?? fallbackSourceText;
|
|
200
|
+
let rangeStart = mappedRange.start;
|
|
201
|
+
let rangeEnd = mappedRange.end;
|
|
202
|
+
const exactMatchIndexes: number[] = [];
|
|
203
|
+
let searchFrom = 0;
|
|
204
|
+
while (searchFrom <= sourceText.length) {
|
|
205
|
+
const exactMatchIndex = sourceText.indexOf(diagnostic.expressionText, searchFrom);
|
|
206
|
+
if (exactMatchIndex === -1) {
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
exactMatchIndexes.push(exactMatchIndex);
|
|
210
|
+
searchFrom = exactMatchIndex + 1;
|
|
211
|
+
}
|
|
212
|
+
const inMappedRange = exactMatchIndexes.find((index) =>
|
|
213
|
+
index >= mappedRange.start && index < mappedRange.end
|
|
214
|
+
);
|
|
215
|
+
const refinedIndex = inMappedRange ??
|
|
216
|
+
(exactMatchIndexes.length === 1 ? exactMatchIndexes[0] : undefined);
|
|
217
|
+
if (refinedIndex !== undefined) {
|
|
218
|
+
rangeStart = refinedIndex;
|
|
219
|
+
rangeEnd = refinedIndex + diagnostic.expressionText.length;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const start = getLineAndCharacterOfPosition(sourceText, rangeStart);
|
|
223
|
+
const end = getLineAndCharacterOfPosition(sourceText, rangeEnd);
|
|
224
|
+
const familyText = diagnostic.abstractFamilies.map((family) => `\`${family}\``).join(' and ');
|
|
225
|
+
return {
|
|
226
|
+
source: 'cli',
|
|
227
|
+
code: 'SOUNDSCRIPT_NUMERIC_ABSTRACT_FAMILY',
|
|
228
|
+
category: 'error',
|
|
229
|
+
message:
|
|
230
|
+
`Applying numeric operator \`${diagnostic.operatorText}\` to abstract numeric family ${familyText} requires narrowing to a carrier or coercing to a concrete machine leaf first.`,
|
|
231
|
+
hint:
|
|
232
|
+
'Use `typeof` to narrow to `number` or `bigint`, or coerce explicitly with a machine numeric helper first.',
|
|
233
|
+
filePath: toSourceFileName(diagnostic.fileName),
|
|
234
|
+
line: start.line + 1,
|
|
235
|
+
column: start.character + 1,
|
|
236
|
+
endLine: end.line + 1,
|
|
237
|
+
endColumn: end.character + 1,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function createSortComparatorRequiredDiagnostic(
|
|
242
|
+
diagnostic: SortCallWithoutComparator,
|
|
243
|
+
preparedFile: PreparedSourceFile | undefined,
|
|
244
|
+
fallbackSourceText: string,
|
|
245
|
+
): MergedDiagnostic {
|
|
246
|
+
const mappedRange = preparedFile
|
|
247
|
+
? mapProgramRangeToSource(preparedFile, diagnostic.start, diagnostic.end)
|
|
248
|
+
: {
|
|
249
|
+
intersectsReplacement: false,
|
|
250
|
+
start: diagnostic.start,
|
|
251
|
+
end: diagnostic.end,
|
|
252
|
+
};
|
|
253
|
+
const sourceText = preparedFile?.originalText ?? fallbackSourceText;
|
|
254
|
+
let rangeStart = mappedRange.start;
|
|
255
|
+
let rangeEnd = mappedRange.end;
|
|
256
|
+
const exactMatchIndex = sourceText.indexOf(diagnostic.expressionText, mappedRange.start);
|
|
257
|
+
if (exactMatchIndex !== -1) {
|
|
258
|
+
rangeStart = exactMatchIndex;
|
|
259
|
+
rangeEnd = exactMatchIndex + diagnostic.expressionText.length;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const start = getLineAndCharacterOfPosition(sourceText, rangeStart);
|
|
263
|
+
const end = getLineAndCharacterOfPosition(sourceText, rangeEnd);
|
|
264
|
+
return {
|
|
265
|
+
source: 'cli',
|
|
266
|
+
code: 'SOUNDSCRIPT_SORT_COMPARE_REQUIRED',
|
|
267
|
+
category: 'error',
|
|
268
|
+
message: `In .sts, \`${diagnostic.methodName}()\` requires an explicit comparator.`,
|
|
269
|
+
hint: 'Pass an explicit compare function such as `values.sort(F64.compare)`.',
|
|
270
|
+
filePath: toSourceFileName(diagnostic.fileName),
|
|
271
|
+
line: start.line + 1,
|
|
272
|
+
column: start.character + 1,
|
|
273
|
+
endLine: end.line + 1,
|
|
274
|
+
endColumn: end.character + 1,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function isSingleExpressionReplacement(text: string): boolean {
|
|
279
|
+
const probeSource = ts.createSourceFile(
|
|
280
|
+
'/__soundscript_macro_probe__.tsx',
|
|
281
|
+
`const __sts_value = ${text};`,
|
|
282
|
+
ts.ScriptTarget.Latest,
|
|
283
|
+
true,
|
|
284
|
+
ts.ScriptKind.TSX,
|
|
285
|
+
);
|
|
286
|
+
const parseDiagnostics = (
|
|
287
|
+
probeSource as ts.SourceFile & { parseDiagnostics?: readonly ts.Diagnostic[] }
|
|
288
|
+
).parseDiagnostics ?? [];
|
|
289
|
+
if (parseDiagnostics.length > 0 || probeSource.statements.length !== 1) {
|
|
290
|
+
return false;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const [statement] = probeSource.statements;
|
|
294
|
+
return ts.isVariableStatement(statement) &&
|
|
295
|
+
statement.declarationList.declarations.length === 1 &&
|
|
296
|
+
!!statement.declarationList.declarations[0]?.initializer;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function stripGeneratedCommentTrivia(text: string): string {
|
|
300
|
+
const scanner = ts.createScanner(
|
|
301
|
+
ts.ScriptTarget.Latest,
|
|
302
|
+
false,
|
|
303
|
+
ts.LanguageVariant.Standard,
|
|
304
|
+
text,
|
|
305
|
+
);
|
|
306
|
+
let sanitized = '';
|
|
307
|
+
|
|
308
|
+
for (let token = scanner.scan(); token !== ts.SyntaxKind.EndOfFileToken; token = scanner.scan()) {
|
|
309
|
+
if (
|
|
310
|
+
token === ts.SyntaxKind.SingleLineCommentTrivia ||
|
|
311
|
+
token === ts.SyntaxKind.MultiLineCommentTrivia
|
|
312
|
+
) {
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
sanitized += scanner.getTokenText();
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return sanitized;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function findEnclosingReplacementSpan(
|
|
322
|
+
sourceFile: ts.SourceFile,
|
|
323
|
+
start: number,
|
|
324
|
+
end: number,
|
|
325
|
+
): { start: number; end: number } {
|
|
326
|
+
let best: ts.Node | undefined;
|
|
327
|
+
|
|
328
|
+
const visit = (node: ts.Node): void => {
|
|
329
|
+
const nodeStart = node.getStart(sourceFile);
|
|
330
|
+
const nodeEnd = node.getEnd();
|
|
331
|
+
if (start < nodeStart || end > nodeEnd) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const isCandidate = (ts.isStatement(node) && !ts.isBlock(node)) ||
|
|
336
|
+
(ts.isExpression(node) && ts.isArrowFunction(node.parent) && node.parent.body === node);
|
|
337
|
+
if (isCandidate) {
|
|
338
|
+
if (!best || (nodeEnd - nodeStart) < (best.getEnd() - best.getStart(sourceFile))) {
|
|
339
|
+
best = node;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
ts.forEachChild(node, visit);
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
visit(sourceFile);
|
|
347
|
+
|
|
348
|
+
if (!best) {
|
|
349
|
+
return { start, end };
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
return {
|
|
353
|
+
start: best.getStart(sourceFile),
|
|
354
|
+
end: best.getEnd(),
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function buildDiagnosticPreparedSourceFile(
|
|
359
|
+
originalPreparedFile: PreparedSourceFile,
|
|
360
|
+
annotatedExpandedText: string,
|
|
361
|
+
placeholdersById: ReadonlyMap<number, IndexedMacroPlaceholder>,
|
|
362
|
+
augmentPlaceholderIds: ReadonlySet<number>,
|
|
363
|
+
includeProgramRewriteStage = false,
|
|
364
|
+
): { cleanedProgramText: string; preparedFile: PreparedSourceFile } {
|
|
365
|
+
const startPrefix = `${MACRO_EXPANSION_START_MARKER_PREFIX}`;
|
|
366
|
+
const endPrefix = `${MACRO_EXPANSION_END_MARKER_PREFIX}`;
|
|
367
|
+
const tokenPattern = new RegExp(
|
|
368
|
+
`/\\*(${startPrefix}\\d+__|${endPrefix}\\d+__)\\*/`,
|
|
369
|
+
'gu',
|
|
370
|
+
);
|
|
371
|
+
const expansionTexts = new Map<number, string>();
|
|
372
|
+
const openContentStarts = new Map<number, number>();
|
|
373
|
+
const replacements: Array<PreparedSourceFile['rewriteResult']['replacements'][number]> = [];
|
|
374
|
+
const cleanedProgramParts: string[] = [];
|
|
375
|
+
let cleanedProgramCursor = 0;
|
|
376
|
+
|
|
377
|
+
for (const match of annotatedExpandedText.matchAll(tokenPattern)) {
|
|
378
|
+
const markerText = match[1];
|
|
379
|
+
const rawText = match[0];
|
|
380
|
+
const index = match.index ?? 0;
|
|
381
|
+
const rawEnd = index + rawText.length;
|
|
382
|
+
|
|
383
|
+
if (markerText.startsWith(startPrefix)) {
|
|
384
|
+
cleanedProgramParts.push(annotatedExpandedText.slice(cleanedProgramCursor, index));
|
|
385
|
+
cleanedProgramCursor = rawEnd;
|
|
386
|
+
const id = Number(markerText.slice(startPrefix.length, -2));
|
|
387
|
+
openContentStarts.set(id, rawEnd);
|
|
388
|
+
} else if (markerText.startsWith(endPrefix)) {
|
|
389
|
+
const id = Number(markerText.slice(endPrefix.length, -2));
|
|
390
|
+
const contentStart = openContentStarts.get(id);
|
|
391
|
+
if (contentStart !== undefined) {
|
|
392
|
+
const sanitizedExpansionText = stripGeneratedCommentTrivia(
|
|
393
|
+
annotatedExpandedText.slice(contentStart, index),
|
|
394
|
+
);
|
|
395
|
+
expansionTexts.set(id, sanitizedExpansionText);
|
|
396
|
+
cleanedProgramParts.push(sanitizedExpansionText);
|
|
397
|
+
cleanedProgramCursor = rawEnd;
|
|
398
|
+
}
|
|
399
|
+
openContentStarts.delete(id);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
cleanedProgramParts.push(annotatedExpandedText.slice(cleanedProgramCursor));
|
|
403
|
+
const cleanedProgramText = cleanedProgramParts.join('');
|
|
404
|
+
|
|
405
|
+
const rewrittenParts: string[] = [];
|
|
406
|
+
const originalText = originalPreparedFile.originalText;
|
|
407
|
+
const originalSourceFile = ts.createSourceFile(
|
|
408
|
+
originalPreparedFile.rewriteResult.replacements[0]?.originalSpan.fileName ??
|
|
409
|
+
'/__soundscript_macro_original__.tsx',
|
|
410
|
+
originalText,
|
|
411
|
+
ts.ScriptTarget.Latest,
|
|
412
|
+
true,
|
|
413
|
+
ts.ScriptKind.TSX,
|
|
414
|
+
);
|
|
415
|
+
const orderedPlaceholders = [...placeholdersById.values()].sort((left, right) =>
|
|
416
|
+
left.replacement.originalSpan.start - right.replacement.originalSpan.start
|
|
417
|
+
);
|
|
418
|
+
let originalCursor = 0;
|
|
419
|
+
let rewrittenLength = 0;
|
|
420
|
+
|
|
421
|
+
for (const placeholder of orderedPlaceholders) {
|
|
422
|
+
const { id, replacement } = placeholder;
|
|
423
|
+
const expansionText = expansionTexts.get(id) ?? replacement.rewriteText;
|
|
424
|
+
const sourceMappedDeclarationSpan = augmentPlaceholderIds.has(id)
|
|
425
|
+
? placeholder.invocation.declarationSpan
|
|
426
|
+
: undefined;
|
|
427
|
+
const targetSpan = isSingleExpressionReplacement(expansionText)
|
|
428
|
+
? replacement.originalSpan
|
|
429
|
+
: (() => {
|
|
430
|
+
const originalTargetSpan = findEnclosingReplacementSpan(
|
|
431
|
+
originalSourceFile,
|
|
432
|
+
replacement.originalSpan.start,
|
|
433
|
+
replacement.originalSpan.end,
|
|
434
|
+
);
|
|
435
|
+
return {
|
|
436
|
+
fileName: replacement.originalSpan.fileName,
|
|
437
|
+
start: originalTargetSpan.start,
|
|
438
|
+
end: originalTargetSpan.end,
|
|
439
|
+
};
|
|
440
|
+
})();
|
|
441
|
+
if (targetSpan.start < originalCursor) {
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
const before = originalText.slice(originalCursor, targetSpan.start);
|
|
446
|
+
rewrittenParts.push(before);
|
|
447
|
+
rewrittenLength += before.length;
|
|
448
|
+
|
|
449
|
+
const rewrittenStart = rewrittenLength;
|
|
450
|
+
const sourceMappedText = sourceMappedDeclarationSpan
|
|
451
|
+
? originalText.slice(sourceMappedDeclarationSpan.start, sourceMappedDeclarationSpan.end)
|
|
452
|
+
: expansionText;
|
|
453
|
+
rewrittenParts.push(sourceMappedText);
|
|
454
|
+
rewrittenLength += sourceMappedText.length;
|
|
455
|
+
replacements.push({
|
|
456
|
+
id,
|
|
457
|
+
mappedSegments: sourceMappedDeclarationSpan
|
|
458
|
+
? [{
|
|
459
|
+
originalStart: sourceMappedDeclarationSpan.start,
|
|
460
|
+
originalEnd: sourceMappedDeclarationSpan.end,
|
|
461
|
+
rewrittenStart,
|
|
462
|
+
rewrittenEnd: rewrittenLength,
|
|
463
|
+
}]
|
|
464
|
+
: undefined,
|
|
465
|
+
originalSpan: targetSpan,
|
|
466
|
+
rewriteText: sourceMappedText,
|
|
467
|
+
rewrittenSpan: {
|
|
468
|
+
fileName: targetSpan.fileName,
|
|
469
|
+
start: rewrittenStart,
|
|
470
|
+
end: rewrittenLength,
|
|
471
|
+
},
|
|
472
|
+
});
|
|
473
|
+
originalCursor = targetSpan.end;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
const trailing = originalText.slice(originalCursor);
|
|
477
|
+
rewrittenParts.push(trailing);
|
|
478
|
+
const cleanedText = rewrittenParts.join('');
|
|
479
|
+
|
|
480
|
+
replacements.sort((left, right) => left.originalSpan.start - right.originalSpan.start);
|
|
481
|
+
|
|
482
|
+
return {
|
|
483
|
+
cleanedProgramText,
|
|
484
|
+
preparedFile: {
|
|
485
|
+
diagnostics: [],
|
|
486
|
+
originalText: originalPreparedFile.originalText,
|
|
487
|
+
postRewriteStage: includeProgramRewriteStage && cleanedText !== cleanedProgramText
|
|
488
|
+
? buildRewriteStageFromTexts(
|
|
489
|
+
orderedPlaceholders[0]?.replacement.originalSpan.fileName ??
|
|
490
|
+
originalPreparedFile.rewriteResult.replacements[0]?.originalSpan.fileName ??
|
|
491
|
+
'/__soundscript_macro_diagnostic__.tsx',
|
|
492
|
+
cleanedText,
|
|
493
|
+
cleanedProgramText,
|
|
494
|
+
)
|
|
495
|
+
: undefined,
|
|
496
|
+
rewriteResult: {
|
|
497
|
+
diagnostics: [],
|
|
498
|
+
generatedSpans: [],
|
|
499
|
+
macrosById: originalPreparedFile.rewriteResult.macrosById,
|
|
500
|
+
replacements,
|
|
501
|
+
rewrittenText: cleanedText,
|
|
502
|
+
},
|
|
503
|
+
rewrittenText: includeProgramRewriteStage ? cleanedProgramText : cleanedText,
|
|
504
|
+
},
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
export function getBuiltinMacroDefinitionsBySpecifier(): ReadonlyMap<
|
|
509
|
+
string,
|
|
510
|
+
ReadonlyMap<string, MacroDefinition>
|
|
511
|
+
> {
|
|
512
|
+
return withBuiltinRuntimeSpecifierAliases<ReadonlyMap<string, MacroDefinition>>([
|
|
513
|
+
[
|
|
514
|
+
HKT_STDLIB_MODULE_SPECIFIER,
|
|
515
|
+
collectNamedMacroDefinitions(
|
|
516
|
+
HKT_STDLIB_MODULE_SPECIFIER,
|
|
517
|
+
{ hkt: hktMacro },
|
|
518
|
+
),
|
|
519
|
+
],
|
|
520
|
+
[
|
|
521
|
+
TYPECLASSES_STDLIB_MODULE_SPECIFIER,
|
|
522
|
+
collectNamedMacroDefinitions(
|
|
523
|
+
TYPECLASSES_STDLIB_MODULE_SPECIFIER,
|
|
524
|
+
{ Do },
|
|
525
|
+
),
|
|
526
|
+
],
|
|
527
|
+
[
|
|
528
|
+
DERIVE_STDLIB_MODULE_SPECIFIER,
|
|
529
|
+
collectNamedMacroDefinitions(
|
|
530
|
+
DERIVE_STDLIB_MODULE_SPECIFIER,
|
|
531
|
+
{
|
|
532
|
+
codec: codecMacro,
|
|
533
|
+
decode: decodeMacro,
|
|
534
|
+
encode: encodeMacro,
|
|
535
|
+
eq: eqMacro,
|
|
536
|
+
hash: hashMacro,
|
|
537
|
+
tagged: taggedMacro,
|
|
538
|
+
},
|
|
539
|
+
),
|
|
540
|
+
],
|
|
541
|
+
[
|
|
542
|
+
RESULT_STDLIB_MODULE_SPECIFIER,
|
|
543
|
+
collectNamedMacroDefinitions(
|
|
544
|
+
RESULT_STDLIB_MODULE_SPECIFIER,
|
|
545
|
+
{ Try },
|
|
546
|
+
),
|
|
547
|
+
],
|
|
548
|
+
[
|
|
549
|
+
MATCH_STDLIB_MODULE_SPECIFIER,
|
|
550
|
+
collectNamedMacroDefinitions(
|
|
551
|
+
MATCH_STDLIB_MODULE_SPECIFIER,
|
|
552
|
+
{ Match },
|
|
553
|
+
),
|
|
554
|
+
],
|
|
555
|
+
[
|
|
556
|
+
MATCH_STDLIB_MODULE_SPECIFIER,
|
|
557
|
+
collectNamedMacroDefinitions(
|
|
558
|
+
MATCH_STDLIB_MODULE_SPECIFIER,
|
|
559
|
+
{ Match },
|
|
560
|
+
),
|
|
561
|
+
],
|
|
562
|
+
[
|
|
563
|
+
THUNK_STDLIB_MODULE_SPECIFIER,
|
|
564
|
+
collectNamedMacroDefinitions(
|
|
565
|
+
THUNK_STDLIB_MODULE_SPECIFIER,
|
|
566
|
+
{ lazy, memo },
|
|
567
|
+
),
|
|
568
|
+
],
|
|
569
|
+
[
|
|
570
|
+
STDLIB_MODULE_SPECIFIER,
|
|
571
|
+
collectNamedMacroDefinitions(
|
|
572
|
+
STDLIB_MODULE_SPECIFIER,
|
|
573
|
+
{ Defer, Match, todo, Try, unreachable },
|
|
574
|
+
),
|
|
575
|
+
],
|
|
576
|
+
[
|
|
577
|
+
SQL_STDLIB_MODULE_SPECIFIER,
|
|
578
|
+
collectNamedMacroDefinitions(
|
|
579
|
+
SQL_STDLIB_MODULE_SPECIFIER,
|
|
580
|
+
{ sql },
|
|
581
|
+
),
|
|
582
|
+
],
|
|
583
|
+
[
|
|
584
|
+
CSS_STDLIB_MODULE_SPECIFIER,
|
|
585
|
+
collectNamedMacroDefinitions(
|
|
586
|
+
CSS_STDLIB_MODULE_SPECIFIER,
|
|
587
|
+
{ css },
|
|
588
|
+
),
|
|
589
|
+
],
|
|
590
|
+
[
|
|
591
|
+
GRAPHQL_STDLIB_MODULE_SPECIFIER,
|
|
592
|
+
collectNamedMacroDefinitions(
|
|
593
|
+
GRAPHQL_STDLIB_MODULE_SPECIFIER,
|
|
594
|
+
{ graphql },
|
|
595
|
+
),
|
|
596
|
+
],
|
|
597
|
+
[
|
|
598
|
+
DEBUG_STDLIB_MODULE_SPECIFIER,
|
|
599
|
+
collectNamedMacroDefinitions(
|
|
600
|
+
DEBUG_STDLIB_MODULE_SPECIFIER,
|
|
601
|
+
{ assert: assertMacro, log },
|
|
602
|
+
),
|
|
603
|
+
],
|
|
604
|
+
]);
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
function collectMacroSiteKindsFromFactories(
|
|
608
|
+
factories: Readonly<Record<string, unknown>>,
|
|
609
|
+
): ReadonlyMap<string, ImportedMacroSiteKind> {
|
|
610
|
+
const kinds = new Map<string, ImportedMacroSiteKind>();
|
|
611
|
+
for (const [exportName, factory] of Object.entries(factories)) {
|
|
612
|
+
const metadata = getMacroFactoryMetadata(factory);
|
|
613
|
+
if (!metadata) {
|
|
614
|
+
continue;
|
|
615
|
+
}
|
|
616
|
+
kinds.set(
|
|
617
|
+
exportName,
|
|
618
|
+
metadata.form === 'decl' ? 'annotation' : metadata.form,
|
|
619
|
+
);
|
|
620
|
+
}
|
|
621
|
+
return kinds;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
export function getBuiltinMacroSiteKindsBySpecifier(): ReadonlyMap<
|
|
625
|
+
string,
|
|
626
|
+
ReadonlyMap<string, ImportedMacroSiteKind>
|
|
627
|
+
> {
|
|
628
|
+
return withBuiltinRuntimeSpecifierAliases<ReadonlyMap<string, ImportedMacroSiteKind>>([
|
|
629
|
+
[HKT_STDLIB_MODULE_SPECIFIER, collectMacroSiteKindsFromFactories({ hkt: hktMacro })],
|
|
630
|
+
[TYPECLASSES_STDLIB_MODULE_SPECIFIER, collectMacroSiteKindsFromFactories({ Do })],
|
|
631
|
+
[
|
|
632
|
+
DERIVE_STDLIB_MODULE_SPECIFIER,
|
|
633
|
+
collectMacroSiteKindsFromFactories({
|
|
634
|
+
codec: codecMacro,
|
|
635
|
+
decode: decodeMacro,
|
|
636
|
+
encode: encodeMacro,
|
|
637
|
+
eq: eqMacro,
|
|
638
|
+
hash: hashMacro,
|
|
639
|
+
tagged: taggedMacro,
|
|
640
|
+
}),
|
|
641
|
+
],
|
|
642
|
+
[RESULT_STDLIB_MODULE_SPECIFIER, collectMacroSiteKindsFromFactories({ Try })],
|
|
643
|
+
[MATCH_STDLIB_MODULE_SPECIFIER, collectMacroSiteKindsFromFactories({ Match })],
|
|
644
|
+
[THUNK_STDLIB_MODULE_SPECIFIER, collectMacroSiteKindsFromFactories({ lazy, memo })],
|
|
645
|
+
[
|
|
646
|
+
STDLIB_MODULE_SPECIFIER,
|
|
647
|
+
collectMacroSiteKindsFromFactories({ Defer, Match, todo, Try, unreachable }),
|
|
648
|
+
],
|
|
649
|
+
[SQL_STDLIB_MODULE_SPECIFIER, collectMacroSiteKindsFromFactories({ sql })],
|
|
650
|
+
[CSS_STDLIB_MODULE_SPECIFIER, collectMacroSiteKindsFromFactories({ css })],
|
|
651
|
+
[GRAPHQL_STDLIB_MODULE_SPECIFIER, collectMacroSiteKindsFromFactories({ graphql })],
|
|
652
|
+
[
|
|
653
|
+
DEBUG_STDLIB_MODULE_SPECIFIER,
|
|
654
|
+
collectMacroSiteKindsFromFactories({ assert: assertMacro, log }),
|
|
655
|
+
],
|
|
656
|
+
]);
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
export function getAlwaysAvailableBuiltinMacroDefinitions(): ReadonlyMap<string, MacroDefinition> {
|
|
660
|
+
return new Map<string, MacroDefinition>([
|
|
661
|
+
['Defer', Defer() as MacroDefinition],
|
|
662
|
+
['Match', Match() as MacroDefinition],
|
|
663
|
+
['Try', Try() as MacroDefinition],
|
|
664
|
+
['todo', todo() as MacroDefinition],
|
|
665
|
+
['unreachable', unreachable() as MacroDefinition],
|
|
666
|
+
]);
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
export function getAlwaysAvailableBuiltinMacroExports(
|
|
670
|
+
preparedProgram: PreparedProgram,
|
|
671
|
+
): LoadedNamedMacroExports {
|
|
672
|
+
return collectNamedMacroExports(
|
|
673
|
+
STDLIB_MODULE_SPECIFIER,
|
|
674
|
+
{ Defer, Match, todo, Try, unreachable },
|
|
675
|
+
preparedProgram,
|
|
676
|
+
);
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
export function getAlwaysAvailableBuiltinMacroSiteKinds(): ReadonlyMap<
|
|
680
|
+
string,
|
|
681
|
+
ImportedMacroSiteKind
|
|
682
|
+
> {
|
|
683
|
+
return new Map([
|
|
684
|
+
['Defer', 'call'],
|
|
685
|
+
['Match', 'call'],
|
|
686
|
+
['Try', 'call'],
|
|
687
|
+
['todo', 'call'],
|
|
688
|
+
['unreachable', 'call'],
|
|
689
|
+
]);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
export function getBuiltinMacroExportsBySpecifier(
|
|
693
|
+
preparedProgram: PreparedProgram,
|
|
694
|
+
): ReadonlyMap<string, LoadedNamedMacroExports> {
|
|
695
|
+
return withBuiltinRuntimeSpecifierAliases<LoadedNamedMacroExports>([
|
|
696
|
+
[
|
|
697
|
+
HKT_STDLIB_MODULE_SPECIFIER,
|
|
698
|
+
collectNamedMacroExports(
|
|
699
|
+
HKT_STDLIB_MODULE_SPECIFIER,
|
|
700
|
+
{ hkt: hktMacro },
|
|
701
|
+
preparedProgram,
|
|
702
|
+
),
|
|
703
|
+
],
|
|
704
|
+
[
|
|
705
|
+
TYPECLASSES_STDLIB_MODULE_SPECIFIER,
|
|
706
|
+
collectNamedMacroExports(
|
|
707
|
+
TYPECLASSES_STDLIB_MODULE_SPECIFIER,
|
|
708
|
+
{ Do },
|
|
709
|
+
preparedProgram,
|
|
710
|
+
),
|
|
711
|
+
],
|
|
712
|
+
[
|
|
713
|
+
DERIVE_STDLIB_MODULE_SPECIFIER,
|
|
714
|
+
collectNamedMacroExports(
|
|
715
|
+
DERIVE_STDLIB_MODULE_SPECIFIER,
|
|
716
|
+
{
|
|
717
|
+
codec: codecMacro,
|
|
718
|
+
decode: decodeMacro,
|
|
719
|
+
encode: encodeMacro,
|
|
720
|
+
eq: eqMacro,
|
|
721
|
+
hash: hashMacro,
|
|
722
|
+
tagged: taggedMacro,
|
|
723
|
+
},
|
|
724
|
+
preparedProgram,
|
|
725
|
+
),
|
|
726
|
+
],
|
|
727
|
+
[
|
|
728
|
+
RESULT_STDLIB_MODULE_SPECIFIER,
|
|
729
|
+
collectNamedMacroExports(
|
|
730
|
+
RESULT_STDLIB_MODULE_SPECIFIER,
|
|
731
|
+
{ Try },
|
|
732
|
+
preparedProgram,
|
|
733
|
+
),
|
|
734
|
+
],
|
|
735
|
+
[
|
|
736
|
+
MATCH_STDLIB_MODULE_SPECIFIER,
|
|
737
|
+
collectNamedMacroExports(
|
|
738
|
+
MATCH_STDLIB_MODULE_SPECIFIER,
|
|
739
|
+
{ Match },
|
|
740
|
+
preparedProgram,
|
|
741
|
+
),
|
|
742
|
+
],
|
|
743
|
+
[
|
|
744
|
+
MATCH_STDLIB_MODULE_SPECIFIER,
|
|
745
|
+
collectNamedMacroExports(
|
|
746
|
+
MATCH_STDLIB_MODULE_SPECIFIER,
|
|
747
|
+
{ Match },
|
|
748
|
+
preparedProgram,
|
|
749
|
+
),
|
|
750
|
+
],
|
|
751
|
+
[
|
|
752
|
+
THUNK_STDLIB_MODULE_SPECIFIER,
|
|
753
|
+
collectNamedMacroExports(
|
|
754
|
+
THUNK_STDLIB_MODULE_SPECIFIER,
|
|
755
|
+
{ lazy, memo },
|
|
756
|
+
preparedProgram,
|
|
757
|
+
),
|
|
758
|
+
],
|
|
759
|
+
[
|
|
760
|
+
STDLIB_MODULE_SPECIFIER,
|
|
761
|
+
collectNamedMacroExports(
|
|
762
|
+
STDLIB_MODULE_SPECIFIER,
|
|
763
|
+
{ Defer, Match, todo, Try, unreachable },
|
|
764
|
+
preparedProgram,
|
|
765
|
+
),
|
|
766
|
+
],
|
|
767
|
+
[
|
|
768
|
+
SQL_STDLIB_MODULE_SPECIFIER,
|
|
769
|
+
collectNamedMacroExports(
|
|
770
|
+
SQL_STDLIB_MODULE_SPECIFIER,
|
|
771
|
+
{ sql },
|
|
772
|
+
preparedProgram,
|
|
773
|
+
),
|
|
774
|
+
],
|
|
775
|
+
[
|
|
776
|
+
CSS_STDLIB_MODULE_SPECIFIER,
|
|
777
|
+
collectNamedMacroExports(
|
|
778
|
+
CSS_STDLIB_MODULE_SPECIFIER,
|
|
779
|
+
{ css },
|
|
780
|
+
preparedProgram,
|
|
781
|
+
),
|
|
782
|
+
],
|
|
783
|
+
[
|
|
784
|
+
GRAPHQL_STDLIB_MODULE_SPECIFIER,
|
|
785
|
+
collectNamedMacroExports(
|
|
786
|
+
GRAPHQL_STDLIB_MODULE_SPECIFIER,
|
|
787
|
+
{ graphql },
|
|
788
|
+
preparedProgram,
|
|
789
|
+
),
|
|
790
|
+
],
|
|
791
|
+
[
|
|
792
|
+
DEBUG_STDLIB_MODULE_SPECIFIER,
|
|
793
|
+
collectNamedMacroExports(
|
|
794
|
+
DEBUG_STDLIB_MODULE_SPECIFIER,
|
|
795
|
+
{ assert: assertMacro, log },
|
|
796
|
+
preparedProgram,
|
|
797
|
+
),
|
|
798
|
+
],
|
|
799
|
+
]);
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
export function getBuiltinMacroFactoriesBySpecifier(): ReadonlyMap<
|
|
803
|
+
string,
|
|
804
|
+
Readonly<Record<string, unknown>>
|
|
805
|
+
> {
|
|
806
|
+
return withBuiltinRuntimeSpecifierAliases<Readonly<Record<string, unknown>>>([
|
|
807
|
+
[HKT_STDLIB_MODULE_SPECIFIER, { hkt: hktMacro }],
|
|
808
|
+
[TYPECLASSES_STDLIB_MODULE_SPECIFIER, { Do }],
|
|
809
|
+
[
|
|
810
|
+
DERIVE_STDLIB_MODULE_SPECIFIER,
|
|
811
|
+
{
|
|
812
|
+
codec: codecMacro,
|
|
813
|
+
decode: decodeMacro,
|
|
814
|
+
encode: encodeMacro,
|
|
815
|
+
eq: eqMacro,
|
|
816
|
+
hash: hashMacro,
|
|
817
|
+
tagged: taggedMacro,
|
|
818
|
+
},
|
|
819
|
+
],
|
|
820
|
+
[RESULT_STDLIB_MODULE_SPECIFIER, { Try }],
|
|
821
|
+
[MATCH_STDLIB_MODULE_SPECIFIER, { Match }],
|
|
822
|
+
[THUNK_STDLIB_MODULE_SPECIFIER, { lazy, memo }],
|
|
823
|
+
[STDLIB_MODULE_SPECIFIER, { Defer, Match, todo, Try, unreachable }],
|
|
824
|
+
[SQL_STDLIB_MODULE_SPECIFIER, { sql }],
|
|
825
|
+
[CSS_STDLIB_MODULE_SPECIFIER, { css }],
|
|
826
|
+
[GRAPHQL_STDLIB_MODULE_SPECIFIER, { graphql }],
|
|
827
|
+
[DEBUG_STDLIB_MODULE_SPECIFIER, { assert: assertMacro, log }],
|
|
828
|
+
]);
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
function mapsEqual(
|
|
832
|
+
left: ReadonlyMap<string, string>,
|
|
833
|
+
right: ReadonlyMap<string, string>,
|
|
834
|
+
): boolean {
|
|
835
|
+
if (left.size !== right.size) {
|
|
836
|
+
return false;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
for (const [key, value] of left) {
|
|
840
|
+
if (right.get(key) !== value) {
|
|
841
|
+
return false;
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
return true;
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
function programMatchesOverrides(
|
|
849
|
+
preparedProgram: PreparedProgram,
|
|
850
|
+
overrides: ReadonlyMap<string, string>,
|
|
851
|
+
): boolean {
|
|
852
|
+
for (const [sourceFileName, text] of overrides) {
|
|
853
|
+
const sourceFile = preparedProgram.program.getSourceFile(
|
|
854
|
+
preparedProgram.toProgramFileName(sourceFileName),
|
|
855
|
+
);
|
|
856
|
+
if (!sourceFile || sourceFile.text !== text) {
|
|
857
|
+
return false;
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
return true;
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
function sourceFileImportsBuiltinMacros(sourceFile: ts.SourceFile | undefined): boolean {
|
|
865
|
+
if (!sourceFile) {
|
|
866
|
+
return false;
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
const builtinSpecifiers = new Set(getBuiltinMacroDefinitionsBySpecifier().keys());
|
|
870
|
+
return sourceFile.statements.some((statement) =>
|
|
871
|
+
ts.isImportDeclaration(statement) &&
|
|
872
|
+
ts.isStringLiteral(statement.moduleSpecifier) &&
|
|
873
|
+
builtinSpecifiers.has(statement.moduleSpecifier.text) &&
|
|
874
|
+
!!statement.importClause?.namedBindings &&
|
|
875
|
+
ts.isNamedImports(statement.importClause.namedBindings)
|
|
876
|
+
);
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
function createBuiltinMacroDiagnostic(error: MacroError): MergedDiagnostic {
|
|
880
|
+
return {
|
|
881
|
+
source: 'cli',
|
|
882
|
+
code: error.code,
|
|
883
|
+
category: 'error',
|
|
884
|
+
message: error.message,
|
|
885
|
+
filePath: error.filePath,
|
|
886
|
+
line: error.line,
|
|
887
|
+
column: error.column,
|
|
888
|
+
endLine: error.endLine,
|
|
889
|
+
endColumn: error.endColumn,
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
export function withBuiltinMacroSupport(
|
|
894
|
+
options: CreatePreparedProgramOptions,
|
|
895
|
+
): CreatePreparedProgramOptions {
|
|
896
|
+
const runtime = options.runtime ?? normalizeRuntimeContext({
|
|
897
|
+
externs: [],
|
|
898
|
+
target: 'js-node',
|
|
899
|
+
});
|
|
900
|
+
|
|
901
|
+
return {
|
|
902
|
+
...options,
|
|
903
|
+
alwaysAvailableMacroSiteKinds: new Map([
|
|
904
|
+
...getAlwaysAvailableBuiltinMacroSiteKinds().entries(),
|
|
905
|
+
...(options.alwaysAvailableMacroSiteKinds ?? new Map()).entries(),
|
|
906
|
+
]),
|
|
907
|
+
baseHost: withStdPackageModuleResolution(
|
|
908
|
+
withMacroApiModuleResolution(withBundledRuntimeExterns(options.baseHost, runtime)),
|
|
909
|
+
),
|
|
910
|
+
importedMacroSiteKindsBySpecifier: new Map([
|
|
911
|
+
...getBuiltinMacroSiteKindsBySpecifier().entries(),
|
|
912
|
+
...(options.importedMacroSiteKindsBySpecifier ?? new Map()).entries(),
|
|
913
|
+
]),
|
|
914
|
+
rootNames: [...new Set([...options.rootNames, ...getBundledExternRootNames(runtime)])],
|
|
915
|
+
runtime,
|
|
916
|
+
};
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
export function expandPreparedProgramWithBuiltins(
|
|
920
|
+
preparedProgram: PreparedProgram,
|
|
921
|
+
): ReadonlyMap<string, ts.SourceFile> {
|
|
922
|
+
const environment = createProjectMacroEnvironment(
|
|
923
|
+
preparedProgram,
|
|
924
|
+
getBuiltinMacroDefinitionsBySpecifier(),
|
|
925
|
+
getBuiltinMacroExportsBySpecifier(preparedProgram),
|
|
926
|
+
getBuiltinMacroFactoriesBySpecifier(),
|
|
927
|
+
getAlwaysAvailableBuiltinMacroDefinitions(),
|
|
928
|
+
getAlwaysAvailableBuiltinMacroExports(preparedProgram),
|
|
929
|
+
);
|
|
930
|
+
try {
|
|
931
|
+
return environment.expandPreparedProgram();
|
|
932
|
+
} finally {
|
|
933
|
+
environment.dispose();
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
export function expandPreparedProgramWithBuiltinsForDiagnostics(
|
|
938
|
+
preparedProgram: PreparedProgram,
|
|
939
|
+
): ReadonlyMap<string, ts.SourceFile> {
|
|
940
|
+
const environment = createProjectMacroEnvironment(
|
|
941
|
+
preparedProgram,
|
|
942
|
+
getBuiltinMacroDefinitionsBySpecifier(),
|
|
943
|
+
getBuiltinMacroExportsBySpecifier(preparedProgram),
|
|
944
|
+
getBuiltinMacroFactoriesBySpecifier(),
|
|
945
|
+
getAlwaysAvailableBuiltinMacroDefinitions(),
|
|
946
|
+
getAlwaysAvailableBuiltinMacroExports(preparedProgram),
|
|
947
|
+
);
|
|
948
|
+
try {
|
|
949
|
+
return environment.expandPreparedProgram(true, true);
|
|
950
|
+
} finally {
|
|
951
|
+
environment.dispose();
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
function createBuiltinExpandedProgramResult(
|
|
956
|
+
analysisPreparedProgram: PreparedProgram,
|
|
957
|
+
diagnosticPreparedFiles: ReadonlyMap<string, PreparedSourceFile>,
|
|
958
|
+
frontendDiagnostics: readonly MergedDiagnostic[],
|
|
959
|
+
macroEnvironment: ProjectMacroEnvironment,
|
|
960
|
+
ownedPreparedPrograms: readonly PreparedProgram[],
|
|
961
|
+
preparedProgram: PreparedProgram,
|
|
962
|
+
program: ts.Program,
|
|
963
|
+
tsDiagnosticPrograms: readonly BuiltinExpandedTsDiagnosticProgram[] = [{ program }],
|
|
964
|
+
): BuiltinExpandedProgram {
|
|
965
|
+
return {
|
|
966
|
+
analysisPreparedProgram,
|
|
967
|
+
diagnosticPreparedFiles,
|
|
968
|
+
dispose() {
|
|
969
|
+
macroEnvironment.dispose();
|
|
970
|
+
const disposedPreparedPrograms = new Set<PreparedProgram>();
|
|
971
|
+
const disposedReuseStates = new Set<object>();
|
|
972
|
+
for (const ownedPreparedProgram of ownedPreparedPrograms) {
|
|
973
|
+
if (disposedPreparedPrograms.has(ownedPreparedProgram)) {
|
|
974
|
+
continue;
|
|
975
|
+
}
|
|
976
|
+
disposedPreparedPrograms.add(ownedPreparedProgram);
|
|
977
|
+
const reuseState = ownedPreparedProgram.preparedHost.reuseState;
|
|
978
|
+
ownedPreparedProgram.dispose(false);
|
|
979
|
+
if (disposedReuseStates.has(reuseState as object)) {
|
|
980
|
+
continue;
|
|
981
|
+
}
|
|
982
|
+
disposedReuseStates.add(reuseState as object);
|
|
983
|
+
clearPreparedCompilerHostReuseState(reuseState);
|
|
984
|
+
}
|
|
985
|
+
},
|
|
986
|
+
frontendDiagnostics: () => frontendDiagnostics,
|
|
987
|
+
macroEnvironment,
|
|
988
|
+
preparedProgram,
|
|
989
|
+
program,
|
|
990
|
+
tsDiagnosticPrograms,
|
|
991
|
+
};
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
export function createBuiltinExpandedProgram(
|
|
995
|
+
options: CreateBuiltinExpandedProgramOptions,
|
|
996
|
+
): BuiltinExpandedProgram {
|
|
997
|
+
const {
|
|
998
|
+
allowSupplementalDiagnosticPrograms = false,
|
|
999
|
+
numericLoweringTarget = 'js',
|
|
1000
|
+
...preparedProgramOptions
|
|
1001
|
+
} = options;
|
|
1002
|
+
const supportedOptions = withBuiltinMacroSupport(preparedProgramOptions);
|
|
1003
|
+
const ownedPreparedPrograms = new Set<PreparedProgram>();
|
|
1004
|
+
const trackPreparedProgram = (preparedProgram: PreparedProgram): PreparedProgram => {
|
|
1005
|
+
ownedPreparedPrograms.add(preparedProgram);
|
|
1006
|
+
return preparedProgram;
|
|
1007
|
+
};
|
|
1008
|
+
const timingMetadata = {
|
|
1009
|
+
rootCount: supportedOptions.rootNames.length,
|
|
1010
|
+
};
|
|
1011
|
+
const preparedProgram = measureCheckerTiming(
|
|
1012
|
+
'project.prepare.builtin.initialProgram',
|
|
1013
|
+
timingMetadata,
|
|
1014
|
+
() => trackPreparedProgram(createPreparedProgram(supportedOptions)),
|
|
1015
|
+
{ always: true },
|
|
1016
|
+
);
|
|
1017
|
+
const diagnosticPreparedFiles = new Map<string, PreparedSourceFile>();
|
|
1018
|
+
const frontendDiagnostics: MergedDiagnostic[] = [...preparedProgram.frontendDiagnostics()];
|
|
1019
|
+
const macroEnvironment = measureCheckerTiming(
|
|
1020
|
+
'project.prepare.builtin.macroEnvironment',
|
|
1021
|
+
timingMetadata,
|
|
1022
|
+
() =>
|
|
1023
|
+
createProjectMacroEnvironment(
|
|
1024
|
+
preparedProgram,
|
|
1025
|
+
getBuiltinMacroDefinitionsBySpecifier(),
|
|
1026
|
+
getBuiltinMacroExportsBySpecifier(preparedProgram),
|
|
1027
|
+
getBuiltinMacroFactoriesBySpecifier(),
|
|
1028
|
+
getAlwaysAvailableBuiltinMacroDefinitions(),
|
|
1029
|
+
getAlwaysAvailableBuiltinMacroExports(preparedProgram),
|
|
1030
|
+
),
|
|
1031
|
+
{ always: true },
|
|
1032
|
+
);
|
|
1033
|
+
|
|
1034
|
+
if (hasErrorDiagnostics(frontendDiagnostics)) {
|
|
1035
|
+
return createBuiltinExpandedProgramResult(
|
|
1036
|
+
preparedProgram,
|
|
1037
|
+
diagnosticPreparedFiles,
|
|
1038
|
+
frontendDiagnostics,
|
|
1039
|
+
macroEnvironment,
|
|
1040
|
+
[...ownedPreparedPrograms],
|
|
1041
|
+
preparedProgram,
|
|
1042
|
+
preparedProgram.program,
|
|
1043
|
+
);
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
let expandedFiles: ReadonlyMap<string, ts.SourceFile>;
|
|
1047
|
+
try {
|
|
1048
|
+
expandedFiles = measureCheckerTiming(
|
|
1049
|
+
'project.prepare.builtin.expandMacros',
|
|
1050
|
+
timingMetadata,
|
|
1051
|
+
() => macroEnvironment.expandPreparedProgram(true, true, true),
|
|
1052
|
+
{ always: true },
|
|
1053
|
+
);
|
|
1054
|
+
} catch (error) {
|
|
1055
|
+
if (error instanceof MacroError) {
|
|
1056
|
+
frontendDiagnostics.push(createBuiltinMacroDiagnostic(error));
|
|
1057
|
+
return createBuiltinExpandedProgramResult(
|
|
1058
|
+
preparedProgram,
|
|
1059
|
+
diagnosticPreparedFiles,
|
|
1060
|
+
frontendDiagnostics,
|
|
1061
|
+
macroEnvironment,
|
|
1062
|
+
[...ownedPreparedPrograms],
|
|
1063
|
+
preparedProgram,
|
|
1064
|
+
preparedProgram.program,
|
|
1065
|
+
);
|
|
1066
|
+
}
|
|
1067
|
+
throw error;
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
const printer = ts.createPrinter();
|
|
1071
|
+
const originalOverrides = supportedOptions.fileOverrides ?? new Map<string, string>();
|
|
1072
|
+
const annotatedOverrides = new Map(originalOverrides);
|
|
1073
|
+
const placeholdersByFile = new Map<string, Map<number, IndexedMacroPlaceholder>>();
|
|
1074
|
+
const augmentPlaceholderIdsByFile = new Map<string, Set<number>>();
|
|
1075
|
+
measureCheckerTiming(
|
|
1076
|
+
'project.prepare.builtin.annotatedOverrides',
|
|
1077
|
+
timingMetadata,
|
|
1078
|
+
() => {
|
|
1079
|
+
for (const placeholder of preparedProgram.placeholderIndex().entries()) {
|
|
1080
|
+
const filePlaceholders = placeholdersByFile.get(placeholder.fileName) ?? new Map();
|
|
1081
|
+
filePlaceholders.set(placeholder.id, placeholder);
|
|
1082
|
+
placeholdersByFile.set(placeholder.fileName, filePlaceholders);
|
|
1083
|
+
|
|
1084
|
+
const sourceFile = preparedProgram.program.getSourceFile(
|
|
1085
|
+
preparedProgram.toProgramFileName(placeholder.fileName),
|
|
1086
|
+
);
|
|
1087
|
+
const definition = sourceFile
|
|
1088
|
+
? macroEnvironment.definitionsForFile(sourceFile).get(placeholder.invocation.nameText)
|
|
1089
|
+
: undefined;
|
|
1090
|
+
const definitionMetadata = definition ? getLoadedMacroDefinitionMetadata(definition) : null;
|
|
1091
|
+
const expansionMode = definitionMetadata?.expansionMode ?? definition?.expansionMode;
|
|
1092
|
+
if (expansionMode === 'augment') {
|
|
1093
|
+
const augmentIds = augmentPlaceholderIdsByFile.get(placeholder.fileName) ?? new Set<
|
|
1094
|
+
number
|
|
1095
|
+
>();
|
|
1096
|
+
augmentIds.add(placeholder.id);
|
|
1097
|
+
augmentPlaceholderIdsByFile.set(placeholder.fileName, augmentIds);
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
for (const [fileName, sourceFile] of expandedFiles.entries()) {
|
|
1101
|
+
const sourceFileName = preparedProgram.toSourceFileName(fileName);
|
|
1102
|
+
const preparedSource = preparedProgram.preparedHost.getPreparedSourceFile(sourceFileName);
|
|
1103
|
+
const containsMacroSyntax = (preparedSource?.rewriteResult.replacements.length ?? 0) > 0;
|
|
1104
|
+
const importsBuiltinMacros = sourceFileImportsBuiltinMacros(
|
|
1105
|
+
preparedProgram.program.getSourceFile(fileName),
|
|
1106
|
+
);
|
|
1107
|
+
if (!containsMacroSyntax && !importsBuiltinMacros) {
|
|
1108
|
+
continue;
|
|
1109
|
+
}
|
|
1110
|
+
annotatedOverrides.set(
|
|
1111
|
+
sourceFileName,
|
|
1112
|
+
repairBuiltinMacroModuleSpecifiers(printer.printFile(sourceFile)),
|
|
1113
|
+
);
|
|
1114
|
+
}
|
|
1115
|
+
},
|
|
1116
|
+
{ always: true },
|
|
1117
|
+
);
|
|
1118
|
+
|
|
1119
|
+
const annotatedProgram = mapsEqual(annotatedOverrides, originalOverrides)
|
|
1120
|
+
|| programMatchesOverrides(preparedProgram, annotatedOverrides)
|
|
1121
|
+
? preparedProgram
|
|
1122
|
+
: measureCheckerTiming(
|
|
1123
|
+
'project.prepare.builtin.annotatedProgram',
|
|
1124
|
+
timingMetadata,
|
|
1125
|
+
() =>
|
|
1126
|
+
trackPreparedProgram(createPreparedProgram({
|
|
1127
|
+
...supportedOptions,
|
|
1128
|
+
fileOverrides: annotatedOverrides,
|
|
1129
|
+
invalidateModuleResolutions: false,
|
|
1130
|
+
oldProgram: preparedProgram.program,
|
|
1131
|
+
})),
|
|
1132
|
+
{ always: true },
|
|
1133
|
+
);
|
|
1134
|
+
if (annotatedProgram !== preparedProgram) {
|
|
1135
|
+
frontendDiagnostics.push(...annotatedProgram.frontendDiagnostics());
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
let numericsProgram = annotatedProgram;
|
|
1139
|
+
const numericOverrides = new Map(annotatedOverrides);
|
|
1140
|
+
const numericallyAffectedFiles = new Set<string>();
|
|
1141
|
+
measureCheckerTiming(
|
|
1142
|
+
'project.prepare.builtin.numericNormalization',
|
|
1143
|
+
timingMetadata,
|
|
1144
|
+
() => {
|
|
1145
|
+
for (let pass = 0; pass < NUMERIC_NORMALIZATION_MAX_PASSES; pass += 1) {
|
|
1146
|
+
const numericNormalizedFiles = normalizeMachineNumericSemanticsInProgram(
|
|
1147
|
+
numericsProgram.program,
|
|
1148
|
+
numericLoweringTarget,
|
|
1149
|
+
).changedFiles;
|
|
1150
|
+
if (numericNormalizedFiles.size === 0) {
|
|
1151
|
+
break;
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
for (const [fileName, normalized] of numericNormalizedFiles.entries()) {
|
|
1155
|
+
numericallyAffectedFiles.add(fileName);
|
|
1156
|
+
numericOverrides.set(
|
|
1157
|
+
numericsProgram.toSourceFileName(fileName),
|
|
1158
|
+
normalized.rewriteStage.rewrittenText,
|
|
1159
|
+
);
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
const nextNumericsProgram = trackPreparedProgram(createPreparedProgram({
|
|
1163
|
+
...supportedOptions,
|
|
1164
|
+
fileOverrides: numericOverrides,
|
|
1165
|
+
invalidateModuleResolutions: false,
|
|
1166
|
+
oldProgram: numericsProgram.program,
|
|
1167
|
+
}));
|
|
1168
|
+
if (nextNumericsProgram !== numericsProgram) {
|
|
1169
|
+
frontendDiagnostics.push(...nextNumericsProgram.frontendDiagnostics());
|
|
1170
|
+
}
|
|
1171
|
+
numericsProgram = nextNumericsProgram;
|
|
1172
|
+
}
|
|
1173
|
+
},
|
|
1174
|
+
{ always: true },
|
|
1175
|
+
);
|
|
1176
|
+
|
|
1177
|
+
const finalOverrides = new Map(numericOverrides);
|
|
1178
|
+
const normalizedFiles = measureCheckerTiming(
|
|
1179
|
+
'project.prepare.builtin.errorNormalization',
|
|
1180
|
+
timingMetadata,
|
|
1181
|
+
() => normalizeErrorBoundariesInProgram(numericsProgram.program).changedFiles,
|
|
1182
|
+
{ always: true },
|
|
1183
|
+
);
|
|
1184
|
+
measureCheckerTiming(
|
|
1185
|
+
'project.prepare.builtin.finalOverrides',
|
|
1186
|
+
timingMetadata,
|
|
1187
|
+
() => {
|
|
1188
|
+
for (const sourceFile of numericsProgram.program.getSourceFiles()) {
|
|
1189
|
+
if (sourceFile.isDeclarationFile) {
|
|
1190
|
+
continue;
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
const sourceFileName = numericsProgram.toSourceFileName(sourceFile.fileName);
|
|
1194
|
+
const preparedSource = preparedProgram.preparedHost.getPreparedSourceFile(sourceFileName);
|
|
1195
|
+
const containsMacroSyntax = (preparedSource?.rewriteResult.replacements.length ?? 0) > 0;
|
|
1196
|
+
const importsBuiltinMacros = sourceFileImportsBuiltinMacros(
|
|
1197
|
+
numericsProgram.program.getSourceFile(sourceFile.fileName),
|
|
1198
|
+
);
|
|
1199
|
+
const normalized = normalizedFiles.get(sourceFile.fileName);
|
|
1200
|
+
const numericNormalized = numericallyAffectedFiles.has(sourceFile.fileName);
|
|
1201
|
+
if (
|
|
1202
|
+
!containsMacroSyntax &&
|
|
1203
|
+
!importsBuiltinMacros &&
|
|
1204
|
+
!normalized &&
|
|
1205
|
+
!numericNormalized &&
|
|
1206
|
+
!preparedSource?.postRewriteStage
|
|
1207
|
+
) {
|
|
1208
|
+
continue;
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
const finalText = normalized
|
|
1212
|
+
? normalized.rewriteStage.rewrittenText
|
|
1213
|
+
: repairBuiltinMacroModuleSpecifiers(printer.printFile(sourceFile));
|
|
1214
|
+
if (containsMacroSyntax && preparedSource) {
|
|
1215
|
+
const { cleanedProgramText, preparedFile } = buildDiagnosticPreparedSourceFile(
|
|
1216
|
+
preparedSource,
|
|
1217
|
+
finalText,
|
|
1218
|
+
placeholdersByFile.get(sourceFileName) ?? new Map(),
|
|
1219
|
+
augmentPlaceholderIdsByFile.get(sourceFileName) ?? new Set(),
|
|
1220
|
+
true,
|
|
1221
|
+
);
|
|
1222
|
+
diagnosticPreparedFiles.set(sourceFileName, preparedFile);
|
|
1223
|
+
finalOverrides.set(sourceFileName, cleanedProgramText);
|
|
1224
|
+
continue;
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
if (preparedSource && finalText !== preparedSource.rewrittenText) {
|
|
1228
|
+
diagnosticPreparedFiles.set(sourceFileName, {
|
|
1229
|
+
diagnostics: [],
|
|
1230
|
+
originalText: preparedSource.originalText,
|
|
1231
|
+
postRewriteStage: buildRewriteStageFromTexts(
|
|
1232
|
+
sourceFileName,
|
|
1233
|
+
preparedSource.rewriteResult.rewrittenText,
|
|
1234
|
+
finalText,
|
|
1235
|
+
),
|
|
1236
|
+
rewriteResult: preparedSource.rewriteResult,
|
|
1237
|
+
rewrittenText: finalText,
|
|
1238
|
+
});
|
|
1239
|
+
} else if (preparedSource?.postRewriteStage) {
|
|
1240
|
+
diagnosticPreparedFiles.set(sourceFileName, preparedSource);
|
|
1241
|
+
}
|
|
1242
|
+
finalOverrides.set(sourceFileName, finalText);
|
|
1243
|
+
}
|
|
1244
|
+
},
|
|
1245
|
+
{ always: true },
|
|
1246
|
+
);
|
|
1247
|
+
|
|
1248
|
+
const collectBuiltinFrontendDiagnosticsForProgram = (
|
|
1249
|
+
targetProgram: PreparedProgram,
|
|
1250
|
+
): void => {
|
|
1251
|
+
const abstractNumericFamilyDiagnostics = collectAbstractNumericFamilyArithmeticInProgram(
|
|
1252
|
+
targetProgram.program,
|
|
1253
|
+
).map((diagnostic) =>
|
|
1254
|
+
createAbstractNumericFamilyDiagnostic(
|
|
1255
|
+
diagnostic,
|
|
1256
|
+
diagnosticPreparedFiles.get(toSourceFileName(diagnostic.fileName)) ??
|
|
1257
|
+
targetProgram.preparedHost.getPreparedSourceFile(
|
|
1258
|
+
toSourceFileName(diagnostic.fileName),
|
|
1259
|
+
),
|
|
1260
|
+
targetProgram.program.getSourceFile(diagnostic.fileName)?.text ?? '',
|
|
1261
|
+
)
|
|
1262
|
+
);
|
|
1263
|
+
frontendDiagnostics.push(...abstractNumericFamilyDiagnostics);
|
|
1264
|
+
const mixedMachineNumericDiagnostics = collectMixedMachineNumericArithmeticInProgram(
|
|
1265
|
+
targetProgram.program,
|
|
1266
|
+
).map((diagnostic) =>
|
|
1267
|
+
createMixedMachineNumericDiagnostic(
|
|
1268
|
+
diagnostic,
|
|
1269
|
+
diagnosticPreparedFiles.get(toSourceFileName(diagnostic.fileName)) ??
|
|
1270
|
+
targetProgram.preparedHost.getPreparedSourceFile(
|
|
1271
|
+
toSourceFileName(diagnostic.fileName),
|
|
1272
|
+
),
|
|
1273
|
+
targetProgram.program.getSourceFile(diagnostic.fileName)?.text ?? '',
|
|
1274
|
+
)
|
|
1275
|
+
);
|
|
1276
|
+
frontendDiagnostics.push(...mixedMachineNumericDiagnostics);
|
|
1277
|
+
const sortComparatorDiagnostics = collectSortCallsWithoutComparatorInProgram(
|
|
1278
|
+
targetProgram.program,
|
|
1279
|
+
).map((diagnostic) =>
|
|
1280
|
+
createSortComparatorRequiredDiagnostic(
|
|
1281
|
+
diagnostic,
|
|
1282
|
+
diagnosticPreparedFiles.get(toSourceFileName(diagnostic.fileName)) ??
|
|
1283
|
+
targetProgram.preparedHost.getPreparedSourceFile(
|
|
1284
|
+
toSourceFileName(diagnostic.fileName),
|
|
1285
|
+
),
|
|
1286
|
+
targetProgram.program.getSourceFile(diagnostic.fileName)?.text ?? '',
|
|
1287
|
+
)
|
|
1288
|
+
);
|
|
1289
|
+
frontendDiagnostics.push(...sortComparatorDiagnostics);
|
|
1290
|
+
};
|
|
1291
|
+
|
|
1292
|
+
const canReuseAnalysisProgram = programMatchesOverrides(numericsProgram, finalOverrides);
|
|
1293
|
+
let supplementalTsDiagnosticPrograms:
|
|
1294
|
+
| readonly BuiltinExpandedTsDiagnosticProgram[]
|
|
1295
|
+
| undefined;
|
|
1296
|
+
if (!canReuseAnalysisProgram && allowSupplementalDiagnosticPrograms) {
|
|
1297
|
+
const supplementalFilePaths: string[] = [];
|
|
1298
|
+
let hasOnlyNormalizedLocalDiffs = true;
|
|
1299
|
+
|
|
1300
|
+
for (const [sourceFileName, finalText] of finalOverrides) {
|
|
1301
|
+
const programFileName = numericsProgram.toProgramFileName(sourceFileName);
|
|
1302
|
+
const sourceFile = numericsProgram.program.getSourceFile(programFileName);
|
|
1303
|
+
if (sourceFile?.text === finalText) {
|
|
1304
|
+
continue;
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
const preparedSource = preparedProgram.preparedHost.getPreparedSourceFile(sourceFileName);
|
|
1308
|
+
const normalizedOnly = normalizedFiles.has(programFileName) &&
|
|
1309
|
+
!numericallyAffectedFiles.has(programFileName) &&
|
|
1310
|
+
(preparedSource?.rewriteResult.replacements.length ?? 0) === 0 &&
|
|
1311
|
+
!preparedSource?.postRewriteStage;
|
|
1312
|
+
if (!normalizedOnly) {
|
|
1313
|
+
hasOnlyNormalizedLocalDiffs = false;
|
|
1314
|
+
break;
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
supplementalFilePaths.push(sourceFileName);
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
if (hasOnlyNormalizedLocalDiffs && supplementalFilePaths.length > 0) {
|
|
1321
|
+
const supplementalDiagnosticProgram = measureCheckerTiming(
|
|
1322
|
+
'project.prepare.builtin.supplementalTsDiagnosticsProgram',
|
|
1323
|
+
{
|
|
1324
|
+
...timingMetadata,
|
|
1325
|
+
fileCount: supplementalFilePaths.length,
|
|
1326
|
+
},
|
|
1327
|
+
() =>
|
|
1328
|
+
trackPreparedProgram(createPreparedProgram({
|
|
1329
|
+
...supportedOptions,
|
|
1330
|
+
fileOverrides: finalOverrides,
|
|
1331
|
+
invalidateModuleResolutions: false,
|
|
1332
|
+
oldProgram: numericsProgram.program,
|
|
1333
|
+
rootNames: supplementalFilePaths,
|
|
1334
|
+
})),
|
|
1335
|
+
{ always: true },
|
|
1336
|
+
);
|
|
1337
|
+
supplementalTsDiagnosticPrograms = [
|
|
1338
|
+
{ program: numericsProgram.program },
|
|
1339
|
+
{
|
|
1340
|
+
filePaths: supplementalFilePaths,
|
|
1341
|
+
program: supplementalDiagnosticProgram.program,
|
|
1342
|
+
},
|
|
1343
|
+
];
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
if (canReuseAnalysisProgram || supplementalTsDiagnosticPrograms) {
|
|
1348
|
+
const analysisPreparedProgram = numericsProgram;
|
|
1349
|
+
collectBuiltinFrontendDiagnosticsForProgram(analysisPreparedProgram);
|
|
1350
|
+
return createBuiltinExpandedProgramResult(
|
|
1351
|
+
analysisPreparedProgram,
|
|
1352
|
+
diagnosticPreparedFiles,
|
|
1353
|
+
frontendDiagnostics,
|
|
1354
|
+
macroEnvironment,
|
|
1355
|
+
[...ownedPreparedPrograms],
|
|
1356
|
+
preparedProgram,
|
|
1357
|
+
analysisPreparedProgram.program,
|
|
1358
|
+
supplementalTsDiagnosticPrograms,
|
|
1359
|
+
);
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
const expandedProgram = measureCheckerTiming(
|
|
1363
|
+
'project.prepare.builtin.finalProgram',
|
|
1364
|
+
timingMetadata,
|
|
1365
|
+
() =>
|
|
1366
|
+
trackPreparedProgram(createPreparedProgram({
|
|
1367
|
+
...supportedOptions,
|
|
1368
|
+
fileOverrides: finalOverrides,
|
|
1369
|
+
invalidateModuleResolutions: false,
|
|
1370
|
+
oldProgram: numericsProgram.program,
|
|
1371
|
+
})),
|
|
1372
|
+
{ always: true },
|
|
1373
|
+
);
|
|
1374
|
+
frontendDiagnostics.push(...expandedProgram.frontendDiagnostics());
|
|
1375
|
+
collectBuiltinFrontendDiagnosticsForProgram(expandedProgram);
|
|
1376
|
+
|
|
1377
|
+
return createBuiltinExpandedProgramResult(
|
|
1378
|
+
expandedProgram,
|
|
1379
|
+
diagnosticPreparedFiles,
|
|
1380
|
+
frontendDiagnostics,
|
|
1381
|
+
macroEnvironment,
|
|
1382
|
+
[...ownedPreparedPrograms],
|
|
1383
|
+
preparedProgram,
|
|
1384
|
+
expandedProgram.program,
|
|
1385
|
+
);
|
|
1386
|
+
}
|