@shapeshift-labs/frontier-lang-compiler 0.2.149 → 0.2.151

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.
Files changed (280) hide show
  1. package/README.md +315 -9
  2. package/bench/real-repo-corpus-checkout-identity.mjs +134 -0
  3. package/bench/real-repo-corpus-checkout-proof.mjs +263 -0
  4. package/bench/real-repo-corpus-command-execution.mjs +314 -0
  5. package/bench/real-repo-corpus-evidence.mjs +165 -0
  6. package/bench/real-repo-corpus-suite.mjs +273 -0
  7. package/bench/smoke.mjs +109 -7
  8. package/dist/declarations/import-adapter-core.d.ts +4 -3
  9. package/dist/declarations/import-adapter-options-native.d.ts +21 -0
  10. package/dist/declarations/js-ts-project-merge-admission-routes.d.ts +35 -0
  11. package/dist/declarations/js-ts-project-merge-commonjs-interop.d.ts +29 -0
  12. package/dist/declarations/js-ts-project-merge-confidence.d.ts +64 -0
  13. package/dist/declarations/js-ts-project-merge-declaration-emit-parity.d.ts +37 -0
  14. package/dist/declarations/js-ts-project-merge-declarations.d.ts +65 -0
  15. package/dist/declarations/js-ts-project-merge-diagnostics.d.ts +97 -0
  16. package/dist/declarations/js-ts-project-merge-global-augmentation.d.ts +30 -0
  17. package/dist/declarations/js-ts-project-merge-jsx-render-branch.d.ts +48 -0
  18. package/dist/declarations/js-ts-project-merge-proof-levels.d.ts +109 -0
  19. package/dist/declarations/js-ts-project-merge-quality-gates.d.ts +38 -0
  20. package/dist/declarations/js-ts-project-merge-semantic-equivalence-proof.d.ts +45 -0
  21. package/dist/declarations/js-ts-project-merge-tsconfig.d.ts +43 -0
  22. package/dist/declarations/js-ts-safe-merge.d.ts +47 -0
  23. package/dist/declarations/js-ts-safe-project-merge.d.ts +120 -38
  24. package/dist/declarations/native-project-compiler-assignability-oracle.d.ts +41 -0
  25. package/dist/declarations/native-project-compiler-callable-signatures.d.ts +31 -0
  26. package/dist/declarations/native-project-compiler-class-member-runtime-proof.d.ts +87 -0
  27. package/dist/declarations/native-project-compiler-composite-types.d.ts +23 -0
  28. package/dist/declarations/native-project-compiler-enum-proof.d.ts +58 -0
  29. package/dist/declarations/native-project-compiler-index-signature.d.ts +7 -0
  30. package/dist/declarations/native-project-compiler-public-api-source-binding.d.ts +8 -0
  31. package/dist/declarations/native-project-compiler-scope.d.ts +37 -0
  32. package/dist/declarations/native-project-compiler-type-reference-targets.d.ts +38 -0
  33. package/dist/declarations/native-project-css-modules.d.ts +90 -0
  34. package/dist/declarations/native-project-decorator-metadata.d.ts +126 -0
  35. package/dist/declarations/native-project-jsx-graph.d.ts +313 -0
  36. package/dist/declarations/native-project-module-declarations.d.ts +52 -0
  37. package/dist/declarations/native-project-module-resolution.d.ts +76 -1
  38. package/dist/declarations/native-project-runtime-effect-target.d.ts +29 -0
  39. package/dist/declarations/native-project-runtime-executable-effect-evidence.d.ts +107 -0
  40. package/dist/declarations/native-project-runtime-mutation-target.d.ts +33 -0
  41. package/dist/declarations/native-project-runtime-promise-chain.d.ts +30 -0
  42. package/dist/declarations/native-project-runtime-promise-combinator.d.ts +22 -0
  43. package/dist/declarations/native-project-runtime-reachability.d.ts +30 -0
  44. package/dist/declarations/native-project-runtime-resource-management.d.ts +27 -0
  45. package/dist/declarations/native-project-runtime-yield-delegation.d.ts +10 -0
  46. package/dist/declarations/native-project-scope-template-reference.d.ts +13 -0
  47. package/dist/declarations/native-project-source-evidence.d.ts +8 -0
  48. package/dist/declarations/native-project.d.ts +40 -39
  49. package/dist/declarations/semantic-edit-script.d.ts +10 -8
  50. package/dist/declarations/semantic-graph-layers.d.ts +79 -0
  51. package/dist/declarations/semantic-patch-bundle-composition.d.ts +62 -0
  52. package/dist/declarations/semantic-sidecar.d.ts +3 -2
  53. package/dist/declarations/semantic-structural-diff.d.ts +94 -0
  54. package/dist/declarations/source-preservation.d.ts +32 -1
  55. package/dist/declarations/target-adapters.d.ts +22 -2
  56. package/dist/index.d.ts +32 -0
  57. package/dist/index.js +6 -0
  58. package/dist/internal/index-impl/compileNativeSource.js +53 -5
  59. package/dist/internal/index-impl/createLightweightNativeImport.js +58 -4
  60. package/dist/internal/index-impl/createNativeImportFromSyntaxAst.js +17 -1
  61. package/dist/internal/index-impl/createNativeImportFromTypeScriptAst.js +28 -4
  62. package/dist/internal/index-impl/createNativeProjectImportResult.js +31 -27
  63. package/dist/internal/index-impl/createNativeProjectModuleResolutionFromPackageManifests.js +145 -0
  64. package/dist/internal/index-impl/createNativeSourcePreservation.js +34 -7
  65. package/dist/internal/index-impl/createSemanticImportSidecar.js +27 -1
  66. package/dist/internal/index-impl/createTypeScriptCompilerNativeImporterAdapter.js +16 -5
  67. package/dist/internal/index-impl/dynamicImportExpressionMetadata.js +80 -0
  68. package/dist/internal/index-impl/importMetaUrlDependencyMetadata.js +176 -0
  69. package/dist/internal/index-impl/importNativeSource.js +2 -3
  70. package/dist/internal/index-impl/moduleImportAttributeMetadata.js +232 -0
  71. package/dist/internal/index-impl/projectSemanticEditScriptToSource.js +8 -1
  72. package/dist/internal/index-impl/projectSymbolGraphClassStaticBlocks.js +148 -0
  73. package/dist/internal/index-impl/projectSymbolGraphCompilerAdvancedTypeMetadata.js +45 -0
  74. package/dist/internal/index-impl/projectSymbolGraphCompilerCallableSignatureEquivalence.js +107 -0
  75. package/dist/internal/index-impl/projectSymbolGraphCompilerClassPrivateAccessorRuntimeProof.js +280 -0
  76. package/dist/internal/index-impl/projectSymbolGraphCompilerClassShapeEquivalence.js +103 -0
  77. package/dist/internal/index-impl/projectSymbolGraphCompilerConditionalTypeEquivalence.js +242 -0
  78. package/dist/internal/index-impl/projectSymbolGraphCompilerDecoratorRuntimeProof.js +197 -0
  79. package/dist/internal/index-impl/projectSymbolGraphCompilerEnumEquivalence.js +188 -0
  80. package/dist/internal/index-impl/projectSymbolGraphCompilerFacts.js +244 -0
  81. package/dist/internal/index-impl/projectSymbolGraphCompilerIndexSignatureEquivalence.js +58 -0
  82. package/dist/internal/index-impl/projectSymbolGraphCompilerMetadata.js +168 -0
  83. package/dist/internal/index-impl/projectSymbolGraphCompilerTypeEquivalence.js +199 -0
  84. package/dist/internal/index-impl/projectSymbolGraphCompilerTypeEquivalenceProof.js +204 -0
  85. package/dist/internal/index-impl/projectSymbolGraphCompilerTypeReferenceTargetEquivalence.js +99 -0
  86. package/dist/internal/index-impl/projectSymbolGraphCssModuleRecords.js +264 -0
  87. package/dist/internal/index-impl/projectSymbolGraphCssModuleScanners.js +242 -0
  88. package/dist/internal/index-impl/projectSymbolGraphCssModuleUtils.js +152 -0
  89. package/dist/internal/index-impl/projectSymbolGraphCssModules.js +82 -0
  90. package/dist/internal/index-impl/projectSymbolGraphJsxComponentImports.js +170 -0
  91. package/dist/internal/index-impl/projectSymbolGraphJsxComponentProviderLookup.js +167 -0
  92. package/dist/internal/index-impl/projectSymbolGraphJsxComponentWrappers.js +150 -0
  93. package/dist/internal/index-impl/projectSymbolGraphJsxContextTargets.js +71 -0
  94. package/dist/internal/index-impl/projectSymbolGraphJsxContextValues.js +212 -0
  95. package/dist/internal/index-impl/projectSymbolGraphJsxEventHandlers.js +172 -0
  96. package/dist/internal/index-impl/projectSymbolGraphJsxHookEffects.js +124 -0
  97. package/dist/internal/index-impl/projectSymbolGraphJsxHooks.js +281 -0
  98. package/dist/internal/index-impl/projectSymbolGraphJsxMemberComponents.js +139 -0
  99. package/dist/internal/index-impl/projectSymbolGraphJsxPropFlows.js +320 -0
  100. package/dist/internal/index-impl/projectSymbolGraphJsxPropValues.js +145 -0
  101. package/dist/internal/index-impl/projectSymbolGraphJsxProviderFlows.js +133 -0
  102. package/dist/internal/index-impl/projectSymbolGraphJsxRecords.js +315 -0
  103. package/dist/internal/index-impl/projectSymbolGraphJsxRenderCollections.js +155 -0
  104. package/dist/internal/index-impl/projectSymbolGraphJsxRenderReturns.js +291 -0
  105. package/dist/internal/index-impl/projectSymbolGraphJsxRenderRisk.js +279 -0
  106. package/dist/internal/index-impl/projectSymbolGraphModuleDeclarationShapes.js +138 -0
  107. package/dist/internal/index-impl/projectSymbolGraphModuleResolution.js +89 -87
  108. package/dist/internal/index-impl/projectSymbolGraphPackageConditions.js +314 -0
  109. package/dist/internal/index-impl/projectSymbolGraphReExportImportTargets.js +43 -0
  110. package/dist/internal/index-impl/projectSymbolGraphReExports.js +55 -1
  111. package/dist/internal/index-impl/projectSymbolGraphRuntimeRegions.js +108 -0
  112. package/dist/internal/index-impl/projectSymbolGraphScopeUseDefAliases.js +307 -0
  113. package/dist/internal/index-impl/projectSymbolGraphScopeUseDefLexical.js +320 -0
  114. package/dist/internal/index-impl/projectSymbolGraphScopeUseDefOwners.js +50 -0
  115. package/dist/internal/index-impl/projectSymbolGraphScopeUseDefRecordBuilders.js +112 -0
  116. package/dist/internal/index-impl/projectSymbolGraphScopeUseDefRecords.js +238 -0
  117. package/dist/internal/index-impl/projectSymbolGraphScopeUseDefStructural.js +104 -0
  118. package/dist/internal/index-impl/projectSymbolGraphScopeUseDefStructuralNormalize.js +242 -0
  119. package/dist/internal/index-impl/projectSymbolGraphScopeUseDefUseHashes.js +107 -0
  120. package/dist/internal/index-impl/projectSymbolGraphSourceMapGeneratedBoundary.js +111 -0
  121. package/dist/internal/index-impl/projectSymbolGraphSourceRecords.js +268 -0
  122. package/dist/internal/index-impl/projectSymbolGraphSourceRecordsOwnership.js +309 -0
  123. package/dist/internal/index-impl/replaySemanticEditProjection.js +53 -39
  124. package/dist/internal/index-impl/runtimeOrderEvidenceBinding.js +151 -0
  125. package/dist/internal/index-impl/runtimeOrderProofSurfaces.js +253 -0
  126. package/dist/internal/index-impl/semanticEditCallsiteArgumentMerge.js +319 -0
  127. package/dist/internal/index-impl/semanticEditExplicitSourceReplacement.js +7 -2
  128. package/dist/internal/index-impl/semanticEditProjectionRecord.js +8 -0
  129. package/dist/internal/index-impl/semanticEditReplayDiagnostics.js +7 -2
  130. package/dist/internal/index-impl/semanticEditReplayOutputBinding.js +61 -0
  131. package/dist/internal/index-impl/semanticEditReplayRerunRoute.js +27 -0
  132. package/dist/internal/index-impl/semanticEditReplaySourceReplacement.js +6 -1
  133. package/dist/internal/index-impl/semanticEditRuntimeOrderReasons.js +320 -0
  134. package/dist/internal/index-impl/semanticEditScriptClassification.js +90 -5
  135. package/dist/internal/index-impl/semanticEditScripts.js +42 -5
  136. package/dist/internal/index-impl/semanticEditTypeSyntaxReasons.js +134 -0
  137. package/dist/internal/index-impl/semanticIndexFromNativeDeclarations.js +11 -5
  138. package/dist/internal/index-impl/semanticPatchBundleComposition.js +166 -0
  139. package/dist/internal/index-impl/semanticStructuralDiffRecords.js +150 -0
  140. package/dist/internal/index-impl/sourceMapGeneratedBoundaryGate.js +185 -0
  141. package/dist/internal/index-impl/staticMemberLiteral.js +31 -0
  142. package/dist/internal/index-impl/staticOptionalMemberReference.js +22 -0
  143. package/dist/internal/index-impl/syntaxAstSourcePreservation.js +273 -0
  144. package/dist/internal/index-impl/syntaxCommonJsModuleDeclarationEntries.js +297 -0
  145. package/dist/internal/index-impl/syntaxModuleDeclarationEntries.js +56 -132
  146. package/dist/internal/index-impl/syntaxModuleEntryRecords.js +160 -0
  147. package/dist/internal/index-impl/typeScriptCompilerAdvancedTypeShapes.js +160 -0
  148. package/dist/internal/index-impl/typeScriptCompilerAssignabilityOracle.js +97 -0
  149. package/dist/internal/index-impl/typeScriptCompilerClassApi.js +238 -0
  150. package/dist/internal/index-impl/typeScriptCompilerDecoratorMetadata.js +290 -0
  151. package/dist/internal/index-impl/typeScriptCompilerEnumShape.js +279 -0
  152. package/dist/internal/index-impl/typeScriptCompilerFacts.js +294 -0
  153. package/dist/internal/index-impl/typeScriptCompilerInferenceSyntax.js +170 -0
  154. package/dist/internal/index-impl/typeScriptCompilerReferenceGraph.js +186 -0
  155. package/dist/internal/index-impl/typeScriptCompilerSymbolIdentity.js +294 -0
  156. package/dist/internal/index-impl/typeScriptCompilerTypeReferenceTargets.js +142 -0
  157. package/dist/internal/index-impl/typeScriptDeclaration.js +10 -38
  158. package/dist/internal/index-impl/typeScriptModuleDeclarationEntries.js +52 -15
  159. package/dist/internal/index-impl/typeScriptSourceFilePreservation.js +296 -0
  160. package/dist/js-ts-safe-member-class-invariants.js +247 -0
  161. package/dist/js-ts-safe-member-merge-result.js +23 -3
  162. package/dist/js-ts-safe-member-merge.js +28 -4
  163. package/dist/js-ts-safe-merge-binding-patterns.js +170 -0
  164. package/dist/js-ts-safe-merge-context.js +1 -0
  165. package/dist/js-ts-safe-merge-jsx-attribute-fallback.js +314 -0
  166. package/dist/js-ts-safe-merge-jsx-attribute-parser.js +277 -0
  167. package/dist/js-ts-safe-merge-jsx-child-expression-fallback.js +161 -0
  168. package/dist/js-ts-safe-merge-jsx-child-expression-merge.js +319 -0
  169. package/dist/js-ts-safe-merge-jsx-child-expression-parser.js +300 -0
  170. package/dist/js-ts-safe-merge-parse-declarations.js +46 -2
  171. package/dist/js-ts-safe-merge-parse-statements.js +8 -0
  172. package/dist/js-ts-safe-merge-plan.js +3 -1
  173. package/dist/js-ts-safe-merge-semantic-edit-fallback.js +49 -0
  174. package/dist/js-ts-safe-merge-source-shape-fallbacks.js +5 -1
  175. package/dist/js-ts-safe-merge-top-level-rename-fallback.js +31 -5
  176. package/dist/js-ts-safe-merge-top-level-rename-result.js +7 -2
  177. package/dist/js-ts-safe-merge-variable-declarator-fallback.js +124 -6
  178. package/dist/js-ts-safe-merge-variable-declarator-parser.js +34 -4
  179. package/dist/js-ts-safe-merge.js +136 -0
  180. package/dist/js-ts-safe-project-merge-admission-routes.js +216 -0
  181. package/dist/js-ts-safe-project-merge-admission.js +161 -0
  182. package/dist/js-ts-safe-project-merge-ambient.js +110 -0
  183. package/dist/js-ts-safe-project-merge-core.js +85 -0
  184. package/dist/js-ts-safe-project-merge-css-module-conflicts.js +60 -0
  185. package/dist/js-ts-safe-project-merge-declaration-emit-parity.js +186 -0
  186. package/dist/js-ts-safe-project-merge-declarations.js +227 -0
  187. package/dist/js-ts-safe-project-merge-diagnostics-metadata.js +42 -0
  188. package/dist/js-ts-safe-project-merge-diagnostics-ts.js +73 -0
  189. package/dist/js-ts-safe-project-merge-diagnostics.js +283 -0
  190. package/dist/js-ts-safe-project-merge-evidence-routing.js +38 -0
  191. package/dist/js-ts-safe-project-merge-files.js +70 -0
  192. package/dist/js-ts-safe-project-merge-global-augmentation-compatibility.js +99 -0
  193. package/dist/js-ts-safe-project-merge-graph-conflicts.js +90 -2
  194. package/dist/js-ts-safe-project-merge-graph-delta-commonjs-interop.js +108 -0
  195. package/dist/js-ts-safe-project-merge-graph-delta-compiler-conflicts.js +179 -0
  196. package/dist/js-ts-safe-project-merge-graph-delta-compiler-details.js +189 -0
  197. package/dist/js-ts-safe-project-merge-graph-delta-conflicts.js +51 -184
  198. package/dist/js-ts-safe-project-merge-graph-delta-identity-conflicts.js +202 -0
  199. package/dist/js-ts-safe-project-merge-graph-delta-inference-syntax.js +80 -0
  200. package/dist/js-ts-safe-project-merge-graph-delta-module-declarations.js +155 -0
  201. package/dist/js-ts-safe-project-merge-graph-limits.js +16 -1
  202. package/dist/js-ts-safe-project-merge-graph.js +37 -5
  203. package/dist/js-ts-safe-project-merge-import-removal.js +292 -0
  204. package/dist/js-ts-safe-project-merge-jsx-graph-conflict-details.js +235 -0
  205. package/dist/js-ts-safe-project-merge-jsx-graph-conflicts.js +173 -0
  206. package/dist/js-ts-safe-project-merge-jsx-prop-contracts.js +86 -0
  207. package/dist/js-ts-safe-project-merge-jsx-render-branch-proof.js +189 -0
  208. package/dist/js-ts-safe-project-merge-missing-evidence.js +310 -0
  209. package/dist/js-ts-safe-project-merge-move-rename.js +209 -0
  210. package/dist/js-ts-safe-project-merge-proof-conflicts.js +44 -0
  211. package/dist/js-ts-safe-project-merge-proof-levels.js +320 -0
  212. package/dist/js-ts-safe-project-merge-quality-gates.js +140 -0
  213. package/dist/js-ts-safe-project-merge-routing-calibration.js +125 -0
  214. package/dist/js-ts-safe-project-merge-runtime-region-conflicts.js +156 -0
  215. package/dist/js-ts-safe-project-merge-scope-use-def-conflicts.js +292 -0
  216. package/dist/js-ts-safe-project-merge-semantic-equivalence-proof.js +175 -0
  217. package/dist/js-ts-safe-project-merge-semantic-replay-proof.js +311 -0
  218. package/dist/js-ts-safe-project-merge-semantic-replay-routes.js +179 -0
  219. package/dist/js-ts-safe-project-merge-source-span-conflicts.js +310 -0
  220. package/dist/js-ts-safe-project-merge-source-span-roundtrip-proof.js +172 -0
  221. package/dist/js-ts-safe-project-merge-split-merge-admission.js +96 -0
  222. package/dist/js-ts-safe-project-merge-split-merge-records.js +320 -0
  223. package/dist/js-ts-safe-project-merge-split-merge-shapes.js +234 -0
  224. package/dist/js-ts-safe-project-merge-split-merge.js +218 -0
  225. package/dist/js-ts-safe-project-merge-summary.js +320 -0
  226. package/dist/js-ts-safe-project-merge-symbol-move-admission.js +63 -0
  227. package/dist/js-ts-safe-project-merge-symbol-move-default-admission.js +143 -0
  228. package/dist/js-ts-safe-project-merge-symbol-move-risks.js +213 -0
  229. package/dist/js-ts-safe-project-merge-symbol-move.js +316 -0
  230. package/dist/js-ts-safe-project-merge-symbol-rename-admission.js +59 -0
  231. package/dist/js-ts-safe-project-merge-symbol-rename-default-admission.js +111 -0
  232. package/dist/js-ts-safe-project-merge-symbol-rename.js +319 -0
  233. package/dist/js-ts-safe-project-merge-ts-options.js +205 -0
  234. package/dist/js-ts-safe-project-merge-ts-program.js +268 -0
  235. package/dist/js-ts-safe-project-merge-typed-property-rename-rebase-utils.js +69 -0
  236. package/dist/js-ts-safe-project-merge-typed-property-rename-rebase.js +317 -0
  237. package/dist/js-ts-safe-project-merge-unsupported-surfaces.js +319 -0
  238. package/dist/js-ts-safe-project-merge.js +171 -172
  239. package/dist/js-ts-semantic-scope-use-def-bindings.js +287 -0
  240. package/dist/js-ts-semantic-scope-use-def-scan.js +241 -0
  241. package/dist/js-ts-semantic-scope-use-def-utils.js +132 -0
  242. package/dist/js-ts-semantic-scope-use-def.js +217 -0
  243. package/dist/lightweight-dependency-effects.js +28 -4
  244. package/dist/lightweight-dependency-relations.js +13 -7
  245. package/dist/lightweight-dependency-top-level.js +63 -0
  246. package/dist/native-import-language-profiles.js +27 -1
  247. package/dist/native-js-ts-importers.js +9 -5
  248. package/dist/native-parser-ast-format-profiles.js +12 -0
  249. package/dist/native-parser-html-css-format-profiles.js +85 -0
  250. package/dist/native-region-scanner-core.js +5 -3
  251. package/dist/native-region-scanner-js-commonjs.js +155 -0
  252. package/dist/native-region-scanner-js-imports.js +51 -13
  253. package/dist/native-region-scanner-js-reexports.js +79 -0
  254. package/dist/native-region-scanner-js-ts-helpers.js +23 -0
  255. package/dist/native-source-ledger-helpers.js +1 -1
  256. package/dist/native-source-ledger.js +24 -10
  257. package/dist/native-source-maps-ecma426.js +316 -0
  258. package/dist/native-source-maps.js +36 -6
  259. package/dist/native-source-preservation-ownership.js +292 -0
  260. package/dist/native-source-preservation-scanner.js +63 -25
  261. package/dist/native-source-preservation-types.d.ts +3 -0
  262. package/dist/semantic-import-effect-occurrences.js +242 -0
  263. package/dist/semantic-import-effect-regions.js +95 -58
  264. package/dist/semantic-import-graph-layers.js +224 -0
  265. package/dist/semantic-import-runtime-conditional-evidence.js +135 -0
  266. package/dist/semantic-import-runtime-effect-target-evidence.js +145 -0
  267. package/dist/semantic-import-runtime-exit-evidence.js +32 -0
  268. package/dist/semantic-import-runtime-import-meta-evidence.js +33 -0
  269. package/dist/semantic-import-runtime-mutation-evidence.js +155 -0
  270. package/dist/semantic-import-runtime-order-evidence.js +318 -0
  271. package/dist/semantic-import-runtime-promise-chain-evidence.js +103 -0
  272. package/dist/semantic-import-runtime-promise-combinator-evidence.js +166 -0
  273. package/dist/semantic-import-runtime-reachability-evidence.js +269 -0
  274. package/dist/semantic-import-runtime-resource-management-evidence.js +293 -0
  275. package/dist/semantic-import-runtime-switch-evidence.js +304 -0
  276. package/dist/semantic-import-runtime-throw-evidence.js +44 -0
  277. package/dist/semantic-import-runtime-try-finally-evidence.js +172 -0
  278. package/dist/semantic-import-sidecar-entry.js +4 -0
  279. package/dist/semantic-import-source-preservation.js +6 -2
  280. package/package.json +1 -1
