@automaton-labs/aib 0.0.6 → 0.0.8
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/README.md +36 -257
- package/config/agent-dx-policy.default.json +31 -0
- package/config/control-plane-client.default.json +3 -0
- package/dist/agent-dx/agent-dx.js +805 -0
- package/dist/agent-dx/presentation.js +32 -0
- package/dist/alias-advisor/analyze.js +982 -0
- package/dist/alias-advisor/exact-text-cost.js +74 -0
- package/dist/alias-advisor/lexical.js +240 -0
- package/dist/alias-advisor/model.js +2 -0
- package/dist/alias-advisor/path-identity.js +49 -0
- package/dist/alias-advisor/ranking.js +171 -0
- package/dist/alias-advisor/token-estimator.js +85 -0
- package/dist/bin/aib.js +5 -1
- package/dist/bin/cli.js +811 -2
- package/dist/commands/add-missing-imports-preview-cache.js +99 -2
- package/dist/commands/add-missing-imports.js +241 -2
- package/dist/commands/apply-module-plan.js +1319 -3
- package/dist/commands/background-command.js +378 -0
- package/dist/commands/captured-input.js +74 -2
- package/dist/commands/config-command.js +314 -2
- package/dist/commands/config-output.js +357 -10
- package/dist/commands/control-plane-command.js +183 -0
- package/dist/commands/declaration-command.js +1209 -0
- package/dist/commands/declaration-execution-cache.js +79 -0
- package/dist/commands/declaration-format.js +221 -0
- package/dist/commands/declaration-preview-cache.js +114 -0
- package/dist/commands/diagnostics-command.js +70 -3
- package/dist/commands/doctor.js +137 -2
- package/dist/commands/execution-command.js +117 -1
- package/dist/commands/exports-star-collapse-command.js +178 -0
- package/dist/commands/exports-star-command.js +252 -0
- package/dist/commands/exports-star-preview-cache.js +84 -0
- package/dist/commands/feedback-command.js +176 -3
- package/dist/commands/file-move-to-dir-execution-cache.js +92 -0
- package/dist/commands/file-move-to-dir-preview-cache.js +125 -0
- package/dist/commands/file-move-to-dir-worker.js +54 -0
- package/dist/commands/file-move-to-dir.js +1073 -0
- package/dist/commands/file-mutation-runtime.js +102 -0
- package/dist/commands/file-mutation-worker-apply.js +180 -0
- package/dist/commands/file-refactor-batch-execution-cache.js +90 -0
- package/dist/commands/file-refactor-batch-preview-cache.js +125 -0
- package/dist/commands/file-refactor-batch-worker.js +54 -0
- package/dist/commands/file-refactor-batch.js +1154 -0
- package/dist/commands/file-rename-execution-cache.js +92 -0
- package/dist/commands/file-rename-preview-cache.js +125 -0
- package/dist/commands/file-rename-worker.js +54 -0
- package/dist/commands/file-rename.js +1053 -0
- package/dist/commands/file-text-edit-executor.js +205 -0
- package/dist/commands/find-importers.js +52 -1
- package/dist/commands/find-unused-imports.js +55 -1
- package/dist/commands/generate-docs-command.js +244 -6
- package/dist/commands/help-command.js +460 -7
- package/dist/commands/import-specifier-policy.js +391 -0
- package/dist/commands/imports-command.js +68 -1
- package/dist/commands/imports-rebase.js +1138 -0
- package/dist/commands/init-skill-usage.js +92 -3
- package/dist/commands/init-workspace.js +30 -1
- package/dist/commands/inspect-alias-candidates.js +413 -0
- package/dist/commands/inspect-cycles.js +811 -5
- package/dist/commands/inspect-direct-usages.js +98 -0
- package/dist/commands/inspect-duplicates-format.js +229 -0
- package/dist/commands/inspect-format-primitives.js +127 -0
- package/dist/commands/inspect-format.js +1590 -18
- package/dist/commands/inspect-graph.js +1553 -9
- package/dist/commands/inspect-imports.js +339 -2
- package/dist/commands/inspect-mixed-format.js +524 -0
- package/dist/commands/inspect-module-plan-format.js +216 -0
- package/dist/commands/inspect-module-plan-serialization.js +402 -0
- package/dist/commands/inspect-reference-path-format.js +157 -0
- package/dist/commands/inspect-request-values.js +599 -0
- package/dist/commands/inspect-selector-kind.js +21 -0
- package/dist/commands/inspect-selector.js +50 -0
- package/dist/commands/inspect-symbol-format.js +90 -0
- package/dist/commands/inspect-topology.js +435 -0
- package/dist/commands/inspect-tree.js +827 -5
- package/dist/commands/inspect-usages-detail.js +793 -0
- package/dist/commands/inspect-usages-evidence.js +31 -0
- package/dist/commands/inspect-usages-format.js +367 -0
- package/dist/commands/inspect.js +1450 -16
- package/dist/commands/internal-command.js +64 -0
- package/dist/commands/json-file-input.js +60 -1
- package/dist/commands/module-plan-cache.js +156 -2
- package/dist/commands/module-plan-standalone.js +208 -0
- package/dist/commands/module-plan-timeout.js +77 -1
- package/dist/commands/move-preview-cache.js +101 -2
- package/dist/commands/mutate-aggregate-output.js +996 -0
- package/dist/commands/mutate-child-execution.js +374 -0
- package/dist/commands/mutate-command.js +1394 -0
- package/dist/commands/mutate-declaration-output.js +313 -0
- package/dist/commands/mutate-domain-adapters.js +638 -0
- package/dist/commands/mutate-execution-cache.js +114 -0
- package/dist/commands/mutate-execution-status.js +598 -0
- package/dist/commands/mutate-failure-output.js +531 -0
- package/dist/commands/mutate-file-view.js +151 -0
- package/dist/commands/mutate-object-output.js +91 -0
- package/dist/commands/mutate-output-values.js +97 -0
- package/dist/commands/mutate-preview-cache.js +86 -0
- package/dist/commands/mutate-response-replay.js +153 -0
- package/dist/commands/mutate-result-projection.js +818 -0
- package/dist/commands/mutation-eta.js +28 -0
- package/dist/commands/mutation-execution-cache.js +140 -3
- package/dist/commands/mutation-recovery-journal.js +195 -0
- package/dist/commands/normalize-imports.js +1120 -4
- package/dist/commands/object-pack-command.js +546 -0
- package/dist/commands/object-pack-preview-cache.js +88 -0
- package/dist/commands/observability-command.js +47 -3
- package/dist/commands/ota-command.js +403 -0
- package/dist/commands/print-config.js +10 -1
- package/dist/commands/quick-read.js +1113 -11
- package/dist/commands/refactor-batch-builder.js +265 -1
- package/dist/commands/refactor-batch-execution-cache.js +85 -1
- package/dist/commands/refactor-batch-preview-cache.js +96 -2
- package/dist/commands/refactor-batch.js +461 -4
- package/dist/commands/rename-entities.js +794 -4
- package/dist/commands/rename-execution-cache.js +49 -1
- package/dist/commands/rename-input.js +22 -1
- package/dist/commands/rename-polling-policy.js +68 -0
- package/dist/commands/rename-preview-cache.js +96 -2
- package/dist/commands/result-view.js +993 -6
- package/dist/commands/reveal-command.js +445 -5
- package/dist/commands/selector-suggestions.js +93 -0
- package/dist/commands/session-workspace.js +1836 -31
- package/dist/commands/shared.js +2 -1
- package/dist/commands/skills-command.js +315 -0
- package/dist/commands/sync-command.js +59 -2
- package/dist/commands/worker-command.js +173 -0
- package/dist/commands/workspace-cache.js +55 -1
- package/dist/config/defaults.js +26 -1
- package/dist/config/env-vars.js +77 -1
- package/dist/config/glob-match.js +44 -1
- package/dist/config/import-rules.js +165 -1
- package/dist/config/local-config.js +293 -3
- package/dist/config/mutation-comments.js +51 -1
- package/dist/config/path-aliases.js +165 -1
- package/dist/config/path-display.js +84 -1
- package/dist/config/product-storage.js +37 -1
- package/dist/config/request-env.js +21 -0
- package/dist/config/request-routing-context.js +23 -0
- package/dist/config/resolve-command-alias.js +74 -1
- package/dist/config/resolve.js +24 -1
- package/dist/config/tsconfig-discovery.js +113 -1
- package/dist/config/typescript-preferences.js +131 -0
- package/dist/config/workspace-root.js +310 -3
- package/dist/config/workspace-state.js +254 -1
- package/dist/content/content-bundle.js +88 -1
- package/dist/diagnostics/module-plan-timeline.js +75 -2
- package/dist/diagnostics/readiness-text.js +45 -8
- package/dist/dsl/aib-dsl.js +838 -1
- package/dist/dsl/declaration-dsl.js +264 -0
- package/dist/dsl/file-move-to-dir-dsl.js +123 -0
- package/dist/dsl/file-refactor-batch-dsl.js +203 -0
- package/dist/dsl/file-rename-dsl.js +135 -0
- package/dist/dsl/mutate-dsl.js +746 -0
- package/dist/help/bootstrap.bash.md +742 -0
- package/dist/help/bootstrap.md +236 -437
- package/dist/help/bootstrap.pwsh.md +742 -0
- package/dist/help/docs/basics.md +1 -1
- package/dist/help/docs/config-setup.import-normalize.md +65 -65
- package/dist/help/docs/config-setup.import-rules.md +6 -5
- package/dist/help/docs/dsl.md +4 -3
- package/dist/help/docs/first-setup.md +6 -5
- package/dist/help/docs/help-protocol.md +4 -3
- package/dist/help/docs/import.base.md +38 -0
- package/dist/help/docs/import.rebase.md +85 -0
- package/dist/help/docs/inspect.aliasCandidates.md +39 -0
- package/dist/help/docs/inspect.code.md +5 -11
- package/dist/help/docs/inspect.deps.md +7 -7
- package/dist/help/docs/inspect.file.md +10 -18
- package/dist/help/docs/inspect.graph.md +6 -20
- package/dist/help/docs/{inspect.md → inspect.shared.md} +18 -17
- package/dist/help/docs/modulePlan.md +24 -28
- package/dist/help/docs/move.md +19 -22
- package/dist/help/docs/moveToDir.md +46 -0
- package/dist/help/docs/mutate.mixed.md +34 -0
- package/dist/help/docs/mutation.shared.md +55 -0
- package/dist/help/docs/patterns.md +3 -16
- package/dist/help/docs/qr.md +13 -22
- package/dist/help/docs/quick-map.md +36 -23
- package/dist/help/docs/recipe.file-layout.md +15 -0
- package/dist/help/docs/recipe.import-boundary.md +92 -0
- package/dist/help/docs/recipe.safe-artifact-probing.md +68 -0
- package/dist/help/docs/recipe.unfamiliar-area.md +64 -0
- package/dist/help/docs/recipes.md +20 -0
- package/dist/help/docs/rename.md +19 -27
- package/dist/help/docs/renameFile.md +36 -0
- package/dist/help/docs/rg.md +22 -0
- package/dist/help/docs/rules.md +26 -0
- package/dist/help/docs/selectors.md +3 -2
- package/dist/help/docs/session.md +1 -1
- package/dist/help/dsl/bootstrap.bash.md +742 -0
- package/dist/help/dsl/bootstrap.md +236 -437
- package/dist/help/dsl/bootstrap.pwsh.md +742 -0
- package/dist/help/dsl/docs/basics.md +1 -1
- package/dist/help/dsl/docs/config-setup.import-normalize.md +65 -65
- package/dist/help/dsl/docs/config-setup.import-rules.md +6 -5
- package/dist/help/dsl/docs/dsl.md +4 -3
- package/dist/help/dsl/docs/first-setup.md +6 -5
- package/dist/help/dsl/docs/help-protocol.md +4 -3
- package/dist/help/dsl/docs/import.base.md +38 -0
- package/dist/help/dsl/docs/import.rebase.md +85 -0
- package/dist/help/dsl/docs/inspect.aliasCandidates.md +39 -0
- package/dist/help/dsl/docs/inspect.code.md +5 -11
- package/dist/help/dsl/docs/inspect.deps.md +7 -7
- package/dist/help/dsl/docs/inspect.file.md +10 -18
- package/dist/help/dsl/docs/inspect.graph.md +6 -20
- package/dist/help/dsl/docs/{inspect.md → inspect.shared.md} +18 -17
- package/dist/help/dsl/docs/modulePlan.md +24 -28
- package/dist/help/dsl/docs/move.md +19 -22
- package/dist/help/dsl/docs/moveToDir.md +46 -0
- package/dist/help/dsl/docs/mutate.mixed.md +34 -0
- package/dist/help/dsl/docs/mutation.shared.md +55 -0
- package/dist/help/dsl/docs/patterns.md +3 -16
- package/dist/help/dsl/docs/qr.md +13 -22
- package/dist/help/dsl/docs/quick-map.md +36 -23
- package/dist/help/dsl/docs/recipe.file-layout.md +15 -0
- package/dist/help/dsl/docs/recipe.import-boundary.md +92 -0
- package/dist/help/dsl/docs/recipe.safe-artifact-probing.md +68 -0
- package/dist/help/dsl/docs/recipe.unfamiliar-area.md +64 -0
- package/dist/help/dsl/docs/recipes.md +20 -0
- package/dist/help/dsl/docs/rename.md +19 -27
- package/dist/help/dsl/docs/renameFile.md +36 -0
- package/dist/help/dsl/docs/rg.md +22 -0
- package/dist/help/dsl/docs/rules.md +26 -0
- package/dist/help/dsl/docs/selectors.md +3 -2
- package/dist/help/dsl/docs/session.md +1 -1
- package/dist/help/dsl/full.md +236 -437
- package/dist/help/dsl/help-index.md +49 -0
- package/dist/help/dsl/snippets/agents.md +2 -2
- package/dist/help/dsl/tokens/qr.inline.examples.md +2 -0
- package/dist/help/dsl/tokens/stdin.examples.bash.md +8 -0
- package/dist/help/dsl/tokens/stdin.examples.pwsh.md +8 -0
- package/dist/help/dsl/tokens/stdin.examples.with-qr.bash.md +12 -0
- package/dist/help/dsl/tokens/stdin.examples.with-qr.pwsh.md +12 -0
- package/dist/help/dsl/topics/basics.md +1 -1
- package/dist/help/dsl/topics/config-setup.import-normalize.md +65 -65
- package/dist/help/dsl/topics/config-setup.import-rules.md +6 -5
- package/dist/help/dsl/topics/dsl.md +4 -3
- package/dist/help/dsl/topics/first-setup.md +6 -5
- package/dist/help/dsl/topics/help-protocol.md +4 -3
- package/dist/help/dsl/topics/import.base.md +36 -0
- package/dist/help/dsl/topics/import.rebase.md +83 -0
- package/dist/help/dsl/topics/inspect.aliasCandidates.md +37 -0
- package/dist/help/dsl/topics/inspect.code.md +5 -11
- package/dist/help/dsl/topics/inspect.deps.md +7 -7
- package/dist/help/dsl/topics/inspect.file.md +10 -18
- package/dist/help/dsl/topics/inspect.graph.md +6 -20
- package/dist/help/dsl/topics/{inspect.md → inspect.shared.md} +18 -17
- package/dist/help/dsl/topics/modulePlan.md +21 -26
- package/dist/help/dsl/topics/move.md +17 -18
- package/dist/help/dsl/topics/moveToDir.md +44 -0
- package/dist/help/dsl/topics/mutate.mixed.md +32 -0
- package/dist/help/dsl/topics/mutation.shared.md +53 -0
- package/dist/help/dsl/topics/patterns.md +3 -16
- package/dist/help/dsl/topics/qr.md +13 -22
- package/dist/help/dsl/topics/quick-map.md +36 -23
- package/dist/help/dsl/topics/recipe.file-layout.md +13 -0
- package/dist/help/dsl/topics/recipe.import-boundary.md +90 -0
- package/dist/help/dsl/topics/recipe.safe-artifact-probing.md +66 -0
- package/dist/help/dsl/topics/recipe.unfamiliar-area.md +62 -0
- package/dist/help/dsl/topics/recipes.md +18 -0
- package/dist/help/dsl/topics/rename.md +15 -15
- package/dist/help/dsl/topics/renameFile.md +34 -0
- package/dist/help/dsl/topics/rg.md +20 -0
- package/dist/help/dsl/topics/rules.md +24 -0
- package/dist/help/dsl/topics/selectors.md +3 -2
- package/dist/help/dsl/topics/session.md +1 -1
- package/dist/help/full.md +236 -437
- package/dist/help/help-index.md +49 -0
- package/dist/help/help-meta.json +114 -48
- package/dist/help/index.md +76 -87
- package/dist/help/snippets/agents.md +2 -2
- package/dist/help/tokens/qr.inline.examples.md +2 -0
- package/dist/help/tokens/stdin.examples.bash.md +8 -0
- package/dist/help/tokens/stdin.examples.pwsh.md +8 -0
- package/dist/help/tokens/stdin.examples.with-qr.bash.md +12 -0
- package/dist/help/tokens/stdin.examples.with-qr.pwsh.md +12 -0
- package/dist/help/topics/basics.md +1 -1
- package/dist/help/topics/config-setup.import-normalize.md +65 -65
- package/dist/help/topics/config-setup.import-rules.md +6 -5
- package/dist/help/topics/dsl.md +4 -3
- package/dist/help/topics/first-setup.md +6 -5
- package/dist/help/topics/help-protocol.md +4 -3
- package/dist/help/topics/import.base.md +36 -0
- package/dist/help/topics/import.rebase.md +83 -0
- package/dist/help/topics/inspect.aliasCandidates.md +37 -0
- package/dist/help/topics/inspect.code.md +5 -11
- package/dist/help/topics/inspect.deps.md +7 -7
- package/dist/help/topics/inspect.file.md +10 -18
- package/dist/help/topics/inspect.graph.md +6 -20
- package/dist/help/topics/{inspect.md → inspect.shared.md} +18 -17
- package/dist/help/topics/modulePlan.md +21 -26
- package/dist/help/topics/move.md +17 -18
- package/dist/help/topics/moveToDir.md +44 -0
- package/dist/help/topics/mutate.mixed.md +32 -0
- package/dist/help/topics/mutation.shared.md +53 -0
- package/dist/help/topics/patterns.md +3 -16
- package/dist/help/topics/qr.md +13 -22
- package/dist/help/topics/quick-map.md +36 -23
- package/dist/help/topics/recipe.file-layout.md +13 -0
- package/dist/help/topics/recipe.import-boundary.md +90 -0
- package/dist/help/topics/recipe.safe-artifact-probing.md +66 -0
- package/dist/help/topics/recipe.unfamiliar-area.md +62 -0
- package/dist/help/topics/recipes.md +18 -0
- package/dist/help/topics/rename.md +15 -15
- package/dist/help/topics/renameFile.md +34 -0
- package/dist/help/topics/rg.md +20 -0
- package/dist/help/topics/rules.md +24 -0
- package/dist/help/topics/selectors.md +3 -2
- package/dist/help/topics/session.md +1 -1
- package/dist/host/capabilities.js +56 -0
- package/dist/imports/standalone-import-analysis.js +602 -0
- package/dist/imports/standalone-import-model.js +2 -0
- package/dist/imports/standalone-import-process.js +66 -0
- package/dist/imports/standalone-import-worker.js +27 -0
- package/dist/imports/standalone-ts-project.js +147 -0
- package/dist/inspect/inspect-duplicates-service.js +526 -0
- package/dist/inspect/inspect-reverse-module-closure.js +338 -0
- package/dist/inspect/inspect-source-ranges.js +82 -0
- package/dist/inspect/inspect-source-shape.js +649 -0
- package/dist/inspect/standalone-inspect-analysis.js +319 -0
- package/dist/inspect/standalone-inspect-model.js +9 -0
- package/dist/inspect/standalone-inspect-process.js +55 -0
- package/dist/inspect/standalone-inspect-usages.js +274 -0
- package/dist/inspect/standalone-inspect-worker.js +13 -0
- package/dist/metrics/central-metrics.js +101 -2
- package/dist/mutation/concrete-edit-plan.js +157 -0
- package/dist/mutation/exports-star-collapse-preview.js +361 -0
- package/dist/mutation/exports-star-expand-apply.js +373 -0
- package/dist/mutation/exports-star-expand-preview.js +807 -0
- package/dist/mutation/file-impact-scan.js +182 -0
- package/dist/mutation/file-mutation-discovery.js +674 -0
- package/dist/mutation/file-mutation-eta.js +99 -0
- package/dist/mutation/file-mutation-standalone-apply.js +584 -0
- package/dist/mutation/file-mutation-standalone-planner.js +500 -0
- package/dist/mutation/file-mutation-tsserver-session.js +473 -0
- package/dist/mutation/mutation-estimate.js +45 -0
- package/dist/mutation/mutation-plan.js +467 -0
- package/dist/mutation/object-mutation-foundation.js +2 -0
- package/dist/mutation/object-mutation-partition.js +148 -0
- package/dist/mutation/object-pack-semantic-apply.js +507 -0
- package/dist/mutation/object-pack-semantic-preview.js +984 -0
- package/dist/mutation/object-unpack-semantic-preview.js +993 -0
- package/dist/mutation/package-manifest-impact.js +176 -0
- package/dist/mutation/rename-owner-worker-child.js +37 -0
- package/dist/mutation/rename-owner-worker.js +122 -0
- package/dist/mutation/runtime-cycle-query.js +66 -0
- package/dist/mutation/semantic-execution-progress.js +63 -0
- package/dist/mutation/semantic-export-index.js +474 -0
- package/dist/mutation/semantic-impact-scan.js +434 -0
- package/dist/mutation/semantic-model.js +2 -0
- package/dist/mutation/semantic-move-best-effort-planner.js +209 -0
- package/dist/mutation/semantic-move-config-worker-child.js +61 -0
- package/dist/mutation/semantic-move-config-worker.js +449 -0
- package/dist/mutation/semantic-move-declarations.js +94 -0
- package/dist/mutation/semantic-move-metrics.js +119 -0
- package/dist/mutation/semantic-move-model.js +2 -0
- package/dist/mutation/semantic-move-owner-authority.js +122 -0
- package/dist/mutation/semantic-move-owner-candidates.js +300 -0
- package/dist/mutation/semantic-move-owner-divergence-harness.js +474 -0
- package/dist/mutation/semantic-move-owner-divergence-runner.js +162 -0
- package/dist/mutation/semantic-move-plan-hash.js +56 -0
- package/dist/mutation/semantic-move-policy.js +360 -0
- package/dist/mutation/semantic-move-process.js +218 -0
- package/dist/mutation/semantic-move-provider-diagnostics.js +27 -0
- package/dist/mutation/semantic-move-standalone-engine.js +919 -0
- package/dist/mutation/semantic-move-standalone-planner.js +1553 -0
- package/dist/mutation/semantic-move-transaction.js +639 -0
- package/dist/mutation/semantic-mutation-engine.js +478 -0
- package/dist/mutation/semantic-mutation-runtime.js +521 -0
- package/dist/mutation/semantic-planner-retry.js +26 -0
- package/dist/mutation/semantic-program-roots.js +69 -0
- package/dist/mutation/semantic-rename-commonjs.js +229 -0
- package/dist/mutation/semantic-rename-config-worker-child.js +46 -0
- package/dist/mutation/semantic-rename-config-worker.js +498 -0
- package/dist/mutation/semantic-rename-locations.js +192 -0
- package/dist/mutation/semantic-rename-model.js +2 -0
- package/dist/mutation/semantic-rename-process.js +210 -0
- package/dist/mutation/semantic-rename-standalone-engine.js +302 -0
- package/dist/mutation/semantic-rename-standalone-planner.js +567 -0
- package/dist/mutation/semantic-rename-transaction.js +333 -0
- package/dist/mutation/semantic-unused-import-cleanup.js +248 -0
- package/dist/mutation/semantic-worker-retry.js +40 -0
- package/dist/mutation/semantic-workspace.js +804 -0
- package/dist/mutation/targeted-import-canonicalizer.js +359 -0
- package/dist/observability/config.js +206 -1
- package/dist/observability/context.js +59 -1
- package/dist/observability/failure-snapshot.js +124 -2
- package/dist/observability/recent.js +63 -2
- package/dist/payloads/read-stdin-json.js +212 -1
- package/dist/rg-wrapper/core.js +714 -0
- package/dist/rg-wrapper/options.js +125 -0
- package/dist/rtk-wrapper/core.js +144 -0
- package/dist/rtk-wrapper/git-safety.js +203 -0
- package/dist/rtk-wrapper/output-adapter.js +106 -0
- package/dist/runtime/buffered-process.js +114 -0
- package/dist/runtime/bundled-node.js +97 -1
- package/dist/runtime/command-lifecycle.js +2 -0
- package/dist/runtime/input-source.js +238 -1
- package/dist/runtime/node-cli-identity.js +37 -0
- package/dist/runtime/run-command.js +191 -1
- package/dist/selectors/parse-entities.js +84 -1
- package/dist/semantic/semantic-context-pool.js +830 -0
- package/dist/semantic/semantic-context-provider.js +416 -0
- package/dist/semantic/semantic-resident-admission.js +38 -0
- package/dist/semantic/semantic-worker-child.js +40 -0
- package/dist/semantic/semantic-worker-manager.js +460 -0
- package/dist/semantic/semantic-worker-protocol.js +2 -0
- package/dist/semantic/semantic-worker-runtime.js +38 -0
- package/dist/semantic/workspace-semantic-context-pools.js +136 -0
- package/dist/session/client.js +359 -1
- package/dist/session/daemon-state.js +185 -0
- package/dist/session/external-tool-coordinator.js +88 -0
- package/dist/session/external-tool-request.js +52 -0
- package/dist/session/lane-owner.js +116 -0
- package/dist/session/paths.js +71 -1
- package/dist/session/runtime-lifecycle.js +225 -0
- package/dist/session/runtime-shutdown.js +95 -0
- package/dist/session/server.js +1194 -8
- package/dist/session/session-health.js +27 -0
- package/dist/shared/agent-text.js +29 -1
- package/dist/shared/errors.js +496 -30
- package/dist/shared/event-loop.js +6 -1
- package/dist/shared/hints.js +37 -1
- package/dist/shared/metrics.js +43 -1
- package/dist/shared/presentation.js +69 -4
- package/dist/shared/stdin-examples.js +77 -3
- package/dist/shared/stdout.js +6 -2
- package/dist/shared/types.js +23 -1
- package/dist/tool-runtime/runtime-tools.js +120 -0
- package/dist/topology/availability.js +663 -0
- package/dist/topology/cache.js +130 -0
- package/dist/topology/candidates.js +372 -0
- package/dist/topology/core.js +903 -0
- package/dist/topology/dependency-snapshot.js +189 -0
- package/dist/topology/model.js +2 -0
- package/dist/topology/scope.js +100 -0
- package/dist/topology/ts-oracle-batch.js +529 -0
- package/dist/topology/ts-oracle-host.js +69 -0
- package/dist/topology/ts-oracle-model.js +2 -0
- package/dist/topology/ts-oracle.js +224 -0
- package/dist/topology/tsconfig-loader.js +105 -0
- package/dist/topology/workspace-project-index.js +542 -0
- package/dist/tracing/config.js +192 -2
- package/dist/tracing/failure-summary.js +100 -0
- package/dist/tracing/trace.js +318 -5
- package/dist/tsc-wrapper/core.js +697 -0
- package/dist/workers/control-plane/aib-control-plane-worker.cjs +80 -0
- package/dist/workers/control-plane/client-config.default.json +3 -0
- package/dist/workers/lexical-worker-child.js +27 -0
- package/dist/workers/lexical-worker-manager.js +394 -0
- package/dist/workers/lexical-worker-protocol.js +2 -0
- package/dist/workers/lexical-worker-runtime.js +25 -0
- package/dist/workers/owned-one-shot-process.js +115 -0
- package/dist/workers/product-storage.js +23 -0
- package/dist/workers/registry.js +241 -0
- package/package.json +8 -11
- package/runtimes/tools/rg/darwin-arm64/rg +0 -0
- package/runtimes/tools/rg/darwin-x64/rg +0 -0
- package/runtimes/tools/rg/linux-arm64/rg +0 -0
- package/runtimes/tools/rg/linux-x64/rg +0 -0
- package/runtimes/tools/rg/manifest.json +36 -0
- package/runtimes/tools/rg/win32-x64/rg.exe +0 -0
- package/runtimes/tools/rtk/darwin-arm64/rtk +0 -0
- package/runtimes/tools/rtk/darwin-x64/rtk +0 -0
- package/runtimes/tools/rtk/linux-arm64/rtk +0 -0
- package/runtimes/tools/rtk/linux-x64/rtk +0 -0
- package/runtimes/tools/rtk/manifest.json +36 -0
- package/runtimes/tools/rtk/win32-x64/rtk.exe +0 -0
- package/scripts/postinstall.cjs +29 -29
- package/scripts/provision-runtime.cjs +411 -459
- package/dist/client/http-client.js +0 -1
- package/dist/client/transport-options.js +0 -1
- package/dist/client/websocket-client.js +0 -1
- package/dist/commands/entity-resolution.js +0 -1
- package/dist/commands/inspect-symbol-query.js +0 -1
- package/dist/commands/list-instances.js +0 -1
- package/dist/commands/module-plan-command.js +0 -1
- package/dist/commands/move-command.js +0 -1
- package/dist/commands/move-to-file.js +0 -2
- package/dist/commands/ping.js +0 -1
- package/dist/commands/refactor-command.js +0 -1
- package/dist/commands/rename-command.js +0 -1
- package/dist/commands/runtime-command.js +0 -4
- package/dist/commands/runtime-info.js +0 -1
- package/dist/commands/validate-module-plan.js +0 -2
- package/dist/compatibility/policy.js +0 -1
- package/dist/config/auto-start-ide.js +0 -1
- package/dist/discovery/registry.js +0 -1
- package/dist/discovery/select-instance.js +0 -1
- package/dist/help/docs/mutation.md +0 -50
- package/dist/help/docs/refactor.batch.md +0 -44
- package/dist/help/dsl/docs/mutation.md +0 -50
- package/dist/help/dsl/docs/refactor.batch.md +0 -44
- package/dist/help/dsl/topics/mutation.md +0 -48
- package/dist/help/dsl/topics/refactor.batch.md +0 -33
- package/dist/help/json/bootstrap.md +0 -1085
- package/dist/help/json/docs/basics.md +0 -15
- package/dist/help/json/docs/config-setup.aliases.md +0 -56
- package/dist/help/json/docs/config-setup.excludes.md +0 -45
- package/dist/help/json/docs/config-setup.import-normalize.md +0 -86
- package/dist/help/json/docs/config-setup.import-rules.md +0 -96
- package/dist/help/json/docs/config-setup.tsconfigs.md +0 -33
- package/dist/help/json/docs/dsl.md +0 -25
- package/dist/help/json/docs/first-setup.md +0 -292
- package/dist/help/json/docs/help-format.md +0 -9
- package/dist/help/json/docs/help-protocol.md +0 -26
- package/dist/help/json/docs/imports.normalize.md +0 -47
- package/dist/help/json/docs/inspect.code.md +0 -41
- package/dist/help/json/docs/inspect.cycles.md +0 -38
- package/dist/help/json/docs/inspect.deps.md +0 -46
- package/dist/help/json/docs/inspect.duplicates.md +0 -65
- package/dist/help/json/docs/inspect.exports.md +0 -40
- package/dist/help/json/docs/inspect.file.md +0 -38
- package/dist/help/json/docs/inspect.graph.md +0 -139
- package/dist/help/json/docs/inspect.imports.md +0 -15
- package/dist/help/json/docs/inspect.md +0 -88
- package/dist/help/json/docs/inspect.members.md +0 -32
- package/dist/help/json/docs/inspect.tree.md +0 -32
- package/dist/help/json/docs/inspect.usages.md +0 -61
- package/dist/help/json/docs/modulePlan.md +0 -73
- package/dist/help/json/docs/move.md +0 -56
- package/dist/help/json/docs/mutation.md +0 -65
- package/dist/help/json/docs/patterns.md +0 -76
- package/dist/help/json/docs/prefs.md +0 -40
- package/dist/help/json/docs/qr.md +0 -37
- package/dist/help/json/docs/quick-map.md +0 -30
- package/dist/help/json/docs/refactor.batch.md +0 -72
- package/dist/help/json/docs/rename.md +0 -47
- package/dist/help/json/docs/reveal.md +0 -30
- package/dist/help/json/docs/selectors.md +0 -23
- package/dist/help/json/docs/session.md +0 -77
- package/dist/help/json/docs/view.md +0 -30
- package/dist/help/json/full.md +0 -1085
- package/dist/help/json/snippets/agents.md +0 -14
- package/dist/help/json/topics/basics.md +0 -13
- package/dist/help/json/topics/config-setup.aliases.md +0 -54
- package/dist/help/json/topics/config-setup.excludes.md +0 -43
- package/dist/help/json/topics/config-setup.import-normalize.md +0 -84
- package/dist/help/json/topics/config-setup.import-rules.md +0 -94
- package/dist/help/json/topics/config-setup.tsconfigs.md +0 -31
- package/dist/help/json/topics/dsl.md +0 -23
- package/dist/help/json/topics/first-setup.md +0 -290
- package/dist/help/json/topics/help-format.md +0 -7
- package/dist/help/json/topics/help-protocol.md +0 -24
- package/dist/help/json/topics/imports.normalize.md +0 -45
- package/dist/help/json/topics/inspect.code.md +0 -39
- package/dist/help/json/topics/inspect.cycles.md +0 -36
- package/dist/help/json/topics/inspect.deps.md +0 -44
- package/dist/help/json/topics/inspect.duplicates.md +0 -37
- package/dist/help/json/topics/inspect.exports.md +0 -38
- package/dist/help/json/topics/inspect.file.md +0 -36
- package/dist/help/json/topics/inspect.graph.md +0 -137
- package/dist/help/json/topics/inspect.imports.md +0 -13
- package/dist/help/json/topics/inspect.md +0 -86
- package/dist/help/json/topics/inspect.members.md +0 -30
- package/dist/help/json/topics/inspect.tree.md +0 -22
- package/dist/help/json/topics/inspect.usages.md +0 -59
- package/dist/help/json/topics/modulePlan.md +0 -60
- package/dist/help/json/topics/move.md +0 -46
- package/dist/help/json/topics/mutation.md +0 -63
- package/dist/help/json/topics/patterns.md +0 -74
- package/dist/help/json/topics/prefs.md +0 -38
- package/dist/help/json/topics/qr.md +0 -35
- package/dist/help/json/topics/quick-map.md +0 -28
- package/dist/help/json/topics/refactor.batch.md +0 -61
- package/dist/help/json/topics/rename.md +0 -42
- package/dist/help/json/topics/reveal.md +0 -28
- package/dist/help/json/topics/selectors.md +0 -21
- package/dist/help/json/topics/session.md +0 -59
- package/dist/help/json/topics/view.md +0 -28
- package/dist/help/topics/mutation.md +0 -48
- package/dist/help/topics/refactor.batch.md +0 -33
- package/dist/ide-launch/common.cjs +0 -162
- package/dist/managed-host/extension-vsix-resolver.js +0 -1
- package/dist/managed-host/manage-serve-web-host.cjs +0 -141
- package/dist/managed-host/serve-web-autostart.js +0 -1
- package/dist/managed-host/serve-web-host.cjs +0 -1904
- package/dist/runtime/managed-runtime-provisioning.js +0 -1
- package/dist/shared/diagnostic-catalog.js +0 -1
- package/dist/shared/diagnostics.js +0 -1
- package/dist/shared/operations.js +0 -1
- package/dist/shared/protocol.js +0 -1
- package/dist/shared/routes.js +0 -1
- package/extension/vscode-refactor-bridge-extension.vsix +0 -0
- package/runtimes/launcher/linux-x64/aib +0 -0
- package/runtimes/launcher/win-x64/aib.exe +0 -0
|
@@ -0,0 +1,993 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.planObjectUnpackSemanticPreview = planObjectUnpackSemanticPreview;
|
|
40
|
+
const crypto = __importStar(require("node:crypto"));
|
|
41
|
+
const fs = __importStar(require("node:fs"));
|
|
42
|
+
const path = __importStar(require("node:path"));
|
|
43
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
44
|
+
const targeted_import_canonicalizer_1 = require("./targeted-import-canonicalizer");
|
|
45
|
+
const concrete_edit_plan_1 = require("./concrete-edit-plan");
|
|
46
|
+
const object_mutation_partition_1 = require("./object-mutation-partition");
|
|
47
|
+
const semantic_workspace_1 = require("./semantic-workspace");
|
|
48
|
+
const runtime_cycle_query_1 = require("./runtime-cycle-query");
|
|
49
|
+
const object_pack_semantic_preview_1 = require("./object-pack-semantic-preview");
|
|
50
|
+
function planObjectUnpackSemanticPreview(cwd, input) {
|
|
51
|
+
return (0, object_mutation_partition_1.planBestEffortObjectMutation)(input.rows, (rows) => planObjectUnpackSemanticPreviewStrict(cwd, { sourceFile: input.sourceFile, rows }), {
|
|
52
|
+
blocksWholeGroup: (issue) => !issue.selector || issue.code === "OBJECT_UNPACK_OBJECT_WRITE_UNSUPPORTED"
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function planObjectUnpackSemanticPreviewStrict(cwd, input) {
|
|
56
|
+
const root = path.resolve(cwd);
|
|
57
|
+
const sourceFile = path.resolve(root, input.sourceFile);
|
|
58
|
+
const displaySource = toRepoPath(root, sourceFile);
|
|
59
|
+
const rows = input.rows.map((row) => ({
|
|
60
|
+
objectName: row.objectName,
|
|
61
|
+
selectors: [...new Set(row.selectors)].sort()
|
|
62
|
+
})).sort((left, right) => left.objectName.localeCompare(right.objectName));
|
|
63
|
+
const unsupported = [];
|
|
64
|
+
if (!isSupportedSourceExtension(sourceFile)) {
|
|
65
|
+
unsupported.push({
|
|
66
|
+
code: "OBJECT_UNPACK_SOURCE_KIND_UNSUPPORTED",
|
|
67
|
+
message: "object.unpack semantic preview supports TS/TSX/MTS ESM sources only",
|
|
68
|
+
file: displaySource
|
|
69
|
+
});
|
|
70
|
+
return failure(displaySource, rows, unsupported);
|
|
71
|
+
}
|
|
72
|
+
const workspace = (0, semantic_workspace_1.createSemanticWorkspace)({ workspaceRoot: root, focusFiles: [sourceFile] });
|
|
73
|
+
const moduleCollection = (0, semantic_workspace_1.collectSemanticModuleEdges)(workspace);
|
|
74
|
+
let moduleScope = (0, semantic_workspace_1.scopeRelevantSemanticModuleEdges)(workspace, moduleCollection, {
|
|
75
|
+
sourceFiles: [displaySource]
|
|
76
|
+
});
|
|
77
|
+
if (!moduleScope.coverage.complete) {
|
|
78
|
+
unsupported.push(...moduleScope.coverage.incompleteReasons.map(toCoverageEvidence));
|
|
79
|
+
unsupported.push({
|
|
80
|
+
code: "OBJECT_UNPACK_CYCLE_EVIDENCE_UNAVAILABLE",
|
|
81
|
+
message: "runtime cycle evidence is unavailable because semantic coverage is incomplete",
|
|
82
|
+
file: displaySource
|
|
83
|
+
});
|
|
84
|
+
return failure(displaySource, rows, unsupported, moduleScope.coverage);
|
|
85
|
+
}
|
|
86
|
+
const sourceProjects = (0, semantic_workspace_1.ownersForSemanticFile)(workspace, sourceFile);
|
|
87
|
+
if (sourceProjects.length !== 1) {
|
|
88
|
+
unsupported.push({
|
|
89
|
+
code: "OBJECT_UNPACK_MULTIPLE_OWNERS_UNSUPPORTED",
|
|
90
|
+
message: "object.unpack semantic preview requires exactly one owning source project",
|
|
91
|
+
file: displaySource,
|
|
92
|
+
details: sourceProjects.map((project) => toRepoPath(root, project.config.file))
|
|
93
|
+
});
|
|
94
|
+
return failure(displaySource, rows, unsupported, moduleScope.coverage);
|
|
95
|
+
}
|
|
96
|
+
const sourceProject = sourceProjects[0];
|
|
97
|
+
const source = sourceProject.program.getSourceFile(sourceFile);
|
|
98
|
+
if (!source || !isEsmSourceFile(sourceProject, source)) {
|
|
99
|
+
unsupported.push({
|
|
100
|
+
code: "OBJECT_UNPACK_ESM_REQUIRED",
|
|
101
|
+
message: "object.unpack semantic preview requires an actual ESM source in its owning project",
|
|
102
|
+
file: displaySource
|
|
103
|
+
});
|
|
104
|
+
return failure(displaySource, rows, unsupported, moduleScope.coverage);
|
|
105
|
+
}
|
|
106
|
+
const objects = resolveObjects(workspace, sourceProject, source, rows, unsupported);
|
|
107
|
+
for (const object of objects) {
|
|
108
|
+
object.usages = (0, semantic_workspace_1.findSemanticReferences)(workspace, object.symbol);
|
|
109
|
+
for (const member of object.members) {
|
|
110
|
+
member.usages = (0, semantic_workspace_1.findSemanticReferences)(workspace, member.symbol);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
moduleScope = (0, semantic_workspace_1.scopeRelevantSemanticModuleEdges)(workspace, moduleCollection, {
|
|
114
|
+
sourceFiles: [displaySource],
|
|
115
|
+
affectedFiles: objects.flatMap((object) => [
|
|
116
|
+
...object.usages.map((usage) => usage.file),
|
|
117
|
+
...object.members.flatMap((member) => member.usages.map((usage) => usage.file))
|
|
118
|
+
])
|
|
119
|
+
});
|
|
120
|
+
if (!moduleScope.coverage.complete) {
|
|
121
|
+
unsupported.push(...moduleScope.coverage.incompleteReasons.map(toCoverageEvidence));
|
|
122
|
+
unsupported.push({
|
|
123
|
+
code: "OBJECT_UNPACK_CYCLE_EVIDENCE_UNAVAILABLE",
|
|
124
|
+
message: "runtime cycle evidence is unavailable because relevant module resolution is incomplete",
|
|
125
|
+
file: displaySource
|
|
126
|
+
});
|
|
127
|
+
return failure(displaySource, rows, unsupported, moduleScope.coverage);
|
|
128
|
+
}
|
|
129
|
+
for (const edge of moduleScope.edges) {
|
|
130
|
+
if (edge.toFile !== displaySource) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (edge.kind === "dynamic") {
|
|
134
|
+
unsupported.push({ code: "OBJECT_UNPACK_DYNAMIC_IMPORT_UNSUPPORTED", message: "dynamic imports of the unpacked source are unsupported", file: edge.fromFile });
|
|
135
|
+
}
|
|
136
|
+
else if (edge.kind === "require") {
|
|
137
|
+
unsupported.push({ code: "OBJECT_UNPACK_REQUIRE_UNSUPPORTED", message: "CommonJS require of the unpacked source is unsupported", file: edge.fromFile });
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
validateRequireConsumers(workspace, sourceFile, unsupported);
|
|
141
|
+
const cycleEvidence = (0, runtime_cycle_query_1.queryRuntimeCycleEvidence)(moduleScope.edges, [displaySource]);
|
|
142
|
+
if (cycleEvidence.cycles.length > 0) {
|
|
143
|
+
unsupported.push({
|
|
144
|
+
code: "OBJECT_UNPACK_RUNTIME_CYCLE_UNSUPPORTED",
|
|
145
|
+
message: "unpacked source participates in a runtime import cycle; initialization order cannot be proven safe",
|
|
146
|
+
file: displaySource,
|
|
147
|
+
details: cycleEvidence.cycles
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
validateAffectedOwnership(workspace, sourceFile, objects, moduleScope.edges, unsupported);
|
|
151
|
+
validateMemberReferenceFlows(workspace, sourceFile, objects, unsupported);
|
|
152
|
+
validateReExports(workspace, sourceFile, objects, unsupported);
|
|
153
|
+
if (unsupported.length > 0) {
|
|
154
|
+
return failure(displaySource, rows, unsupported, moduleScope.coverage);
|
|
155
|
+
}
|
|
156
|
+
const sourceReplacements = [];
|
|
157
|
+
const consumers = new Map();
|
|
158
|
+
const remainingObjectUse = new Set();
|
|
159
|
+
const memberByObjectAndName = new Map();
|
|
160
|
+
for (const object of objects) {
|
|
161
|
+
for (const member of object.members) {
|
|
162
|
+
memberByObjectAndName.set(`${object.objectName}\0${member.selector}`, member);
|
|
163
|
+
addExportModifier(source, member, sourceReplacements);
|
|
164
|
+
}
|
|
165
|
+
planObjectReferences(workspace, sourceFile, object, consumers, sourceReplacements, remainingObjectUse, unsupported);
|
|
166
|
+
}
|
|
167
|
+
if (unsupported.length > 0) {
|
|
168
|
+
return failure(displaySource, rows, unsupported, moduleScope.coverage);
|
|
169
|
+
}
|
|
170
|
+
planConsumerImports(workspace, sourceFile, objects, memberByObjectAndName, consumers, remainingObjectUse, unsupported);
|
|
171
|
+
if (unsupported.length > 0) {
|
|
172
|
+
return failure(displaySource, rows, unsupported, moduleScope.coverage);
|
|
173
|
+
}
|
|
174
|
+
const sourceText = fs.readFileSync(sourceFile, "utf8");
|
|
175
|
+
for (const object of objects) {
|
|
176
|
+
if (object.full && !remainingObjectUse.has(`${displaySource}\0${object.objectName}`)) {
|
|
177
|
+
addReplacement(sourceReplacements, {
|
|
178
|
+
start: object.statement.getStart(source),
|
|
179
|
+
end: statementEndWithTrailingNewline(sourceText, object.statement.end),
|
|
180
|
+
text: "",
|
|
181
|
+
reason: `object.unpack remove ${object.objectName}`
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
const remaining = object.literal.properties.filter((property) => !object.members.some((member) => member.property === property));
|
|
186
|
+
const printer = typescript_1.default.createPrinter({ newLine: typescript_1.default.NewLineKind.LineFeed });
|
|
187
|
+
const nextLiteral = typescript_1.default.factory.updateObjectLiteralExpression(object.literal, remaining);
|
|
188
|
+
addReplacement(sourceReplacements, {
|
|
189
|
+
start: object.literal.getStart(source),
|
|
190
|
+
end: object.literal.end,
|
|
191
|
+
text: printer.printNode(typescript_1.default.EmitHint.Expression, nextLiteral, source),
|
|
192
|
+
reason: `object.unpack retain ${object.objectName}`
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
const virtualTexts = new Map();
|
|
197
|
+
const sourceNext = applyReplacements(sourceText, sourceReplacements);
|
|
198
|
+
virtualTexts.set(displaySource, sourceNext);
|
|
199
|
+
const consumerSummaries = [];
|
|
200
|
+
for (const plan of [...consumers.values()].sort((left, right) => left.file.localeCompare(right.file))) {
|
|
201
|
+
const absolute = path.resolve(root, plan.file);
|
|
202
|
+
const original = fs.readFileSync(absolute, "utf8");
|
|
203
|
+
const rewritten = applyReplacements(original, plan.replacements);
|
|
204
|
+
const canonicalized = (0, targeted_import_canonicalizer_1.formatChangedNamedImports)(original, rewritten, absolute).text;
|
|
205
|
+
if (canonicalized === original) {
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
virtualTexts.set(plan.file, canonicalized);
|
|
209
|
+
consumerSummaries.push({
|
|
210
|
+
file: plan.file,
|
|
211
|
+
objectNames: [...plan.objectNames].sort(),
|
|
212
|
+
selectors: [...plan.selectors.keys()].sort(),
|
|
213
|
+
referenceCount: plan.referenceCount
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
if (!moduleShapesUnchanged(root, virtualTexts)) {
|
|
217
|
+
unsupported.push({
|
|
218
|
+
code: "OBJECT_UNPACK_MODULE_EDGE_CHANGE_UNSUPPORTED",
|
|
219
|
+
message: "planned edits change module edge shape; cycle evidence is no longer sufficient",
|
|
220
|
+
file: displaySource
|
|
221
|
+
});
|
|
222
|
+
return failure(displaySource, rows, unsupported, moduleScope.coverage);
|
|
223
|
+
}
|
|
224
|
+
const diagnostics = (0, object_pack_semantic_preview_1.validateVirtualProjectDiagnostics)(workspace, virtualTexts);
|
|
225
|
+
if (diagnostics.added.length > 0) {
|
|
226
|
+
unsupported.push({
|
|
227
|
+
code: "OBJECT_UNPACK_NEW_DIAGNOSTICS",
|
|
228
|
+
message: "virtual object.unpack edits introduce new project diagnostics",
|
|
229
|
+
file: displaySource,
|
|
230
|
+
details: diagnostics.added
|
|
231
|
+
});
|
|
232
|
+
return failure(displaySource, rows, unsupported, moduleScope.coverage);
|
|
233
|
+
}
|
|
234
|
+
const edits = [...virtualTexts.entries()].map(([file, text]) => ({
|
|
235
|
+
file,
|
|
236
|
+
start: 0,
|
|
237
|
+
end: fs.readFileSync(path.resolve(root, file), "utf8").length,
|
|
238
|
+
text,
|
|
239
|
+
reason: file === displaySource ? "object.unpack source preview" : "object.unpack consumer preview"
|
|
240
|
+
})).sort((left, right) => left.file.localeCompare(right.file));
|
|
241
|
+
const beforeHashes = (0, concrete_edit_plan_1.createConcretePreconditions)(root, edits);
|
|
242
|
+
const symbols = uniqueSymbols(objects.flatMap((object) => [object.symbol, ...object.members.map((member) => member.symbol)]));
|
|
243
|
+
const usages = uniqueUsages(objects.flatMap((object) => [object.usages, ...object.members.map((member) => member.usages)]).flat());
|
|
244
|
+
const fingerprintEdges = collectFingerprintModuleEdges(moduleScope.edges, displaySource);
|
|
245
|
+
const rowFingerprints = objects.map((object) => (0, concrete_edit_plan_1.createSemanticFingerprint)({
|
|
246
|
+
intent: {
|
|
247
|
+
operation: "object.unpack",
|
|
248
|
+
sourceFile: displaySource,
|
|
249
|
+
objectName: object.objectName,
|
|
250
|
+
members: object.members.map((member) => member.selector),
|
|
251
|
+
exportMode: "named"
|
|
252
|
+
},
|
|
253
|
+
projects: moduleScope.coverage.projects,
|
|
254
|
+
symbols: [object.symbol, ...object.members.map((member) => member.symbol)],
|
|
255
|
+
references: uniqueUsages([object.usages, ...object.members.map((member) => member.usages)].flat()),
|
|
256
|
+
moduleEdges: fingerprintEdges
|
|
257
|
+
}));
|
|
258
|
+
return {
|
|
259
|
+
ok: true,
|
|
260
|
+
operation: "exports.object.unpack.preview",
|
|
261
|
+
applyAvailable: true,
|
|
262
|
+
sourceFile: displaySource,
|
|
263
|
+
objectCount: objects.length,
|
|
264
|
+
memberCount: objects.reduce((sum, object) => sum + object.members.length, 0),
|
|
265
|
+
importerCount: consumerSummaries.length,
|
|
266
|
+
referenceCount: consumerSummaries.reduce((sum, item) => sum + item.referenceCount, 0),
|
|
267
|
+
objects: objects.map((object) => ({
|
|
268
|
+
objectName: object.objectName,
|
|
269
|
+
selectors: object.members.map((member) => member.selector).sort(),
|
|
270
|
+
full: object.full
|
|
271
|
+
})),
|
|
272
|
+
importers: consumerSummaries,
|
|
273
|
+
filesTouched: edits.map((edit) => edit.file),
|
|
274
|
+
filesWritten: [],
|
|
275
|
+
semanticFingerprint: sha256(rowFingerprints.join("\0")),
|
|
276
|
+
rowFingerprints,
|
|
277
|
+
edits,
|
|
278
|
+
beforeHashes,
|
|
279
|
+
coverage: moduleScope.coverage,
|
|
280
|
+
symbols,
|
|
281
|
+
usages,
|
|
282
|
+
moduleEdges: fingerprintEdges,
|
|
283
|
+
cycleEvidence,
|
|
284
|
+
diagnostics,
|
|
285
|
+
unsupported: []
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
function resolveObjects(workspace, project, source, rows, unsupported) {
|
|
289
|
+
const result = [];
|
|
290
|
+
const seenObjects = new Set();
|
|
291
|
+
for (const row of rows) {
|
|
292
|
+
if (seenObjects.has(row.objectName)) {
|
|
293
|
+
unsupported.push({ code: "OBJECT_UNPACK_DUPLICATE_OBJECT", message: "object name is used by more than one row", objectName: row.objectName });
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
seenObjects.add(row.objectName);
|
|
297
|
+
const resolution = (0, semantic_workspace_1.resolveExportedSemanticSymbol)(workspace, source.fileName, row.objectName);
|
|
298
|
+
if (resolution.status !== "resolved" || !resolution.symbol) {
|
|
299
|
+
unsupported.push({
|
|
300
|
+
code: resolution.status === "ambiguous" ? "OBJECT_UNPACK_OBJECT_AMBIGUOUS" : "OBJECT_UNPACK_OBJECT_NOT_FOUND",
|
|
301
|
+
message: "named exported object could not be resolved uniquely",
|
|
302
|
+
objectName: row.objectName,
|
|
303
|
+
details: resolution.reason
|
|
304
|
+
});
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
const declarationNode = findDeclarationByIdentity(source, resolution.symbol);
|
|
308
|
+
const declaration = declarationNode && typescript_1.default.isVariableDeclaration(declarationNode) ? declarationNode : null;
|
|
309
|
+
if (!declaration || !typescript_1.default.isIdentifier(declaration.name) || !typescript_1.default.isVariableDeclarationList(declaration.parent)) {
|
|
310
|
+
unsupported.push({
|
|
311
|
+
code: "OBJECT_UNPACK_SOURCE_OBJECT_UNSUPPORTED",
|
|
312
|
+
message: "object.unpack requires one named exported immutable const object declaration",
|
|
313
|
+
objectName: row.objectName,
|
|
314
|
+
file: toRepoPath(workspace.root, source.fileName)
|
|
315
|
+
});
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
const list = declaration.parent;
|
|
319
|
+
const statement = list.parent;
|
|
320
|
+
if (!typescript_1.default.isVariableStatement(statement) || list.declarations.length !== 1 ||
|
|
321
|
+
(list.flags & typescript_1.default.NodeFlags.Const) === 0 || !hasExportModifier(statement) || hasDefaultModifier(statement) || !declaration.initializer) {
|
|
322
|
+
unsupported.push({
|
|
323
|
+
code: "OBJECT_UNPACK_SOURCE_OBJECT_UNSUPPORTED",
|
|
324
|
+
message: "object.unpack requires one named exported immutable const object declaration",
|
|
325
|
+
objectName: row.objectName,
|
|
326
|
+
file: toRepoPath(workspace.root, source.fileName)
|
|
327
|
+
});
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
const literal = unwrapObjectLiteral(declaration.initializer);
|
|
331
|
+
if (!literal) {
|
|
332
|
+
unsupported.push({
|
|
333
|
+
code: "OBJECT_UNPACK_OBJECT_LITERAL_REQUIRED",
|
|
334
|
+
message: "object.unpack requires a statically unwrap-able object literal initializer",
|
|
335
|
+
objectName: row.objectName
|
|
336
|
+
});
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
const shorthandByName = new Map();
|
|
340
|
+
for (const property of literal.properties) {
|
|
341
|
+
if (typescript_1.default.isShorthandPropertyAssignment(property)) {
|
|
342
|
+
if (shorthandByName.has(property.name.text)) {
|
|
343
|
+
unsupported.push({ code: "OBJECT_UNPACK_DUPLICATE_PROPERTY", message: "object literal contains duplicate shorthand properties", objectName: row.objectName, selector: property.name.text });
|
|
344
|
+
}
|
|
345
|
+
shorthandByName.set(property.name.text, property);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
const members = [];
|
|
349
|
+
for (const selector of row.selectors) {
|
|
350
|
+
const property = shorthandByName.get(selector);
|
|
351
|
+
if (!property) {
|
|
352
|
+
const propertyWithName = literal.properties.find((candidate) => propertyNameText(candidate.name) === selector ||
|
|
353
|
+
candidate.name && typescript_1.default.isComputedPropertyName(candidate.name) &&
|
|
354
|
+
typescript_1.default.isStringLiteralLike(candidate.name.expression) && candidate.name.expression.text === selector);
|
|
355
|
+
const obscuredBySpread = literal.properties.some(typescript_1.default.isSpreadAssignment);
|
|
356
|
+
unsupported.push({
|
|
357
|
+
code: propertyWithName || obscuredBySpread ? "OBJECT_UNPACK_MEMBER_SHAPE_UNSUPPORTED" : "OBJECT_UNPACK_MEMBER_NOT_FOUND",
|
|
358
|
+
message: propertyWithName || obscuredBySpread ? "selected member must be a plain shorthand property" : "selected object member was not found",
|
|
359
|
+
objectName: row.objectName,
|
|
360
|
+
selector
|
|
361
|
+
});
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
const memberSymbol = project.checker.getShorthandAssignmentValueSymbol(property);
|
|
365
|
+
const identity = memberSymbol ? (0, semantic_workspace_1.resolveSemanticSymbolIdentity)(workspace, project, memberSymbol) : null;
|
|
366
|
+
const memberDeclarationNode = identity ? findDeclarationByIdentity(source, identity) : null;
|
|
367
|
+
const validated = validateMemberDeclaration(memberDeclarationNode, row.objectName, selector, source, unsupported);
|
|
368
|
+
if (identity && validated) {
|
|
369
|
+
members.push({
|
|
370
|
+
objectName: row.objectName,
|
|
371
|
+
selector,
|
|
372
|
+
symbol: identity,
|
|
373
|
+
declaration: validated.declaration,
|
|
374
|
+
statement: validated.statement,
|
|
375
|
+
property,
|
|
376
|
+
usages: []
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
else if (!identity) {
|
|
380
|
+
unsupported.push({ code: "OBJECT_UNPACK_MEMBER_SYMBOL_UNRESOLVED", message: "shorthand member symbol could not be resolved", objectName: row.objectName, selector });
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
result.push({
|
|
384
|
+
objectName: row.objectName,
|
|
385
|
+
symbol: resolution.symbol,
|
|
386
|
+
declaration,
|
|
387
|
+
statement,
|
|
388
|
+
literal,
|
|
389
|
+
members,
|
|
390
|
+
full: members.length === literal.properties.length && literal.properties.every(typescript_1.default.isShorthandPropertyAssignment),
|
|
391
|
+
usages: []
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
return result;
|
|
395
|
+
}
|
|
396
|
+
function validateMemberDeclaration(node, objectName, selector, source, unsupported) {
|
|
397
|
+
if (node && typescript_1.default.isFunctionDeclaration(node) && node.name && !hasDefaultModifier(node)) {
|
|
398
|
+
if (containsThisSensitiveSyntax(node)) {
|
|
399
|
+
unsupported.push({ code: "OBJECT_UNPACK_THIS_SENSITIVE", message: "selected function contains this/super-sensitive semantics", objectName, selector, file: source.fileName });
|
|
400
|
+
return null;
|
|
401
|
+
}
|
|
402
|
+
return { declaration: node, statement: node };
|
|
403
|
+
}
|
|
404
|
+
if (node && typescript_1.default.isVariableDeclaration(node) && typescript_1.default.isIdentifier(node.name)) {
|
|
405
|
+
const list = node.parent;
|
|
406
|
+
const statement = list.parent;
|
|
407
|
+
if (!typescript_1.default.isVariableDeclarationList(list) || !typescript_1.default.isVariableStatement(statement) || list.declarations.length !== 1 ||
|
|
408
|
+
(list.flags & typescript_1.default.NodeFlags.Const) === 0 || !node.initializer || hasDefaultModifier(statement)) {
|
|
409
|
+
unsupported.push({ code: "OBJECT_UNPACK_MEMBER_DECLARATION_UNSUPPORTED", message: "selected member must resolve to one initialized const declaration", objectName, selector });
|
|
410
|
+
return null;
|
|
411
|
+
}
|
|
412
|
+
if (containsThisSensitiveSyntax(node.initializer)) {
|
|
413
|
+
unsupported.push({ code: "OBJECT_UNPACK_THIS_SENSITIVE", message: "selected const initializer contains this/super-sensitive semantics", objectName, selector });
|
|
414
|
+
return null;
|
|
415
|
+
}
|
|
416
|
+
return { declaration: node, statement };
|
|
417
|
+
}
|
|
418
|
+
unsupported.push({
|
|
419
|
+
code: "OBJECT_UNPACK_MEMBER_DECLARATION_UNSUPPORTED",
|
|
420
|
+
message: "selected shorthand member must resolve to a local named function or initialized const",
|
|
421
|
+
objectName,
|
|
422
|
+
selector
|
|
423
|
+
});
|
|
424
|
+
return null;
|
|
425
|
+
}
|
|
426
|
+
function validateAffectedOwnership(workspace, sourceFile, objects, edges, unsupported) {
|
|
427
|
+
const sourceDisplay = toRepoPath(workspace.root, sourceFile);
|
|
428
|
+
const affected = new Set();
|
|
429
|
+
for (const object of objects) {
|
|
430
|
+
for (const usage of object.usages)
|
|
431
|
+
affected.add(usage.file);
|
|
432
|
+
for (const member of object.members)
|
|
433
|
+
for (const usage of member.usages)
|
|
434
|
+
affected.add(usage.file);
|
|
435
|
+
}
|
|
436
|
+
for (const edge of edges)
|
|
437
|
+
if (edge.toFile === sourceDisplay)
|
|
438
|
+
affected.add(edge.fromFile);
|
|
439
|
+
affected.delete(sourceDisplay);
|
|
440
|
+
for (const file of [...affected].sort()) {
|
|
441
|
+
const owners = (0, semantic_workspace_1.ownersForSemanticFile)(workspace, file);
|
|
442
|
+
if (owners.length > 1) {
|
|
443
|
+
unsupported.push({
|
|
444
|
+
code: "OBJECT_UNPACK_MULTIPLE_OWNERS_UNSUPPORTED",
|
|
445
|
+
message: "affected object.unpack file belongs to multiple owning projects",
|
|
446
|
+
file,
|
|
447
|
+
details: owners.map((project) => toRepoPath(workspace.root, project.config.file))
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
function validateMemberReferenceFlows(workspace, sourceFile, objects, unsupported) {
|
|
453
|
+
for (const object of objects) {
|
|
454
|
+
for (const member of object.members) {
|
|
455
|
+
for (const usage of member.usages) {
|
|
456
|
+
const project = projectForUsage(workspace, usage);
|
|
457
|
+
const source = project?.program.getSourceFile(path.resolve(workspace.root, usage.file));
|
|
458
|
+
const node = source ? findIdentifierAt(source, usage.start, usage.end) : null;
|
|
459
|
+
if (!project || !source || !node) {
|
|
460
|
+
unsupported.push({ code: "OBJECT_UNPACK_REFERENCE_NODE_UNRESOLVED", message: "member reference could not be mapped back to syntax", objectName: object.objectName, selector: member.selector, file: usage.file });
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
if (isDeclarationName(node) || node === member.property.name) {
|
|
464
|
+
continue;
|
|
465
|
+
}
|
|
466
|
+
const rejected = usage.kinds.filter((kind) => [
|
|
467
|
+
"property-write", "update/delete", "destructure", "namespace", "re-export",
|
|
468
|
+
"type-position/type-query", "escape/identity", "dynamic/require"
|
|
469
|
+
].includes(kind));
|
|
470
|
+
if (rejected.length > 0) {
|
|
471
|
+
unsupported.push({
|
|
472
|
+
code: "OBJECT_UNPACK_MEMBER_FLOW_UNSUPPORTED",
|
|
473
|
+
message: "selected member has an unsupported reference flow",
|
|
474
|
+
objectName: object.objectName,
|
|
475
|
+
selector: member.selector,
|
|
476
|
+
file: usage.file,
|
|
477
|
+
usageKinds: [...new Set(rejected)].sort()
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
function planObjectReferences(workspace, sourceFile, object, consumers, sourceReplacements, remainingObjectUse, unsupported) {
|
|
485
|
+
const sourceDisplay = toRepoPath(workspace.root, sourceFile);
|
|
486
|
+
const selected = new Map(object.members.map((member) => [member.selector, member]));
|
|
487
|
+
for (const usage of object.usages) {
|
|
488
|
+
const project = projectForUsage(workspace, usage);
|
|
489
|
+
const source = project?.program.getSourceFile(path.resolve(workspace.root, usage.file));
|
|
490
|
+
const node = source ? findIdentifierAt(source, usage.start, usage.end) : null;
|
|
491
|
+
if (!project || !source || !node) {
|
|
492
|
+
unsupported.push({ code: "OBJECT_UNPACK_REFERENCE_NODE_UNRESOLVED", message: "object reference could not be mapped back to syntax", objectName: object.objectName, file: usage.file });
|
|
493
|
+
continue;
|
|
494
|
+
}
|
|
495
|
+
if (node === object.declaration.name || findAncestor(node, typescript_1.default.isImportSpecifier)) {
|
|
496
|
+
continue;
|
|
497
|
+
}
|
|
498
|
+
if (findAncestor(node, typescript_1.default.isExportSpecifier)) {
|
|
499
|
+
unsupported.push({ code: "OBJECT_UNPACK_REEXPORT_UNSUPPORTED", message: "re-export of unpacked object is unsupported", objectName: object.objectName, file: usage.file });
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
502
|
+
const parent = node.parent;
|
|
503
|
+
if (parent && typescript_1.default.isPropertyAccessExpression(parent) && parent.expression === node) {
|
|
504
|
+
if (parent.questionDotToken || parent.parent && typescript_1.default.isCallExpression(parent.parent) &&
|
|
505
|
+
parent.parent.expression === parent && parent.parent.questionDotToken) {
|
|
506
|
+
unsupported.push({ code: "OBJECT_UNPACK_OPTIONAL_ACCESS_UNSUPPORTED", message: "optional object member access is unsupported", objectName: object.objectName, file: usage.file });
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
const member = selected.get(parent.name.text);
|
|
510
|
+
if (!member) {
|
|
511
|
+
remainingObjectUse.add(`${usage.file}\0${object.objectName}`);
|
|
512
|
+
continue;
|
|
513
|
+
}
|
|
514
|
+
if (isWriteOrUpdateTarget(parent)) {
|
|
515
|
+
unsupported.push({ code: "OBJECT_UNPACK_OBJECT_WRITE_UNSUPPORTED", message: "selected object member is written, updated, or deleted", objectName: object.objectName, selector: member.selector, file: usage.file });
|
|
516
|
+
continue;
|
|
517
|
+
}
|
|
518
|
+
if (parent.parent && typescript_1.default.isCallExpression(parent.parent) && parent.parent.expression === parent && !supportsDirectCall(member)) {
|
|
519
|
+
unsupported.push({ code: "OBJECT_UNPACK_CALL_BINDING_UNPROVEN", message: "selected member is not proven callable with preserved binding semantics", objectName: object.objectName, selector: member.selector, file: usage.file });
|
|
520
|
+
continue;
|
|
521
|
+
}
|
|
522
|
+
const targetName = usage.file === sourceDisplay
|
|
523
|
+
? member.selector
|
|
524
|
+
: chooseConsumerBinding(workspace, project, source, sourceFile, object.objectName, member);
|
|
525
|
+
const replacement = {
|
|
526
|
+
start: parent.getStart(source),
|
|
527
|
+
end: parent.end,
|
|
528
|
+
text: targetName,
|
|
529
|
+
reason: `object.unpack reference ${object.objectName}.${member.selector}`
|
|
530
|
+
};
|
|
531
|
+
if (usage.file === sourceDisplay) {
|
|
532
|
+
addReplacement(sourceReplacements, replacement);
|
|
533
|
+
}
|
|
534
|
+
else {
|
|
535
|
+
const plan = consumerPlan(consumers, usage.file);
|
|
536
|
+
addReplacement(plan.replacements, replacement);
|
|
537
|
+
plan.objectNames.add(object.objectName);
|
|
538
|
+
plan.selectors.set(member.selector, targetName);
|
|
539
|
+
plan.referenceCount += 1;
|
|
540
|
+
}
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
if (parent && typescript_1.default.isElementAccessExpression(parent) && parent.expression === node) {
|
|
544
|
+
unsupported.push({ code: "OBJECT_UNPACK_COMPUTED_ACCESS_UNSUPPORTED", message: "computed object member access is unsupported", objectName: object.objectName, file: usage.file });
|
|
545
|
+
continue;
|
|
546
|
+
}
|
|
547
|
+
if (parent && typescript_1.default.isPropertyAccessExpression(parent) && parent.name === node) {
|
|
548
|
+
unsupported.push({ code: "OBJECT_UNPACK_NAMESPACE_USAGE_UNSUPPORTED", message: "namespace-qualified object usage is unsupported", objectName: object.objectName, file: usage.file });
|
|
549
|
+
continue;
|
|
550
|
+
}
|
|
551
|
+
unsupported.push({
|
|
552
|
+
code: objectUsageCode(usage.kinds),
|
|
553
|
+
message: "object value has an unsupported identity, enumeration, destructure, or escape flow",
|
|
554
|
+
objectName: object.objectName,
|
|
555
|
+
file: usage.file,
|
|
556
|
+
usageKinds: usage.kinds
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
function planConsumerImports(workspace, sourceFile, objects, memberByObjectAndName, consumers, remainingObjectUse, unsupported) {
|
|
561
|
+
const objectByKey = new Map(objects.map((object) => [object.symbol.key, object]));
|
|
562
|
+
seedConsumerPlansForUnusedFullObjectImports(workspace, sourceFile, objectByKey, consumers, remainingObjectUse);
|
|
563
|
+
for (const plan of consumers.values()) {
|
|
564
|
+
const owners = (0, semantic_workspace_1.ownersForSemanticFile)(workspace, plan.file);
|
|
565
|
+
const project = owners[0];
|
|
566
|
+
const source = project?.program.getSourceFile(path.resolve(workspace.root, plan.file));
|
|
567
|
+
if (!project || owners.length !== 1 || !source) {
|
|
568
|
+
unsupported.push({ code: "OBJECT_UNPACK_CONSUMER_PROJECT_UNRESOLVED", message: "consumer project could not be resolved uniquely", file: plan.file });
|
|
569
|
+
continue;
|
|
570
|
+
}
|
|
571
|
+
const imports = [];
|
|
572
|
+
for (const statement of source.statements) {
|
|
573
|
+
if (!typescript_1.default.isImportDeclaration(statement) || !typescript_1.default.isStringLiteralLike(statement.moduleSpecifier) ||
|
|
574
|
+
!resolvesToFile(project, source.fileName, statement.moduleSpecifier.text, sourceFile)) {
|
|
575
|
+
continue;
|
|
576
|
+
}
|
|
577
|
+
if (statement.attributes) {
|
|
578
|
+
unsupported.push({ code: "OBJECT_UNPACK_IMPORT_ATTRIBUTES_UNSUPPORTED", message: "imports with attributes are unsupported", file: plan.file });
|
|
579
|
+
continue;
|
|
580
|
+
}
|
|
581
|
+
const clause = statement.importClause;
|
|
582
|
+
if (!clause || clause.isTypeOnly || clause.namedBindings && typescript_1.default.isNamespaceImport(clause.namedBindings)) {
|
|
583
|
+
unsupported.push({ code: "OBJECT_UNPACK_NAMESPACE_IMPORT_UNSUPPORTED", message: "namespace/type-only import from unpacked source is unsupported", file: plan.file });
|
|
584
|
+
continue;
|
|
585
|
+
}
|
|
586
|
+
const bindings = clause.namedBindings;
|
|
587
|
+
const objectElements = [];
|
|
588
|
+
if (bindings && typescript_1.default.isNamedImports(bindings)) {
|
|
589
|
+
for (const element of bindings.elements) {
|
|
590
|
+
const identity = (0, semantic_workspace_1.resolveSemanticNodeIdentity)(workspace, project, element.name);
|
|
591
|
+
const object = identity ? objectByKey.get(identity.key) : undefined;
|
|
592
|
+
if (object)
|
|
593
|
+
objectElements.push({ element, object });
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
imports.push({ statement, objectElements });
|
|
597
|
+
}
|
|
598
|
+
const relevant = imports.filter((entry) => entry.objectElements.length > 0);
|
|
599
|
+
if (relevant.length === 0) {
|
|
600
|
+
unsupported.push({ code: "OBJECT_UNPACK_OBJECT_IMPORT_UNRESOLVED", message: "consumer object import could not be mapped to selected references", file: plan.file });
|
|
601
|
+
continue;
|
|
602
|
+
}
|
|
603
|
+
const additions = [...plan.selectors.entries()].map(([selector, localName]) => selector === localName ? selector : `${selector} as ${localName}`);
|
|
604
|
+
let added = false;
|
|
605
|
+
for (const entry of relevant) {
|
|
606
|
+
const bindings = entry.statement.importClause.namedBindings;
|
|
607
|
+
const remove = new Set(entry.objectElements.filter(({ object }) => !remainingObjectUse.has(`${plan.file}\0${object.objectName}`)).map(({ element }) => element));
|
|
608
|
+
const elements = bindings.elements.filter((element) => !remove.has(element)).map((element) => element.getText(source));
|
|
609
|
+
if (!added) {
|
|
610
|
+
elements.push(...additions);
|
|
611
|
+
added = true;
|
|
612
|
+
}
|
|
613
|
+
const rendered = renderImportDeclaration(source, entry.statement, [...new Set(elements)].sort(importElementCompare));
|
|
614
|
+
addReplacement(plan.replacements, {
|
|
615
|
+
start: entry.statement.getStart(source),
|
|
616
|
+
end: rendered ? entry.statement.end : statementEndWithTrailingNewline(source.text, entry.statement.end),
|
|
617
|
+
text: rendered,
|
|
618
|
+
reason: "object.unpack import rewrite"
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
for (const [selector] of plan.selectors) {
|
|
622
|
+
if (![...plan.objectNames].some((objectName) => memberByObjectAndName.has(`${objectName}\0${selector}`))) {
|
|
623
|
+
unsupported.push({ code: "OBJECT_UNPACK_IMPORT_MEMBER_UNRESOLVED", message: "direct member import could not be resolved", selector, file: plan.file });
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
function seedConsumerPlansForUnusedFullObjectImports(workspace, sourceFile, objectByKey, consumers, remainingObjectUse) {
|
|
629
|
+
const seen = new Set();
|
|
630
|
+
for (const project of workspace.projects) {
|
|
631
|
+
for (const file of project.config.parsed.fileNames) {
|
|
632
|
+
if ((0, semantic_workspace_1.canonicalPathIdentity)(file) === (0, semantic_workspace_1.canonicalPathIdentity)(sourceFile) || seen.has((0, semantic_workspace_1.canonicalPathIdentity)(file)))
|
|
633
|
+
continue;
|
|
634
|
+
seen.add((0, semantic_workspace_1.canonicalPathIdentity)(file));
|
|
635
|
+
const source = project.program.getSourceFile(file);
|
|
636
|
+
if (!source)
|
|
637
|
+
continue;
|
|
638
|
+
const display = toRepoPath(workspace.root, file);
|
|
639
|
+
for (const statement of source.statements) {
|
|
640
|
+
if (!typescript_1.default.isImportDeclaration(statement) || !typescript_1.default.isStringLiteralLike(statement.moduleSpecifier) ||
|
|
641
|
+
!resolvesToFile(project, source.fileName, statement.moduleSpecifier.text, sourceFile))
|
|
642
|
+
continue;
|
|
643
|
+
const bindings = statement.importClause?.namedBindings;
|
|
644
|
+
if (!bindings || !typescript_1.default.isNamedImports(bindings))
|
|
645
|
+
continue;
|
|
646
|
+
for (const element of bindings.elements) {
|
|
647
|
+
const identity = (0, semantic_workspace_1.resolveSemanticNodeIdentity)(workspace, project, element.name);
|
|
648
|
+
const object = identity ? objectByKey.get(identity.key) : undefined;
|
|
649
|
+
if (object?.full && !remainingObjectUse.has(`${display}\0${object.objectName}`)) {
|
|
650
|
+
consumerPlan(consumers, display).objectNames.add(object.objectName);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
function validateReExports(workspace, sourceFile, objects, unsupported) {
|
|
658
|
+
const objectKeys = new Set(objects.map((object) => object.symbol.key));
|
|
659
|
+
const seen = new Set();
|
|
660
|
+
for (const project of workspace.projects) {
|
|
661
|
+
for (const file of project.config.parsed.fileNames) {
|
|
662
|
+
const key = (0, semantic_workspace_1.canonicalPathIdentity)(file);
|
|
663
|
+
if (seen.has(key))
|
|
664
|
+
continue;
|
|
665
|
+
seen.add(key);
|
|
666
|
+
const source = project.program.getSourceFile(file);
|
|
667
|
+
if (!source)
|
|
668
|
+
continue;
|
|
669
|
+
for (const statement of source.statements) {
|
|
670
|
+
if (!typescript_1.default.isExportDeclaration(statement) || !statement.moduleSpecifier || !typescript_1.default.isStringLiteralLike(statement.moduleSpecifier) ||
|
|
671
|
+
!resolvesToFile(project, source.fileName, statement.moduleSpecifier.text, sourceFile))
|
|
672
|
+
continue;
|
|
673
|
+
if (!statement.exportClause || typescript_1.default.isNamespaceExport(statement.exportClause)) {
|
|
674
|
+
unsupported.push({ code: "OBJECT_UNPACK_REEXPORT_UNSUPPORTED", message: "export-star/namespace re-export from unpacked source is unsupported", file: toRepoPath(workspace.root, file) });
|
|
675
|
+
continue;
|
|
676
|
+
}
|
|
677
|
+
for (const element of statement.exportClause.elements) {
|
|
678
|
+
const identity = (0, semantic_workspace_1.resolveSemanticNodeIdentity)(workspace, project, element.propertyName ?? element.name);
|
|
679
|
+
if (identity && objectKeys.has(identity.key)) {
|
|
680
|
+
unsupported.push({ code: "OBJECT_UNPACK_REEXPORT_UNSUPPORTED", message: "re-export of unpacked object is unsupported", file: toRepoPath(workspace.root, file) });
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
function validateRequireConsumers(workspace, sourceFile, unsupported) {
|
|
688
|
+
const seen = new Set();
|
|
689
|
+
for (const project of workspace.projects) {
|
|
690
|
+
for (const file of project.config.parsed.fileNames) {
|
|
691
|
+
const key = (0, semantic_workspace_1.canonicalPathIdentity)(file);
|
|
692
|
+
if (seen.has(key))
|
|
693
|
+
continue;
|
|
694
|
+
seen.add(key);
|
|
695
|
+
const source = project.program.getSourceFile(file);
|
|
696
|
+
if (!source)
|
|
697
|
+
continue;
|
|
698
|
+
const visit = (node) => {
|
|
699
|
+
if (typescript_1.default.isCallExpression(node) && typescript_1.default.isIdentifier(node.expression) && node.expression.text === "require" &&
|
|
700
|
+
node.arguments.length === 1 && typescript_1.default.isStringLiteralLike(node.arguments[0]) &&
|
|
701
|
+
resolvesToFile(project, source.fileName, node.arguments[0].text, sourceFile)) {
|
|
702
|
+
const symbol = project.checker.getSymbolAtLocation(node.expression);
|
|
703
|
+
const declarations = symbol?.getDeclarations() ?? [];
|
|
704
|
+
const provenRequire = declarations.some((declaration) => declaration.getSourceFile().isDeclarationFile || modifiersOf(declaration).some((modifier) => modifier.kind === typescript_1.default.SyntaxKind.DeclareKeyword));
|
|
705
|
+
if (!symbol) {
|
|
706
|
+
unsupported.push({ code: "OBJECT_UNPACK_REQUIRE_EVIDENCE_UNAVAILABLE", message: "require-like call targets unpacked source but require identity is unavailable", file: toRepoPath(workspace.root, file) });
|
|
707
|
+
}
|
|
708
|
+
else if (provenRequire) {
|
|
709
|
+
unsupported.push({ code: "OBJECT_UNPACK_REQUIRE_UNSUPPORTED", message: "CommonJS require of unpacked source is unsupported", file: toRepoPath(workspace.root, file) });
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
typescript_1.default.forEachChild(node, visit);
|
|
713
|
+
};
|
|
714
|
+
visit(source);
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
function chooseConsumerBinding(workspace, project, source, sourceFile, objectName, member) {
|
|
719
|
+
for (const statement of source.statements) {
|
|
720
|
+
if (!typescript_1.default.isImportDeclaration(statement) || !typescript_1.default.isStringLiteralLike(statement.moduleSpecifier) ||
|
|
721
|
+
!resolvesToFile(project, source.fileName, statement.moduleSpecifier.text, sourceFile))
|
|
722
|
+
continue;
|
|
723
|
+
const bindings = statement.importClause?.namedBindings;
|
|
724
|
+
if (!bindings || !typescript_1.default.isNamedImports(bindings))
|
|
725
|
+
continue;
|
|
726
|
+
for (const element of bindings.elements) {
|
|
727
|
+
const identity = (0, semantic_workspace_1.resolveSemanticNodeIdentity)(workspace, project, element.name);
|
|
728
|
+
if (identity?.key === member.symbol.key)
|
|
729
|
+
return element.name.text;
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
if (!project.checker.resolveName(member.selector, source, typescript_1.default.SymbolFlags.Value, false)) {
|
|
733
|
+
return member.selector;
|
|
734
|
+
}
|
|
735
|
+
const base = `${objectName}${member.selector[0].toUpperCase()}${member.selector.slice(1)}`;
|
|
736
|
+
let candidate = base;
|
|
737
|
+
let suffix = 2;
|
|
738
|
+
while (project.checker.resolveName(candidate, source, typescript_1.default.SymbolFlags.Value, false)) {
|
|
739
|
+
candidate = `${base}${suffix}`;
|
|
740
|
+
suffix += 1;
|
|
741
|
+
}
|
|
742
|
+
return candidate;
|
|
743
|
+
}
|
|
744
|
+
function addExportModifier(source, member, replacements) {
|
|
745
|
+
if (hasExportModifier(member.statement))
|
|
746
|
+
return;
|
|
747
|
+
addReplacement(replacements, {
|
|
748
|
+
start: member.statement.getStart(source),
|
|
749
|
+
end: member.statement.getStart(source),
|
|
750
|
+
text: "export ",
|
|
751
|
+
reason: `object.unpack export ${member.selector}`
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
function unwrapObjectLiteral(initializer) {
|
|
755
|
+
let current = initializer;
|
|
756
|
+
while (true) {
|
|
757
|
+
if (typescript_1.default.isParenthesizedExpression(current) || typescript_1.default.isSatisfiesExpression(current)) {
|
|
758
|
+
current = current.expression;
|
|
759
|
+
continue;
|
|
760
|
+
}
|
|
761
|
+
if (typescript_1.default.isAsExpression(current) && current.type.getText() === "const") {
|
|
762
|
+
current = current.expression;
|
|
763
|
+
continue;
|
|
764
|
+
}
|
|
765
|
+
return typescript_1.default.isObjectLiteralExpression(current) ? current : null;
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
function projectForUsage(workspace, usage) {
|
|
769
|
+
return workspace.projects.find((project) => toRepoPath(workspace.root, project.config.file) === usage.project);
|
|
770
|
+
}
|
|
771
|
+
function consumerPlan(target, file) {
|
|
772
|
+
const current = target.get(file) ?? {
|
|
773
|
+
file,
|
|
774
|
+
replacements: [],
|
|
775
|
+
objectNames: new Set(),
|
|
776
|
+
selectors: new Map(),
|
|
777
|
+
referenceCount: 0
|
|
778
|
+
};
|
|
779
|
+
target.set(file, current);
|
|
780
|
+
return current;
|
|
781
|
+
}
|
|
782
|
+
function objectUsageCode(kinds) {
|
|
783
|
+
if (kinds.includes("property-write") || kinds.includes("update/delete"))
|
|
784
|
+
return "OBJECT_UNPACK_OBJECT_WRITE_UNSUPPORTED";
|
|
785
|
+
if (kinds.includes("destructure"))
|
|
786
|
+
return "OBJECT_UNPACK_DESTRUCTURE_UNSUPPORTED";
|
|
787
|
+
if (kinds.includes("type-position/type-query"))
|
|
788
|
+
return "OBJECT_UNPACK_TYPE_USAGE_UNSUPPORTED";
|
|
789
|
+
return "OBJECT_UNPACK_OBJECT_IDENTITY_UNSUPPORTED";
|
|
790
|
+
}
|
|
791
|
+
function isWriteOrUpdateTarget(node) {
|
|
792
|
+
const parent = node.parent;
|
|
793
|
+
return Boolean(parent && (typescript_1.default.isBinaryExpression(parent) && parent.left === node && parent.operatorToken.kind >= typescript_1.default.SyntaxKind.FirstAssignment && parent.operatorToken.kind <= typescript_1.default.SyntaxKind.LastAssignment ||
|
|
794
|
+
typescript_1.default.isPrefixUnaryExpression(parent) || typescript_1.default.isPostfixUnaryExpression(parent) || typescript_1.default.isDeleteExpression(parent)));
|
|
795
|
+
}
|
|
796
|
+
function supportsDirectCall(member) {
|
|
797
|
+
if (typescript_1.default.isFunctionDeclaration(member.declaration))
|
|
798
|
+
return true;
|
|
799
|
+
const initializer = member.declaration.initializer;
|
|
800
|
+
return Boolean(initializer && (typescript_1.default.isArrowFunction(initializer) || typescript_1.default.isFunctionExpression(initializer)));
|
|
801
|
+
}
|
|
802
|
+
function renderImportDeclaration(source, statement, elements) {
|
|
803
|
+
const clause = statement.importClause;
|
|
804
|
+
const defaultName = clause.name?.getText(source);
|
|
805
|
+
if (elements.length === 0) {
|
|
806
|
+
return defaultName ? `import ${defaultName} from ${statement.moduleSpecifier.getText(source)};` : "";
|
|
807
|
+
}
|
|
808
|
+
return `import ${defaultName ? `${defaultName}, ` : ""}{ ${elements.join(", ")} } from ${statement.moduleSpecifier.getText(source)};`;
|
|
809
|
+
}
|
|
810
|
+
function importElementCompare(left, right) {
|
|
811
|
+
return left.replace(/\s+as\s+.*/, "").localeCompare(right.replace(/\s+as\s+.*/, "")) || left.localeCompare(right);
|
|
812
|
+
}
|
|
813
|
+
function applyReplacements(text, replacements) {
|
|
814
|
+
const sorted = [...replacements].sort((left, right) => right.start - left.start || right.end - left.end || left.text.localeCompare(right.text));
|
|
815
|
+
for (let index = 1; index < sorted.length; index += 1) {
|
|
816
|
+
if (sorted[index].end > sorted[index - 1].start) {
|
|
817
|
+
throw new Error(`Overlapping object.unpack replacements: ${sorted[index].start}-${sorted[index].end} and ${sorted[index - 1].start}-${sorted[index - 1].end}.`);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
let next = text;
|
|
821
|
+
for (const replacement of sorted)
|
|
822
|
+
next = `${next.slice(0, replacement.start)}${replacement.text}${next.slice(replacement.end)}`;
|
|
823
|
+
return next;
|
|
824
|
+
}
|
|
825
|
+
function addReplacement(target, replacement) {
|
|
826
|
+
if (!target.some((item) => item.start === replacement.start && item.end === replacement.end && item.text === replacement.text)) {
|
|
827
|
+
target.push(replacement);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
function moduleShapesUnchanged(root, virtualTexts) {
|
|
831
|
+
for (const [file, nextText] of virtualTexts) {
|
|
832
|
+
const absolute = path.resolve(root, file);
|
|
833
|
+
const before = new Set(moduleShape(fs.readFileSync(absolute, "utf8"), absolute));
|
|
834
|
+
const after = moduleShape(nextText, absolute);
|
|
835
|
+
if (after.some((edge) => !before.has(edge)))
|
|
836
|
+
return false;
|
|
837
|
+
}
|
|
838
|
+
return true;
|
|
839
|
+
}
|
|
840
|
+
function moduleShape(text, file) {
|
|
841
|
+
const source = typescript_1.default.createSourceFile(file, text, typescript_1.default.ScriptTarget.Latest, true, scriptKindForFile(file));
|
|
842
|
+
const shape = [];
|
|
843
|
+
const visit = (node) => {
|
|
844
|
+
if (typescript_1.default.isImportDeclaration(node) && typescript_1.default.isStringLiteralLike(node.moduleSpecifier)) {
|
|
845
|
+
shape.push(`import:${node.importClause?.isTypeOnly ? "type" : "runtime"}:${node.moduleSpecifier.text}`);
|
|
846
|
+
}
|
|
847
|
+
else if (typescript_1.default.isExportDeclaration(node) && node.moduleSpecifier && typescript_1.default.isStringLiteralLike(node.moduleSpecifier)) {
|
|
848
|
+
shape.push(`export:${node.isTypeOnly ? "type" : "runtime"}:${node.moduleSpecifier.text}`);
|
|
849
|
+
}
|
|
850
|
+
else if (typescript_1.default.isCallExpression(node) && node.expression.kind === typescript_1.default.SyntaxKind.ImportKeyword && node.arguments.length === 1 && typescript_1.default.isStringLiteralLike(node.arguments[0])) {
|
|
851
|
+
shape.push(`dynamic:${node.arguments[0].text}`);
|
|
852
|
+
}
|
|
853
|
+
typescript_1.default.forEachChild(node, visit);
|
|
854
|
+
};
|
|
855
|
+
visit(source);
|
|
856
|
+
return [...new Set(shape)].sort();
|
|
857
|
+
}
|
|
858
|
+
function collectFingerprintModuleEdges(edges, sourceFile) {
|
|
859
|
+
return edges.filter((edge) => edge.fromFile === sourceFile || edge.toFile === sourceFile);
|
|
860
|
+
}
|
|
861
|
+
function failure(sourceFile, rows, unsupported, coverage) {
|
|
862
|
+
const ordered = [...unsupported].sort((left, right) => (left.file ?? "").localeCompare(right.file ?? "") || (left.objectName ?? "").localeCompare(right.objectName ?? "") ||
|
|
863
|
+
(left.selector ?? "").localeCompare(right.selector ?? "") || left.code.localeCompare(right.code));
|
|
864
|
+
return {
|
|
865
|
+
ok: false,
|
|
866
|
+
operation: "exports.object.unpack.preview",
|
|
867
|
+
applyAvailable: false,
|
|
868
|
+
code: "OBJECT_UNPACK_SEMANTIC_PREVIEW_REJECTED",
|
|
869
|
+
sourceFile,
|
|
870
|
+
objectCount: rows.length,
|
|
871
|
+
memberCount: rows.reduce((sum, row) => sum + row.selectors.length, 0),
|
|
872
|
+
filesTouched: [],
|
|
873
|
+
filesWritten: [],
|
|
874
|
+
...(coverage ? { coverage } : {}),
|
|
875
|
+
unsupportedCount: ordered.length,
|
|
876
|
+
unsupported: ordered
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
function findDeclarationByIdentity(source, identity) {
|
|
880
|
+
let found = null;
|
|
881
|
+
const visit = (node) => {
|
|
882
|
+
if (found)
|
|
883
|
+
return;
|
|
884
|
+
if (node.getStart(source) === identity.declarationStart && node.end === identity.declarationEnd) {
|
|
885
|
+
found = node;
|
|
886
|
+
return;
|
|
887
|
+
}
|
|
888
|
+
typescript_1.default.forEachChild(node, visit);
|
|
889
|
+
};
|
|
890
|
+
visit(source);
|
|
891
|
+
return found;
|
|
892
|
+
}
|
|
893
|
+
function findIdentifierAt(source, start, end) {
|
|
894
|
+
let found = null;
|
|
895
|
+
const visit = (node) => {
|
|
896
|
+
if (found || node.end < start || node.getStart(source) > end)
|
|
897
|
+
return;
|
|
898
|
+
if (typescript_1.default.isIdentifier(node) && node.getStart(source) === start && node.end === end) {
|
|
899
|
+
found = node;
|
|
900
|
+
return;
|
|
901
|
+
}
|
|
902
|
+
typescript_1.default.forEachChild(node, visit);
|
|
903
|
+
};
|
|
904
|
+
visit(source);
|
|
905
|
+
return found;
|
|
906
|
+
}
|
|
907
|
+
function isDeclarationName(node) {
|
|
908
|
+
const parent = node.parent;
|
|
909
|
+
return Boolean(parent && (typescript_1.default.isVariableDeclaration(parent) && parent.name === node ||
|
|
910
|
+
typescript_1.default.isFunctionDeclaration(parent) && parent.name === node ||
|
|
911
|
+
typescript_1.default.isImportSpecifier(parent) && parent.name === node));
|
|
912
|
+
}
|
|
913
|
+
function propertyNameText(name) {
|
|
914
|
+
if (!name)
|
|
915
|
+
return null;
|
|
916
|
+
return typescript_1.default.isIdentifier(name) || typescript_1.default.isStringLiteralLike(name) || typescript_1.default.isNumericLiteral(name) ? name.text : null;
|
|
917
|
+
}
|
|
918
|
+
function containsThisSensitiveSyntax(node) {
|
|
919
|
+
let sensitive = false;
|
|
920
|
+
const visit = (current) => {
|
|
921
|
+
if (current.kind === typescript_1.default.SyntaxKind.ThisKeyword || current.kind === typescript_1.default.SyntaxKind.SuperKeyword) {
|
|
922
|
+
sensitive = true;
|
|
923
|
+
return;
|
|
924
|
+
}
|
|
925
|
+
typescript_1.default.forEachChild(current, visit);
|
|
926
|
+
};
|
|
927
|
+
visit(node);
|
|
928
|
+
return sensitive;
|
|
929
|
+
}
|
|
930
|
+
function hasExportModifier(node) {
|
|
931
|
+
return modifiersOf(node).some((modifier) => modifier.kind === typescript_1.default.SyntaxKind.ExportKeyword);
|
|
932
|
+
}
|
|
933
|
+
function hasDefaultModifier(node) {
|
|
934
|
+
return modifiersOf(node).some((modifier) => modifier.kind === typescript_1.default.SyntaxKind.DefaultKeyword);
|
|
935
|
+
}
|
|
936
|
+
function modifiersOf(node) {
|
|
937
|
+
return typescript_1.default.canHaveModifiers(node) ? typescript_1.default.getModifiers(node) ?? [] : [];
|
|
938
|
+
}
|
|
939
|
+
function resolvesToFile(project, fromFile, specifier, targetFile) {
|
|
940
|
+
const resolved = typescript_1.default.resolveModuleName(specifier, fromFile, project.config.parsed.options, typescript_1.default.sys).resolvedModule?.resolvedFileName;
|
|
941
|
+
return Boolean(resolved && (0, semantic_workspace_1.canonicalPathIdentity)(resolved) === (0, semantic_workspace_1.canonicalPathIdentity)(targetFile));
|
|
942
|
+
}
|
|
943
|
+
function isSupportedSourceExtension(file) {
|
|
944
|
+
return [".ts", ".tsx", ".mts"].includes(path.extname(file).toLowerCase());
|
|
945
|
+
}
|
|
946
|
+
function isEsmSourceFile(project, source) {
|
|
947
|
+
const kind = project.config.parsed.options.module;
|
|
948
|
+
if (kind === undefined || [typescript_1.default.ModuleKind.None, typescript_1.default.ModuleKind.CommonJS, typescript_1.default.ModuleKind.AMD, typescript_1.default.ModuleKind.UMD, typescript_1.default.ModuleKind.System].includes(kind))
|
|
949
|
+
return false;
|
|
950
|
+
return [typescript_1.default.ModuleKind.Node16, typescript_1.default.ModuleKind.NodeNext].includes(kind) ? source.impliedNodeFormat === typescript_1.default.ModuleKind.ESNext : true;
|
|
951
|
+
}
|
|
952
|
+
function statementEndWithTrailingNewline(text, end) {
|
|
953
|
+
if (text[end] === "\r" && text[end + 1] === "\n")
|
|
954
|
+
return end + 2;
|
|
955
|
+
return text[end] === "\n" ? end + 1 : end;
|
|
956
|
+
}
|
|
957
|
+
function scriptKindForFile(file) {
|
|
958
|
+
const extension = path.extname(file).toLowerCase();
|
|
959
|
+
return extension === ".tsx" ? typescript_1.default.ScriptKind.TSX : extension === ".jsx" ? typescript_1.default.ScriptKind.JSX : [".js", ".mjs", ".cjs"].includes(extension) ? typescript_1.default.ScriptKind.JS : typescript_1.default.ScriptKind.TS;
|
|
960
|
+
}
|
|
961
|
+
function findAncestor(node, predicate) {
|
|
962
|
+
let current = node.parent;
|
|
963
|
+
while (current) {
|
|
964
|
+
if (predicate(current))
|
|
965
|
+
return current;
|
|
966
|
+
if (typescript_1.default.isStatement(current))
|
|
967
|
+
break;
|
|
968
|
+
current = current.parent;
|
|
969
|
+
}
|
|
970
|
+
return undefined;
|
|
971
|
+
}
|
|
972
|
+
function uniqueSymbols(symbols) {
|
|
973
|
+
return [...new Map(symbols.map((symbol) => [symbol.key, symbol])).values()].sort((left, right) => left.key.localeCompare(right.key));
|
|
974
|
+
}
|
|
975
|
+
function uniqueUsages(usages) {
|
|
976
|
+
return [...new Map(usages.map((usage) => [`${usage.symbol.key}\0${usage.file}\0${usage.start}\0${usage.end}`, usage])).values()]
|
|
977
|
+
.sort((left, right) => left.file.localeCompare(right.file) || left.start - right.start || left.end - right.end || left.symbol.key.localeCompare(right.symbol.key));
|
|
978
|
+
}
|
|
979
|
+
function toCoverageEvidence(reason) {
|
|
980
|
+
const record = reason;
|
|
981
|
+
return {
|
|
982
|
+
code: `OBJECT_UNPACK_COVERAGE_${reason.code}`,
|
|
983
|
+
message: "semantic reference coverage is incomplete",
|
|
984
|
+
...(typeof record.file === "string" ? { file: record.file } : {}),
|
|
985
|
+
details: reason
|
|
986
|
+
};
|
|
987
|
+
}
|
|
988
|
+
function toRepoPath(root, file) {
|
|
989
|
+
return path.relative(root, path.resolve(file)).replace(/\\/g, "/") || ".";
|
|
990
|
+
}
|
|
991
|
+
function sha256(value) {
|
|
992
|
+
return crypto.createHash("sha256").update(value).digest("hex");
|
|
993
|
+
}
|