@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,155 @@
|
|
|
1
|
+
function mutationTargetOrderEvidence(line, lineNumber, group, start = 0, end = String(line ?? '').length) {
|
|
2
|
+
if (group?.regionKind !== 'mutation') return [];
|
|
3
|
+
const mutationKind = mutationFactKind(group);
|
|
4
|
+
const record = mutationTargetRecord(String(line ?? '').slice(Math.max(0, start), Math.max(start, end)), mutationKind);
|
|
5
|
+
return record ? [compactRecord({
|
|
6
|
+
kind: 'mutation-target',
|
|
7
|
+
mutationKind,
|
|
8
|
+
line: lineNumber,
|
|
9
|
+
...record,
|
|
10
|
+
staticMutationTargetEvidence: true,
|
|
11
|
+
runtimeEquivalenceClaim: false,
|
|
12
|
+
semanticEquivalenceClaim: false
|
|
13
|
+
})] : [];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function mutationTargetSignatureEvidence(record) {
|
|
17
|
+
return compactRecord({
|
|
18
|
+
mutationKind: record?.mutationKind,
|
|
19
|
+
targetText: record?.targetText,
|
|
20
|
+
targetRoot: record?.targetRoot,
|
|
21
|
+
operator: record?.operator,
|
|
22
|
+
methodName: record?.methodName,
|
|
23
|
+
optionalCall: record?.optionalCall,
|
|
24
|
+
methodComputed: record?.methodComputed,
|
|
25
|
+
computedMethodName: record?.computedMethodName,
|
|
26
|
+
computedMethodStatic: record?.computedMethodStatic,
|
|
27
|
+
computedMethodDynamic: record?.computedMethodDynamic,
|
|
28
|
+
computedProperty: record?.computedProperty,
|
|
29
|
+
computedPropertyKeys: record?.computedPropertyKeys,
|
|
30
|
+
computedPropertyStatic: record?.computedPropertyStatic,
|
|
31
|
+
computedPropertyDynamic: record?.computedPropertyDynamic
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function mutationTargetContextReasonCodes(record) {
|
|
36
|
+
return uniqueStrings([
|
|
37
|
+
'runtime-order-mutation-target-merge-requires-write-target-evidence',
|
|
38
|
+
record?.operator ? 'runtime-order-mutation-target-merge-requires-operator-evidence' : undefined,
|
|
39
|
+
record?.methodName ? 'runtime-order-mutation-target-merge-requires-mutator-method-evidence' : undefined,
|
|
40
|
+
record?.computedMethodStatic ? 'runtime-order-mutation-target-merge-requires-computed-mutator-method-evidence' : undefined,
|
|
41
|
+
record?.computedMethodDynamic ? 'runtime-order-mutation-target-merge-requires-dynamic-mutator-method-evidence' : undefined,
|
|
42
|
+
record?.computedPropertyStatic ? 'runtime-order-mutation-target-merge-requires-computed-literal-key-evidence' : undefined,
|
|
43
|
+
record?.computedProperty ? 'runtime-order-mutation-target-merge-requires-computed-key-evidence' : undefined,
|
|
44
|
+
record?.optionalCall ? 'runtime-order-mutation-target-merge-requires-nullish-boundary-evidence' : undefined
|
|
45
|
+
]);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function mutationFactKind(group) {
|
|
49
|
+
return ['mutating-call', 'assignment', 'update', 'delete']
|
|
50
|
+
.find((kind) => (group?.factKinds ?? []).includes(kind)) ?? 'mutation';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function mutationTargetRecord(line, mutationKind) {
|
|
54
|
+
if (mutationKind === 'mutating-call') return mutatingCallTarget(line);
|
|
55
|
+
if (mutationKind === 'delete') return deleteTarget(line);
|
|
56
|
+
if (mutationKind === 'assignment') return assignmentTarget(line);
|
|
57
|
+
if (mutationKind === 'update') return updateTarget(line) ?? assignmentTarget(line);
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function mutatingCallTarget(line) {
|
|
62
|
+
const match = /([A-Za-z_$][\w$]*(?:(?:\s*(?:\.|\?\.)\s*[A-Za-z_$][\w$]*)|\s*\[[^\]]+\])*)\s*(\.|\?\.)\s*(push|pop|shift|unshift|splice|sort|reverse|set|add|delete|clear)\s*(\?\.)?\s*\(/.exec(line);
|
|
63
|
+
if (match) {
|
|
64
|
+
const text = statementText(line, match.index);
|
|
65
|
+
return targetRecord(text, match[1], { methodName: match[3], optionalCall: match[2] === '?.' || Boolean(match[4]) });
|
|
66
|
+
}
|
|
67
|
+
const computed = /([A-Za-z_$][\w$]*(?:(?:\s*(?:\.|\?\.)\s*[A-Za-z_$][\w$]*)|\s*\[[^\]]+\])*)\s*(\?\.)?\s*\[\s*(['"`])(push|pop|shift|unshift|splice|sort|reverse|set|add|delete|clear)\3\s*\]\s*(\?\.)?\s*\(/.exec(line);
|
|
68
|
+
if (!computed) return undefined;
|
|
69
|
+
const text = statementText(line, computed.index);
|
|
70
|
+
return targetRecord(text, computed[1], {
|
|
71
|
+
methodName: computed[4],
|
|
72
|
+
optionalCall: Boolean(computed[2] || computed[5]),
|
|
73
|
+
methodComputed: true,
|
|
74
|
+
computedMethodName: computed[4],
|
|
75
|
+
computedMethodStatic: true,
|
|
76
|
+
computedMethodRuntimeEquivalenceClaim: false
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function deleteTarget(line) {
|
|
81
|
+
const match = /\bdelete\s+([^;]+)/.exec(line);
|
|
82
|
+
return match ? targetRecord(statementText(line, match.index), match[1], { operator: 'delete' }) : undefined;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function assignmentTarget(line) {
|
|
86
|
+
const match = /(^|[^\w$])([A-Za-z_$][\w$]*(?:(?:\s*(?:\.|\?\.)\s*[A-Za-z_$][\w$]*)|\s*\[[^\]]+\])*)\s*(\|\|=|&&=|\?\?=|\+=|-=|\*=|\/=|%=|\*\*=|<<=|>>=|>>>=|&=|\^=|\|=|=(?!=|>))/.exec(line);
|
|
87
|
+
return match ? targetRecord(statementText(line, match.index + match[1].length), match[2], { operator: match[3] }) : undefined;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function updateTarget(line) {
|
|
91
|
+
const prefix = /(^|[^\w$])(\+\+|--)\s*([A-Za-z_$][\w$]*(?:(?:\s*(?:\.|\?\.)\s*[A-Za-z_$][\w$]*)|\s*\[[^\]]+\])*)/.exec(line);
|
|
92
|
+
if (prefix) return targetRecord(statementText(line, prefix.index + prefix[1].length), prefix[3], { operator: prefix[2], updatePosition: 'prefix' });
|
|
93
|
+
const postfix = /(^|[^\w$])([A-Za-z_$][\w$]*(?:(?:\s*(?:\.|\?\.)\s*[A-Za-z_$][\w$]*)|\s*\[[^\]]+\])*)\s*(\+\+|--)/.exec(line);
|
|
94
|
+
return postfix ? targetRecord(statementText(line, postfix.index + postfix[1].length), postfix[2], { operator: postfix[3], updatePosition: 'postfix' }) : undefined;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function targetRecord(text, target, extra = {}) {
|
|
98
|
+
const targetText = normalizeTargetText(target);
|
|
99
|
+
if (!targetText) return undefined;
|
|
100
|
+
const computedProperties = computedPropertySegments(targetText);
|
|
101
|
+
const literalComputedProperties = computedProperties.filter((entry) => entry.static);
|
|
102
|
+
return compactRecord({
|
|
103
|
+
text: normalizeOrderEvidenceText(text),
|
|
104
|
+
targetText,
|
|
105
|
+
targetRoot: targetRoot(targetText),
|
|
106
|
+
computedProperty: computedProperties.length > 0 || undefined,
|
|
107
|
+
computedPropertyKeys: literalComputedProperties.map((entry) => entry.key),
|
|
108
|
+
computedPropertyStatic: computedProperties.length > 0 && literalComputedProperties.length === computedProperties.length || undefined,
|
|
109
|
+
computedPropertyDynamic: computedProperties.length > literalComputedProperties.length || undefined,
|
|
110
|
+
computedPropertyCount: computedProperties.length || undefined,
|
|
111
|
+
computedPropertyStaticCount: literalComputedProperties.length || undefined,
|
|
112
|
+
computedPropertyRuntimeEquivalenceClaim: computedProperties.length > 0 ? false : undefined,
|
|
113
|
+
...extra
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function statementText(line, start) {
|
|
118
|
+
const end = statementEnd(line, start);
|
|
119
|
+
return String(line ?? '').slice(Math.max(0, start), end);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function statementEnd(line, start) {
|
|
123
|
+
const semicolon = String(line ?? '').indexOf(';', start);
|
|
124
|
+
return semicolon === -1 ? String(line ?? '').length : semicolon + 1;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function normalizeTargetText(value) {
|
|
128
|
+
return normalizeOrderEvidenceText(String(value ?? '')
|
|
129
|
+
.replace(/\s*(?:\.|\?\.)\s*/g, (match) => match.includes('?.') ? '?.' : '.')
|
|
130
|
+
.replace(/\s*\[\s*/g, '[')
|
|
131
|
+
.replace(/\s*\]\s*/g, ']'));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function targetRoot(targetText) {
|
|
135
|
+
return /^[A-Za-z_$][\w$]*/.exec(targetText)?.[0];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function computedPropertySegments(targetText) {
|
|
139
|
+
return [...String(targetText ?? '').matchAll(/\[([^\]]+)\]/g)].map((match) => {
|
|
140
|
+
const expression = normalizeOrderEvidenceText(match[1]);
|
|
141
|
+
const key = literalComputedPropertyKey(expression);
|
|
142
|
+
return compactRecord({ expression, key, static: key !== undefined || undefined });
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function literalComputedPropertyKey(expression) {
|
|
147
|
+
const quoted = /^(['\"`])((?:\\.|(?!\1)[\s\S])*)\1$/.exec(expression);
|
|
148
|
+
if (quoted && !quoted[2].includes('${')) return quoted[2].replace(/\\([\\'\"`])/g, '$1');
|
|
149
|
+
return /^(?:0|[1-9]\d*)$/.test(expression) ? expression : undefined;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function normalizeOrderEvidenceText(value) { return String(value ?? '').replace(/\s+/g, ' ').trim(); }
|
|
153
|
+
function uniqueStrings(values) { return [...new Set((values ?? []).filter(Boolean).map(String))]; }
|
|
154
|
+
function compactRecord(record) { return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined && (!Array.isArray(value) || value.length > 0))); }
|
|
155
|
+
export { mutationTargetContextReasonCodes, mutationTargetOrderEvidence, mutationTargetSignatureEvidence };
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import { tryCatchOrderEvidence, tryFinallyOrderEvidence } from './semantic-import-runtime-try-finally-evidence.js';
|
|
2
|
+
import { conditionalExpressionEvidenceRecords } from './semantic-import-runtime-conditional-evidence.js';
|
|
3
|
+
import { exitCompletionOrderEvidence } from './semantic-import-runtime-exit-evidence.js';
|
|
4
|
+
import { controlTransferOrderEvidence, loopIterationOrderEvidence, switchDispatchOrderEvidence } from './semantic-import-runtime-switch-evidence.js';
|
|
5
|
+
import { importMetaHostContextEvidence } from './semantic-import-runtime-import-meta-evidence.js';
|
|
6
|
+
import { mutationTargetOrderEvidence, mutationTargetSignatureEvidence } from './semantic-import-runtime-mutation-evidence.js';
|
|
7
|
+
import { effectTargetOrderEvidence, effectTargetSignatureEvidence } from './semantic-import-runtime-effect-target-evidence.js';
|
|
8
|
+
import { reachabilityOrderEvidence } from './semantic-import-runtime-reachability-evidence.js';
|
|
9
|
+
import { throwOrderEvidenceRecords } from './semantic-import-runtime-throw-evidence.js';
|
|
10
|
+
import { promiseCombinatorEvidenceRecords } from './semantic-import-runtime-promise-combinator-evidence.js';
|
|
11
|
+
import { promiseChainEvidenceRecords } from './semantic-import-runtime-promise-chain-evidence.js';
|
|
12
|
+
function semanticFactOrderInfo(groups) {
|
|
13
|
+
const bySubject = new Map();
|
|
14
|
+
const info = new Map();
|
|
15
|
+
for (const group of groups) {
|
|
16
|
+
const fact = group.facts[0];
|
|
17
|
+
const key = [fact?.subjectId, group.sourcePath].join('\0');
|
|
18
|
+
const entries = bySubject.get(key) ?? [];
|
|
19
|
+
const previous = entries[entries.length - 1];
|
|
20
|
+
const entry = {
|
|
21
|
+
runtimeOrderIndex: entries.length + 1,
|
|
22
|
+
previousRegionKind: previous?.regionKind,
|
|
23
|
+
previousRuntimeKind: previous?.runtimeKind,
|
|
24
|
+
previousRuntimeKinds: previous?.runtimeKinds
|
|
25
|
+
};
|
|
26
|
+
info.set(group, entry);
|
|
27
|
+
entries.push({ regionKind: group.regionKind, runtimeKind: group.factKinds?.[0] ?? group.regionKind, runtimeKinds: group.factKinds });
|
|
28
|
+
bySubject.set(key, entries);
|
|
29
|
+
}
|
|
30
|
+
return info;
|
|
31
|
+
}
|
|
32
|
+
function semanticFactRuntimeOrderEvidence(sourceText, group, fact, spanInfo, orderInfo) {
|
|
33
|
+
const lineNumber = Number(group.line);
|
|
34
|
+
const lines = sourceLines(sourceText);
|
|
35
|
+
const line = lines[lineNumber - 1] ?? '';
|
|
36
|
+
const start = Math.max(0, Number(spanInfo?.span?.startColumn ?? 1) - 1);
|
|
37
|
+
const end = Math.max(start, Number(spanInfo?.span?.endColumn ?? start + 1) - 1);
|
|
38
|
+
const sameLineEvidence = sameLineRuntimeOrderEvidence(line, start, end);
|
|
39
|
+
const enclosingControlFlow = enclosingControlFlowEvidence(lines, lineNumber);
|
|
40
|
+
const controlFlowOrder = controlFlowOrderEvidence(line, lineNumber, group);
|
|
41
|
+
const tryCatchOrder = tryCatchOrderEvidence(lines, lineNumber, enclosingControlFlow);
|
|
42
|
+
const tryFinallyOrder = tryFinallyOrderEvidence(lines, lineNumber, enclosingControlFlow);
|
|
43
|
+
const switchDispatchOrder = switchDispatchOrderEvidence(lines, lineNumber), loopIterationOrder = loopIterationOrderEvidence(lines, lineNumber), controlTransferOrder = controlTransferOrderEvidence(lines, lineNumber), exitOrder = exitCompletionOrderEvidence(lines, lineNumber), reachabilityOrder = reachabilityOrderEvidence(lines, lineNumber), mutationTargetOrder = mutationTargetOrderEvidence(line, lineNumber, group, start, end), effectTargetOrder = effectTargetOrderEvidence(line, lineNumber, group, start, end, lines);
|
|
44
|
+
const evidence = compactRecord({
|
|
45
|
+
schema: 'frontier.lang.runtimeOrderEvidence.v1',
|
|
46
|
+
source: 'lexical-source-scan',
|
|
47
|
+
subjectId: fact?.subjectId,
|
|
48
|
+
runtimeScope: fact?.value?.runtimeScope, topLevelAwait: fact?.value?.topLevelAwait === true || undefined,
|
|
49
|
+
regionKind: group.regionKind,
|
|
50
|
+
runtimeKinds: group.factKinds,
|
|
51
|
+
line: lineNumber,
|
|
52
|
+
runtimeOrderIndex: orderInfo?.runtimeOrderIndex,
|
|
53
|
+
previousRegionKind: orderInfo?.previousRegionKind,
|
|
54
|
+
previousRuntimeKind: orderInfo?.previousRuntimeKind,
|
|
55
|
+
previousRuntimeKinds: orderInfo?.previousRuntimeKinds,
|
|
56
|
+
branchOrder: controlFlowOrder.branch,
|
|
57
|
+
loopOrder: controlFlowOrder.loop,
|
|
58
|
+
sameLineControlFlow: sameLineEvidence.controlFlow,
|
|
59
|
+
sameLineShortCircuit: sameLineEvidence.shortCircuit,
|
|
60
|
+
sameLineAwait: sameLineEvidence.await,
|
|
61
|
+
sameLineAwaitOrder: sameLineEvidence.awaitOrder,
|
|
62
|
+
sameLineOptionalChain: sameLineEvidence.optionalChain,
|
|
63
|
+
sameLineConditionalExpression: sameLineEvidence.conditionalExpression,
|
|
64
|
+
sameLinePromiseCombinator: sameLineEvidence.promiseCombinator,
|
|
65
|
+
sameLinePromiseChain: sameLineEvidence.promiseChain,
|
|
66
|
+
sameLineThrow: sameLineEvidence.throw,
|
|
67
|
+
sameLineThrowOrder: sameLineEvidence.throwOrder,
|
|
68
|
+
enclosingControlFlow: enclosingControlFlow.length ? enclosingControlFlow : undefined,
|
|
69
|
+
switchDispatchOrder: switchDispatchOrder.length ? switchDispatchOrder : undefined, loopIterationOrder: loopIterationOrder.length ? loopIterationOrder : undefined, controlTransferOrder: controlTransferOrder.length ? controlTransferOrder : undefined, exitOrder: exitOrder.length ? exitOrder : undefined, reachabilityOrder: reachabilityOrder.length ? reachabilityOrder : undefined,
|
|
70
|
+
mutationTargetOrder: mutationTargetOrder.length ? mutationTargetOrder : undefined, effectTargetOrder: effectTargetOrder.length ? effectTargetOrder : undefined,
|
|
71
|
+
tryCatchOrder: tryCatchOrder.length ? tryCatchOrder : undefined,
|
|
72
|
+
tryFinallyOrder: tryFinallyOrder.length ? tryFinallyOrder : undefined
|
|
73
|
+
});
|
|
74
|
+
return importMetaHostContextEvidence(String(line).slice(start, end), evidence);
|
|
75
|
+
}
|
|
76
|
+
function semanticFactRuntimeOrderSignatureEvidence(evidence) {
|
|
77
|
+
return compactRecord({
|
|
78
|
+
previousRegionKind: evidence?.previousRegionKind,
|
|
79
|
+
previousRuntimeKind: evidence?.previousRuntimeKind,
|
|
80
|
+
previousRuntimeKinds: evidence?.previousRuntimeKinds,
|
|
81
|
+
branchOrder: evidence?.branchOrder,
|
|
82
|
+
loopOrder: evidence?.loopOrder,
|
|
83
|
+
sameLineShortCircuit: evidence?.sameLineShortCircuit,
|
|
84
|
+
sameLineAwait: evidence?.sameLineAwait,
|
|
85
|
+
sameLineAwaitOrder: evidence?.sameLineAwaitOrder,
|
|
86
|
+
sameLineOptionalChain: evidence?.sameLineOptionalChain,
|
|
87
|
+
sameLineConditionalExpression: evidence?.sameLineConditionalExpression,
|
|
88
|
+
sameLinePromiseCombinator: evidence?.sameLinePromiseCombinator,
|
|
89
|
+
sameLinePromiseChain: evidence?.sameLinePromiseChain,
|
|
90
|
+
sameLineThrow: evidence?.sameLineThrow,
|
|
91
|
+
sameLineThrowOrder: evidence?.sameLineThrowOrder,
|
|
92
|
+
hostContext: evidence?.hostContext, importMetaHostContext: evidence?.importMetaHostContext, importMetaMemberNames: evidence?.importMetaMemberNames,
|
|
93
|
+
switchDispatchOrder: evidence?.switchDispatchOrder, loopIterationOrder: evidence?.loopIterationOrder, controlTransferOrder: evidence?.controlTransferOrder, exitOrder: evidence?.exitOrder?.map(({ line: _line, ...record }) => record), reachabilityOrder: evidence?.reachabilityOrder?.map(({ completionLine: _completionLine, targetLine: _targetLine, ...record }) => record),
|
|
94
|
+
mutationTargetOrder: evidence?.mutationTargetOrder?.map(mutationTargetSignatureEvidence), effectTargetOrder: evidence?.effectTargetOrder?.map(effectTargetSignatureEvidence),
|
|
95
|
+
tryCatchOrder: evidence?.tryCatchOrder,
|
|
96
|
+
tryFinallyOrder: evidence?.tryFinallyOrder
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function sameLineRuntimeOrderEvidence(line, start, end) {
|
|
100
|
+
const prefix = String(line ?? '').slice(0, start);
|
|
101
|
+
const controlFlow = controlHeadEvidenceRecords(prefix), shortCircuit = shortCircuitEvidenceRecords(prefix), awaitOrder = awaitOrderEvidenceRecords(prefix);
|
|
102
|
+
const optionalChain = optionalChainEvidenceRecords(line, start, end), conditionalExpression = conditionalExpressionEvidenceRecords(line, start, end);
|
|
103
|
+
const promiseCombinator = promiseCombinatorEvidenceRecords(line, start, end), promiseChain = promiseChainEvidenceRecords(line, start, end), throwOrder = throwOrderEvidenceRecords(line, start, end);
|
|
104
|
+
return {
|
|
105
|
+
controlFlow: controlFlow.length ? controlFlow : undefined,
|
|
106
|
+
shortCircuit: shortCircuit.length ? shortCircuit : undefined,
|
|
107
|
+
await: awaitOrder.length ? true : undefined,
|
|
108
|
+
awaitOrder: awaitOrder.length ? awaitOrder : undefined,
|
|
109
|
+
optionalChain: optionalChain.length ? optionalChain : undefined,
|
|
110
|
+
conditionalExpression: conditionalExpression.length ? conditionalExpression : undefined,
|
|
111
|
+
promiseCombinator: promiseCombinator.length ? promiseCombinator : undefined,
|
|
112
|
+
promiseChain: promiseChain.length ? promiseChain : undefined,
|
|
113
|
+
throw: throwOrder.length ? true : /\bthrow\b/.test(prefix) || undefined,
|
|
114
|
+
throwOrder: throwOrder.length ? throwOrder : undefined
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function controlFlowOrderEvidence(line, lineNumber, group) {
|
|
118
|
+
if (group?.regionKind !== 'controlFlow') return {};
|
|
119
|
+
const kinds = new Set(group.factKinds ?? []);
|
|
120
|
+
const records = controlHeadEvidenceRecords(line)
|
|
121
|
+
.filter((record) => (record.kind === 'branch' && kinds.has('branch'))
|
|
122
|
+
|| (record.kind === 'loop' && kinds.has('loop')))
|
|
123
|
+
.map((record) => compactRecord({ ...record, line: lineNumber }));
|
|
124
|
+
return {
|
|
125
|
+
branch: records.filter((record) => record.kind === 'branch'),
|
|
126
|
+
loop: records.filter((record) => record.kind === 'loop')
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function optionalChainEvidenceRecords(line, start, end) {
|
|
131
|
+
const expression = String(line ?? '').slice(Math.max(0, start), Math.max(start, end));
|
|
132
|
+
const matches = [...expression.matchAll(/\?\.(?:\s*\(|\s*[A-Za-z_$][\w$]*|\s*\[)/g)];
|
|
133
|
+
return matches.map((match, index) => compactRecord({
|
|
134
|
+
kind: match[0].includes('(') ? 'optional-call' : 'optional-chain',
|
|
135
|
+
ordinal: index + 1,
|
|
136
|
+
text: normalizeOrderEvidenceText(expression.slice(Math.max(0, match.index - 24), match.index + match[0].length + 24))
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function awaitOrderEvidenceRecords(prefix) {
|
|
141
|
+
const text = String(prefix ?? '');
|
|
142
|
+
const tokens = awaitTokenIndexes(text);
|
|
143
|
+
if (!tokens.length) return [];
|
|
144
|
+
const start = statementStartBefore(text, tokens[tokens.length - 1]);
|
|
145
|
+
return tokens.filter((index) => index >= start).slice(-3)
|
|
146
|
+
.map((index, ordinal, items) => compactRecord({ kind: 'await', ordinal: ordinal + 1, text: normalizeOrderEvidenceText(text.slice(index, items[ordinal + 1] ?? text.length)) }))
|
|
147
|
+
.filter((record) => record.text);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function awaitTokenIndexes(text) {
|
|
151
|
+
const indexes = [];
|
|
152
|
+
let quote;
|
|
153
|
+
let escaped = false;
|
|
154
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
155
|
+
const char = text[index];
|
|
156
|
+
if (quote) {
|
|
157
|
+
if (escaped) escaped = false;
|
|
158
|
+
else if (char === '\\') escaped = true;
|
|
159
|
+
else if (char === quote) quote = undefined;
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (char === '\'' || char === '"' || char === '`') { quote = char; continue; }
|
|
163
|
+
if (text.slice(index, index + 5) === 'await' && !isIdentifierPart(text[index - 1]) && !isIdentifierPart(text[index + 5])) indexes.push(index);
|
|
164
|
+
}
|
|
165
|
+
return indexes;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function shortCircuitEvidenceRecords(prefix) {
|
|
169
|
+
const text = String(prefix ?? '');
|
|
170
|
+
const operators = shortCircuitOperators(text);
|
|
171
|
+
if (!operators.length) return [];
|
|
172
|
+
const last = operators[operators.length - 1];
|
|
173
|
+
const start = statementStartBefore(text, last.index);
|
|
174
|
+
const statementOperators = operators.filter((operator) => operator.index >= start).map((operator) => operator.operator);
|
|
175
|
+
const guardText = normalizeShortCircuitGuardText(text.slice(start));
|
|
176
|
+
return guardText ? [{ kind: 'short-circuit', operators: uniqueStrings(statementOperators), guardText }] : [];
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function shortCircuitOperators(text) {
|
|
180
|
+
const operators = [];
|
|
181
|
+
let parenDepth = 0;
|
|
182
|
+
let bracketDepth = 0;
|
|
183
|
+
let quote;
|
|
184
|
+
let escaped = false;
|
|
185
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
186
|
+
const char = text[index];
|
|
187
|
+
const next = text[index + 1];
|
|
188
|
+
if (quote) {
|
|
189
|
+
if (escaped) escaped = false;
|
|
190
|
+
else if (char === '\\') escaped = true;
|
|
191
|
+
else if (char === quote) quote = undefined;
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
if (char === '\'' || char === '"' || char === '`') {
|
|
195
|
+
quote = char;
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
if (char === '(') parenDepth += 1;
|
|
199
|
+
else if (char === ')') parenDepth = Math.max(0, parenDepth - 1);
|
|
200
|
+
else if (char === '[') bracketDepth += 1;
|
|
201
|
+
else if (char === ']') bracketDepth = Math.max(0, bracketDepth - 1);
|
|
202
|
+
if (parenDepth || bracketDepth) continue;
|
|
203
|
+
const pair = `${char}${next}`;
|
|
204
|
+
if (pair === '&&' || pair === '||' || pair === '??') {
|
|
205
|
+
operators.push({ operator: text[index + 2] === '=' ? `${pair}=` : pair, index });
|
|
206
|
+
index += 1;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return operators;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function statementStartBefore(text, endIndex) {
|
|
213
|
+
for (let index = endIndex - 1; index >= 0; index -= 1) {
|
|
214
|
+
if (text[index] === ';' || text[index] === '{' || text[index] === '}' || text[index] === '\n' || text[index] === '\r') return index + 1;
|
|
215
|
+
}
|
|
216
|
+
return 0;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function normalizeShortCircuitGuardText(value) {
|
|
220
|
+
return normalizeOrderEvidenceText(String(value ?? '')
|
|
221
|
+
.replace(/\s*(?:&&|\|\||\?\?)=?\s*$/, '')
|
|
222
|
+
.replace(/^(?:return|throw|yield|await)\s+/, ''));
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function enclosingControlFlowEvidence(lines, lineNumber) {
|
|
226
|
+
if (!Array.isArray(lines) || lineNumber <= 1) return [];
|
|
227
|
+
const stack = [];
|
|
228
|
+
let depth = 0;
|
|
229
|
+
for (let index = 0; index < lineNumber - 1; index += 1) {
|
|
230
|
+
const line = lines[index] ?? '';
|
|
231
|
+
const leadingClose = leadingCloseBraceCount(line);
|
|
232
|
+
if (leadingClose) {
|
|
233
|
+
depth = Math.max(0, depth - leadingClose);
|
|
234
|
+
while (stack.length && stack[stack.length - 1].depth > depth) stack.pop();
|
|
235
|
+
}
|
|
236
|
+
const heads = controlHeadEvidenceRecords(line);
|
|
237
|
+
const opens = openBraceCount(line);
|
|
238
|
+
const closes = closeBraceCount(line) - leadingClose;
|
|
239
|
+
if (heads.length && opens > 0) {
|
|
240
|
+
stack.push({ line: index + 1, depth: depth + 1, kind: heads[heads.length - 1].kind, text: heads[heads.length - 1].text });
|
|
241
|
+
}
|
|
242
|
+
depth = Math.max(0, depth + opens - Math.max(0, closes));
|
|
243
|
+
while (stack.length && stack[stack.length - 1].depth > depth) stack.pop();
|
|
244
|
+
}
|
|
245
|
+
return stack.slice(-3).map(({ depth: _depth, ...entry }) => entry);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function controlHeadEvidenceRecords(line) {
|
|
249
|
+
const text = String(line ?? '');
|
|
250
|
+
const records = [];
|
|
251
|
+
const branch = parenthesizedControlHead(text, /\b(?:else\s+)?if\b/g, 'branch') ?? parenthesizedControlHead(text, /\bswitch\b/g, 'branch') ?? caseControlHead(text) ?? keywordControlHead(text, /\belse\b/g, 'branch');
|
|
252
|
+
const loop = parenthesizedControlHead(text, /\bfor\b/g, 'loop') ?? parenthesizedControlHead(text, /\bwhile\b/g, 'loop') ?? keywordControlHead(text, /\bdo\b/g, 'loop');
|
|
253
|
+
const exception = parenthesizedControlHead(text, /\bcatch\b/g, 'exception') ?? keywordControlHead(text, /\b(?:try|finally)\b/g, 'exception');
|
|
254
|
+
for (const record of [branch, loop, exception].filter(Boolean)) records.push(record);
|
|
255
|
+
return records;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function parenthesizedControlHead(line, pattern, kind) {
|
|
259
|
+
for (const match of line.matchAll(pattern)) {
|
|
260
|
+
const open = line.indexOf('(', match.index);
|
|
261
|
+
const close = matchingParenIndex(line, open);
|
|
262
|
+
if (open >= 0 && close !== undefined) return { kind, text: normalizeOrderEvidenceText(line.slice(match.index, close + 1)) };
|
|
263
|
+
}
|
|
264
|
+
return undefined;
|
|
265
|
+
}
|
|
266
|
+
function keywordControlHead(line, pattern, kind) { const match = pattern.exec(line); return match ? { kind, text: normalizeOrderEvidenceText(match[0]) } : undefined; }
|
|
267
|
+
function caseControlHead(line) {
|
|
268
|
+
const match = /\b(?:case|default)\b/.exec(line);
|
|
269
|
+
if (!match) return undefined;
|
|
270
|
+
const colon = line.indexOf(':', match.index);
|
|
271
|
+
return { kind: 'branch', text: normalizeOrderEvidenceText(line.slice(match.index, colon === -1 ? statementEnd(line, match.index) : colon + 1)) };
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function normalizeOrderEvidenceText(value) { return String(value ?? '').replace(/\s+/g, ' ').trim(); }
|
|
275
|
+
function uniqueStrings(values) { return [...new Set((values ?? []).filter(Boolean).map(String))]; }
|
|
276
|
+
function sourceLines(sourceText) { return typeof sourceText === 'string' ? sourceText.split(/\r\n|\n|\r/) : []; }
|
|
277
|
+
function leadingCloseBraceCount(line) { const match = String(line ?? '').match(/^\s*}+/); return match ? match[0].replace(/\s/g, '').length : 0; }
|
|
278
|
+
function openBraceCount(line) { return countCharsOutsideStrings(line, '{'); }
|
|
279
|
+
function closeBraceCount(line) { return countCharsOutsideStrings(line, '}'); }
|
|
280
|
+
function isIdentifierPart(char) { return /[A-Za-z0-9_$]/.test(char ?? ''); }
|
|
281
|
+
function countCharsOutsideStrings(line, target) {
|
|
282
|
+
let count = 0;
|
|
283
|
+
let quote;
|
|
284
|
+
let escaped = false;
|
|
285
|
+
for (const char of String(line ?? '')) {
|
|
286
|
+
if (quote) {
|
|
287
|
+
if (escaped) escaped = false;
|
|
288
|
+
else if (char === '\\') escaped = true;
|
|
289
|
+
else if (char === quote) quote = undefined;
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
if (char === '\'' || char === '"' || char === '`') { quote = char; continue; }
|
|
293
|
+
if (char === target) count += 1;
|
|
294
|
+
}
|
|
295
|
+
return count;
|
|
296
|
+
}
|
|
297
|
+
function statementEnd(line, start) { const semicolon = line.indexOf(';', start); return semicolon === -1 ? line.length : semicolon + 1; }
|
|
298
|
+
function matchingParenIndex(line, open) {
|
|
299
|
+
if (open < 0) return undefined;
|
|
300
|
+
let depth = 0;
|
|
301
|
+
let quote;
|
|
302
|
+
let escaped = false;
|
|
303
|
+
for (let index = open; index < line.length; index += 1) {
|
|
304
|
+
const char = line[index];
|
|
305
|
+
if (quote) {
|
|
306
|
+
if (escaped) escaped = false;
|
|
307
|
+
else if (char === '\\') escaped = true;
|
|
308
|
+
else if (char === quote) quote = undefined;
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
if (char === '\'' || char === '"' || char === '`') { quote = char; continue; }
|
|
312
|
+
if (char === '(') depth += 1;
|
|
313
|
+
else if (char === ')' && --depth === 0) return index;
|
|
314
|
+
}
|
|
315
|
+
return undefined;
|
|
316
|
+
}
|
|
317
|
+
function compactRecord(record) { return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined && (!Array.isArray(value) || value.length > 0))); }
|
|
318
|
+
export { semanticFactOrderInfo, semanticFactRuntimeOrderEvidence, semanticFactRuntimeOrderSignatureEvidence };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
function promiseChainEvidenceRecords(line, start, end) {
|
|
2
|
+
const text = String(line ?? '');
|
|
3
|
+
const statement = statementAround(text, start, end);
|
|
4
|
+
const steps = promiseChainSteps(text, statement.start, statement.end);
|
|
5
|
+
if (!steps.length || start < statement.start || end > statement.end) return [];
|
|
6
|
+
const methodNames = steps.map((step) => step.methodName);
|
|
7
|
+
const handlerStep = steps.find((step) => start >= step.open + 1 && end <= step.close);
|
|
8
|
+
return [compactRecord({
|
|
9
|
+
kind: 'promise-chain',
|
|
10
|
+
regionRole: handlerStep ? 'chain-handler' : end <= steps[0].dot ? 'source-promise' : 'chain-expression',
|
|
11
|
+
handlerMethodName: handlerStep?.methodName,
|
|
12
|
+
handlerStepOrdinal: handlerStep ? steps.indexOf(handlerStep) + 1 : undefined,
|
|
13
|
+
chainMethods: methodNames,
|
|
14
|
+
stepCount: steps.length,
|
|
15
|
+
hasThen: methodNames.includes('then') || undefined,
|
|
16
|
+
hasCatch: methodNames.includes('catch') || undefined,
|
|
17
|
+
hasFinally: methodNames.includes('finally') || undefined,
|
|
18
|
+
chainText: normalizeOrderEvidenceText(text.slice(statement.start, statement.end)),
|
|
19
|
+
steps: steps.map((step, index) => compactRecord({
|
|
20
|
+
ordinal: index + 1,
|
|
21
|
+
methodName: step.methodName,
|
|
22
|
+
handlerText: normalizeOrderEvidenceText(text.slice(step.open + 1, step.close)),
|
|
23
|
+
handlerOrdinal: index + 1
|
|
24
|
+
})),
|
|
25
|
+
regionWithinPromiseChain: true,
|
|
26
|
+
handlerExecutionEquivalenceClaim: false,
|
|
27
|
+
runtimeEquivalenceClaim: false,
|
|
28
|
+
semanticEquivalenceClaim: false
|
|
29
|
+
})];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function promiseChainContextReasonCodes(record) {
|
|
33
|
+
return uniqueStrings([
|
|
34
|
+
'runtime-order-promise-chain-merge-requires-handler-order-evidence',
|
|
35
|
+
record?.hasCatch ? 'runtime-order-promise-chain-merge-requires-rejection-flow-evidence' : undefined,
|
|
36
|
+
record?.hasFinally ? 'runtime-order-promise-chain-merge-requires-finalizer-evidence' : undefined,
|
|
37
|
+
record?.handlerExecutionEquivalenceClaim === false ? 'runtime-order-promise-chain-handler-equivalence-not-proven' : undefined,
|
|
38
|
+
record?.runtimeEquivalenceClaim === false ? 'runtime-order-promise-chain-runtime-equivalence-not-proven' : undefined
|
|
39
|
+
]);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function promiseChainSteps(text, start, end) {
|
|
43
|
+
const steps = [];
|
|
44
|
+
const state = scanState();
|
|
45
|
+
for (let index = start; index < end; index += 1) {
|
|
46
|
+
const char = text[index], next = text[index + 1];
|
|
47
|
+
if (advanceIgnoredState(state, char, next)) { if (state.skipNext) { state.skipNext = false; index += 1; } continue; }
|
|
48
|
+
if (char !== '.') continue;
|
|
49
|
+
const methodStart = skipSpaces(text, index + 1);
|
|
50
|
+
const methodName = chainMethodNameAt(text, methodStart);
|
|
51
|
+
if (!methodName) continue;
|
|
52
|
+
const open = skipSpaces(text, methodStart + methodName.length);
|
|
53
|
+
if (text[open] !== '(') continue;
|
|
54
|
+
const close = matchingIndex(text, open, '(', ')');
|
|
55
|
+
if (close === undefined || close > end) continue;
|
|
56
|
+
steps.push({ methodName, dot: index, open, close });
|
|
57
|
+
index = close;
|
|
58
|
+
}
|
|
59
|
+
return steps.length && steps[0].dot > start ? steps : [];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function statementAround(text, start, end) {
|
|
63
|
+
return { start: statementStartBefore(text, start), end: statementEndAfter(text, end) };
|
|
64
|
+
}
|
|
65
|
+
function statementStartBefore(text, endIndex) {
|
|
66
|
+
for (let index = endIndex - 1; index >= 0; index -= 1) if (';{}\n\r'.includes(text[index])) return index + 1;
|
|
67
|
+
return 0;
|
|
68
|
+
}
|
|
69
|
+
function statementEndAfter(text, startIndex) {
|
|
70
|
+
const semi = text.indexOf(';', startIndex);
|
|
71
|
+
return semi >= 0 ? semi : text.length;
|
|
72
|
+
}
|
|
73
|
+
function chainMethodNameAt(text, index) {
|
|
74
|
+
for (const name of ['finally', 'catch', 'then']) if (wordAt(text, index, name)) return name;
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
function matchingIndex(text, open, openChar, closeChar) {
|
|
78
|
+
const state = scanState();
|
|
79
|
+
let depth = 0;
|
|
80
|
+
for (let index = open; index < text.length; index += 1) {
|
|
81
|
+
const char = text[index], next = text[index + 1];
|
|
82
|
+
if (advanceIgnoredState(state, char, next)) { if (state.skipNext) { state.skipNext = false; index += 1; } continue; }
|
|
83
|
+
if (char === openChar) depth += 1;
|
|
84
|
+
else if (char === closeChar && --depth === 0) return index;
|
|
85
|
+
}
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
function advanceIgnoredState(state, char, next) {
|
|
89
|
+
if (state.blockComment) { if (char === '*' && next === '/') { state.blockComment = false; state.skipNext = true; } return true; }
|
|
90
|
+
if (state.quote) { if (state.escaped) state.escaped = false; else if (char === '\\') state.escaped = true; else if (char === state.quote) state.quote = undefined; return true; }
|
|
91
|
+
if (char === '/' && next === '*') { state.blockComment = true; state.skipNext = true; return true; }
|
|
92
|
+
if (char === '\'' || char === '"' || char === '`') { state.quote = char; return true; }
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
function wordAt(text, index, word) { return text.slice(index, index + word.length) === word && !isIdentifierPart(text[index - 1]) && !isIdentifierPart(text[index + word.length]); }
|
|
96
|
+
function skipSpaces(text, index) { let cursor = index; while (/\s/.test(text[cursor] ?? '')) cursor += 1; return cursor; }
|
|
97
|
+
function scanState() { return {}; }
|
|
98
|
+
function normalizeOrderEvidenceText(value) { return String(value ?? '').replace(/\s+/g, ' ').trim(); }
|
|
99
|
+
function isIdentifierPart(char) { return /[A-Za-z0-9_$]/.test(char ?? ''); }
|
|
100
|
+
function uniqueStrings(values) { return [...new Set((values ?? []).filter(Boolean).map(String))]; }
|
|
101
|
+
function compactRecord(record) { return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined && (!Array.isArray(value) || value.length > 0))); }
|
|
102
|
+
|
|
103
|
+
export { promiseChainContextReasonCodes, promiseChainEvidenceRecords };
|