@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,268 @@
|
|
|
1
|
+
import { hashSemanticValue } from '@shapeshift-labs/frontier-lang-kernel';
|
|
2
|
+
import { idFragment } from '../../native-import-utils.js';
|
|
3
|
+
import { createParserTriviaExactnessRecord } from '../../native-source-preservation-ownership.js';
|
|
4
|
+
import {
|
|
5
|
+
sourceFileOwnershipEvidence,
|
|
6
|
+
sourceSpanOwnershipAnchor,
|
|
7
|
+
sourceSpanOwnershipBlockReasonCodes
|
|
8
|
+
} from './projectSymbolGraphSourceRecordsOwnership.js';
|
|
9
|
+
import {
|
|
10
|
+
sourceMapGeneratedBoundaryGateForImport,
|
|
11
|
+
sourceMapGeneratedBoundaryRecord,
|
|
12
|
+
sourceMapGeneratedBoundaryRecordForSpan,
|
|
13
|
+
sourceMapsForImport
|
|
14
|
+
} from './projectSymbolGraphSourceMapGeneratedBoundary.js';
|
|
15
|
+
|
|
16
|
+
function createProjectSourceEvidenceRecords(imports) {
|
|
17
|
+
const records = imports.map(sourceRecordsForImport).filter(Boolean);
|
|
18
|
+
return {
|
|
19
|
+
sourceFileRecords: uniqueRecords(records.flatMap((record) => record.sourceFileRecords)),
|
|
20
|
+
sourceSpanRecords: uniqueRecords(records.flatMap((record) => record.sourceSpanRecords))
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function sourceRecordsForImport(imported) {
|
|
25
|
+
const preservation = sourcePreservationForImport(imported);
|
|
26
|
+
const sourcePath = preservation?.sourcePath ?? imported?.sourcePath ?? imported?.nativeSource?.sourcePath;
|
|
27
|
+
if (!preservation || !sourcePath) return undefined;
|
|
28
|
+
const sourceHash = preservation.sourceHash ?? imported?.nativeSource?.sourceHash ?? imported?.metadata?.sourceHash;
|
|
29
|
+
const sourceMaps = sourceMapsForImport(imported);
|
|
30
|
+
const generatedBoundaryGate = sourceMapGeneratedBoundaryGateForImport(imported, sourceMaps, { preservation, sourcePath, sourceHash });
|
|
31
|
+
const context = { preservation, sourcePath, sourceHash, sourceMaps, generatedBoundaryGate };
|
|
32
|
+
return {
|
|
33
|
+
sourceFileRecords: [sourceFileRecord(context)],
|
|
34
|
+
sourceSpanRecords: sourceSpanRecords(context)
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function sourceFileRecord(context) {
|
|
39
|
+
const summary = context.preservation.summary ?? {};
|
|
40
|
+
const ledger = summary.ledger ?? {};
|
|
41
|
+
const ownership = sourceFileOwnershipEvidence(context, summary);
|
|
42
|
+
const parserTriviaExactness = parserTriviaExactnessForPreservation(context.preservation);
|
|
43
|
+
const generatedBoundary = sourceMapGeneratedBoundaryRecord(context, summary);
|
|
44
|
+
return compactRecord({
|
|
45
|
+
id: `source_file_${idFragment(context.sourcePath)}`,
|
|
46
|
+
sourcePath: context.sourcePath,
|
|
47
|
+
language: context.preservation.language,
|
|
48
|
+
sourceHash: context.sourceHash,
|
|
49
|
+
preservationId: context.preservation.id,
|
|
50
|
+
sourceBytes: context.preservation.sourceBytes,
|
|
51
|
+
lineCount: context.preservation.lineCount,
|
|
52
|
+
newline: context.preservation.newline,
|
|
53
|
+
encoding: context.preservation.encoding,
|
|
54
|
+
exactSourceAvailable: summary.exactSourceAvailable,
|
|
55
|
+
tokenCount: summary.tokens,
|
|
56
|
+
triviaCount: summary.trivia,
|
|
57
|
+
directiveCount: summary.directives,
|
|
58
|
+
commentCount: summary.comments,
|
|
59
|
+
whitespaceCount: summary.whitespace,
|
|
60
|
+
sourceMapCommentCount: summary.sourceMapComments ?? ledger.sourceMapComments,
|
|
61
|
+
protectedRegionCount: summary.protectedRegions ?? ledger.protectedRegions,
|
|
62
|
+
importExportSpanCount: summary.importExportSpans ?? ledger.importExportSpans,
|
|
63
|
+
braceCount: summary.braces ?? ledger.braces,
|
|
64
|
+
truncated: summary.truncated,
|
|
65
|
+
sourceTextHash: typeof context.preservation.sourceText === 'string' ? hashSemanticValue(context.preservation.sourceText) : undefined,
|
|
66
|
+
roundtripHash: context.sourceHash,
|
|
67
|
+
parserEvidence: ownership.parserEvidence,
|
|
68
|
+
losslessCst: parserTriviaExactness.losslessCst === true,
|
|
69
|
+
parserTriviaExactnessStatus: parserTriviaExactness.status,
|
|
70
|
+
exactParserTrivia: parserTriviaExactness.exactParserTrivia,
|
|
71
|
+
parserTriviaEvidenceId: parserTriviaExactness.evidenceId,
|
|
72
|
+
parserTriviaAdapterId: parserTriviaExactness.adapterId,
|
|
73
|
+
parserTriviaExactnessReasonCodes: parserTriviaExactness.reasonCodes,
|
|
74
|
+
parserTriviaExactnessBlockReasonCodes: parserTriviaExactness.blockReasonCodes,
|
|
75
|
+
sourceLedgerAvailable: ownership.sourceLedgerAvailable,
|
|
76
|
+
triviaOwnershipStatus: ownership.status,
|
|
77
|
+
triviaOwnershipReasonCodes: ownership.reasonCodes,
|
|
78
|
+
triviaOwnershipBlockReasonCodes: ownership.blockReasonCodes,
|
|
79
|
+
ownershipAnchorMode: 'exact-source-span',
|
|
80
|
+
generatedSourceBoundaryEvidence: ownership.generatedSourceBoundaryEvidence,
|
|
81
|
+
...generatedBoundary,
|
|
82
|
+
shapeHash: hashSemanticValue({ kind: 'frontier.lang.projectSourceFileShape', sourcePath: context.sourcePath, sourceHash: context.sourceHash, summary })
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function sourceSpanRecords(context) {
|
|
87
|
+
const preservation = context.preservation;
|
|
88
|
+
const ledgerSpans = Array.isArray(preservation.ledger?.spans) ? preservation.ledger.spans : [];
|
|
89
|
+
const spans = ledgerSpans.length ? ledgerSpans : fallbackSpans(preservation);
|
|
90
|
+
const identityCounts = new Map();
|
|
91
|
+
return spans.map((span, index) => {
|
|
92
|
+
const sourceSpan = span.span;
|
|
93
|
+
if (!sourceSpan) return undefined;
|
|
94
|
+
const role = span.role ?? fallbackRole(span.kind);
|
|
95
|
+
const ownershipAnchor = sourceSpanOwnershipAnchor(span, role, context, spans, index);
|
|
96
|
+
const ownershipBlockReasonCodes = sourceSpanOwnershipBlockReasonCodes(span, ownershipAnchor, context);
|
|
97
|
+
const identitySeed = sourceSpanIdentitySeed(span, role, context, ownershipAnchor);
|
|
98
|
+
const occurrence = (identityCounts.get(identitySeed) ?? 0) + 1;
|
|
99
|
+
identityCounts.set(identitySeed, occurrence);
|
|
100
|
+
const identityKey = occurrence === 1 ? identitySeed : stableKey([identitySeed, occurrence]);
|
|
101
|
+
return sourceSpanRecord(span, index, context, { role, identityKey, occurrence, ownershipAnchor, ownershipBlockReasonCodes });
|
|
102
|
+
}).filter(Boolean);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function sourceSpanRecord(span, index, context, identity) {
|
|
106
|
+
const sourceSpan = span.span;
|
|
107
|
+
if (!sourceSpan) return undefined;
|
|
108
|
+
const role = identity?.role ?? span.role ?? fallbackRole(span.kind);
|
|
109
|
+
const identityKey = identity?.identityKey ?? sourceSpanIdentitySeed(span, role, context);
|
|
110
|
+
const textLength = typeof span.text === 'string' ? span.text.length : undefined;
|
|
111
|
+
const trivia = role === 'trivia' || role === 'comment' || isCommentKind(span.kind) || span.kind === 'source-map-comment' || undefined;
|
|
112
|
+
const directive = role === 'directive' || span.kind === 'runtime-directive' || span.kind === 'module-directive' || span.kind === 'typescript-reference' || undefined;
|
|
113
|
+
const protectedSpan = role === 'protected' || undefined;
|
|
114
|
+
const baseOwnershipAnchor = identity?.ownershipAnchor ?? sourceSpanOwnershipAnchor(span, role, context, [], index);
|
|
115
|
+
const ownershipAnchor = baseOwnershipAnchor ? { ...baseOwnershipAnchor, key: identityKey, identityKey, identityOccurrence: identity?.occurrence } : undefined;
|
|
116
|
+
const ownershipAnchorKey = ownershipAnchor?.key ?? ownershipAnchor?.identityKey;
|
|
117
|
+
const ownershipBlockReasonCodes = identity?.ownershipBlockReasonCodes ?? sourceSpanOwnershipBlockReasonCodes(span, ownershipAnchor, context);
|
|
118
|
+
const ownershipAnchorStatus = ownershipBlockReasonCodes.length ? 'blocked' : 'deterministic-lightweight';
|
|
119
|
+
const parserTriviaExactness = parserTriviaExactnessForPreservation(context.preservation);
|
|
120
|
+
const parserEvidence = parserEvidenceForPreservation(context.preservation, parserTriviaExactness);
|
|
121
|
+
const parserTriviaOwnershipStatus = ownershipAnchor?.parserTriviaOwnershipStatus;
|
|
122
|
+
const parserTriviaOwnershipRelation = ownershipAnchor?.parserTriviaOwnershipRelation;
|
|
123
|
+
const parserTriviaOwnershipReasonCodes = ownershipAnchor?.parserTriviaOwnershipReasonCodes;
|
|
124
|
+
const parserTriviaOwnershipBlockReasonCodes = ownershipAnchor?.parserTriviaOwnershipBlockReasonCodes;
|
|
125
|
+
const generatedBoundary = sourceMapGeneratedBoundaryRecordForSpan(context, span);
|
|
126
|
+
const ownershipAnchorHash = ownershipAnchor ? hashSemanticValue({
|
|
127
|
+
kind: 'frontier.lang.projectSourceSpanOwnershipAnchor',
|
|
128
|
+
ownershipAnchor,
|
|
129
|
+
identityKey,
|
|
130
|
+
sourcePath: context.sourcePath
|
|
131
|
+
}) : undefined;
|
|
132
|
+
return compactRecord({
|
|
133
|
+
id: `source_span_${idFragment(context.sourcePath)}_${index + 1}`,
|
|
134
|
+
stableId: `source_span_${idFragment(identityKey)}`,
|
|
135
|
+
identityKey,
|
|
136
|
+
sourcePath: context.sourcePath,
|
|
137
|
+
sourceHash: context.sourceHash,
|
|
138
|
+
preservationId: context.preservation.id,
|
|
139
|
+
sourceSpan,
|
|
140
|
+
start: sourceSpan.start,
|
|
141
|
+
end: sourceSpan.end,
|
|
142
|
+
role,
|
|
143
|
+
kind: span.kind,
|
|
144
|
+
ordinal: index + 1,
|
|
145
|
+
identityOccurrence: identity?.occurrence,
|
|
146
|
+
textHash: span.textHash,
|
|
147
|
+
textLength,
|
|
148
|
+
trivia,
|
|
149
|
+
directive,
|
|
150
|
+
protected: protectedSpan,
|
|
151
|
+
ownershipAnchor,
|
|
152
|
+
ownershipAnchorKey,
|
|
153
|
+
ownershipAnchorHash,
|
|
154
|
+
ownershipAnchorStatus,
|
|
155
|
+
ownershipBlockReasonCodes,
|
|
156
|
+
parserEvidence,
|
|
157
|
+
losslessCst: parserTriviaExactness.losslessCst === true,
|
|
158
|
+
parserTriviaExactnessStatus: parserTriviaExactness.status,
|
|
159
|
+
exactParserTrivia: parserTriviaExactness.exactParserTrivia,
|
|
160
|
+
parserTriviaEvidenceId: parserTriviaExactness.evidenceId,
|
|
161
|
+
parserTriviaAdapterId: parserTriviaExactness.adapterId,
|
|
162
|
+
parserTriviaExactnessReasonCodes: parserTriviaExactness.reasonCodes,
|
|
163
|
+
parserTriviaExactnessBlockReasonCodes: parserTriviaExactness.blockReasonCodes,
|
|
164
|
+
parserTriviaOwnershipStatus,
|
|
165
|
+
parserTriviaOwnershipRelation,
|
|
166
|
+
parserTriviaOwnershipReasonCodes,
|
|
167
|
+
parserTriviaOwnershipBlockReasonCodes,
|
|
168
|
+
...generatedBoundary,
|
|
169
|
+
roundtripHash: context.sourceHash,
|
|
170
|
+
stableHash: hashSemanticValue({ kind: 'frontier.lang.projectSourceSpanStableEvidence', sourcePath: context.sourcePath, role, spanKind: span.kind, textHash: span.textHash, textLength, trivia, directive, protected: protectedSpan, ownershipAnchorKey, ownershipAnchorStatus, parserTriviaOwnershipStatus, parserTriviaOwnershipRelation, parserTriviaOwnershipBlockReasonCodes }),
|
|
171
|
+
signatureHash: hashSemanticValue({ kind: 'frontier.lang.projectSourceSpanSignature', sourcePath: context.sourcePath, role, spanKind: span.kind, textHash: span.textHash, sourceSpan: semanticSpanForHash(sourceSpan), ownershipAnchorKey })
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function sourceSpanIdentitySeed(span, role, context, ownershipAnchor) {
|
|
176
|
+
return stableKey(['source-span', context.sourcePath, role, span.kind, sourceSpanIdentityAnchor(span, role, ownershipAnchor)]);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function sourceSpanIdentityAnchor(span, role, ownershipAnchor) {
|
|
180
|
+
if (ownershipAnchor?.identityAnchor) return ownershipAnchor.identityAnchor;
|
|
181
|
+
if (role === 'directive') {
|
|
182
|
+
if (span.kind === 'runtime-directive') return 'runtime-directive-prologue';
|
|
183
|
+
if (span.kind === 'source-map-comment') return 'source-map-comment';
|
|
184
|
+
if (span.kind === 'typescript-reference') return 'typescript-reference';
|
|
185
|
+
if (span.kind === 'shebang') return 'file-entrypoint-directive';
|
|
186
|
+
return span.textHash ?? span.kind ?? 'directive';
|
|
187
|
+
}
|
|
188
|
+
if (span.kind === 'source-map-comment') return 'source-map-comment';
|
|
189
|
+
if (role === 'protected') return stableKey(['protected', span.textHash ?? span.kind]);
|
|
190
|
+
if (role === 'comment' || role === 'trivia') return stableKey(['trivia', span.textHash ?? span.kind]);
|
|
191
|
+
return span.textHash ?? span.kind ?? role;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function fallbackSpans(preservation) {
|
|
195
|
+
return [
|
|
196
|
+
...(preservation.trivia ?? []).map((span) => ({ ...span, role: fallbackRole(span.kind) })),
|
|
197
|
+
...(preservation.directives ?? []).map((span) => ({ ...span, role: 'directive' }))
|
|
198
|
+
];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function sourcePreservationForImport(imported) {
|
|
202
|
+
return imported?.metadata?.sourcePreservation
|
|
203
|
+
?? imported?.nativeSource?.metadata?.sourcePreservation
|
|
204
|
+
?? imported?.nativeAst?.metadata?.sourcePreservation
|
|
205
|
+
?? imported?.universalAst?.metadata?.sourcePreservation;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function semanticSpanForHash(span) {
|
|
209
|
+
return { path: span.path, start: span.start, end: span.end, startLine: span.startLine, startColumn: span.startColumn, endLine: span.endLine, endColumn: span.endColumn };
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function parserTriviaExactnessForPreservation(preservation) {
|
|
213
|
+
const existing = preservation?.metadata?.parserTriviaExactness;
|
|
214
|
+
const tokenTriviaParserEvidence = parserTokenTriviaEvidenceForPreservation(preservation);
|
|
215
|
+
if (existing?.status === 'exact' || existing?.exactParserTrivia === true) {
|
|
216
|
+
return createParserTriviaExactnessRecord(existing, {
|
|
217
|
+
sourcePath: preservation?.sourcePath,
|
|
218
|
+
sourceHash: preservation?.sourceHash,
|
|
219
|
+
parserEvidence: tokenTriviaParserEvidence,
|
|
220
|
+
parserTokenTriviaEvidence: tokenTriviaParserEvidence,
|
|
221
|
+
truncated: preservation?.summary?.truncated === true
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
return existing ?? {
|
|
225
|
+
status: preservation?.summary?.parserTriviaExactnessStatus ?? 'approximate',
|
|
226
|
+
exactParserTrivia: preservation?.summary?.exactParserTrivia === true,
|
|
227
|
+
reasonCodes: preservation?.summary?.parserTriviaExactnessReasonCodes ?? ['parser-trivia-proof-approximate'],
|
|
228
|
+
blockReasonCodes: preservation?.summary?.parserTriviaExactnessBlockReasonCodes ?? []
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function parserEvidenceForPreservation(preservation, parserTriviaExactness) {
|
|
233
|
+
const lightweightEvidence = preservation?.ledger?.summary ? 'frontier-lightweight-js-ts-source-ledger' : 'frontier-lightweight-lexical-scan';
|
|
234
|
+
if (parserTriviaExactness?.status !== 'exact') return lightweightEvidence;
|
|
235
|
+
return firstString(parserTriviaExactness.parserEvidence, parserTokenTriviaEvidenceForPreservation(preservation), parserTriviaExactness.adapterId ? `parser-adapter:${parserTriviaExactness.adapterId}` : undefined, lightweightEvidence);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function parserTokenTriviaEvidenceForPreservation(preservation) {
|
|
239
|
+
const lightweightEvidence = preservation?.ledger?.summary ? 'frontier-lightweight-js-ts-source-ledger' : 'frontier-lightweight-lexical-scan';
|
|
240
|
+
return firstString(preservation?.metadata?.tokenization, preservation?.metadata?.parserTokenTriviaEvidence, lightweightEvidence);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function fallbackRole(kind) {
|
|
244
|
+
if (isCommentKind(kind) || kind === 'source-map-comment' || kind === 'whitespace' || kind === 'newline' || kind === 'shebang') return 'trivia';
|
|
245
|
+
return 'token';
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function isCommentKind(kind) {
|
|
249
|
+
return kind === 'comment' || kind === 'jsdoc-comment' || kind === 'block-comment';
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function compactRecord(record) { return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined)); }
|
|
253
|
+
function stableKey(parts) {
|
|
254
|
+
const values = parts.map((part) => part === undefined || part === null ? '' : String(part));
|
|
255
|
+
return values.some(Boolean) ? values.join('#') : undefined;
|
|
256
|
+
}
|
|
257
|
+
function firstString(...values) { return values.find((value) => typeof value === 'string' && value.length > 0); }
|
|
258
|
+
function uniqueRecords(records) {
|
|
259
|
+
const seen = new Set();
|
|
260
|
+
return records.filter((record) => {
|
|
261
|
+
const key = record.id ?? JSON.stringify(record);
|
|
262
|
+
if (seen.has(key)) return false;
|
|
263
|
+
seen.add(key);
|
|
264
|
+
return true;
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export { createProjectSourceEvidenceRecords };
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createParserTriviaExactnessRecord,
|
|
3
|
+
createPreservedSourceOwnershipAnchor
|
|
4
|
+
} from '../../native-source-preservation-ownership.js';
|
|
5
|
+
|
|
6
|
+
function sourceFileOwnershipEvidence(context, summary) {
|
|
7
|
+
const reasonCodes = [];
|
|
8
|
+
const blockReasonCodes = [];
|
|
9
|
+
const hasExactSourceText = summary.exactSourceAvailable === true && typeof context.preservation.sourceText === 'string';
|
|
10
|
+
const sourceLedgerAvailable = Boolean(context.preservation.ledger?.summary);
|
|
11
|
+
const parserTriviaExactness = parserTriviaExactnessForContext(context);
|
|
12
|
+
const exactParserTrivia = parserTriviaExactness.status === 'exact' && parserTriviaExactness.exactParserTrivia === true;
|
|
13
|
+
reasonCodes.push(parserTriviaExactness.losslessCst === true ? 'lossless-cst-available' : 'lossless-cst-unavailable');
|
|
14
|
+
if (hasExactSourceText) reasonCodes.push('exact-source-text');
|
|
15
|
+
else blockReasonCodes.push('source-text-unavailable-for-trivia-ownership');
|
|
16
|
+
if (summary.truncated) blockReasonCodes.push('source-preservation-truncated');
|
|
17
|
+
if (sourceLedgerAvailable) reasonCodes.push('source-ledger-spans');
|
|
18
|
+
else if (isJavaScriptTypeScriptEvidence(context)) blockReasonCodes.push('js-ts-source-ledger-missing');
|
|
19
|
+
reasonCodes.push(...(parserTriviaExactness.reasonCodes ?? []));
|
|
20
|
+
blockReasonCodes.push(...(parserTriviaExactness.blockReasonCodes ?? []));
|
|
21
|
+
const parserEvidence = parserEvidenceForContext(context, parserTriviaExactness);
|
|
22
|
+
return {
|
|
23
|
+
status: blockReasonCodes.length ? 'blocked' : exactParserTrivia ? 'exact' : 'deterministic-lightweight',
|
|
24
|
+
reasonCodes: uniqueStrings([...reasonCodes, ...blockReasonCodes]),
|
|
25
|
+
blockReasonCodes: uniqueStrings(blockReasonCodes),
|
|
26
|
+
parserEvidence,
|
|
27
|
+
sourceLedgerAvailable,
|
|
28
|
+
generatedSourceBoundaryEvidence: (summary.sourceMapComments ?? summary.ledger?.sourceMapComments ?? 0) > 0 ? 'source-map-comment-detected' : undefined,
|
|
29
|
+
parserTriviaExactness
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function sourceSpanOwnershipAnchor(span, role, context, spans, index) {
|
|
34
|
+
const before = nearestOwnershipBoundary(spans, index, -1);
|
|
35
|
+
const after = nearestOwnershipBoundary(spans, index, 1);
|
|
36
|
+
const anchorKind = sourceSpanOwnershipAnchorKind(span, role);
|
|
37
|
+
const identityAnchor = sourceSpanOwnershipIdentityAnchor(span, role, before, after);
|
|
38
|
+
const parserTriviaExactness = parserTriviaExactnessForContext(context);
|
|
39
|
+
const parserEvidence = parserEvidenceForContext(context, parserTriviaExactness);
|
|
40
|
+
const parserTriviaOwnership = sourceSpanParserTriviaOwnership(span, role, parserTriviaExactness, before, after);
|
|
41
|
+
const base = span.ownershipAnchor ?? createPreservedSourceOwnershipAnchor({
|
|
42
|
+
kind: span.kind,
|
|
43
|
+
role,
|
|
44
|
+
text: span.text,
|
|
45
|
+
textHash: span.textHash,
|
|
46
|
+
textLength: typeof span.text === 'string' ? span.text.length : undefined,
|
|
47
|
+
sourcePath: context.sourcePath,
|
|
48
|
+
sourceHash: context.sourceHash,
|
|
49
|
+
span: span.span,
|
|
50
|
+
anchorKind,
|
|
51
|
+
identityAnchor,
|
|
52
|
+
parserEvidence,
|
|
53
|
+
parserTriviaExactness
|
|
54
|
+
});
|
|
55
|
+
const key = base?.key ?? stableKey(['source-ownership', context.sourcePath, role, span.kind, base?.identityAnchor ?? identityAnchor ?? base?.spanHash]);
|
|
56
|
+
return compactRecord({
|
|
57
|
+
...base,
|
|
58
|
+
key,
|
|
59
|
+
identityKey: base?.identityKey ?? key,
|
|
60
|
+
identityAnchor: base?.identityAnchor ?? identityAnchor,
|
|
61
|
+
boundaryBefore: ownershipBoundaryRecord(before),
|
|
62
|
+
boundaryAfter: ownershipBoundaryRecord(after),
|
|
63
|
+
insertionAnchor: sourceSpanInsertionAnchor(role, span, ownershipBoundaryRecord(before), ownershipBoundaryRecord(after)),
|
|
64
|
+
parserEvidence,
|
|
65
|
+
losslessCst: parserTriviaExactness.losslessCst === true,
|
|
66
|
+
parserTriviaExactnessStatus: parserTriviaExactness.status,
|
|
67
|
+
exactParserTrivia: parserTriviaExactness.exactParserTrivia,
|
|
68
|
+
parserTriviaEvidenceId: parserTriviaExactness.evidenceId,
|
|
69
|
+
parserTriviaAdapterId: parserTriviaExactness.adapterId,
|
|
70
|
+
parserTriviaExactnessReasonCodes: parserTriviaExactness.reasonCodes,
|
|
71
|
+
parserTriviaExactnessBlockReasonCodes: parserTriviaExactness.blockReasonCodes,
|
|
72
|
+
...parserTriviaOwnership
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function sourceSpanOwnershipBlockReasonCodes(span, ownershipAnchor, context) {
|
|
77
|
+
const parserTriviaExactness = parserTriviaExactnessForContext(context);
|
|
78
|
+
return uniqueStrings([
|
|
79
|
+
ownershipAnchor ? undefined : 'source-ownership-anchor-missing',
|
|
80
|
+
context.preservation.summary?.exactSourceAvailable === true && typeof context.preservation.sourceText === 'string' ? undefined : 'source-text-unavailable-for-trivia-ownership',
|
|
81
|
+
context.preservation.summary?.truncated ? 'source-preservation-truncated' : undefined,
|
|
82
|
+
!span.span ? 'source-span-missing' : undefined,
|
|
83
|
+
!context.sourceHash ? 'source-hash-missing' : undefined,
|
|
84
|
+
...(parserTriviaExactness.blockReasonCodes ?? [])
|
|
85
|
+
]);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function parserTriviaExactnessForContext(context) {
|
|
89
|
+
const parserEvidence = parserTokenTriviaEvidenceForContext(context);
|
|
90
|
+
const existing = context.preservation.metadata?.parserTriviaExactness;
|
|
91
|
+
if (existing?.status === 'exact' || existing?.exactParserTrivia === true) {
|
|
92
|
+
return createParserTriviaExactnessRecord(existing, {
|
|
93
|
+
sourcePath: context.sourcePath,
|
|
94
|
+
sourceHash: context.sourceHash,
|
|
95
|
+
parserEvidence,
|
|
96
|
+
parserTokenTriviaEvidence: parserEvidence,
|
|
97
|
+
truncated: context.preservation.summary?.truncated === true
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return existing ?? createParserTriviaExactnessRecord(context.preservation.metadata?.parserTriviaEvidence, {
|
|
101
|
+
sourcePath: context.sourcePath,
|
|
102
|
+
sourceHash: context.sourceHash,
|
|
103
|
+
parserEvidence,
|
|
104
|
+
parserTokenTriviaEvidence: parserEvidence,
|
|
105
|
+
truncated: context.preservation.summary?.truncated === true
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function parserEvidenceForContext(context, parserTriviaExactness) {
|
|
110
|
+
const lightweightEvidence = lightweightParserEvidenceForContext(context);
|
|
111
|
+
if (parserTriviaExactness?.status !== 'exact') return lightweightEvidence;
|
|
112
|
+
return firstString(parserTriviaExactness.parserEvidence, parserTriviaExactness.adapterId ? `parser-adapter:${parserTriviaExactness.adapterId}` : undefined, lightweightEvidence);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function parserTokenTriviaEvidenceForContext(context) {
|
|
116
|
+
return firstString(
|
|
117
|
+
context.preservation.metadata?.tokenization,
|
|
118
|
+
context.preservation.metadata?.parserTokenTriviaEvidence,
|
|
119
|
+
lightweightParserEvidenceForContext(context)
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function lightweightParserEvidenceForContext(context) {
|
|
124
|
+
return context.preservation.ledger?.summary ? 'frontier-lightweight-js-ts-source-ledger' : 'frontier-lightweight-lexical-scan';
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function sourceSpanOwnershipAnchorKind(span, role) {
|
|
128
|
+
if (span.kind === 'source-map-comment') return 'generated-source-boundary';
|
|
129
|
+
if (span.kind === 'shebang') return 'file-entrypoint-directive';
|
|
130
|
+
if (role === 'directive' && span.kind === 'runtime-directive') return 'directive-prologue';
|
|
131
|
+
if (role === 'directive') return 'source-directive';
|
|
132
|
+
if (role === 'protected') return 'protected-source-span';
|
|
133
|
+
if (role === 'comment' || role === 'trivia' || isCommentKind(span.kind)) return sourceCommentAnchorKind(span.kind);
|
|
134
|
+
return 'lexical-source-span';
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function sourceSpanOwnershipIdentityAnchor(span, role, before, after) {
|
|
138
|
+
if (role === 'directive') {
|
|
139
|
+
if (span.kind === 'runtime-directive') return 'runtime-directive-prologue';
|
|
140
|
+
if (span.kind === 'source-map-comment') return 'source-map-comment';
|
|
141
|
+
if (span.kind === 'typescript-reference') return 'typescript-reference';
|
|
142
|
+
if (span.kind === 'module-directive') return span.textHash ?? span.kind;
|
|
143
|
+
if (span.kind === 'shebang') return 'file-entrypoint-directive';
|
|
144
|
+
return stableKey(['directive', span.kind, boundaryIdentity(before), boundaryIdentity(after)]);
|
|
145
|
+
}
|
|
146
|
+
if (span.kind === 'source-map-comment') return 'source-map-comment';
|
|
147
|
+
if (role === 'protected') return stableKey(['protected', span.kind, boundaryIdentity(before), boundaryIdentity(after)]);
|
|
148
|
+
if (role === 'comment' || role === 'trivia' || isCommentKind(span.kind) || span.kind === 'shebang') {
|
|
149
|
+
return stableKey(['trivia', span.kind, boundaryIdentity(before), boundaryIdentity(after)]);
|
|
150
|
+
}
|
|
151
|
+
return span.textHash ?? span.kind ?? role;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function sourceSpanParserTriviaOwnership(span, role, parserTriviaExactness, before, after) {
|
|
155
|
+
const relation = sourceSpanParserTriviaOwnershipRelation(span, role, before, after);
|
|
156
|
+
if (!relation) return undefined;
|
|
157
|
+
const exact = parserTriviaExactness.status === 'exact' && parserTriviaExactness.exactParserTrivia === true;
|
|
158
|
+
const blockReasonCodes = exact ? [] : uniqueStrings([
|
|
159
|
+
'exact-parser-trivia-ownership-requires-parser-evidence',
|
|
160
|
+
parserTriviaExactness.status === 'blocked' ? 'exact-parser-trivia-ownership-blocked' : undefined,
|
|
161
|
+
...(parserTriviaExactness.blockReasonCodes ?? [])
|
|
162
|
+
]);
|
|
163
|
+
return compactRecord({
|
|
164
|
+
parserTriviaOwnershipStatus: exact ? 'exact' : 'blocked',
|
|
165
|
+
parserTriviaOwnershipRelation: relation,
|
|
166
|
+
parserTriviaOwnershipReasonCodes: uniqueStrings([
|
|
167
|
+
exact ? 'exact-parser-trivia-ownership' : 'exact-parser-trivia-ownership-blocked',
|
|
168
|
+
relationReasonCode(relation),
|
|
169
|
+
...(parserTriviaExactness.reasonCodes ?? [])
|
|
170
|
+
]),
|
|
171
|
+
parserTriviaOwnershipBlockReasonCodes: blockReasonCodes
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function sourceSpanParserTriviaOwnershipRelation(span, role, before, after) {
|
|
176
|
+
if (role === 'directive') {
|
|
177
|
+
if (span.kind === 'runtime-directive') return 'directive-prologue';
|
|
178
|
+
if (span.kind === 'source-map-comment') return 'generated-source-boundary';
|
|
179
|
+
if (span.kind === 'shebang') return 'file-entrypoint-directive';
|
|
180
|
+
return 'source-directive';
|
|
181
|
+
}
|
|
182
|
+
if (span.kind === 'source-map-comment') return 'generated-source-boundary';
|
|
183
|
+
if (span.kind === 'shebang') return 'file-entrypoint-directive';
|
|
184
|
+
if (!isCommentKind(span.kind)) return undefined;
|
|
185
|
+
if (span.kind === 'jsdoc-comment') return 'jsdoc-comment';
|
|
186
|
+
if (span.kind === 'block-comment') return 'block-comment';
|
|
187
|
+
if (sameLineTrailingComment(span, before)) return 'trailing-comment';
|
|
188
|
+
if (after) return 'leading-comment';
|
|
189
|
+
if (before) return 'trailing-comment';
|
|
190
|
+
return 'file-comment';
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function sameLineTrailingComment(span, before) {
|
|
194
|
+
const commentStartLine = span?.span?.startLine;
|
|
195
|
+
const beforeEndLine = before?.span?.endLine ?? before?.span?.startLine;
|
|
196
|
+
return Number.isFinite(commentStartLine)
|
|
197
|
+
&& Number.isFinite(beforeEndLine)
|
|
198
|
+
&& commentStartLine === beforeEndLine
|
|
199
|
+
&& Number.isFinite(before?.span?.end)
|
|
200
|
+
&& Number.isFinite(span?.span?.start)
|
|
201
|
+
&& before.span.end <= span.span.start;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function relationReasonCode(relation) {
|
|
205
|
+
if (relation === 'directive-prologue') return 'directive-prologue-ownership';
|
|
206
|
+
if (relation === 'leading-comment') return 'leading-comment-ownership';
|
|
207
|
+
if (relation === 'trailing-comment') return 'trailing-comment-ownership';
|
|
208
|
+
if (relation === 'jsdoc-comment') return 'jsdoc-comment-ownership';
|
|
209
|
+
if (relation === 'block-comment') return 'block-comment-ownership';
|
|
210
|
+
if (relation === 'generated-source-boundary') return 'generated-source-boundary-ownership';
|
|
211
|
+
if (relation === 'file-entrypoint-directive') return 'file-entrypoint-directive-ownership';
|
|
212
|
+
if (relation === 'file-comment') return 'file-comment-ownership';
|
|
213
|
+
return 'source-directive-ownership';
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function sourceSpanInsertionAnchor(role, span, before, after) {
|
|
217
|
+
if (!(role === 'comment' || role === 'trivia' || isCommentKind(span.kind) || span.kind === 'source-map-comment' || span.kind === 'shebang')) return undefined;
|
|
218
|
+
return compactRecord({
|
|
219
|
+
mode: before && after ? 'between' : before ? 'after' : after ? 'before' : 'file',
|
|
220
|
+
anchorKind: span.kind === 'source-map-comment' ? 'generated-source-boundary' : 'trivia-insertion',
|
|
221
|
+
before,
|
|
222
|
+
after,
|
|
223
|
+
reasonCodes: [
|
|
224
|
+
before ? 'nearest-previous-source-span' : 'file-start-boundary',
|
|
225
|
+
after ? 'nearest-next-source-span' : 'file-end-boundary'
|
|
226
|
+
]
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function nearestOwnershipBoundary(spans, index, direction) {
|
|
231
|
+
for (let cursor = index + direction; cursor >= 0 && cursor < spans.length; cursor += direction) {
|
|
232
|
+
const span = spans[cursor];
|
|
233
|
+
if (isOwnershipBoundarySpan(span)) return span;
|
|
234
|
+
}
|
|
235
|
+
return undefined;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function isOwnershipBoundarySpan(span) {
|
|
239
|
+
const role = span?.role ?? fallbackRole(span?.kind);
|
|
240
|
+
if (!span?.span) return false;
|
|
241
|
+
if (role === 'trivia' || role === 'comment') return false;
|
|
242
|
+
if (span.kind === 'whitespace' || span.kind === 'newline' || isCommentKind(span.kind) || span.kind === 'source-map-comment') return false;
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function ownershipBoundaryRecord(span) {
|
|
247
|
+
if (!span) return undefined;
|
|
248
|
+
const role = span.role ?? fallbackRole(span.kind);
|
|
249
|
+
return compactRecord({
|
|
250
|
+
key: boundaryIdentity(span),
|
|
251
|
+
role,
|
|
252
|
+
kind: span.kind,
|
|
253
|
+
textHash: span.textHash,
|
|
254
|
+
startLine: span.span?.startLine,
|
|
255
|
+
startColumn: span.span?.startColumn,
|
|
256
|
+
endLine: span.span?.endLine,
|
|
257
|
+
endColumn: span.span?.endColumn
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function boundaryIdentity(span) {
|
|
262
|
+
if (!span) return undefined;
|
|
263
|
+
const role = span.role ?? fallbackRole(span.kind);
|
|
264
|
+
return stableKey(['boundary', role, span.kind, span.textHash]);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function isJavaScriptTypeScriptEvidence(context) {
|
|
268
|
+
const language = String(context.preservation.language ?? '').toLowerCase();
|
|
269
|
+
if (language === 'javascript' || language === 'typescript') return true;
|
|
270
|
+
return /\.(?:[cm]?js|jsx|[cm]?ts|tsx)$/i.test(String(context.sourcePath ?? ''));
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function fallbackRole(kind) {
|
|
274
|
+
if (isCommentKind(kind) || kind === 'source-map-comment' || kind === 'whitespace' || kind === 'newline' || kind === 'shebang') return 'trivia';
|
|
275
|
+
return 'token';
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function sourceCommentAnchorKind(kind) {
|
|
279
|
+
if (kind === 'jsdoc-comment') return 'jsdoc-comment-trivia';
|
|
280
|
+
if (kind === 'block-comment') return 'block-comment-trivia';
|
|
281
|
+
return 'comment-trivia';
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function isCommentKind(kind) {
|
|
285
|
+
return kind === 'comment' || kind === 'jsdoc-comment' || kind === 'block-comment';
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function compactRecord(record) {
|
|
289
|
+
return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined));
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function stableKey(parts) {
|
|
293
|
+
const values = parts.map((part) => part === undefined || part === null ? '' : String(part));
|
|
294
|
+
return values.some(Boolean) ? values.join('#') : undefined;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function uniqueStrings(values) {
|
|
298
|
+
return [...new Set((values ?? []).filter((value) => typeof value === 'string' && value.length > 0))];
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function firstString(...values) {
|
|
302
|
+
return values.find((value) => typeof value === 'string' && value.length > 0);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export {
|
|
306
|
+
sourceFileOwnershipEvidence,
|
|
307
|
+
sourceSpanOwnershipAnchor,
|
|
308
|
+
sourceSpanOwnershipBlockReasonCodes
|
|
309
|
+
};
|