@shapeshift-labs/frontier-lang-compiler 0.2.150 → 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.
- package/README.md +315 -9
- package/bench/real-repo-corpus-checkout-identity.mjs +134 -0
- package/bench/real-repo-corpus-checkout-proof.mjs +263 -0
- package/bench/real-repo-corpus-command-execution.mjs +314 -0
- package/bench/real-repo-corpus-evidence.mjs +165 -0
- package/bench/real-repo-corpus-suite.mjs +273 -0
- package/bench/smoke.mjs +109 -7
- package/dist/declarations/import-adapter-core.d.ts +4 -3
- package/dist/declarations/import-adapter-options-native.d.ts +21 -0
- package/dist/declarations/js-ts-project-merge-admission-routes.d.ts +35 -0
- package/dist/declarations/js-ts-project-merge-commonjs-interop.d.ts +29 -0
- package/dist/declarations/js-ts-project-merge-confidence.d.ts +64 -0
- package/dist/declarations/js-ts-project-merge-declaration-emit-parity.d.ts +37 -0
- package/dist/declarations/js-ts-project-merge-declarations.d.ts +65 -0
- package/dist/declarations/js-ts-project-merge-diagnostics.d.ts +97 -0
- package/dist/declarations/js-ts-project-merge-global-augmentation.d.ts +30 -0
- package/dist/declarations/js-ts-project-merge-jsx-render-branch.d.ts +48 -0
- package/dist/declarations/js-ts-project-merge-proof-levels.d.ts +109 -0
- package/dist/declarations/js-ts-project-merge-quality-gates.d.ts +38 -0
- package/dist/declarations/js-ts-project-merge-semantic-equivalence-proof.d.ts +45 -0
- package/dist/declarations/js-ts-project-merge-tsconfig.d.ts +43 -0
- package/dist/declarations/js-ts-safe-merge.d.ts +47 -0
- package/dist/declarations/js-ts-safe-project-merge.d.ts +120 -38
- package/dist/declarations/native-project-compiler-assignability-oracle.d.ts +41 -0
- package/dist/declarations/native-project-compiler-callable-signatures.d.ts +31 -0
- package/dist/declarations/native-project-compiler-class-member-runtime-proof.d.ts +87 -0
- package/dist/declarations/native-project-compiler-composite-types.d.ts +23 -0
- package/dist/declarations/native-project-compiler-enum-proof.d.ts +58 -0
- package/dist/declarations/native-project-compiler-index-signature.d.ts +7 -0
- package/dist/declarations/native-project-compiler-public-api-source-binding.d.ts +8 -0
- package/dist/declarations/native-project-compiler-scope.d.ts +37 -0
- package/dist/declarations/native-project-compiler-type-reference-targets.d.ts +38 -0
- package/dist/declarations/native-project-css-modules.d.ts +90 -0
- package/dist/declarations/native-project-decorator-metadata.d.ts +126 -0
- package/dist/declarations/native-project-jsx-graph.d.ts +313 -0
- package/dist/declarations/native-project-module-declarations.d.ts +52 -0
- package/dist/declarations/native-project-module-resolution.d.ts +76 -1
- package/dist/declarations/native-project-runtime-effect-target.d.ts +29 -0
- package/dist/declarations/native-project-runtime-executable-effect-evidence.d.ts +107 -0
- package/dist/declarations/native-project-runtime-mutation-target.d.ts +33 -0
- package/dist/declarations/native-project-runtime-promise-chain.d.ts +30 -0
- package/dist/declarations/native-project-runtime-promise-combinator.d.ts +22 -0
- package/dist/declarations/native-project-runtime-reachability.d.ts +30 -0
- package/dist/declarations/native-project-runtime-resource-management.d.ts +27 -0
- package/dist/declarations/native-project-runtime-yield-delegation.d.ts +10 -0
- package/dist/declarations/native-project-scope-template-reference.d.ts +13 -0
- package/dist/declarations/native-project-source-evidence.d.ts +8 -0
- package/dist/declarations/native-project.d.ts +40 -39
- package/dist/declarations/semantic-edit-script.d.ts +10 -8
- package/dist/declarations/semantic-graph-layers.d.ts +79 -0
- package/dist/declarations/semantic-sidecar.d.ts +3 -2
- package/dist/declarations/semantic-structural-diff.d.ts +94 -0
- package/dist/declarations/source-preservation.d.ts +32 -1
- package/dist/declarations/target-adapters.d.ts +22 -2
- package/dist/index.d.ts +31 -0
- package/dist/index.js +5 -0
- package/dist/internal/index-impl/compileNativeSource.js +53 -5
- package/dist/internal/index-impl/createLightweightNativeImport.js +58 -4
- package/dist/internal/index-impl/createNativeImportFromSyntaxAst.js +17 -1
- package/dist/internal/index-impl/createNativeImportFromTypeScriptAst.js +28 -4
- package/dist/internal/index-impl/createNativeProjectImportResult.js +31 -27
- package/dist/internal/index-impl/createNativeProjectModuleResolutionFromPackageManifests.js +145 -0
- package/dist/internal/index-impl/createNativeSourcePreservation.js +34 -7
- package/dist/internal/index-impl/createSemanticImportSidecar.js +27 -1
- package/dist/internal/index-impl/createTypeScriptCompilerNativeImporterAdapter.js +16 -5
- package/dist/internal/index-impl/dynamicImportExpressionMetadata.js +80 -0
- package/dist/internal/index-impl/importMetaUrlDependencyMetadata.js +176 -0
- package/dist/internal/index-impl/importNativeSource.js +2 -3
- package/dist/internal/index-impl/moduleImportAttributeMetadata.js +232 -0
- package/dist/internal/index-impl/projectSemanticEditScriptToSource.js +8 -1
- package/dist/internal/index-impl/projectSymbolGraphClassStaticBlocks.js +148 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerAdvancedTypeMetadata.js +45 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerCallableSignatureEquivalence.js +107 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerClassPrivateAccessorRuntimeProof.js +280 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerClassShapeEquivalence.js +103 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerConditionalTypeEquivalence.js +242 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerDecoratorRuntimeProof.js +197 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerEnumEquivalence.js +188 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerFacts.js +244 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerIndexSignatureEquivalence.js +58 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerMetadata.js +168 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerTypeEquivalence.js +199 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerTypeEquivalenceProof.js +204 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerTypeReferenceTargetEquivalence.js +99 -0
- package/dist/internal/index-impl/projectSymbolGraphCssModuleRecords.js +264 -0
- package/dist/internal/index-impl/projectSymbolGraphCssModuleScanners.js +242 -0
- package/dist/internal/index-impl/projectSymbolGraphCssModuleUtils.js +152 -0
- package/dist/internal/index-impl/projectSymbolGraphCssModules.js +82 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxComponentImports.js +170 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxComponentProviderLookup.js +167 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxComponentWrappers.js +150 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxContextTargets.js +71 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxContextValues.js +212 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxEventHandlers.js +172 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxHookEffects.js +124 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxHooks.js +281 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxMemberComponents.js +139 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxPropFlows.js +320 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxPropValues.js +145 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxProviderFlows.js +133 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxRecords.js +315 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxRenderCollections.js +155 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxRenderReturns.js +291 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxRenderRisk.js +279 -0
- package/dist/internal/index-impl/projectSymbolGraphModuleDeclarationShapes.js +138 -0
- package/dist/internal/index-impl/projectSymbolGraphModuleResolution.js +89 -87
- package/dist/internal/index-impl/projectSymbolGraphPackageConditions.js +314 -0
- package/dist/internal/index-impl/projectSymbolGraphReExportImportTargets.js +43 -0
- package/dist/internal/index-impl/projectSymbolGraphReExports.js +55 -1
- package/dist/internal/index-impl/projectSymbolGraphRuntimeRegions.js +108 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefAliases.js +307 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefLexical.js +320 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefOwners.js +50 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefRecordBuilders.js +112 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefRecords.js +238 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefStructural.js +104 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefStructuralNormalize.js +242 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefUseHashes.js +107 -0
- package/dist/internal/index-impl/projectSymbolGraphSourceMapGeneratedBoundary.js +111 -0
- package/dist/internal/index-impl/projectSymbolGraphSourceRecords.js +268 -0
- package/dist/internal/index-impl/projectSymbolGraphSourceRecordsOwnership.js +309 -0
- package/dist/internal/index-impl/replaySemanticEditProjection.js +53 -39
- package/dist/internal/index-impl/runtimeOrderEvidenceBinding.js +151 -0
- package/dist/internal/index-impl/runtimeOrderProofSurfaces.js +253 -0
- package/dist/internal/index-impl/semanticEditCallsiteArgumentMerge.js +319 -0
- package/dist/internal/index-impl/semanticEditExplicitSourceReplacement.js +7 -2
- package/dist/internal/index-impl/semanticEditProjectionRecord.js +8 -0
- package/dist/internal/index-impl/semanticEditReplayDiagnostics.js +7 -2
- package/dist/internal/index-impl/semanticEditReplayOutputBinding.js +61 -0
- package/dist/internal/index-impl/semanticEditReplayRerunRoute.js +27 -0
- package/dist/internal/index-impl/semanticEditReplaySourceReplacement.js +6 -1
- package/dist/internal/index-impl/semanticEditRuntimeOrderReasons.js +320 -0
- package/dist/internal/index-impl/semanticEditScriptClassification.js +90 -5
- package/dist/internal/index-impl/semanticEditScripts.js +42 -5
- package/dist/internal/index-impl/semanticEditTypeSyntaxReasons.js +134 -0
- package/dist/internal/index-impl/semanticIndexFromNativeDeclarations.js +11 -5
- package/dist/internal/index-impl/semanticStructuralDiffRecords.js +150 -0
- package/dist/internal/index-impl/sourceMapGeneratedBoundaryGate.js +185 -0
- package/dist/internal/index-impl/staticMemberLiteral.js +31 -0
- package/dist/internal/index-impl/staticOptionalMemberReference.js +22 -0
- package/dist/internal/index-impl/syntaxAstSourcePreservation.js +273 -0
- package/dist/internal/index-impl/syntaxCommonJsModuleDeclarationEntries.js +297 -0
- package/dist/internal/index-impl/syntaxModuleDeclarationEntries.js +56 -132
- package/dist/internal/index-impl/syntaxModuleEntryRecords.js +160 -0
- package/dist/internal/index-impl/typeScriptCompilerAdvancedTypeShapes.js +160 -0
- package/dist/internal/index-impl/typeScriptCompilerAssignabilityOracle.js +97 -0
- package/dist/internal/index-impl/typeScriptCompilerClassApi.js +238 -0
- package/dist/internal/index-impl/typeScriptCompilerDecoratorMetadata.js +290 -0
- package/dist/internal/index-impl/typeScriptCompilerEnumShape.js +279 -0
- package/dist/internal/index-impl/typeScriptCompilerFacts.js +294 -0
- package/dist/internal/index-impl/typeScriptCompilerInferenceSyntax.js +170 -0
- package/dist/internal/index-impl/typeScriptCompilerReferenceGraph.js +186 -0
- package/dist/internal/index-impl/typeScriptCompilerSymbolIdentity.js +294 -0
- package/dist/internal/index-impl/typeScriptCompilerTypeReferenceTargets.js +142 -0
- package/dist/internal/index-impl/typeScriptDeclaration.js +10 -38
- package/dist/internal/index-impl/typeScriptModuleDeclarationEntries.js +52 -15
- package/dist/internal/index-impl/typeScriptSourceFilePreservation.js +296 -0
- package/dist/js-ts-safe-member-class-invariants.js +247 -0
- package/dist/js-ts-safe-member-merge-result.js +23 -3
- package/dist/js-ts-safe-member-merge.js +28 -4
- package/dist/js-ts-safe-merge-binding-patterns.js +170 -0
- package/dist/js-ts-safe-merge-jsx-attribute-fallback.js +151 -157
- package/dist/js-ts-safe-merge-jsx-attribute-parser.js +277 -0
- package/dist/js-ts-safe-merge-jsx-child-expression-fallback.js +161 -0
- package/dist/js-ts-safe-merge-jsx-child-expression-merge.js +319 -0
- package/dist/js-ts-safe-merge-jsx-child-expression-parser.js +300 -0
- package/dist/js-ts-safe-merge-parse-declarations.js +46 -2
- package/dist/js-ts-safe-merge-parse-statements.js +8 -0
- package/dist/js-ts-safe-merge-semantic-edit-fallback.js +13 -5
- package/dist/js-ts-safe-merge-source-shape-fallbacks.js +3 -1
- package/dist/js-ts-safe-merge-top-level-rename-fallback.js +31 -5
- package/dist/js-ts-safe-merge-top-level-rename-result.js +7 -2
- package/dist/js-ts-safe-merge-variable-declarator-fallback.js +124 -6
- package/dist/js-ts-safe-merge-variable-declarator-parser.js +34 -4
- package/dist/js-ts-safe-merge.js +136 -0
- package/dist/js-ts-safe-project-merge-admission-routes.js +216 -0
- package/dist/js-ts-safe-project-merge-admission.js +161 -0
- package/dist/js-ts-safe-project-merge-ambient.js +110 -0
- package/dist/js-ts-safe-project-merge-core.js +85 -0
- package/dist/js-ts-safe-project-merge-css-module-conflicts.js +60 -0
- package/dist/js-ts-safe-project-merge-declaration-emit-parity.js +186 -0
- package/dist/js-ts-safe-project-merge-declarations.js +227 -0
- package/dist/js-ts-safe-project-merge-diagnostics-metadata.js +42 -0
- package/dist/js-ts-safe-project-merge-diagnostics-ts.js +73 -0
- package/dist/js-ts-safe-project-merge-diagnostics.js +283 -0
- package/dist/js-ts-safe-project-merge-evidence-routing.js +38 -0
- package/dist/js-ts-safe-project-merge-files.js +70 -0
- package/dist/js-ts-safe-project-merge-global-augmentation-compatibility.js +99 -0
- package/dist/js-ts-safe-project-merge-graph-conflicts.js +90 -2
- package/dist/js-ts-safe-project-merge-graph-delta-commonjs-interop.js +108 -0
- package/dist/js-ts-safe-project-merge-graph-delta-compiler-conflicts.js +179 -0
- package/dist/js-ts-safe-project-merge-graph-delta-compiler-details.js +189 -0
- package/dist/js-ts-safe-project-merge-graph-delta-conflicts.js +51 -184
- package/dist/js-ts-safe-project-merge-graph-delta-identity-conflicts.js +202 -0
- package/dist/js-ts-safe-project-merge-graph-delta-inference-syntax.js +80 -0
- package/dist/js-ts-safe-project-merge-graph-delta-module-declarations.js +155 -0
- package/dist/js-ts-safe-project-merge-graph-limits.js +16 -1
- package/dist/js-ts-safe-project-merge-graph.js +37 -5
- package/dist/js-ts-safe-project-merge-import-removal.js +292 -0
- package/dist/js-ts-safe-project-merge-jsx-graph-conflict-details.js +235 -0
- package/dist/js-ts-safe-project-merge-jsx-graph-conflicts.js +173 -0
- package/dist/js-ts-safe-project-merge-jsx-prop-contracts.js +86 -0
- package/dist/js-ts-safe-project-merge-jsx-render-branch-proof.js +189 -0
- package/dist/js-ts-safe-project-merge-missing-evidence.js +310 -0
- package/dist/js-ts-safe-project-merge-move-rename.js +209 -0
- package/dist/js-ts-safe-project-merge-proof-conflicts.js +44 -0
- package/dist/js-ts-safe-project-merge-proof-levels.js +320 -0
- package/dist/js-ts-safe-project-merge-quality-gates.js +140 -0
- package/dist/js-ts-safe-project-merge-routing-calibration.js +125 -0
- package/dist/js-ts-safe-project-merge-runtime-region-conflicts.js +156 -0
- package/dist/js-ts-safe-project-merge-scope-use-def-conflicts.js +292 -0
- package/dist/js-ts-safe-project-merge-semantic-equivalence-proof.js +175 -0
- package/dist/js-ts-safe-project-merge-semantic-replay-proof.js +311 -0
- package/dist/js-ts-safe-project-merge-semantic-replay-routes.js +179 -0
- package/dist/js-ts-safe-project-merge-source-span-conflicts.js +310 -0
- package/dist/js-ts-safe-project-merge-source-span-roundtrip-proof.js +172 -0
- package/dist/js-ts-safe-project-merge-split-merge-admission.js +96 -0
- package/dist/js-ts-safe-project-merge-split-merge-records.js +320 -0
- package/dist/js-ts-safe-project-merge-split-merge-shapes.js +234 -0
- package/dist/js-ts-safe-project-merge-split-merge.js +218 -0
- package/dist/js-ts-safe-project-merge-summary.js +320 -0
- package/dist/js-ts-safe-project-merge-symbol-move-admission.js +63 -0
- package/dist/js-ts-safe-project-merge-symbol-move-default-admission.js +143 -0
- package/dist/js-ts-safe-project-merge-symbol-move-risks.js +213 -0
- package/dist/js-ts-safe-project-merge-symbol-move.js +316 -0
- package/dist/js-ts-safe-project-merge-symbol-rename-admission.js +59 -0
- package/dist/js-ts-safe-project-merge-symbol-rename-default-admission.js +111 -0
- package/dist/js-ts-safe-project-merge-symbol-rename.js +319 -0
- package/dist/js-ts-safe-project-merge-ts-options.js +205 -0
- package/dist/js-ts-safe-project-merge-ts-program.js +268 -0
- package/dist/js-ts-safe-project-merge-typed-property-rename-rebase-utils.js +69 -0
- package/dist/js-ts-safe-project-merge-typed-property-rename-rebase.js +317 -0
- package/dist/js-ts-safe-project-merge-unsupported-surfaces.js +319 -0
- package/dist/js-ts-safe-project-merge.js +170 -171
- package/dist/js-ts-semantic-scope-use-def-bindings.js +287 -0
- package/dist/js-ts-semantic-scope-use-def-scan.js +241 -0
- package/dist/js-ts-semantic-scope-use-def-utils.js +132 -0
- package/dist/js-ts-semantic-scope-use-def.js +217 -0
- package/dist/lightweight-dependency-effects.js +28 -4
- package/dist/lightweight-dependency-relations.js +13 -7
- package/dist/lightweight-dependency-top-level.js +63 -0
- package/dist/native-import-language-profiles.js +27 -1
- package/dist/native-js-ts-importers.js +9 -5
- package/dist/native-parser-ast-format-profiles.js +12 -0
- package/dist/native-parser-html-css-format-profiles.js +85 -0
- package/dist/native-region-scanner-core.js +5 -3
- package/dist/native-region-scanner-js-commonjs.js +155 -0
- package/dist/native-region-scanner-js-imports.js +51 -13
- package/dist/native-region-scanner-js-reexports.js +79 -0
- package/dist/native-region-scanner-js-ts-helpers.js +23 -0
- package/dist/native-source-ledger-helpers.js +1 -1
- package/dist/native-source-ledger.js +24 -10
- package/dist/native-source-maps-ecma426.js +316 -0
- package/dist/native-source-maps.js +36 -6
- package/dist/native-source-preservation-ownership.js +292 -0
- package/dist/native-source-preservation-scanner.js +63 -25
- package/dist/native-source-preservation-types.d.ts +3 -0
- package/dist/semantic-import-effect-occurrences.js +242 -0
- package/dist/semantic-import-effect-regions.js +95 -58
- package/dist/semantic-import-graph-layers.js +224 -0
- package/dist/semantic-import-runtime-conditional-evidence.js +135 -0
- package/dist/semantic-import-runtime-effect-target-evidence.js +145 -0
- package/dist/semantic-import-runtime-exit-evidence.js +32 -0
- package/dist/semantic-import-runtime-import-meta-evidence.js +33 -0
- package/dist/semantic-import-runtime-mutation-evidence.js +155 -0
- package/dist/semantic-import-runtime-order-evidence.js +318 -0
- package/dist/semantic-import-runtime-promise-chain-evidence.js +103 -0
- package/dist/semantic-import-runtime-promise-combinator-evidence.js +166 -0
- package/dist/semantic-import-runtime-reachability-evidence.js +269 -0
- package/dist/semantic-import-runtime-resource-management-evidence.js +293 -0
- package/dist/semantic-import-runtime-switch-evidence.js +304 -0
- package/dist/semantic-import-runtime-throw-evidence.js +44 -0
- package/dist/semantic-import-runtime-try-finally-evidence.js +172 -0
- package/dist/semantic-import-sidecar-entry.js +4 -0
- package/dist/semantic-import-source-preservation.js +6 -2
- package/package.json +1 -1
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { hashSemanticValue } from '@shapeshift-labs/frontier-lang-kernel';
|
|
2
|
+
import { compactRecord } from './js-ts-safe-merge-context.js';
|
|
3
|
+
import { classEvidence, generatedProjectSourcePath, moduleEvidence } from './js-ts-safe-project-merge-split-merge-shapes.js';
|
|
4
|
+
|
|
5
|
+
const classifierGateId = 'project-split-merge-classifier';
|
|
6
|
+
const exactStructuralPartitionEvidence = 'exact-structural-partition-proof';
|
|
7
|
+
const moduleRequiredEvidence = [
|
|
8
|
+
'module-lineage-evidence',
|
|
9
|
+
'public-api-contract-evidence',
|
|
10
|
+
'import-export-rewrite-evidence',
|
|
11
|
+
'output-project-symbol-graph',
|
|
12
|
+
'output-diagnostics-gate',
|
|
13
|
+
'output-declaration-gate'
|
|
14
|
+
];
|
|
15
|
+
const classRequiredEvidence = [
|
|
16
|
+
'class-lineage-evidence',
|
|
17
|
+
'member-lineage-evidence',
|
|
18
|
+
'public-api-contract-evidence',
|
|
19
|
+
'output-project-symbol-graph',
|
|
20
|
+
'output-diagnostics-gate',
|
|
21
|
+
'output-declaration-gate'
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
function moduleSplitClassification(branch, baseModule, candidates, movedItems) {
|
|
25
|
+
const sourcePaths = uniqueStrings([baseModule.sourcePath, ...candidates.map((candidate) => candidate.file.sourcePath)]);
|
|
26
|
+
const code = `project-${branch}-module-split-blocked`;
|
|
27
|
+
const fingerprint = classificationFingerprint({ kind: 'module-split', branch, sourcePath: baseModule.sourcePath, targetPaths: candidates.map((candidate) => candidate.file.sourcePath), movedItems });
|
|
28
|
+
const partition = moduleSplitPartition(baseModule, candidates);
|
|
29
|
+
return {
|
|
30
|
+
kind: 'module-split',
|
|
31
|
+
branch,
|
|
32
|
+
code,
|
|
33
|
+
operation: `blocked-${branch}-module-split`,
|
|
34
|
+
sourcePaths,
|
|
35
|
+
pathRoles: splitPathRoles(baseModule.sourcePath, candidates.map((candidate) => candidate.file.sourcePath)),
|
|
36
|
+
details: compactRecord({
|
|
37
|
+
reasonCode: code,
|
|
38
|
+
conflictKey: `project-module-split#${branch}#${sourcePaths.join('|')}#${fingerprint}`,
|
|
39
|
+
branch,
|
|
40
|
+
structuralEditKind: 'module-split',
|
|
41
|
+
sourcePath: baseModule.sourcePath,
|
|
42
|
+
targetPaths: uniqueStrings(candidates.map((candidate) => candidate.file.sourcePath)),
|
|
43
|
+
movedDeclarationKeys: movedItems,
|
|
44
|
+
...generatedBoundaryDetails(sourcePaths),
|
|
45
|
+
...partition,
|
|
46
|
+
requiredEvidence: requiredEvidenceForPartition(moduleRequiredEvidence, partition),
|
|
47
|
+
missingRequiredEvidence: requiredEvidenceForPartition(moduleRequiredEvidence, partition),
|
|
48
|
+
baseModule: moduleEvidence(baseModule.baseShape),
|
|
49
|
+
branchModules: candidates.map((candidate) => compactRecord({ ...moduleEvidence(candidate.file.branchShape), overlappingDeclarationKeys: candidate.overlap }))
|
|
50
|
+
})
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function moduleMergeClassification(branch, branchModule, candidates, movedItems) {
|
|
55
|
+
const sourcePaths = uniqueStrings([...candidates.map((candidate) => candidate.file.sourcePath), branchModule.sourcePath]);
|
|
56
|
+
const code = `project-${branch}-module-merge-blocked`;
|
|
57
|
+
const fingerprint = classificationFingerprint({ kind: 'module-merge', branch, sourcePaths: candidates.map((candidate) => candidate.file.sourcePath), targetPath: branchModule.sourcePath, movedItems });
|
|
58
|
+
const partition = moduleMergePartition(branchModule, candidates);
|
|
59
|
+
return {
|
|
60
|
+
kind: 'module-merge',
|
|
61
|
+
branch,
|
|
62
|
+
code,
|
|
63
|
+
operation: `blocked-${branch}-module-merge`,
|
|
64
|
+
sourcePaths,
|
|
65
|
+
pathRoles: mergePathRoles(candidates.map((candidate) => candidate.file.sourcePath), branchModule.sourcePath),
|
|
66
|
+
details: compactRecord({
|
|
67
|
+
reasonCode: code,
|
|
68
|
+
conflictKey: `project-module-merge#${branch}#${sourcePaths.join('|')}#${fingerprint}`,
|
|
69
|
+
branch,
|
|
70
|
+
structuralEditKind: 'module-merge',
|
|
71
|
+
sourcePaths: uniqueStrings(candidates.map((candidate) => candidate.file.sourcePath)),
|
|
72
|
+
targetPath: branchModule.sourcePath,
|
|
73
|
+
movedDeclarationKeys: movedItems,
|
|
74
|
+
...generatedBoundaryDetails(sourcePaths),
|
|
75
|
+
...partition,
|
|
76
|
+
requiredEvidence: requiredEvidenceForPartition(moduleRequiredEvidence, partition),
|
|
77
|
+
missingRequiredEvidence: requiredEvidenceForPartition(moduleRequiredEvidence, partition),
|
|
78
|
+
baseModules: candidates.map((candidate) => compactRecord({ ...moduleEvidence(candidate.file.baseShape), overlappingDeclarationKeys: candidate.overlap })),
|
|
79
|
+
branchModule: moduleEvidence(branchModule.branchShape)
|
|
80
|
+
})
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function classSplitClassification(branch, baseClass, candidates, movedMembers) {
|
|
85
|
+
const sourcePaths = uniqueStrings([baseClass.sourcePath, ...candidates.map((candidate) => candidate.record.sourcePath)]);
|
|
86
|
+
const code = `project-${branch}-class-split-blocked`;
|
|
87
|
+
const fingerprint = classificationFingerprint({ kind: 'class-split', branch, sourcePath: baseClass.sourcePath, className: baseClass.classRecord.name, targetClasses: candidates.map((candidate) => classIdentity(candidate.record)), movedMembers });
|
|
88
|
+
const partition = classSplitPartition(baseClass, candidates);
|
|
89
|
+
return {
|
|
90
|
+
kind: 'class-split',
|
|
91
|
+
branch,
|
|
92
|
+
code,
|
|
93
|
+
operation: `blocked-${branch}-class-split`,
|
|
94
|
+
sourcePaths,
|
|
95
|
+
pathRoles: splitPathRoles(baseClass.sourcePath, candidates.map((candidate) => candidate.record.sourcePath)),
|
|
96
|
+
details: compactRecord({
|
|
97
|
+
reasonCode: code,
|
|
98
|
+
conflictKey: `project-class-split#${branch}#${sourcePaths.join('|')}#${fingerprint}`,
|
|
99
|
+
branch,
|
|
100
|
+
structuralEditKind: 'class-split',
|
|
101
|
+
sourceClass: classEvidence(baseClass),
|
|
102
|
+
targetClasses: candidates.map((candidate) => compactRecord({ ...classEvidence(candidate.record), overlappingMemberKeys: candidate.overlap })),
|
|
103
|
+
movedMemberKeys: movedMembers,
|
|
104
|
+
...generatedBoundaryDetails(sourcePaths),
|
|
105
|
+
...partition,
|
|
106
|
+
requiredEvidence: requiredEvidenceForPartition(classRequiredEvidence, partition),
|
|
107
|
+
missingRequiredEvidence: requiredEvidenceForPartition(classRequiredEvidence, partition)
|
|
108
|
+
})
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function classMergeClassification(branch, branchClass, candidates, movedMembers) {
|
|
113
|
+
const sourcePaths = uniqueStrings([...candidates.map((candidate) => candidate.record.sourcePath), branchClass.sourcePath]);
|
|
114
|
+
const code = `project-${branch}-class-merge-blocked`;
|
|
115
|
+
const fingerprint = classificationFingerprint({ kind: 'class-merge', branch, sourceClasses: candidates.map((candidate) => classIdentity(candidate.record)), targetPath: branchClass.sourcePath, targetClassName: branchClass.classRecord.name, movedMembers });
|
|
116
|
+
const partition = classMergePartition(branchClass, candidates);
|
|
117
|
+
return {
|
|
118
|
+
kind: 'class-merge',
|
|
119
|
+
branch,
|
|
120
|
+
code,
|
|
121
|
+
operation: `blocked-${branch}-class-merge`,
|
|
122
|
+
sourcePaths,
|
|
123
|
+
pathRoles: mergePathRoles(candidates.map((candidate) => candidate.record.sourcePath), branchClass.sourcePath),
|
|
124
|
+
details: compactRecord({
|
|
125
|
+
reasonCode: code,
|
|
126
|
+
conflictKey: `project-class-merge#${branch}#${sourcePaths.join('|')}#${fingerprint}`,
|
|
127
|
+
branch,
|
|
128
|
+
structuralEditKind: 'class-merge',
|
|
129
|
+
sourceClasses: candidates.map((candidate) => compactRecord({ ...classEvidence(candidate.record), overlappingMemberKeys: candidate.overlap })),
|
|
130
|
+
targetClass: classEvidence(branchClass),
|
|
131
|
+
movedMemberKeys: movedMembers,
|
|
132
|
+
...generatedBoundaryDetails(sourcePaths),
|
|
133
|
+
...partition,
|
|
134
|
+
requiredEvidence: requiredEvidenceForPartition(classRequiredEvidence, partition),
|
|
135
|
+
missingRequiredEvidence: requiredEvidenceForPartition(classRequiredEvidence, partition)
|
|
136
|
+
})
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function splitMergeConflictForPath(classification, sourcePath, extraDetails = {}) {
|
|
141
|
+
const details = splitMergeConflictDetails(classification.details, extraDetails);
|
|
142
|
+
return {
|
|
143
|
+
code: classification.code,
|
|
144
|
+
gateId: classifierGateId,
|
|
145
|
+
message: splitMergeMessage(classification),
|
|
146
|
+
sourcePath,
|
|
147
|
+
details: compactRecord({ ...details, sourcePath, pathRole: classification.pathRoles?.[sourcePath] })
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function splitMergeMessage(classification) {
|
|
152
|
+
const structuralKind = classification.details?.structuralEditKind ?? classification.kind;
|
|
153
|
+
if (structuralKind === 'module-split') return `${classification.branch} module split requires an exact declaration partition, module lineage, public API contract, import/export rewrite, diagnostics, and declaration evidence.`;
|
|
154
|
+
if (structuralKind === 'module-merge') return `${classification.branch} module merge requires an exact declaration partition, module lineage, public API contract, import/export rewrite, diagnostics, and declaration evidence.`;
|
|
155
|
+
if (structuralKind === 'class-split') return `${classification.branch} class split requires an exact member partition, class/member lineage, public API contract, diagnostics, and declaration evidence.`;
|
|
156
|
+
return `${classification.branch} class merge requires an exact member partition, class/member lineage, public API contract, diagnostics, and declaration evidence.`;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function classificationSummaryRecord(classification) {
|
|
160
|
+
return compactRecord({
|
|
161
|
+
kind: classification.kind,
|
|
162
|
+
branch: classification.branch,
|
|
163
|
+
code: classification.code,
|
|
164
|
+
operation: classification.operation,
|
|
165
|
+
sourcePaths: classification.sourcePaths,
|
|
166
|
+
conflictKey: classification.details?.conflictKey,
|
|
167
|
+
structuralEditKind: classification.details?.structuralEditKind
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function classifiedOperation(classifications) {
|
|
172
|
+
const operations = uniqueStrings(classifications.map((classification) => classification.operation));
|
|
173
|
+
return operations.length === 1 ? operations[0] : 'blocked-project-split-merge-classification';
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function splitPathRoles(sourcePath, targetPaths) {
|
|
177
|
+
return pathRoles([[sourcePath, 'split-source'], ...targetPaths.map((targetPath) => [targetPath, 'split-target'])]);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function mergePathRoles(sourcePaths, targetPath) {
|
|
181
|
+
return pathRoles([...sourcePaths.map((sourcePath) => [sourcePath, 'merge-source']), [targetPath, 'merge-target']]);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function pathRoles(entries) {
|
|
185
|
+
const roles = {};
|
|
186
|
+
for (const [sourcePath, role] of entries) {
|
|
187
|
+
if (!sourcePath) continue;
|
|
188
|
+
roles[sourcePath] = roles[sourcePath] && roles[sourcePath] !== role ? `${roles[sourcePath]}+${role}` : role;
|
|
189
|
+
}
|
|
190
|
+
return roles;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function generatedBoundaryDetails(sourcePaths) {
|
|
194
|
+
const generatedSourcePaths = uniqueStrings(sourcePaths).filter(generatedProjectSourcePath);
|
|
195
|
+
return generatedSourcePaths.length ? { generatedOutputBoundary: true, generatedSourcePaths } : {};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function moduleSplitPartition(baseModule, candidates) {
|
|
199
|
+
return structuralPartition({
|
|
200
|
+
sourceKeys: baseModule.baseShape.moduleItems.map((item) => item.key),
|
|
201
|
+
targetRecords: candidates.map((candidate) => ({
|
|
202
|
+
sourcePath: candidate.file.sourcePath,
|
|
203
|
+
keys: candidate.file.branchShape.moduleItems.map((item) => item.key)
|
|
204
|
+
})),
|
|
205
|
+
duplicateField: 'duplicateMovedDeclarationKeys',
|
|
206
|
+
missingField: 'missingMovedDeclarationKeys',
|
|
207
|
+
extraField: 'extraTargetDeclarationKeys'
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function moduleMergePartition(branchModule, candidates) {
|
|
212
|
+
return structuralPartition({
|
|
213
|
+
sourceKeys: candidates.flatMap((candidate) => candidate.file.baseShape.moduleItems.map((item) => item.key)),
|
|
214
|
+
targetRecords: [{
|
|
215
|
+
sourcePath: branchModule.sourcePath,
|
|
216
|
+
keys: branchModule.branchShape.moduleItems.map((item) => item.key)
|
|
217
|
+
}],
|
|
218
|
+
duplicateField: 'duplicateMovedDeclarationKeys',
|
|
219
|
+
missingField: 'missingMovedDeclarationKeys',
|
|
220
|
+
extraField: 'extraTargetDeclarationKeys'
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function classSplitPartition(baseClass, candidates) {
|
|
225
|
+
return structuralPartition({
|
|
226
|
+
sourceKeys: baseClass.classRecord.members.map((member) => member.key),
|
|
227
|
+
targetRecords: candidates.map((candidate) => ({
|
|
228
|
+
sourcePath: candidate.record.sourcePath,
|
|
229
|
+
className: candidate.record.classRecord.name,
|
|
230
|
+
keys: candidate.record.classRecord.members.map((member) => member.key)
|
|
231
|
+
})),
|
|
232
|
+
duplicateField: 'duplicateMovedMemberKeys',
|
|
233
|
+
missingField: 'missingMovedMemberKeys',
|
|
234
|
+
extraField: 'extraTargetMemberKeys'
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function classMergePartition(branchClass, candidates) {
|
|
239
|
+
return structuralPartition({
|
|
240
|
+
sourceKeys: candidates.flatMap((candidate) => candidate.record.classRecord.members.map((member) => member.key)),
|
|
241
|
+
targetRecords: [{
|
|
242
|
+
sourcePath: branchClass.sourcePath,
|
|
243
|
+
className: branchClass.classRecord.name,
|
|
244
|
+
keys: branchClass.classRecord.members.map((member) => member.key)
|
|
245
|
+
}],
|
|
246
|
+
duplicateField: 'duplicateMovedMemberKeys',
|
|
247
|
+
missingField: 'missingMovedMemberKeys',
|
|
248
|
+
extraField: 'extraTargetMemberKeys'
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function structuralPartition(options) {
|
|
253
|
+
const sourceCounts = countKeys(options.sourceKeys);
|
|
254
|
+
const targetCounts = countKeys(options.targetRecords.flatMap((record) => record.keys));
|
|
255
|
+
const sourceKeys = [...sourceCounts.keys()];
|
|
256
|
+
const targetKeys = [...targetCounts.keys()];
|
|
257
|
+
const missing = sourceKeys.filter((key) => (targetCounts.get(key) ?? 0) < (sourceCounts.get(key) ?? 0));
|
|
258
|
+
const duplicate = sourceKeys.filter((key) => (targetCounts.get(key) ?? 0) > (sourceCounts.get(key) ?? 0));
|
|
259
|
+
const extra = targetKeys.filter((key) => !sourceCounts.has(key));
|
|
260
|
+
const blockers = [
|
|
261
|
+
duplicate.length ? 'duplicate-moved-structural-key' : undefined,
|
|
262
|
+
missing.length ? 'missing-moved-structural-key' : undefined,
|
|
263
|
+
extra.length ? 'extra-target-structural-key' : undefined
|
|
264
|
+
].filter(Boolean);
|
|
265
|
+
const exact = blockers.length === 0;
|
|
266
|
+
return compactRecord({
|
|
267
|
+
exactStructuralPartition: exact,
|
|
268
|
+
structuralPartitionStatus: exact ? 'passed' : 'blocked',
|
|
269
|
+
structuralPartitionProof: exact ? 'one-to-one-source-target-key-count' : undefined,
|
|
270
|
+
structuralPartitionBlockers: blockers.length ? blockers : undefined,
|
|
271
|
+
[options.duplicateField]: duplicate.length ? duplicate : undefined,
|
|
272
|
+
[options.missingField]: missing.length ? missing : undefined,
|
|
273
|
+
[options.extraField]: extra.length ? extra : undefined
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function requiredEvidenceForPartition(requiredEvidence, partition) {
|
|
278
|
+
return partition.exactStructuralPartition === false
|
|
279
|
+
? uniqueStrings([...requiredEvidence, exactStructuralPartitionEvidence])
|
|
280
|
+
: requiredEvidence;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function splitMergeConflictDetails(details = {}, extraDetails = {}) {
|
|
284
|
+
return compactRecord({
|
|
285
|
+
...details,
|
|
286
|
+
...extraDetails,
|
|
287
|
+
requiredEvidence: uniqueStrings([...(details.requiredEvidence ?? []), ...(extraDetails.requiredEvidence ?? [])]),
|
|
288
|
+
missingRequiredEvidence: uniqueStrings([...(details.missingRequiredEvidence ?? []), ...(extraDetails.missingRequiredEvidence ?? [])]),
|
|
289
|
+
presentRequiredEvidence: uniqueStrings([...(details.presentRequiredEvidence ?? []), ...(extraDetails.presentRequiredEvidence ?? [])])
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function classIdentity(record) { return `${record.sourcePath}#${record.classRecord.name}`; }
|
|
294
|
+
|
|
295
|
+
function classificationFingerprint(value) {
|
|
296
|
+
return hashSemanticValue(value).replace(/[^a-zA-Z0-9]+/g, '').slice(0, 16);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function uniqueStrings(values) {
|
|
300
|
+
return [...new Set(values.filter((value) => typeof value === 'string' && value.length > 0))];
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function countKeys(keys) {
|
|
304
|
+
const counts = new Map();
|
|
305
|
+
for (const key of keys) {
|
|
306
|
+
if (!key) continue;
|
|
307
|
+
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
308
|
+
}
|
|
309
|
+
return counts;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export {
|
|
313
|
+
classMergeClassification,
|
|
314
|
+
classSplitClassification,
|
|
315
|
+
classificationSummaryRecord,
|
|
316
|
+
classifiedOperation,
|
|
317
|
+
moduleMergeClassification,
|
|
318
|
+
moduleSplitClassification,
|
|
319
|
+
splitMergeConflictForPath
|
|
320
|
+
};
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { hashSemanticValue } from '@shapeshift-labs/frontier-lang-kernel';
|
|
2
|
+
import { compactRecord } from './js-ts-safe-merge-context.js';
|
|
3
|
+
|
|
4
|
+
function stageFileShape(file, branch) {
|
|
5
|
+
const sourcePath = file.sourcePath;
|
|
6
|
+
const baseSource = file.baseSourceText;
|
|
7
|
+
const branchSource = branchSourceText(file, branch);
|
|
8
|
+
const changed = baseSource !== branchSource;
|
|
9
|
+
return compactRecord({
|
|
10
|
+
sourcePath,
|
|
11
|
+
changed,
|
|
12
|
+
added: typeof baseSource !== 'string' && typeof branchSource === 'string',
|
|
13
|
+
deleted: typeof baseSource === 'string' && typeof branchSource !== 'string',
|
|
14
|
+
baseShape: typeof baseSource === 'string' ? sourceShape(sourcePath, baseSource) : undefined,
|
|
15
|
+
branchShape: typeof branchSource === 'string' ? sourceShape(sourcePath, branchSource) : undefined
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function changedBaseModules(stageFiles) {
|
|
20
|
+
return stageFiles.filter((file) => file.changed && file.baseShape);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function changedBranchModules(stageFiles) {
|
|
24
|
+
return stageFiles.filter((file) => file.changed && file.branchShape);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function changedBaseClasses(stageFiles) {
|
|
28
|
+
return stageFiles
|
|
29
|
+
.filter((file) => file.changed && file.baseShape)
|
|
30
|
+
.flatMap((file) => file.baseShape.classes.map((classRecord) => ({ sourcePath: file.sourcePath, sourceHash: file.baseShape.sourceHash, classRecord })));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function changedBranchClasses(stageFiles) {
|
|
34
|
+
return stageFiles
|
|
35
|
+
.filter((file) => file.changed && file.branchShape)
|
|
36
|
+
.flatMap((file) => file.branchShape.classes.map((classRecord) => ({ sourcePath: file.sourcePath, sourceHash: file.branchShape.sourceHash, classRecord })));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function sourceShape(sourcePath, sourceText) {
|
|
40
|
+
const declarations = scanTopLevelDeclarations(sourceText);
|
|
41
|
+
const classes = scanClasses(sourceText);
|
|
42
|
+
const moduleItems = uniqueByKey(declarations.map((declaration) => compactRecord({
|
|
43
|
+
key: `${declaration.kind}:${declaration.name}`,
|
|
44
|
+
kind: declaration.kind,
|
|
45
|
+
name: declaration.name,
|
|
46
|
+
exported: declaration.exported || undefined
|
|
47
|
+
})), (item) => item.key);
|
|
48
|
+
return {
|
|
49
|
+
sourcePath,
|
|
50
|
+
sourceHash: hashText(sourceText),
|
|
51
|
+
moduleItems,
|
|
52
|
+
moduleFingerprint: hashSemanticValue(moduleItems.map((item) => item.key).sort()),
|
|
53
|
+
classes
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function scanTopLevelDeclarations(sourceText) {
|
|
58
|
+
const declarations = [];
|
|
59
|
+
for (const line of sourceText.split(/\r?\n/)) {
|
|
60
|
+
const trimmed = line.trim();
|
|
61
|
+
if (!trimmed || trimmed.startsWith('//') || trimmed.startsWith('*')) continue;
|
|
62
|
+
const declaration = declarationFromLine(trimmed);
|
|
63
|
+
if (declaration) declarations.push(declaration);
|
|
64
|
+
}
|
|
65
|
+
return declarations;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function declarationFromLine(trimmed) {
|
|
69
|
+
const exported = /^export\b/.test(trimmed);
|
|
70
|
+
const defaultExported = /^export\s+default\b/.test(trimmed);
|
|
71
|
+
const source = trimmed
|
|
72
|
+
.replace(/^export\s+default\s+/, 'default ')
|
|
73
|
+
.replace(/^export\s+/, '')
|
|
74
|
+
.replace(/^declare\s+/, '');
|
|
75
|
+
let match = source.match(/^(?:default\s+)?(?:abstract\s+)?class\b(?:\s+(?!(?:extends|implements)\b)([A-Za-z_$][\w$]*))?/);
|
|
76
|
+
if (match && (match[1] || defaultExported)) return { kind: 'class', name: match[1] ?? 'default', exported: exported || defaultExported };
|
|
77
|
+
match = source.match(/^(?:namespace|module)\s+([A-Za-z_$][\w$.]*)\b/);
|
|
78
|
+
if (match) return { kind: 'module', name: match[1], exported };
|
|
79
|
+
match = source.match(/^(?:async\s+)?function\*?\s+([A-Za-z_$][\w$]*)\b/);
|
|
80
|
+
if (match) return { kind: 'function', name: match[1], exported };
|
|
81
|
+
match = source.match(/^interface\s+([A-Za-z_$][\w$]*)\b/);
|
|
82
|
+
if (match) return { kind: 'interface', name: match[1], exported };
|
|
83
|
+
match = source.match(/^type\s+([A-Za-z_$][\w$]*)\b/);
|
|
84
|
+
if (match) return { kind: 'type', name: match[1], exported };
|
|
85
|
+
match = source.match(/^(?:const\s+)?enum\s+([A-Za-z_$][\w$]*)\b/);
|
|
86
|
+
if (match) return { kind: 'enum', name: match[1], exported };
|
|
87
|
+
match = source.match(/^(?:const|let|var)\s+([A-Za-z_$][\w$]*)\b/);
|
|
88
|
+
if (match) return { kind: 'variable', name: match[1], exported };
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function scanClasses(sourceText) {
|
|
93
|
+
const classes = [];
|
|
94
|
+
const lines = sourceText.split(/\r?\n/);
|
|
95
|
+
let offset = 0;
|
|
96
|
+
for (const line of lines) {
|
|
97
|
+
const match = line.match(/^\s*(?:export\s+)?(?:(default)\s+)?(?:declare\s+)?(?:abstract\s+)?class\b(?:\s+(?!(?:extends|implements)\b)([A-Za-z_$][\w$]*))?/);
|
|
98
|
+
if (match && (match[1] || match[2])) {
|
|
99
|
+
const name = match[2] ?? 'default';
|
|
100
|
+
const classStart = offset + line.indexOf('class');
|
|
101
|
+
const openIndex = sourceText.indexOf('{', classStart);
|
|
102
|
+
const block = openIndex >= 0 ? balancedBlock(sourceText, openIndex) : undefined;
|
|
103
|
+
classes.push(compactRecord({
|
|
104
|
+
name,
|
|
105
|
+
key: `class:${name}`,
|
|
106
|
+
exported: /^\s*export\b/.test(line) || undefined,
|
|
107
|
+
members: parseClassMembers(block?.body ?? '')
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
offset += line.length + 1;
|
|
111
|
+
}
|
|
112
|
+
return classes;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function parseClassMembers(body) {
|
|
116
|
+
const members = [];
|
|
117
|
+
const methodPattern = /(?:^|[;\n\r])\s*(?:(?:public|private|protected|static|async|override|readonly|abstract|accessor|get|set)\s+)*(?:async\s+)?(?:get\s+|set\s+)?(#?[A-Za-z_$][\w$]*)\??\s*(?:<[^({;]+>)?\s*\(([^)]*)\)/g;
|
|
118
|
+
for (const match of body.matchAll(methodPattern)) {
|
|
119
|
+
if (match[1] !== 'constructor') members.push({ kind: 'method', name: match[1], key: `method:${match[1]}` });
|
|
120
|
+
}
|
|
121
|
+
const propertyPattern = /(?:^|[;\n\r])\s*(?:(?:public|private|protected|static|readonly|declare|accessor)\s+)*(#?[A-Za-z_$][\w$]*)[?!]?\s*(?::\s*[^=;{]+)?(?:[=;]|$)/g;
|
|
122
|
+
for (const match of body.matchAll(propertyPattern)) {
|
|
123
|
+
if (match[1] !== 'constructor') members.push({ kind: 'property', name: match[1], key: `property:${match[1]}` });
|
|
124
|
+
}
|
|
125
|
+
return uniqueByKey(members, (member) => member.key);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function balancedBlock(sourceText, openIndex) {
|
|
129
|
+
let depth = 0;
|
|
130
|
+
for (let index = openIndex; index < sourceText.length; index += 1) {
|
|
131
|
+
const char = sourceText[index];
|
|
132
|
+
if (char === '{') depth += 1;
|
|
133
|
+
if (char === '}') {
|
|
134
|
+
depth -= 1;
|
|
135
|
+
if (depth === 0) return { body: sourceText.slice(openIndex + 1, index), end: index + 1 };
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return { body: sourceText.slice(openIndex + 1), end: sourceText.length };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function moduleItemOverlap(left, right) {
|
|
142
|
+
const rightKeys = new Set(right.moduleItems.map((item) => item.key));
|
|
143
|
+
return left.moduleItems.map((item) => item.key).filter((key) => rightKeys.has(key));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function classMemberOverlap(left, right) {
|
|
147
|
+
const rightKeys = new Set(right.members.map((member) => member.key));
|
|
148
|
+
return left.members.map((member) => member.key).filter((key) => rightKeys.has(key));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function samePathCandidateCoversAllModuleItems(baseModule, candidates) {
|
|
152
|
+
const samePath = candidates.find((candidate) => candidate.file.sourcePath === baseModule.sourcePath);
|
|
153
|
+
return samePath ? samePath.overlap.length === baseModule.baseShape.moduleItems.length : false;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function sameIdentityCandidateCoversAllClassMembers(baseClass, branchClasses) {
|
|
157
|
+
const sameIdentity = branchClasses.find((branchClass) => sameClassIdentity(baseClass, branchClass));
|
|
158
|
+
return sameIdentity ? classMemberOverlap(baseClass.classRecord, sameIdentity.classRecord).length === baseClass.classRecord.members.length : false;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function sameClassIdentity(left, right) {
|
|
162
|
+
return left.sourcePath === right.sourcePath && left.classRecord.name === right.classRecord.name;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function generatedProjectSourcePath(sourcePath) {
|
|
166
|
+
const normalized = String(sourcePath ?? '').replace(/\\/g, '/');
|
|
167
|
+
const basename = normalized.split('/').pop() ?? '';
|
|
168
|
+
return /(?:^|\/)(?:dist|build|coverage|generated|__generated__)(?:\/|$)/.test(normalized)
|
|
169
|
+
|| /\.(?:generated|gen)\.[cm]?[jt]sx?$/.test(basename);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function moduleEvidence(shape) {
|
|
173
|
+
if (!shape) return undefined;
|
|
174
|
+
return compactRecord({
|
|
175
|
+
sourcePath: shape.sourcePath,
|
|
176
|
+
sourceHash: shape.sourceHash,
|
|
177
|
+
declarationKeys: shape.moduleItems.map((item) => item.key),
|
|
178
|
+
exportedDeclarationKeys: shape.moduleItems.filter((item) => item.exported).map((item) => item.key),
|
|
179
|
+
classKeys: shape.classes.map((classRecord) => classRecord.key)
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function classEvidence(record) {
|
|
184
|
+
if (!record) return undefined;
|
|
185
|
+
return compactRecord({
|
|
186
|
+
sourcePath: record.sourcePath,
|
|
187
|
+
sourceHash: record.sourceHash,
|
|
188
|
+
className: record.classRecord.name,
|
|
189
|
+
classKey: record.classRecord.key,
|
|
190
|
+
exported: record.classRecord.exported,
|
|
191
|
+
memberKeys: record.classRecord.members.map((member) => member.key)
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function branchSourceText(file, branch) {
|
|
196
|
+
if (branch === 'worker') {
|
|
197
|
+
if (file.workerDeleted) return undefined;
|
|
198
|
+
return typeof file.workerSourceText === 'string' ? file.workerSourceText : file.baseSourceText;
|
|
199
|
+
}
|
|
200
|
+
if (file.headDeleted) return undefined;
|
|
201
|
+
return typeof file.headSourceText === 'string' ? file.headSourceText : file.baseSourceText;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function hashText(text) {
|
|
205
|
+
return typeof text === 'string' ? hashSemanticValue(text) : undefined;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function uniqueByKey(records, keyForRecord) {
|
|
209
|
+
const results = [];
|
|
210
|
+
const seen = new Set();
|
|
211
|
+
for (const record of records) {
|
|
212
|
+
const key = keyForRecord(record);
|
|
213
|
+
if (!key || seen.has(key)) continue;
|
|
214
|
+
seen.add(key);
|
|
215
|
+
results.push(record);
|
|
216
|
+
}
|
|
217
|
+
return results;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export {
|
|
221
|
+
changedBaseClasses,
|
|
222
|
+
changedBaseModules,
|
|
223
|
+
changedBranchClasses,
|
|
224
|
+
changedBranchModules,
|
|
225
|
+
classEvidence,
|
|
226
|
+
classMemberOverlap,
|
|
227
|
+
generatedProjectSourcePath,
|
|
228
|
+
moduleEvidence,
|
|
229
|
+
moduleItemOverlap,
|
|
230
|
+
sameClassIdentity,
|
|
231
|
+
sameIdentityCandidateCoversAllClassMembers,
|
|
232
|
+
samePathCandidateCoversAllModuleItems,
|
|
233
|
+
stageFileShape
|
|
234
|
+
};
|