@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.
- 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-patch-bundle-composition.d.ts +62 -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 +32 -0
- package/dist/index.js +6 -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/semanticPatchBundleComposition.js +166 -0
- 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-context.js +1 -0
- package/dist/js-ts-safe-merge-jsx-attribute-fallback.js +314 -0
- 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-plan.js +3 -1
- package/dist/js-ts-safe-merge-semantic-edit-fallback.js +49 -0
- package/dist/js-ts-safe-merge-source-shape-fallbacks.js +5 -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 +171 -172
- 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,134 @@
|
|
|
1
|
+
import { uniqueStrings } from '../../native-import-utils.js';
|
|
2
|
+
import { nativeImportSourceText } from './nativeImportSourceText.js';
|
|
3
|
+
import { sourceTextForSpan } from './sourceTextForSpan.js';
|
|
4
|
+
|
|
5
|
+
export function typeSyntaxEditClassification(input) {
|
|
6
|
+
const reasonCodes = typeSyntaxEditReasonCodes(input);
|
|
7
|
+
if (!reasonCodes.length) return undefined;
|
|
8
|
+
const evidenceIds = typeSyntaxEvidenceIds(input);
|
|
9
|
+
if (evidenceIds.length) {
|
|
10
|
+
return {
|
|
11
|
+
status: 'portable',
|
|
12
|
+
reasonCodes: uniqueStrings([...reasonCodes, 'type-syntax-edit-backed-by-typechecker-or-declaration-evidence']),
|
|
13
|
+
evidenceIds
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
status: 'blocked',
|
|
18
|
+
reasonCodes: uniqueStrings([...reasonCodes, 'type-syntax-edit-requires-typechecker-or-declaration-evidence']),
|
|
19
|
+
evidenceIds: []
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function typeSyntaxEditReasonCodes(input) {
|
|
24
|
+
if (!isJsTsLanguage(input) || input.region?.regionKind === 'import') return [];
|
|
25
|
+
if (!['modified', 'removed', 'added'].includes(input.region?.changeKind)) return [];
|
|
26
|
+
const baseText = typeSyntaxSourceText(input.context.base, input.baseSymbol, input.region, 'before');
|
|
27
|
+
const workerText = typeSyntaxSourceText(input.context.worker, input.workerSymbol, input.region, 'after');
|
|
28
|
+
if (typeof baseText !== 'string' || typeof workerText !== 'string' || baseText === workerText) return [];
|
|
29
|
+
const allowAngleAssertion = !isJsxLikeLanguage(input);
|
|
30
|
+
const base = typeSyntaxSignals(baseText, allowAngleAssertion);
|
|
31
|
+
const worker = typeSyntaxSignals(workerText, allowAngleAssertion);
|
|
32
|
+
const reasons = [];
|
|
33
|
+
if (base.satisfies || worker.satisfies) reasons.push('satisfies-expression-edit-requires-typechecker-evidence');
|
|
34
|
+
if (base.asConst || worker.asConst) reasons.push('as-const-assertion-edit-requires-declaration-evidence');
|
|
35
|
+
if (base.typeAssertion || worker.typeAssertion) reasons.push('type-assertion-edit-requires-typechecker-evidence');
|
|
36
|
+
if (base.constTypeParameters !== worker.constTypeParameters) reasons.push('const-type-parameter-edit-requires-declaration-evidence');
|
|
37
|
+
if (base.constraints !== worker.constraints) reasons.push('generic-constraint-edit-requires-typechecker-evidence');
|
|
38
|
+
if (base.generics !== worker.generics) reasons.push('generic-type-parameter-edit-requires-typechecker-evidence');
|
|
39
|
+
if (base.conditionalTypes !== worker.conditionalTypes) reasons.push('conditional-type-edit-requires-declaration-evidence');
|
|
40
|
+
return uniqueStrings(reasons);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function typeSyntaxSignals(text, allowAngleAssertion) {
|
|
44
|
+
const normalized = String(text ?? '').replace(/\s+/g, ' ').trim();
|
|
45
|
+
const genericClauses = typeParameterClauses(normalized);
|
|
46
|
+
return {
|
|
47
|
+
satisfies: /\bsatisfies\b/.test(normalized),
|
|
48
|
+
asConst: /\bas\s+const\b/.test(normalized),
|
|
49
|
+
typeAssertion: hasTypeAssertionSyntax(normalized, allowAngleAssertion),
|
|
50
|
+
generics: genericClauses.join('|'),
|
|
51
|
+
constraints: genericClauses.filter((clause) => /\bextends\b/.test(clause)).join('|'),
|
|
52
|
+
constTypeParameters: genericClauses.filter((clause) => /<[^>]*\bconst\s+[A-Za-z_$]/.test(clause)).join('|'),
|
|
53
|
+
conditionalTypes: conditionalTypeClauses(normalized).join('|')
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function typeSyntaxSourceText(imported, symbol, region, projectionSide) {
|
|
58
|
+
const sourceText = nativeImportSourceText(imported);
|
|
59
|
+
const projection = region?.metadata?.changedRegionProjection;
|
|
60
|
+
const span = symbol?.sourceSpan ?? projection?.[projectionSide]?.sourceSpan ?? region?.sourceSpan;
|
|
61
|
+
const exact = sourceTextForSpan(sourceText, span);
|
|
62
|
+
const lineText = sourceLineTextForSpan(sourceText, span);
|
|
63
|
+
return typeof lineText === 'string' && hasTypeSyntaxCue(lineText) ? lineText : exact;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function hasTypeSyntaxCue(text) {
|
|
67
|
+
return /\b(?:satisfies|extends|infer|as\s+const|as\s+(?:unknown|any|never|string|number|boolean|symbol|bigint))\b|<\s*const\s+[A-Za-z_$]|\btype\s+[A-Za-z_$][\w$]*(?:\s*<[^>\n]+>)?\s*=/.test(String(text ?? ''));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function sourceLineTextForSpan(sourceText, span) {
|
|
71
|
+
if (typeof sourceText !== 'string' || typeof span?.startLine !== 'number') return undefined;
|
|
72
|
+
const lines = sourceText.split('\n');
|
|
73
|
+
const startLine = Math.max(1, span.startLine);
|
|
74
|
+
const endLine = Math.max(startLine, typeof span.endLine === 'number' ? span.endLine : startLine);
|
|
75
|
+
return lines.slice(startLine - 1, endLine).join('\n');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function typeParameterClauses(text) {
|
|
79
|
+
const clauses = [];
|
|
80
|
+
const pattern = /\b(?:export\s+)?(?:declare\s+)?(?:async\s+)?(?:function|class|interface|type)\s+[A-Za-z_$][\w$]*\s*(<[^>\n]+>)/g;
|
|
81
|
+
for (const match of text.matchAll(pattern)) clauses.push(match[1].replace(/\s+/g, ' '));
|
|
82
|
+
return clauses;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function conditionalTypeClauses(text) {
|
|
86
|
+
const clauses = [];
|
|
87
|
+
const pattern = /\btype\s+[A-Za-z_$][\w$]*(?:\s*<[^>\n]+>)?\s*=\s*([^;\n]*\bextends\b[^;\n]*\?[^;\n]*:[^;\n]*)/g;
|
|
88
|
+
for (const match of text.matchAll(pattern)) clauses.push(match[1].replace(/\s+/g, ' '));
|
|
89
|
+
return clauses;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function hasTypeAssertionSyntax(text, allowAngleAssertion) {
|
|
93
|
+
if (/\bas\s+const\b/.test(text)) return true;
|
|
94
|
+
const asAssertion = /\bas\s+(?:unknown|any|never|string|number|boolean|symbol|bigint|readonly|[A-Z_$][\w$]*|\{|\[)/;
|
|
95
|
+
const angleAssertion = /(?:\b(?:return|throw)\b|[=([,])\s*<\s*[A-Za-z_$][^>\n]*>\s*(?:[A-Za-z_$"'[(])/;
|
|
96
|
+
return asAssertion.test(text) || (allowAngleAssertion && angleAssertion.test(text));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function typeSyntaxEvidenceIds(input) {
|
|
100
|
+
return uniqueStrings(typeSyntaxEvidenceRecords(input)
|
|
101
|
+
.filter(typeSyntaxEvidencePassed).map((record) => String(record.id ?? record.evidenceId ?? record.hash ?? record.kind)));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function typeSyntaxEvidenceRecords(input) {
|
|
105
|
+
return [
|
|
106
|
+
input.scriptInput?.typeSyntaxEvidence,
|
|
107
|
+
input.scriptInput?.typeCheckerEvidence,
|
|
108
|
+
input.scriptInput?.typescriptEvidence,
|
|
109
|
+
input.scriptInput?.diagnosticsEvidence,
|
|
110
|
+
input.scriptInput?.declarationEvidence,
|
|
111
|
+
input.scriptInput?.evidence,
|
|
112
|
+
input.context?.typeSyntaxEvidence
|
|
113
|
+
].flatMap((entry) => Array.isArray(entry) ? entry : [entry]).filter((entry) => entry && typeof entry === 'object');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function typeSyntaxEvidencePassed(record) {
|
|
117
|
+
const status = String(record.status ?? record.result ?? '').toLowerCase();
|
|
118
|
+
if (status && !['passed', 'pass', 'ok', 'clean', 'accepted-clean'].includes(status)) return false;
|
|
119
|
+
const text = [
|
|
120
|
+
record.kind, record.type, record.source, record.gateId, record.summary, record.metadata?.kind,
|
|
121
|
+
record.metadata?.source, record.metadata?.diagnosticSource, record.metadata?.declarationSource
|
|
122
|
+
].filter(Boolean).join(' ').toLowerCase();
|
|
123
|
+
return /\b(typechecker|type-checker|typescript|diagnostic|diagnostics|declaration|declarations|d\.ts|type-syntax)\b/.test(text);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function isJsTsLanguage(input) {
|
|
127
|
+
const language = String(input.region?.language ?? input.context?.workerChangeSet?.language ?? input.context?.base?.language ?? '').toLowerCase();
|
|
128
|
+
return ['javascript', 'typescript', 'jsx', 'tsx'].includes(language);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function isJsxLikeLanguage(input) {
|
|
132
|
+
const language = String(input.region?.language ?? input.context?.workerChangeSet?.language ?? input.context?.base?.language ?? '').toLowerCase();
|
|
133
|
+
return ['jsx', 'tsx'].includes(language);
|
|
134
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import{idFragment,caseSensitiveIdFragment}from'../../native-import-utils.js';import{semanticOwnershipRegionForDeclaration}from'../../semantic-import-regions.js';import{createSemanticIndexRecord,hashSemanticValue}from'@shapeshift-labs/frontier-lang-kernel';
|
|
2
|
+
import{dynamicImportExpressionEdgeFields}from'./dynamicImportExpressionMetadata.js';import{hostDependencyEdgeFields}from'./importMetaUrlDependencyMetadata.js';import{moduleImportAttributeEdgeFields}from'./moduleImportAttributeMetadata.js';
|
|
2
3
|
import{relationPredicateForDeclaration}from'./relationPredicateForDeclaration.js';
|
|
3
4
|
export function semanticIndexFromNativeDeclarations(declarations, input, options) {
|
|
4
5
|
const documentId = `doc_${idFragment(input.sourcePath ?? input.language)}_${idFragment(input.sourceHash)}`;
|
|
@@ -94,7 +95,7 @@ export function semanticIndexFromNativeDeclarations(declarations, input, options
|
|
|
94
95
|
granularity: ownershipRegion.granularity,
|
|
95
96
|
key: ownershipRegion.key
|
|
96
97
|
}
|
|
97
|
-
}, ...projectSymbolGraphFacts({ moduleEdge, publicContractRegion, reExportIdentity, relationId, symbolId, evidenceId }));
|
|
98
|
+
}, ...projectSymbolGraphFacts({ moduleEdge, publicContractRegion, reExportIdentity, relationId, symbolId, evidenceId, compilerSymbol: declaration.metadata?.compilerSymbol, compilerSymbolIdentityHash: declaration.metadata?.compilerSymbolIdentityHash, compilerType: declaration.metadata?.compilerType, compilerTypeIdentityHash: declaration.metadata?.compilerTypeIdentityHash }));
|
|
98
99
|
mappings.push({
|
|
99
100
|
id: `map_${idFragment(declaration.nativeNode.id)}_${idFragment(symbolId)}`,
|
|
100
101
|
nativeAstNodeId: declaration.nativeNode.id,
|
|
@@ -124,7 +125,8 @@ export function semanticIndexFromNativeDeclarations(declarations, input, options
|
|
|
124
125
|
fileHashes: input.sourceHash ? 1 : 0,
|
|
125
126
|
moduleEdges: facts.filter((fact) => fact.predicate === 'moduleEdge').length,
|
|
126
127
|
reExportIdentities: facts.filter((fact) => fact.predicate === 'reExportIdentity').length,
|
|
127
|
-
publicContractRegions: facts.filter((fact) => fact.predicate === 'publicContractRegion').length
|
|
128
|
+
publicContractRegions: facts.filter((fact) => fact.predicate === 'publicContractRegion').length,
|
|
129
|
+
compilerSymbols: facts.filter((fact) => fact.predicate === 'compilerSymbol').length, compilerTypes: facts.filter((fact) => fact.predicate === 'compilerType').length
|
|
128
130
|
}
|
|
129
131
|
}
|
|
130
132
|
}];
|
|
@@ -199,6 +201,8 @@ function moduleEdgeForDeclaration(declaration, input, documentId, relationId, ow
|
|
|
199
201
|
namespace: declaration.namespace ?? declaration.metadata?.namespace,
|
|
200
202
|
isTypeOnly: declaration.isTypeOnly ?? declaration.metadata?.isTypeOnly ?? declaration.metadata?.typeOnly,
|
|
201
203
|
exportStar: declaration.exportStar ?? declaration.metadata?.exportStar,
|
|
204
|
+
...dynamicImportExpressionEdgeFields(declaration.metadata), ...hostDependencyEdgeFields(declaration.metadata),
|
|
205
|
+
...moduleImportAttributeEdgeFields(declaration.metadata),
|
|
202
206
|
isReExport: edgeKind === 're-export',
|
|
203
207
|
publicContract: publicContractForDeclaration(declaration, edgeKind)
|
|
204
208
|
});
|
|
@@ -256,16 +260,18 @@ function reExportIdentityForDeclaration(declaration, input, documentId, relation
|
|
|
256
260
|
localName: declaration.localName ?? declaration.metadata?.localName, namespace: declaration.namespace ?? declaration.metadata?.namespace,
|
|
257
261
|
isTypeOnly: declaration.isTypeOnly ?? declaration.metadata?.isTypeOnly ?? declaration.metadata?.typeOnly, exportStar: declaration.exportStar ?? declaration.metadata?.exportStar,
|
|
258
262
|
symbolId: declaration.symbolId, relationId, ownershipRegionId: ownershipRegion.id, ownershipRegionKey: ownershipRegion.key,
|
|
259
|
-
publicContract: true
|
|
263
|
+
publicContract: true, hasImportAttributes: moduleEdge?.hasImportAttributes, importAttributeCount: moduleEdge?.importAttributeCount, importAttributeKeys: moduleEdge?.importAttributeKeys, importAttributeHash: moduleEdge?.importAttributeHash, importAttributes: moduleEdge?.importAttributes
|
|
260
264
|
});
|
|
261
265
|
}
|
|
262
266
|
|
|
263
|
-
function projectSymbolGraphFacts({ moduleEdge, publicContractRegion, reExportIdentity, relationId, symbolId, evidenceId }) {
|
|
267
|
+
function projectSymbolGraphFacts({ moduleEdge, publicContractRegion, reExportIdentity, relationId, symbolId, evidenceId, compilerSymbol, compilerSymbolIdentityHash, compilerType, compilerTypeIdentityHash }) {
|
|
264
268
|
return [
|
|
269
|
+
compilerSymbol ? { id: graphFactId(relationId, symbolId, 'compiler_symbol'), predicate: 'compilerSymbol', subjectId: symbolId, value: { ...compilerSymbol, identityHash: compilerSymbolIdentityHash }, evidenceIds: [evidenceId] } : undefined,
|
|
270
|
+
compilerType ? { id: graphFactId(relationId, symbolId, 'compiler_type'), predicate: 'compilerType', subjectId: symbolId, value: { ...compilerType, identityHash: compilerTypeIdentityHash }, evidenceIds: [evidenceId] } : undefined,
|
|
265
271
|
moduleEdge ? {
|
|
266
272
|
id: graphFactId(relationId, symbolId, 'module_edge'),
|
|
267
273
|
predicate: 'moduleEdge',
|
|
268
|
-
subjectId:
|
|
274
|
+
subjectId: symbolId,
|
|
269
275
|
objectId: symbolId,
|
|
270
276
|
value: moduleEdge,
|
|
271
277
|
evidenceIds: [evidenceId]
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { hashSemanticValue } from '@shapeshift-labs/frontier-lang-kernel';
|
|
2
|
+
import { idFragment, uniqueStrings } from '../../native-import-utils.js';
|
|
3
|
+
import { compareSemanticPatchBundleRecords } from './semanticPatchBundleOverlaps.js';
|
|
4
|
+
import { replaySemanticEditProjection } from './replaySemanticEditProjection.js';
|
|
5
|
+
|
|
6
|
+
function composeSemanticPatchBundleProjections(input = {}) {
|
|
7
|
+
const id = String(input.id ?? 'semantic_patch_bundle_composition');
|
|
8
|
+
const currentSourceText = input.currentSourceText ?? input.headSourceText;
|
|
9
|
+
const projections = array(input.projections ?? input.semanticEditProjections);
|
|
10
|
+
const bundles = array(input.bundles ?? input.semanticPatchBundles);
|
|
11
|
+
const sourcePath = input.sourcePath ?? projections.find((projection) => projection?.sourcePath)?.sourcePath;
|
|
12
|
+
const language = input.language ?? projections.find((projection) => projection?.language)?.language;
|
|
13
|
+
const reasonCodes = baseReasonCodes({ currentSourceText, projections, bundles });
|
|
14
|
+
const overlapRecords = bundleOverlapRecords(bundles, input.overlapOptions);
|
|
15
|
+
reasonCodes.push(...overlapRecords.flatMap((record) => record.admission.status === 'independent'
|
|
16
|
+
? []
|
|
17
|
+
: [`bundle-overlap:${record.admission.status}`]));
|
|
18
|
+
const replays = reasonCodes.length ? [] : projections.map((projection, index) => replaySemanticEditProjection({
|
|
19
|
+
id: `${id}_replay_${index + 1}`,
|
|
20
|
+
projection,
|
|
21
|
+
currentSourceText,
|
|
22
|
+
currentSourcePath: sourcePath ?? projection.sourcePath,
|
|
23
|
+
language: language ?? projection.language,
|
|
24
|
+
parser: input.parser
|
|
25
|
+
}));
|
|
26
|
+
reasonCodes.push(...replayReasonCodes(replays));
|
|
27
|
+
const edits = reasonCodes.length ? [] : appliedReplayEdits(replays);
|
|
28
|
+
reasonCodes.push(...sourceEditOverlapReasons(edits));
|
|
29
|
+
const outputSourceText = reasonCodes.length ? undefined : applyReplayEdits(currentSourceText, edits);
|
|
30
|
+
const verificationReplays = outputSourceText === undefined ? [] : projections.map((projection, index) => replaySemanticEditProjection({
|
|
31
|
+
id: `${id}_already_applied_${index + 1}`,
|
|
32
|
+
projection,
|
|
33
|
+
currentSourceText: outputSourceText,
|
|
34
|
+
currentSourcePath: sourcePath ?? projection.sourcePath,
|
|
35
|
+
language: language ?? projection.language,
|
|
36
|
+
parser: input.parser
|
|
37
|
+
}));
|
|
38
|
+
reasonCodes.push(...verificationReasonCodes(verificationReplays));
|
|
39
|
+
const status = reasonCodes.length ? 'blocked' : 'verified';
|
|
40
|
+
const core = {
|
|
41
|
+
kind: 'frontier.lang.semanticPatchBundleComposition',
|
|
42
|
+
version: 1,
|
|
43
|
+
schema: 'frontier.lang.semanticPatchBundleComposition.v1',
|
|
44
|
+
id,
|
|
45
|
+
status,
|
|
46
|
+
sourcePath,
|
|
47
|
+
language,
|
|
48
|
+
bundleIds: bundles.map((bundle) => bundle?.id).filter(Boolean),
|
|
49
|
+
projectionIds: projections.map((projection) => projection?.id).filter(Boolean),
|
|
50
|
+
currentHash: typeof currentSourceText === 'string' ? hashSemanticValue(currentSourceText) : undefined,
|
|
51
|
+
outputHash: outputSourceText === undefined ? undefined : hashSemanticValue(outputSourceText),
|
|
52
|
+
outputSourceText,
|
|
53
|
+
replays,
|
|
54
|
+
verificationReplays,
|
|
55
|
+
overlapRecords,
|
|
56
|
+
admission: {
|
|
57
|
+
status: status === 'verified' ? 'auto-merge-candidate' : 'blocked',
|
|
58
|
+
action: status === 'verified' ? 'apply' : 'human-review',
|
|
59
|
+
reviewRequired: status !== 'verified',
|
|
60
|
+
autoApplyCandidate: status === 'verified',
|
|
61
|
+
autoMergeClaim: false,
|
|
62
|
+
semanticEquivalenceClaim: false,
|
|
63
|
+
reasonCodes: uniqueStrings(reasonCodes)
|
|
64
|
+
},
|
|
65
|
+
summary: {
|
|
66
|
+
bundles: bundles.length,
|
|
67
|
+
projections: projections.length,
|
|
68
|
+
replays: replays.length,
|
|
69
|
+
verificationReplays: verificationReplays.length,
|
|
70
|
+
appliedEdits: edits.length,
|
|
71
|
+
overlapRecords: overlapRecords.length,
|
|
72
|
+
blockedOverlaps: overlapRecords.filter((record) => record.admission.status !== 'independent').length
|
|
73
|
+
},
|
|
74
|
+
evidence: [{
|
|
75
|
+
id: `evidence_${idFragment(id)}_semantic_patch_bundle_composition`,
|
|
76
|
+
kind: 'semantic-patch-bundle-composition',
|
|
77
|
+
status: status === 'verified' ? 'passed' : 'needs-review',
|
|
78
|
+
path: sourcePath,
|
|
79
|
+
summary: status === 'verified'
|
|
80
|
+
? `Composed ${edits.length} replayed semantic edit(s) from ${projections.length} projection(s).`
|
|
81
|
+
: `Semantic patch bundle composition blocked: ${uniqueStrings(reasonCodes).join(', ')}.`,
|
|
82
|
+
metadata: {
|
|
83
|
+
bundleIds: bundles.map((bundle) => bundle?.id).filter(Boolean),
|
|
84
|
+
projectionIds: projections.map((projection) => projection?.id).filter(Boolean),
|
|
85
|
+
autoMergeClaim: false,
|
|
86
|
+
semanticEquivalenceClaim: false
|
|
87
|
+
}
|
|
88
|
+
}]
|
|
89
|
+
};
|
|
90
|
+
return { ...core, hash: hashSemanticValue(core) };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function baseReasonCodes(input) {
|
|
94
|
+
return uniqueStrings([
|
|
95
|
+
typeof input.currentSourceText === 'string' ? undefined : 'missing-current-source-text',
|
|
96
|
+
input.projections.length ? undefined : 'missing-semantic-edit-projections',
|
|
97
|
+
input.bundles.length && input.bundles.length !== input.projections.length ? 'bundle-projection-count-mismatch' : undefined,
|
|
98
|
+
...input.projections.map((projection, index) => projection?.status === 'projected' ? undefined : `projection-not-projected:${index + 1}`)
|
|
99
|
+
].filter(Boolean));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function bundleOverlapRecords(bundles, options = {}) {
|
|
103
|
+
const records = [];
|
|
104
|
+
for (let left = 0; left < bundles.length; left += 1) {
|
|
105
|
+
for (let right = left + 1; right < bundles.length; right += 1) {
|
|
106
|
+
records.push(compareSemanticPatchBundleRecords(bundles[left], bundles[right], options));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return records;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function replayReasonCodes(replays) {
|
|
113
|
+
return uniqueStrings(replays.flatMap((replay, index) => {
|
|
114
|
+
if (replay.status === 'accepted-clean' || replay.status === 'already-applied') return [];
|
|
115
|
+
return [`replay-not-clean:${index + 1}:${replay.status}`, ...(replay.admission?.reasonCodes ?? replay.summary?.reasonCodes ?? [])];
|
|
116
|
+
}));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function appliedReplayEdits(replays) {
|
|
120
|
+
return replays.flatMap((replay, replayIndex) => (replay.edits ?? [])
|
|
121
|
+
.filter((edit) => edit.status === 'applied')
|
|
122
|
+
.map((edit, editIndex) => ({
|
|
123
|
+
replayIndex,
|
|
124
|
+
editIndex,
|
|
125
|
+
operationId: edit.operationId,
|
|
126
|
+
start: edit.start,
|
|
127
|
+
end: edit.end,
|
|
128
|
+
replacementText: edit.replacementText
|
|
129
|
+
})));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function sourceEditOverlapReasons(edits) {
|
|
133
|
+
const reasons = [];
|
|
134
|
+
const ordered = edits.slice().sort((left, right) => left.start - right.start || left.end - right.end);
|
|
135
|
+
for (let index = 1; index < ordered.length; index += 1) {
|
|
136
|
+
const previous = ordered[index - 1];
|
|
137
|
+
const current = ordered[index];
|
|
138
|
+
if (sourceEditsOverlap(previous, current)) reasons.push(`composed-source-edit-overlap:${previous.operationId}:${current.operationId}`);
|
|
139
|
+
}
|
|
140
|
+
return uniqueStrings(reasons);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function applyReplayEdits(sourceText, edits) {
|
|
144
|
+
return edits.slice().sort((left, right) => right.start - left.start || right.end - left.end)
|
|
145
|
+
.reduce((text, edit) => text.slice(0, edit.start) + edit.replacementText + text.slice(edit.end), sourceText);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function verificationReasonCodes(replays) {
|
|
149
|
+
return uniqueStrings(replays.flatMap((replay, index) => {
|
|
150
|
+
if (replay.status === 'already-applied') return [];
|
|
151
|
+
return [`verification-replay-not-already-applied:${index + 1}:${replay.status}`, ...(replay.admission?.reasonCodes ?? [])];
|
|
152
|
+
}));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function sourceEditsOverlap(left, right) {
|
|
156
|
+
if (left.start === left.end) return right.start < left.start && left.start < right.end;
|
|
157
|
+
if (right.start === right.end) return left.start < right.start && right.start < left.end;
|
|
158
|
+
return left.start < right.end && right.start < left.end;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function array(value) {
|
|
162
|
+
if (value === undefined || value === null) return [];
|
|
163
|
+
return Array.isArray(value) ? value : [value];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export { composeSemanticPatchBundleProjections };
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { hashSemanticValue } from '@shapeshift-labs/frontier-lang-kernel';
|
|
2
|
+
import { idFragment, uniqueStrings } from '../../native-import-utils.js';
|
|
3
|
+
|
|
4
|
+
function semanticStructuralEdit(input) {
|
|
5
|
+
const actions = structuralEditActions(input);
|
|
6
|
+
const structuralKind = structuralEditKind(actions);
|
|
7
|
+
const record = compactRecord({
|
|
8
|
+
id: `semantic_structural_edit_${idFragment(input.operationId)}`,
|
|
9
|
+
kind: 'frontier.lang.semanticStructuralEdit',
|
|
10
|
+
version: 1,
|
|
11
|
+
algorithm: 'frontier.semantic-edit-structural-diff.v1',
|
|
12
|
+
runtimeNeutral: true,
|
|
13
|
+
operationId: input.operationId,
|
|
14
|
+
structuralKind,
|
|
15
|
+
actions,
|
|
16
|
+
operationKind: input.kind,
|
|
17
|
+
changeKind: input.changeKind,
|
|
18
|
+
anchorKey: input.anchor?.key,
|
|
19
|
+
conflictKey: input.anchor?.conflictKey,
|
|
20
|
+
regionKind: input.anchor?.regionKind,
|
|
21
|
+
sourcePath: input.anchor?.sourcePath,
|
|
22
|
+
symbolName: input.anchor?.symbolName,
|
|
23
|
+
symbolKind: input.anchor?.symbolKind,
|
|
24
|
+
from: structuralSpanLocation(input.spans?.base),
|
|
25
|
+
to: structuralSpanLocation(input.spans?.worker),
|
|
26
|
+
head: structuralSpanLocation(input.spans?.head),
|
|
27
|
+
baseTextHash: input.hashes?.baseTextHash,
|
|
28
|
+
workerTextHash: input.hashes?.workerTextHash,
|
|
29
|
+
headTextHash: input.hashes?.headTextHash,
|
|
30
|
+
beforeSignatureHash: input.hashes?.beforeSignatureHash,
|
|
31
|
+
afterSignatureHash: input.hashes?.afterSignatureHash,
|
|
32
|
+
status: input.status,
|
|
33
|
+
reviewRequired: true,
|
|
34
|
+
confidence: input.confidence,
|
|
35
|
+
reasonCodes: uniqueStrings([
|
|
36
|
+
...(input.reasonCodes ?? []),
|
|
37
|
+
'structural-diff-review-required',
|
|
38
|
+
'replay-required-for-safety'
|
|
39
|
+
]),
|
|
40
|
+
reanchor: input.reanchor,
|
|
41
|
+
metadata: {
|
|
42
|
+
autoMergeClaim: false,
|
|
43
|
+
semanticEquivalenceClaim: false
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
return { ...record, hash: hashSemanticValue(record) };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function semanticStructuralDiff(input) {
|
|
50
|
+
const edits = (input.operations ?? []).map((operation) => operation.structuralEdit).filter(Boolean);
|
|
51
|
+
const summary = summarizeStructuralEdits(edits);
|
|
52
|
+
const core = {
|
|
53
|
+
kind: 'frontier.lang.semanticStructuralDiff',
|
|
54
|
+
version: 1,
|
|
55
|
+
schema: 'frontier.lang.semanticStructuralDiff.v1',
|
|
56
|
+
id: input.input.structuralDiffId ?? `semantic_structural_diff_${idFragment(input.input.id ?? input.sourcePath ?? 'semantic_edit')}`,
|
|
57
|
+
algorithm: 'frontier.semantic-edit-structural-diff.v1',
|
|
58
|
+
runtimeNeutral: true,
|
|
59
|
+
language: input.language,
|
|
60
|
+
sourcePath: input.sourcePath,
|
|
61
|
+
workerChangeSetId: input.workerChangeSet.id,
|
|
62
|
+
headChangeSetId: input.headChangeSet?.id,
|
|
63
|
+
edits,
|
|
64
|
+
summary,
|
|
65
|
+
admission: {
|
|
66
|
+
status: 'review-required',
|
|
67
|
+
action: 'run-replay-and-diagnostics',
|
|
68
|
+
reviewRequired: true,
|
|
69
|
+
autoMergeClaim: false,
|
|
70
|
+
semanticEquivalenceClaim: false,
|
|
71
|
+
reasonCodes: ['structural-diff-review-required', 'replay-required-for-safety']
|
|
72
|
+
},
|
|
73
|
+
metadata: {
|
|
74
|
+
autoMergeClaim: false,
|
|
75
|
+
semanticEquivalenceClaim: false,
|
|
76
|
+
note: 'Structural edit records classify AST/CST-neutral anchor movement and content changes; source replay diagnostics still decide safety.'
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
return { ...core, hash: hashSemanticValue(core) };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function structuralEditActions(input) {
|
|
83
|
+
if (input.changeKind === 'added') return ['insert'];
|
|
84
|
+
if (input.changeKind === 'removed') return ['delete'];
|
|
85
|
+
const actions = [];
|
|
86
|
+
if (structuralSpanMoved(input.spans?.base, input.spans?.worker) || input.reanchor?.toAnchorKey) actions.push('move');
|
|
87
|
+
if (structuralContentChanged(input.hashes)) actions.push('update');
|
|
88
|
+
return actions.length ? actions : ['update'];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function structuralEditKind(actions) {
|
|
92
|
+
if (actions.includes('move') && actions.includes('update')) return 'move-update';
|
|
93
|
+
return actions[0] ?? 'update';
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function structuralContentChanged(hashes) {
|
|
97
|
+
return Boolean(
|
|
98
|
+
hashes?.baseTextHash && hashes?.workerTextHash && hashes.baseTextHash !== hashes.workerTextHash
|
|
99
|
+
|| hashes?.beforeSignatureHash && hashes?.afterSignatureHash && hashes.beforeSignatureHash !== hashes.afterSignatureHash
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function structuralSpanMoved(left, right) {
|
|
104
|
+
if (!left || !right) return false;
|
|
105
|
+
return (left.path && right.path && left.path !== right.path)
|
|
106
|
+
|| left.startLine !== right.startLine
|
|
107
|
+
|| left.startColumn !== right.startColumn
|
|
108
|
+
|| left.endLine !== right.endLine
|
|
109
|
+
|| left.endColumn !== right.endColumn;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function structuralSpanLocation(span) {
|
|
113
|
+
return span ? compactRecord({
|
|
114
|
+
path: span.path,
|
|
115
|
+
startLine: span.startLine,
|
|
116
|
+
startColumn: span.startColumn,
|
|
117
|
+
endLine: span.endLine,
|
|
118
|
+
endColumn: span.endColumn
|
|
119
|
+
}) : undefined;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function summarizeStructuralEdits(edits) {
|
|
123
|
+
const byKind = countBy(edits.map((edit) => edit.structuralKind));
|
|
124
|
+
const byAction = countBy(edits.flatMap((edit) => edit.actions ?? []));
|
|
125
|
+
return {
|
|
126
|
+
edits: edits.length,
|
|
127
|
+
byKind,
|
|
128
|
+
byAction,
|
|
129
|
+
moves: byAction.move ?? 0,
|
|
130
|
+
updates: byAction.update ?? 0,
|
|
131
|
+
inserts: byAction.insert ?? 0,
|
|
132
|
+
deletes: byAction.delete ?? 0,
|
|
133
|
+
moveUpdates: byKind['move-update'] ?? 0,
|
|
134
|
+
reviewRequired: edits.length > 0,
|
|
135
|
+
autoMergeClaim: false,
|
|
136
|
+
semanticEquivalenceClaim: false
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function countBy(values) {
|
|
141
|
+
const result = {};
|
|
142
|
+
for (const value of values.filter(Boolean)) result[value] = (result[value] ?? 0) + 1;
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function compactRecord(value) {
|
|
147
|
+
return Object.fromEntries(Object.entries(value ?? {}).filter(([, entry]) => entry !== undefined && (!Array.isArray(entry) || entry.length > 0)));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export { semanticStructuralDiff, semanticStructuralEdit };
|