@@ -0,0 +1,143 @@
1
+ import { compactRecord } from './js-ts-safe-merge-context.js';
2
+
3
+ function projectSymbolMoveDefaultAdmissionProofs(graphDelta, branch, exportedSymbolMoves, importedSymbolMoves, requiredEvidence = []) {
4
+ const proofs = new Map();
5
+ if (exportedSymbolMoves.length !== 1) return proofs;
6
+ const exportMove = exportedSymbolMoves[0];
7
+ const proof = projectSymbolMoveDefaultAdmissionProof(graphDelta, branch, exportMove, importedSymbolMoves, requiredEvidence);
8
+ const proofKey = symbolMoveProofKey(exportMove.details);
9
+ if (proof && proofKey) proofs.set(proofKey, proof);
10
+ return proofs;
11
+ }
12
+
13
+ function projectSymbolMoveDefaultAdmissionProof(graphDelta, branch, exportMove, importedSymbolMoves, requiredEvidence) {
14
+ const details = exportMove.details ?? {};
15
+ const symbolName = details.symbolName;
16
+ const fromPath = details.fromSourcePath;
17
+ const toPath = details.toSourcePath;
18
+ if (!symbolName || !fromPath || !toPath) return undefined;
19
+ const matchingImportMoves = importedSymbolMoves.filter((move) => importedMoveMatchesExportMove(move, details));
20
+ if (!matchingImportMoves.length || matchingImportMoves.length !== importedSymbolMoves.length) return undefined;
21
+ const baseOldReferences = projectSymbolImportReferences(graphDelta, 'base', fromPath, symbolName);
22
+ const branchNewReferences = projectSymbolImportReferences(graphDelta, branch, toPath, symbolName);
23
+ const branchOldReferences = projectSymbolImportReferences(graphDelta, branch, fromPath, symbolName);
24
+ if (branchOldReferences.length) return undefined;
25
+ const rewriteKeys = matchingImportMoves.map(importedMoveReferenceKey);
26
+ const baseOldKeys = baseOldReferences.map(importReferenceKey);
27
+ const branchNewKeys = branchNewReferences.map(importReferenceKey);
28
+ if (!hasCompleteUniqueStringSet(rewriteKeys)
29
+ || !hasCompleteUniqueStringSet(baseOldKeys)
30
+ || !hasCompleteUniqueStringSet(branchNewKeys)) {
31
+ return undefined;
32
+ }
33
+ if (!sameStringSet(rewriteKeys, baseOldKeys) || !sameStringSet(rewriteKeys, branchNewKeys)) return undefined;
34
+ return compactRecord({
35
+ status: 'passed',
36
+ route: 'default-exact-exported-symbol-move',
37
+ branch,
38
+ symbolName,
39
+ fromSourcePath: fromPath,
40
+ toSourcePath: toPath,
41
+ exportedMoveConflictKey: details.conflictKey,
42
+ importRewriteCount: matchingImportMoves.length,
43
+ rewrittenImportSourcePaths: uniqueStrings(matchingImportMoves.map((move) => move.details?.importerSourcePath)),
44
+ importMoveConflictKeys: uniqueStrings(matchingImportMoves.map((move) => move.details?.conflictKey)),
45
+ baseImportReferences: baseOldReferences.length,
46
+ branchImportReferences: branchNewReferences.length,
47
+ staleImportReferences: 0,
48
+ duplicateImportReferences: 0,
49
+ duplicateExportReferences: 0,
50
+ requiredEvidence: ['project-graph-delta-evidence', ...requiredEvidence]
51
+ });
52
+ }
53
+
54
+ function withDefaultAdmissionProof(classification, proofs) {
55
+ const proof = proofs.get(symbolMoveProofKey(classification.details));
56
+ if (!proof) return classification;
57
+ return {
58
+ ...classification,
59
+ details: compactRecord({ ...classification.details, defaultAdmissionProof: proof })
60
+ };
61
+ }
62
+
63
+ function importedMoveMatchesExportMove(move, exportMoveDetails) {
64
+ const details = move.details ?? {};
65
+ return move.kind === 'imported-symbol-move'
66
+ && details.branch === exportMoveDetails.branch
67
+ && details.symbolName === exportMoveDetails.symbolName
68
+ && modulePathMatches(details.fromSourcePath, exportMoveDetails.fromSourcePath)
69
+ && modulePathMatches(details.toSourcePath, exportMoveDetails.toSourcePath)
70
+ && importedMoveReferenceKey(move);
71
+ }
72
+
73
+ function projectSymbolImportReferences(graphDelta, stageName, exportSourcePath, symbolName) {
74
+ const graph = graphDelta.stages?.[stageName]?.projectSymbolGraph;
75
+ return namedImportReferenceEdges(graph)
76
+ .filter((edge) => importTargetName(edge) === symbolName && modulePathMatches(edge.resolvedModulePath, exportSourcePath))
77
+ .map(importEdgeEvidence);
78
+ }
79
+
80
+ function namedImportReferenceEdges(graph) {
81
+ return (graph?.importEdges ?? []).filter((edge) => edge?.sourcePath && edge.resolvedModulePath && importTargetName(edge));
82
+ }
83
+
84
+ function importedMoveReferenceKey(move) {
85
+ const details = move.details ?? {};
86
+ const baseEdge = details.graphEvidence?.base?.importEdge;
87
+ const branchEdge = details.graphEvidence?.[move.branch]?.importEdge;
88
+ if (!baseEdge || !branchEdge) return undefined;
89
+ if (importTargetName(baseEdge) !== details.symbolName || importTargetName(branchEdge) !== details.symbolName) return undefined;
90
+ if (!modulePathMatches(baseEdge.resolvedModulePath, details.fromSourcePath)) return undefined;
91
+ if (!modulePathMatches(branchEdge.resolvedModulePath, details.toSourcePath)) return undefined;
92
+ if (baseEdge.localName !== branchEdge.localName
93
+ || baseEdge.importKind !== branchEdge.importKind
94
+ || Boolean(baseEdge.isTypeOnly) !== Boolean(branchEdge.isTypeOnly)) {
95
+ return undefined;
96
+ }
97
+ return importReferenceKey(baseEdge);
98
+ }
99
+
100
+ function importReferenceKey(reference) {
101
+ return stableKey([
102
+ 'symbol-move-import-reference',
103
+ reference.sourcePath,
104
+ importTargetName(reference),
105
+ reference.localName,
106
+ reference.importKind,
107
+ reference.isTypeOnly ? 'type' : 'value'
108
+ ]);
109
+ }
110
+
111
+ function importEdgeEvidence(edge) {
112
+ return compactRecord({
113
+ sourcePath: edge.sourcePath,
114
+ moduleSpecifier: edge.moduleSpecifier,
115
+ importKind: edge.importKind,
116
+ importedName: edge.importedName,
117
+ localName: edge.localName,
118
+ isTypeOnly: edge.isTypeOnly,
119
+ resolvedModulePath: edge.resolvedModulePath
120
+ });
121
+ }
122
+
123
+ function importTargetName(edge) {
124
+ if (edge?.importKind === 'side-effect' || edge?.importKind === 'namespace') return undefined;
125
+ const name = edge?.importedName ?? edge?.localName ?? edge?.exportedName;
126
+ return name && name !== '*' ? String(name) : undefined;
127
+ }
128
+
129
+ function symbolMoveProofKey(details) {
130
+ return stableKey(['symbol-move-default-admission', details?.branch, details?.symbolName, normalizeModulePath(details?.fromSourcePath), normalizeModulePath(details?.toSourcePath)]);
131
+ }
132
+
133
+ function modulePathMatches(left, right) { return normalizeModulePath(left) === normalizeModulePath(right); }
134
+ function normalizeModulePath(sourcePath) { return String(sourcePath ?? '').replace(/\.(?:c|m)?(?:j|t)sx?$/u, ''); }
135
+ function hasCompleteUniqueStringSet(values) { return values.every((value) => typeof value === 'string' && value.length > 0) && new Set(values).size === values.length; }
136
+ function sameStringSet(left, right) { return left.length === right.length && left.every((value) => new Set(right).has(value)); }
137
+ function stableKey(parts) {
138
+ const values = parts.map((part) => part === undefined || part === null ? '' : String(part));
139
+ return values.some(Boolean) ? values.join('#') : undefined;
140
+ }
141
+ function uniqueStrings(values) { return [...new Set(values.filter((value) => typeof value === 'string' && value.length > 0))]; }
142
+
143
+ export { projectSymbolMoveDefaultAdmissionProofs, withDefaultAdmissionProof };
@@ -0,0 +1,213 @@
1
+ import { compactRecord } from './js-ts-safe-merge-context.js';
2
+
3
+ const symbolMoveRequiredEvidence = [
4
+ 'symbol-lineage-evidence',
5
+ 'import-export-rewrite-evidence',
6
+ 'output-diagnostics-gate',
7
+ 'output-declaration-gate'
8
+ ];
9
+
10
+ function classifySymbolMoveRisks(graphDelta, branch, exportedSymbolMoves) {
11
+ const branchGraph = graphDelta.stages?.[branch]?.projectSymbolGraph;
12
+ if (!branchGraph) return [];
13
+ const classifications = [];
14
+ for (const move of exportedSymbolMoves) {
15
+ const fromPath = move.details?.fromSourcePath;
16
+ const toPath = move.details?.toSourcePath;
17
+ const symbolName = move.details?.symbolName;
18
+ if (!fromPath || !toPath || !symbolName) continue;
19
+ const staleEdges = namedImportReferenceEdges(branchGraph).filter((edge) => (
20
+ importTargetName(edge) === symbolName
21
+ && modulePathMatches(edge.resolvedModulePath, fromPath)
22
+ && !modulePathMatches(edge.resolvedModulePath, toPath)
23
+ ));
24
+ if (staleEdges.length) classifications.push(staleImportedSymbolMoveClassification(graphDelta, branch, move, staleEdges));
25
+ }
26
+ return classifications;
27
+ }
28
+
29
+ function duplicateExportedSymbolMoveClassification(graphDelta, branch, baseSymbol, branchSymbols) {
30
+ const fromPath = symbolSourcePath(baseSymbol);
31
+ const candidateSourcePaths = uniqueStrings(branchSymbols.map(symbolSourcePath));
32
+ const symbolName = String(baseSymbol.name ?? branchSymbols[0]?.name);
33
+ const code = `project-${branch}-exported-symbol-move-duplicate-export-blocked`;
34
+ const sourcePaths = uniqueStrings([fromPath, ...candidateSourcePaths]);
35
+ return {
36
+ kind: 'duplicate-exported-symbol-move',
37
+ branch,
38
+ code,
39
+ operation: `blocked-${branch}-exported-symbol-move`,
40
+ sourcePaths,
41
+ pathRoles: Object.fromEntries(sourcePaths.map((sourcePath) => [
42
+ sourcePath,
43
+ sourcePath === fromPath ? 'base-export-source' : 'duplicate-export-source'
44
+ ])),
45
+ details: compactRecord({
46
+ reasonCode: code,
47
+ conflictKey: stableKey(['project-exported-symbol-move-duplicate-export', branch, fromPath, candidateSourcePaths.join('|'), symbolName, baseSymbol.signatureHash]),
48
+ branch,
49
+ movementKind: 'symbol-move-between-files',
50
+ symbolMoveKind: 'exported',
51
+ ambiguityKind: 'duplicate-export',
52
+ symbolName,
53
+ exportedName: symbolName,
54
+ fromSourcePath: fromPath,
55
+ candidateSourcePaths,
56
+ duplicateExportCount: branchSymbols.length,
57
+ baseSymbolId: baseSymbol.id,
58
+ branchSymbolIds: uniqueStrings(branchSymbols.map((symbol) => symbol.id)),
59
+ signatureHash: baseSymbol.signatureHash,
60
+ requiredEvidence: symbolMoveRequiredEvidence,
61
+ graphEvidence: duplicateExportedGraphEvidence(graphDelta, branch, baseSymbol, branchSymbols)
62
+ })
63
+ };
64
+ }
65
+
66
+ function staleImportedSymbolMoveClassification(graphDelta, branch, exportedMove, staleEdges) {
67
+ const symbolName = exportedMove.details?.symbolName;
68
+ const fromPath = exportedMove.details?.fromSourcePath;
69
+ const toPath = exportedMove.details?.toSourcePath;
70
+ const code = `project-${branch}-imported-symbol-move-stale-import-blocked`;
71
+ const sourcePaths = uniqueStrings([fromPath, toPath, ...staleEdges.map((edge) => edge.sourcePath)]);
72
+ return {
73
+ kind: 'stale-imported-symbol-move',
74
+ branch,
75
+ code,
76
+ operation: `blocked-${branch}-imported-symbol-move`,
77
+ sourcePaths,
78
+ pathRoles: pathRoles(sourcePaths, {
79
+ [fromPath]: 'base-export-source',
80
+ [toPath]: 'branch-export-source',
81
+ ...Object.fromEntries(staleEdges.map((edge) => [edge.sourcePath, edge.importKind === 'reexport' ? 'stale-re-exporter' : 'stale-importer']))
82
+ }),
83
+ details: compactRecord({
84
+ reasonCode: code,
85
+ conflictKey: stableKey(['project-imported-symbol-move-stale-import', branch, fromPath, toPath, symbolName, ...staleEdges.map((edge) => `${edge.sourcePath}:${edge.moduleSpecifier}`)]),
86
+ branch,
87
+ movementKind: 'symbol-move-between-files',
88
+ symbolMoveKind: 'imported',
89
+ ambiguityKind: 'stale-import-reference',
90
+ symbolName,
91
+ importerSourcePaths: uniqueStrings(staleEdges.map((edge) => edge.sourcePath)),
92
+ fromSourcePath: fromPath,
93
+ toSourcePath: toPath,
94
+ staleImportCount: staleEdges.length,
95
+ staleImports: staleEdges.map(importEdgeEvidence),
96
+ baseSymbolMoveConflictKey: exportedMove.details?.conflictKey,
97
+ requiredEvidence: symbolMoveRequiredEvidence,
98
+ graphEvidence: staleImportGraphEvidence(graphDelta, branch, exportedMove, staleEdges)
99
+ })
100
+ };
101
+ }
102
+
103
+ function duplicateExportedGraphEvidence(graphDelta, branch, baseSymbol, branchSymbols) {
104
+ return compactRecord({
105
+ stageSummaries: stageSummaries(graphDelta),
106
+ base: {
107
+ source: sourceEvidence(graphDelta, 'base', symbolSourcePath(baseSymbol)),
108
+ symbol: symbolEvidence(baseSymbol)
109
+ },
110
+ [branch]: {
111
+ sources: uniqueStrings(branchSymbols.map(symbolSourcePath)).map((sourcePath) => sourceEvidence(graphDelta, branch, sourcePath)),
112
+ symbols: branchSymbols.map(symbolEvidence)
113
+ }
114
+ });
115
+ }
116
+
117
+ function staleImportGraphEvidence(graphDelta, branch, exportedMove, staleEdges) {
118
+ return compactRecord({
119
+ stageSummaries: stageSummaries(graphDelta),
120
+ base: {
121
+ source: sourceEvidence(graphDelta, 'base', exportedMove.details?.fromSourcePath),
122
+ symbolMove: exportedMove.details
123
+ },
124
+ [branch]: {
125
+ source: sourceEvidence(graphDelta, branch, exportedMove.details?.toSourcePath),
126
+ staleImporters: uniqueStrings(staleEdges.map((edge) => edge.sourcePath)).map((sourcePath) => sourceEvidence(graphDelta, branch, sourcePath)),
127
+ staleImports: staleEdges.map(importEdgeEvidence)
128
+ }
129
+ });
130
+ }
131
+
132
+ function sourceEvidence(graphDelta, stageName, sourcePath) {
133
+ const graph = graphDelta.stages?.[stageName]?.projectSymbolGraph;
134
+ if (!graph || !sourcePath) return undefined;
135
+ return compactRecord({
136
+ sourcePath,
137
+ fileHash: graph.fileHashes?.find((record) => record.sourcePath === sourcePath),
138
+ importEdges: (graph.importEdges ?? []).filter((edge) => edge.sourcePath === sourcePath || edge.resolvedModulePath === sourcePath).map(importEdgeEvidence)
139
+ });
140
+ }
141
+
142
+ function namedImportReferenceEdges(graph) {
143
+ return (graph?.importEdges ?? []).filter((edge) => edge?.sourcePath
144
+ && edge.resolvedModulePath
145
+ && importTargetName(edge));
146
+ }
147
+
148
+ function importTargetName(edge) {
149
+ if (edge?.importKind === 'side-effect' || edge?.importKind === 'namespace') return undefined;
150
+ const name = edge?.importedName ?? edge?.localName ?? edge?.exportedName;
151
+ return name && name !== '*' ? String(name) : undefined;
152
+ }
153
+
154
+ function symbolSourcePath(symbol) {
155
+ return symbol?.definitionSpan?.path ?? symbol?.metadata?.sourcePath;
156
+ }
157
+
158
+ function importEdgeEvidence(edge) {
159
+ return compactRecord({
160
+ id: edge.id,
161
+ sourcePath: edge.sourcePath,
162
+ moduleSpecifier: edge.moduleSpecifier,
163
+ importKind: edge.importKind,
164
+ importedName: edge.importedName,
165
+ localName: edge.localName,
166
+ isTypeOnly: edge.isTypeOnly,
167
+ resolutionKind: edge.resolutionKind,
168
+ resolvedModulePath: edge.resolvedModulePath,
169
+ resolvedTargetSymbolId: edge.resolvedTargetSymbolId
170
+ });
171
+ }
172
+
173
+ function symbolEvidence(symbol) {
174
+ return compactRecord({
175
+ id: symbol.id,
176
+ name: symbol.name,
177
+ kind: symbol.kind,
178
+ language: symbol.language,
179
+ signatureHash: symbol.signatureHash,
180
+ definitionSpan: symbol.definitionSpan
181
+ });
182
+ }
183
+
184
+ function stageSummaries(graphDelta) {
185
+ return compactRecord({
186
+ base: graphDelta.stages?.base?.summary,
187
+ worker: graphDelta.stages?.worker?.summary,
188
+ head: graphDelta.stages?.head?.summary
189
+ });
190
+ }
191
+
192
+ function pathRoles(sourcePaths, roles) {
193
+ return Object.fromEntries(sourcePaths.map((sourcePath) => [sourcePath, roles[sourcePath]]));
194
+ }
195
+
196
+ function modulePathMatches(left, right) {
197
+ return normalizeModulePath(left) === normalizeModulePath(right);
198
+ }
199
+
200
+ function normalizeModulePath(sourcePath) {
201
+ return String(sourcePath ?? '').replace(/\.(?:c|m)?(?:j|t)sx?$/u, '');
202
+ }
203
+
204
+ function stableKey(parts) {
205
+ const values = parts.map((part) => part === undefined || part === null ? '' : String(part));
206
+ return values.some(Boolean) ? values.join('#') : undefined;
207
+ }
208
+
209
+ function uniqueStrings(values) {
210
+ return [...new Set(values.filter((value) => typeof value === 'string' && value.length > 0))];
211
+ }
212
+
213
+ export { classifySymbolMoveRisks, duplicateExportedSymbolMoveClassification };
@@ -0,0 +1,316 @@
1
+ import { createJsTsProjectSafeMergeGraphDelta } from './js-ts-safe-project-merge-graph.js';
2
+ import { compactRecord } from './js-ts-safe-merge-context.js';
3
+ import { projectSymbolMoveDefaultAdmissionProofs, withDefaultAdmissionProof } from './js-ts-safe-project-merge-symbol-move-default-admission.js';
4
+ import { classifySymbolMoveRisks, duplicateExportedSymbolMoveClassification } from './js-ts-safe-project-merge-symbol-move-risks.js';
5
+
6
+ const symbolMoveRequiredEvidence = ['symbol-lineage-evidence', 'import-export-rewrite-evidence', 'output-diagnostics-gate', 'output-declaration-gate'];
7
+
8
+ function classifyProjectSymbolMoves(input, files, projectId, fileMoveRenames = []) {
9
+ if (!hasSymbolMoveSignal(files)) return [];
10
+ const graphDelta = classificationGraphDelta(input, files, projectId);
11
+ if (!graphDelta?.stages?.base) return [];
12
+ return uniqueClassifications([
13
+ ...classifyBranchSymbolMoves(graphDelta, 'worker', fileMoveRenames),
14
+ ...classifyBranchSymbolMoves(graphDelta, 'head', fileMoveRenames)
15
+ ]);
16
+ }
17
+
18
+ function classifyBranchSymbolMoves(graphDelta, branch, fileMoveRenames) {
19
+ const importedSymbolMoves = classifyImportedSymbolMoves(graphDelta, branch, fileMoveRenames);
20
+ const exportedSymbolMoves = classifyExportedSymbolMoves(graphDelta, branch, fileMoveRenames);
21
+ const exactExportedSymbolMoves = exportedSymbolMoves.filter((classification) => classification.kind === 'exported-symbol-move');
22
+ const defaultAdmissionProofs = projectSymbolMoveDefaultAdmissionProofs(graphDelta, branch, exactExportedSymbolMoves, importedSymbolMoves, symbolMoveRequiredEvidence);
23
+ return [
24
+ ...importedSymbolMoves.map((classification) => withDefaultAdmissionProof(classification, defaultAdmissionProofs)),
25
+ ...exportedSymbolMoves.map((classification) => withDefaultAdmissionProof(classification, defaultAdmissionProofs)),
26
+ ...classifySymbolMoveRisks(graphDelta, branch, exactExportedSymbolMoves)
27
+ ];
28
+ }
29
+
30
+ function classifyImportedSymbolMoves(graphDelta, branch, fileMoveRenames) {
31
+ const baseGraph = graphDelta.stages?.base?.projectSymbolGraph;
32
+ const branchGraph = graphDelta.stages?.[branch]?.projectSymbolGraph;
33
+ if (!baseGraph || !branchGraph) return [];
34
+ const baseGroups = importEdgesGroupedBy(baseGraph);
35
+ const branchGroups = importEdgesGroupedBy(branchGraph);
36
+ const classifications = [];
37
+ for (const [key, baseGroup] of baseGroups) {
38
+ const branchGroup = branchGroups.get(key);
39
+ if (baseGroup.length !== 1 || branchGroup?.length !== 1) continue;
40
+ const baseEdge = baseGroup[0];
41
+ const branchEdge = branchGroup[0];
42
+ if (!baseEdge.resolvedModulePath || !branchEdge.resolvedModulePath) continue;
43
+ if (baseEdge.resolvedModulePath === branchEdge.resolvedModulePath) continue;
44
+ if (isWholeFileMove(fileMoveRenames, branch, baseEdge.resolvedModulePath, branchEdge.resolvedModulePath)) continue;
45
+ classifications.push(importedSymbolMoveClassification(graphDelta, branch, baseEdge, branchEdge));
46
+ }
47
+ return classifications;
48
+ }
49
+
50
+ function classifyExportedSymbolMoves(graphDelta, branch, fileMoveRenames) {
51
+ const baseGroups = exportedSymbolsGroupedBy(graphDelta, 'base');
52
+ const branchGroups = exportedSymbolsGroupedBy(graphDelta, branch);
53
+ const classifications = [];
54
+ for (const [key, baseGroup] of baseGroups) {
55
+ const branchGroup = branchGroups.get(key);
56
+ if (baseGroup.length !== 1) continue;
57
+ const baseSymbol = baseGroup[0];
58
+ if ((branchGroup?.length ?? 0) > 1) {
59
+ const fromPath = symbolSourcePath(baseSymbol);
60
+ if (branchGroup.some((symbol) => symbolSourcePath(symbol) !== fromPath)) {
61
+ classifications.push(duplicateExportedSymbolMoveClassification(graphDelta, branch, baseSymbol, branchGroup));
62
+ }
63
+ continue;
64
+ }
65
+ if (branchGroup?.length !== 1) continue;
66
+ const branchSymbol = branchGroup[0];
67
+ const fromPath = symbolSourcePath(baseSymbol);
68
+ const toPath = symbolSourcePath(branchSymbol);
69
+ if (!fromPath || !toPath || fromPath === toPath) continue;
70
+ if (isWholeFileMove(fileMoveRenames, branch, fromPath, toPath)) continue;
71
+ classifications.push(exportedSymbolMoveClassification(graphDelta, branch, baseSymbol, branchSymbol));
72
+ }
73
+ return classifications;
74
+ }
75
+
76
+ function importedSymbolMoveClassification(graphDelta, branch, baseEdge, branchEdge) {
77
+ const symbolName = importTargetName(baseEdge);
78
+ const code = `project-${branch}-imported-symbol-move-blocked`;
79
+ const sourcePaths = uniqueStrings([baseEdge.sourcePath, baseEdge.resolvedModulePath, branchEdge.resolvedModulePath]);
80
+ return {
81
+ kind: 'imported-symbol-move',
82
+ branch,
83
+ code,
84
+ operation: `blocked-${branch}-imported-symbol-move`,
85
+ sourcePaths,
86
+ pathRoles: pathRoles(sourcePaths, {
87
+ [baseEdge.sourcePath]: 'importer',
88
+ [baseEdge.resolvedModulePath]: 'base-export-source',
89
+ [branchEdge.resolvedModulePath]: 'branch-export-source'
90
+ }),
91
+ details: compactRecord({
92
+ reasonCode: code,
93
+ conflictKey: stableKey(['project-imported-symbol-move', branch, baseEdge.sourcePath, baseEdge.resolvedModulePath, branchEdge.resolvedModulePath, symbolName]),
94
+ branch,
95
+ movementKind: 'symbol-move-between-files',
96
+ symbolMoveKind: 'imported',
97
+ symbolName,
98
+ importerSourcePath: baseEdge.sourcePath,
99
+ fromSourcePath: baseEdge.resolvedModulePath,
100
+ toSourcePath: branchEdge.resolvedModulePath,
101
+ baseModuleSpecifier: baseEdge.moduleSpecifier,
102
+ branchModuleSpecifier: branchEdge.moduleSpecifier,
103
+ baseImportedName: baseEdge.importedName,
104
+ branchImportedName: branchEdge.importedName,
105
+ baseLocalName: baseEdge.localName,
106
+ branchLocalName: branchEdge.localName,
107
+ baseTargetSymbolId: baseEdge.resolvedTargetSymbolId,
108
+ branchTargetSymbolId: branchEdge.resolvedTargetSymbolId,
109
+ requiredEvidence: symbolMoveRequiredEvidence,
110
+ graphEvidence: importedGraphEvidence(graphDelta, branch, baseEdge, branchEdge)
111
+ })
112
+ };
113
+ }
114
+
115
+ function exportedSymbolMoveClassification(graphDelta, branch, baseSymbol, branchSymbol) {
116
+ const fromPath = symbolSourcePath(baseSymbol);
117
+ const toPath = symbolSourcePath(branchSymbol);
118
+ const symbolName = String(baseSymbol.name ?? branchSymbol.name);
119
+ const code = `project-${branch}-exported-symbol-move-blocked`;
120
+ const sourcePaths = uniqueStrings([fromPath, toPath]);
121
+ return {
122
+ kind: 'exported-symbol-move',
123
+ branch,
124
+ code,
125
+ operation: `blocked-${branch}-exported-symbol-move`,
126
+ sourcePaths,
127
+ pathRoles: pathRoles(sourcePaths, { [fromPath]: 'base-export-source', [toPath]: 'branch-export-source' }),
128
+ details: compactRecord({
129
+ reasonCode: code,
130
+ conflictKey: stableKey(['project-exported-symbol-move', branch, fromPath, toPath, symbolName, baseSymbol.signatureHash]),
131
+ branch,
132
+ movementKind: 'symbol-move-between-files',
133
+ symbolMoveKind: 'exported',
134
+ symbolName,
135
+ exportedName: symbolName,
136
+ fromSourcePath: fromPath,
137
+ toSourcePath: toPath,
138
+ baseSymbolId: baseSymbol.id,
139
+ branchSymbolId: branchSymbol.id,
140
+ signatureHash: baseSymbol.signatureHash,
141
+ requiredEvidence: symbolMoveRequiredEvidence,
142
+ graphEvidence: exportedGraphEvidence(graphDelta, branch, baseSymbol, branchSymbol)
143
+ })
144
+ };
145
+ }
146
+
147
+ function importedGraphEvidence(graphDelta, branch, baseEdge, branchEdge) {
148
+ return compactRecord({
149
+ stageSummaries: stageSummaries(graphDelta),
150
+ base: {
151
+ importer: sourceEvidence(graphDelta, 'base', baseEdge.sourcePath),
152
+ target: sourceEvidence(graphDelta, 'base', baseEdge.resolvedModulePath),
153
+ importEdge: importEdgeEvidence(baseEdge)
154
+ },
155
+ [branch]: {
156
+ importer: sourceEvidence(graphDelta, branch, branchEdge.sourcePath),
157
+ target: sourceEvidence(graphDelta, branch, branchEdge.resolvedModulePath),
158
+ importEdge: importEdgeEvidence(branchEdge)
159
+ }
160
+ });
161
+ }
162
+
163
+ function exportedGraphEvidence(graphDelta, branch, baseSymbol, branchSymbol) {
164
+ return compactRecord({
165
+ stageSummaries: stageSummaries(graphDelta),
166
+ base: {
167
+ source: sourceEvidence(graphDelta, 'base', symbolSourcePath(baseSymbol)),
168
+ symbol: symbolEvidence(baseSymbol)
169
+ },
170
+ [branch]: {
171
+ source: sourceEvidence(graphDelta, branch, symbolSourcePath(branchSymbol)),
172
+ symbol: symbolEvidence(branchSymbol)
173
+ }
174
+ });
175
+ }
176
+
177
+ function classificationGraphDelta(input, files, projectId) {
178
+ try {
179
+ return createJsTsProjectSafeMergeGraphDelta(input, files, [], `${projectId}_symbol_move_classifier`);
180
+ } catch {
181
+ return undefined;
182
+ }
183
+ }
184
+
185
+ function sourceEvidence(graphDelta, stageName, sourcePath) {
186
+ const stage = graphDelta.stages?.[stageName];
187
+ const graph = stage?.projectSymbolGraph;
188
+ if (!graph || !sourcePath) return undefined;
189
+ return compactRecord({
190
+ sourcePath,
191
+ fileHash: graph.fileHashes?.find((record) => record.sourcePath === sourcePath),
192
+ importEdges: (graph.importEdges ?? []).filter((edge) => edge.sourcePath === sourcePath || edge.resolvedModulePath === sourcePath).map(importEdgeEvidence)
193
+ });
194
+ }
195
+
196
+ function importEdgesGroupedBy(graph) {
197
+ const groups = new Map();
198
+ for (const edge of namedImportEdges(graph)) {
199
+ const key = stableKey(['imported-symbol-move', edge.sourcePath, importTargetName(edge), edge.localName, edge.importKind, edge.isTypeOnly]);
200
+ const entries = groups.get(key) ?? [];
201
+ entries.push(edge);
202
+ groups.set(key, entries);
203
+ }
204
+ return groups;
205
+ }
206
+
207
+ function exportedSymbolsGroupedBy(graphDelta, stageName) {
208
+ const groups = new Map();
209
+ for (const symbol of exportedSymbols(graphDelta, stageName)) {
210
+ const key = stableKey(['exported-symbol-move', symbol.language, symbol.name, symbol.signatureHash]);
211
+ if (!key) continue;
212
+ const entries = groups.get(key) ?? [];
213
+ entries.push(symbol);
214
+ groups.set(key, entries);
215
+ }
216
+ return groups;
217
+ }
218
+
219
+ function namedImportEdges(graph) {
220
+ return (graph?.importEdges ?? []).filter((edge) => edge?.sourcePath
221
+ && edge.resolvedModulePath
222
+ && edge.resolvedTargetSymbolId
223
+ && importTargetName(edge));
224
+ }
225
+
226
+ function exportedSymbols(graphDelta, stageName) {
227
+ return (graphDelta.stages?.[stageName]?.projectImport?.semanticIndex?.symbols ?? [])
228
+ .filter((symbol) => symbol?.kind === 'export' && symbolSourcePath(symbol) && symbol.name);
229
+ }
230
+
231
+ function importTargetName(edge) {
232
+ if (edge?.importKind === 'side-effect' || edge?.importKind === 'namespace') return undefined;
233
+ const name = edge?.importedName ?? edge?.localName ?? edge?.exportedName;
234
+ return name && name !== '*' ? String(name) : undefined;
235
+ }
236
+
237
+ function symbolSourcePath(symbol) {
238
+ return symbol?.definitionSpan?.path ?? symbol?.metadata?.sourcePath;
239
+ }
240
+
241
+ function importEdgeEvidence(edge) {
242
+ return compactRecord({
243
+ id: edge.id,
244
+ sourcePath: edge.sourcePath,
245
+ moduleSpecifier: edge.moduleSpecifier,
246
+ importKind: edge.importKind,
247
+ importedName: edge.importedName,
248
+ localName: edge.localName,
249
+ isTypeOnly: edge.isTypeOnly,
250
+ resolutionKind: edge.resolutionKind,
251
+ resolvedModulePath: edge.resolvedModulePath,
252
+ resolvedTargetSymbolId: edge.resolvedTargetSymbolId
253
+ });
254
+ }
255
+
256
+ function symbolEvidence(symbol) {
257
+ return compactRecord({
258
+ id: symbol.id,
259
+ name: symbol.name,
260
+ kind: symbol.kind,
261
+ language: symbol.language,
262
+ signatureHash: symbol.signatureHash,
263
+ definitionSpan: symbol.definitionSpan
264
+ });
265
+ }
266
+
267
+ function stageSummaries(graphDelta) {
268
+ return compactRecord({
269
+ base: graphDelta.stages?.base?.summary,
270
+ worker: graphDelta.stages?.worker?.summary,
271
+ head: graphDelta.stages?.head?.summary
272
+ });
273
+ }
274
+
275
+ function hasSymbolMoveSignal(files) {
276
+ return files.some((file) => branchText(file, 'worker') !== file.baseSourceText || branchText(file, 'head') !== file.baseSourceText);
277
+ }
278
+
279
+ function branchText(file, branch) {
280
+ if (branch === 'worker' && file.workerDeleted) return undefined;
281
+ if (branch === 'head' && file.headDeleted) return undefined;
282
+ return branch === 'worker' ? file.workerSourceText ?? file.baseSourceText : file.headSourceText ?? file.baseSourceText;
283
+ }
284
+
285
+ function isWholeFileMove(fileMoveRenames, branch, fromPath, toPath) {
286
+ return fileMoveRenames.some((item) => item.branch === branch
287
+ && item.details?.fromSourcePath === fromPath
288
+ && item.details?.toSourcePath === toPath);
289
+ }
290
+
291
+ function pathRoles(sourcePaths, roles) {
292
+ return Object.fromEntries(sourcePaths.map((sourcePath) => [sourcePath, roles[sourcePath]]));
293
+ }
294
+
295
+ function uniqueClassifications(classifications) {
296
+ const result = [];
297
+ const seen = new Set();
298
+ for (const classification of classifications) {
299
+ const key = classification.details?.conflictKey;
300
+ if (!key || seen.has(key)) continue;
301
+ seen.add(key);
302
+ result.push(classification);
303
+ }
304
+ return result;
305
+ }
306
+
307
+ function stableKey(parts) {
308
+ const values = parts.map((part) => part === undefined || part === null ? '' : String(part));
309
+ return values.some(Boolean) ? values.join('#') : undefined;
310
+ }
311
+
312
+ function uniqueStrings(values) {
313
+ return [...new Set(values.filter((value) => typeof value === 'string' && value.length > 0))];
314
+ }
315
+
316
+ export { classifyProjectSymbolMoves };