@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,232 @@
|
|
|
1
|
+
import { hashSemanticValue } from '@shapeshift-labs/frontier-lang-kernel';
|
|
2
|
+
|
|
3
|
+
export function moduleImportAttributeMetadata(node) {
|
|
4
|
+
const entries = [
|
|
5
|
+
...attributeListEntries(node?.attributes),
|
|
6
|
+
...attributeListEntries(node?.assertions),
|
|
7
|
+
...assertClauseEntries(node?.assertClause),
|
|
8
|
+
...importCallOptionEntries(node?.options),
|
|
9
|
+
...importCallOptionEntries(Array.isArray(node?.arguments) ? node.arguments[1] : undefined)
|
|
10
|
+
];
|
|
11
|
+
return importAttributeMetadataFromEntries(entries, hasImportAttributeSyntax(node));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function importAttributeMetadataFromSource(source) {
|
|
15
|
+
const scan = scanImportAttributeSource(source);
|
|
16
|
+
return importAttributeMetadataFromEntries(scan.entries, scan.syntaxPresent);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function importAttributeMetadataFromEntries(entries, syntaxPresent) {
|
|
20
|
+
const normalized = normalizeEntries(entries);
|
|
21
|
+
if (!normalized.length && syntaxPresent) return { hasImportAttributes: true };
|
|
22
|
+
if (!normalized.length) return {};
|
|
23
|
+
const keys = [...new Set(normalized.map((entry) => entry.key))].sort();
|
|
24
|
+
return {
|
|
25
|
+
hasImportAttributes: true,
|
|
26
|
+
importAttributeCount: normalized.length,
|
|
27
|
+
importAttributeKeys: keys,
|
|
28
|
+
importAttributeHash: hashSemanticValue(normalized.map((entry) => [entry.key, entry.value])),
|
|
29
|
+
importAttributes: normalized
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function scanImportAttributeSource(source) {
|
|
34
|
+
const text = String(source ?? '');
|
|
35
|
+
const clauseBodies = attributeClauseBodies(text);
|
|
36
|
+
const optionBodies = ['with', 'assert'].flatMap((key) => attributeOptionBodies(text, key));
|
|
37
|
+
return {
|
|
38
|
+
syntaxPresent: clauseBodies.length > 0 || optionBodies.length > 0,
|
|
39
|
+
entries: [...clauseBodies, ...optionBodies].flatMap((body) => sourceAttributeEntries(body))
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function attributeClauseBodies(source) {
|
|
44
|
+
const bodies = [];
|
|
45
|
+
const pattern = /\b(?:with|assert)\s*\{/g;
|
|
46
|
+
for (let match = pattern.exec(source); match; match = pattern.exec(source)) {
|
|
47
|
+
const open = source.indexOf('{', match.index);
|
|
48
|
+
const close = matchingBraceIndex(source, open);
|
|
49
|
+
if (close >= 0) {
|
|
50
|
+
bodies.push(source.slice(open + 1, close));
|
|
51
|
+
pattern.lastIndex = close + 1;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return bodies;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function attributeOptionBodies(source, key) {
|
|
58
|
+
const bodies = [];
|
|
59
|
+
const pattern = new RegExp(`(?:^|[,{])\\s*(?:${key}|["']${key}["'])\\s*:\\s*\\{`, 'g');
|
|
60
|
+
for (let match = pattern.exec(source); match; match = pattern.exec(source)) {
|
|
61
|
+
const open = pattern.lastIndex - 1;
|
|
62
|
+
const close = matchingBraceIndex(source, open);
|
|
63
|
+
if (close >= 0) {
|
|
64
|
+
bodies.push(source.slice(open + 1, close));
|
|
65
|
+
pattern.lastIndex = close + 1;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return bodies;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function matchingBraceIndex(source, open) {
|
|
72
|
+
if (open < 0) return -1;
|
|
73
|
+
let depth = 0, quote = '', escaped = false;
|
|
74
|
+
for (let index = open; index < source.length; index += 1) {
|
|
75
|
+
const char = source[index];
|
|
76
|
+
if (quote) {
|
|
77
|
+
if (escaped) escaped = false;
|
|
78
|
+
else if (char === '\\') escaped = true;
|
|
79
|
+
else if (char === quote) quote = '';
|
|
80
|
+
} else if (char === '"' || char === "'") quote = char;
|
|
81
|
+
else if (char === '{') depth += 1;
|
|
82
|
+
else if (char === '}' && --depth === 0) return index;
|
|
83
|
+
}
|
|
84
|
+
return -1;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function sourceAttributeEntries(body) {
|
|
88
|
+
return splitTopLevelCommas(body).map((part) => {
|
|
89
|
+
const colon = part.indexOf(':');
|
|
90
|
+
if (colon < 0) return undefined;
|
|
91
|
+
const key = sourcePropertyKey(part.slice(0, colon).trim());
|
|
92
|
+
const value = sourceStringLiteral(part.slice(colon + 1).trim());
|
|
93
|
+
return key && value !== undefined ? { key, value } : undefined;
|
|
94
|
+
}).filter(Boolean);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function splitTopLevelCommas(source) {
|
|
98
|
+
const parts = [];
|
|
99
|
+
let start = 0, quote = '', escaped = false;
|
|
100
|
+
for (let index = 0; index < source.length; index += 1) {
|
|
101
|
+
const char = source[index];
|
|
102
|
+
if (quote) {
|
|
103
|
+
if (escaped) escaped = false;
|
|
104
|
+
else if (char === '\\') escaped = true;
|
|
105
|
+
else if (char === quote) quote = '';
|
|
106
|
+
} else if (char === '"' || char === "'") quote = char;
|
|
107
|
+
else if (char === ',') {
|
|
108
|
+
parts.push(source.slice(start, index));
|
|
109
|
+
start = index + 1;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
parts.push(source.slice(start));
|
|
113
|
+
return parts;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function sourcePropertyKey(text) {
|
|
117
|
+
return sourceStringLiteral(text) ?? text.match(/^[A-Za-z_$][\w$]*$/)?.[0];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function sourceStringLiteral(text) {
|
|
121
|
+
const quote = text[0];
|
|
122
|
+
if (quote !== '"' && quote !== "'") return undefined;
|
|
123
|
+
let value = '', escaped = false;
|
|
124
|
+
for (let index = 1; index < text.length; index += 1) {
|
|
125
|
+
const char = text[index];
|
|
126
|
+
if (escaped) {
|
|
127
|
+
value += decodeEscape(char);
|
|
128
|
+
escaped = false;
|
|
129
|
+
} else if (char === '\\') escaped = true;
|
|
130
|
+
else if (char === quote) return value;
|
|
131
|
+
else value += char;
|
|
132
|
+
}
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function decodeEscape(char) {
|
|
137
|
+
return ({ n: '\n', r: '\r', t: '\t', b: '\b', f: '\f', v: '\v', 0: '\0' })[char] ?? char;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function moduleImportAttributeEdgeFields(metadata) {
|
|
141
|
+
return compactRecord({
|
|
142
|
+
hasImportAttributes: metadata?.hasImportAttributes,
|
|
143
|
+
importAttributeCount: metadata?.importAttributeCount,
|
|
144
|
+
importAttributeKeys: metadata?.importAttributeKeys,
|
|
145
|
+
importAttributeHash: metadata?.importAttributeHash,
|
|
146
|
+
importAttributes: metadata?.importAttributes
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function attributeListEntries(list) {
|
|
151
|
+
const entries = Array.isArray(list) ? list : Array.isArray(list?.elements) ? list.elements : [];
|
|
152
|
+
return entries.map((entry) => attributeEntry(entry)).filter(Boolean);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function assertClauseEntries(assertClause) {
|
|
156
|
+
return attributeListEntries(assertClause?.elements);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function attributeEntry(entry) {
|
|
160
|
+
const key = propertyKeyName(entry?.key ?? entry?.name);
|
|
161
|
+
const value = literalString(entry?.value ?? entry?.initializer);
|
|
162
|
+
return key && value !== undefined ? { key, value } : undefined;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function importCallOptionEntries(options) {
|
|
166
|
+
const object = objectProperties(options);
|
|
167
|
+
if (!object.length) return [];
|
|
168
|
+
const attributes = [];
|
|
169
|
+
for (const property of object) {
|
|
170
|
+
const key = propertyKeyName(property.key ?? property.name);
|
|
171
|
+
if (key !== 'with' && key !== 'assert') continue;
|
|
172
|
+
for (const nested of objectProperties(property.value ?? property.initializer)) {
|
|
173
|
+
const nestedKey = propertyKeyName(nested.key ?? nested.name);
|
|
174
|
+
const nestedValue = literalString(nested.value ?? nested.initializer);
|
|
175
|
+
if (nestedKey && nestedValue !== undefined) attributes.push({ key: nestedKey, value: nestedValue });
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return attributes;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function objectProperties(node) {
|
|
182
|
+
if (!node) return [];
|
|
183
|
+
if (Array.isArray(node.properties)) return node.properties;
|
|
184
|
+
if (typeof node.with === 'object') return [{ key: { name: 'with' }, value: node.with }];
|
|
185
|
+
if (typeof node.assert === 'object') return [{ key: { name: 'assert' }, value: node.assert }];
|
|
186
|
+
return [];
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function propertyKeyName(node) {
|
|
190
|
+
if (!node) return undefined;
|
|
191
|
+
if (typeof node.name === 'string') return node.name;
|
|
192
|
+
if (typeof node.text === 'string') return node.text;
|
|
193
|
+
if (typeof node.value === 'string') return node.value;
|
|
194
|
+
if (typeof node.escapedText === 'string') return node.escapedText;
|
|
195
|
+
return undefined;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function literalString(node) {
|
|
199
|
+
if (!node) return undefined;
|
|
200
|
+
if (typeof node.value === 'string') return node.value;
|
|
201
|
+
if (typeof node.text === 'string') return node.text;
|
|
202
|
+
if (typeof node.escapedText === 'string') return node.escapedText;
|
|
203
|
+
return undefined;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function normalizeEntries(entries) {
|
|
207
|
+
const seen = new Set();
|
|
208
|
+
return entries
|
|
209
|
+
.filter((entry) => entry?.key && entry.value !== undefined)
|
|
210
|
+
.map((entry) => ({ key: entry.key, value: entry.value }))
|
|
211
|
+
.sort((left, right) => left.key.localeCompare(right.key) || left.value.localeCompare(right.value))
|
|
212
|
+
.filter((entry) => {
|
|
213
|
+
const id = `${entry.key}\0${entry.value}`;
|
|
214
|
+
if (seen.has(id)) return false;
|
|
215
|
+
seen.add(id);
|
|
216
|
+
return true;
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function hasImportAttributeSyntax(node) {
|
|
221
|
+
return Boolean(
|
|
222
|
+
node?.attributes
|
|
223
|
+
|| node?.assertions
|
|
224
|
+
|| node?.assertClause
|
|
225
|
+
|| node?.options
|
|
226
|
+
|| (Array.isArray(node?.arguments) && node.arguments.length > 1)
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function compactRecord(record) {
|
|
231
|
+
return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined));
|
|
232
|
+
}
|
|
@@ -86,6 +86,9 @@ export function projectSemanticEditScriptToSource(input = {}) {
|
|
|
86
86
|
alreadyAppliedEditCount: deduped.edits.filter((edit) => edit.alreadyApplied).length,
|
|
87
87
|
dedupedEditCount: deduped.skippedOperationIds.length,
|
|
88
88
|
anchorMode: headSymbols.length ? 'javascript-like-symbols' : 'offsets',
|
|
89
|
+
structuralDiffId: script.structuralDiff?.id,
|
|
90
|
+
structuralDiffStatus: script.structuralDiff?.admission?.status,
|
|
91
|
+
structuralDiffSummary: script.structuralDiff?.summary,
|
|
89
92
|
...input.metadata
|
|
90
93
|
})
|
|
91
94
|
};
|
|
@@ -291,7 +294,11 @@ function semanticEditIdentity(operation) {
|
|
|
291
294
|
semanticKey: operation.semanticKey,
|
|
292
295
|
semanticIdentityHash: operation.semanticIdentityHash,
|
|
293
296
|
sourceIdentityHash: operation.sourceIdentityHash,
|
|
294
|
-
operationContentHash: operation.operationContentHash
|
|
297
|
+
operationContentHash: operation.operationContentHash,
|
|
298
|
+
structuralEditId: operation.structuralEdit?.id,
|
|
299
|
+
structuralEditHash: operation.structuralEdit?.hash,
|
|
300
|
+
structuralKind: operation.structuralEdit?.structuralKind,
|
|
301
|
+
structuralActions: operation.structuralEdit?.actions
|
|
295
302
|
});
|
|
296
303
|
}
|
|
297
304
|
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { hashSemanticValue } from '@shapeshift-labs/frontier-lang-kernel';
|
|
2
|
+
import { idFragment, uniqueStrings } from '../../native-import-utils.js';
|
|
3
|
+
import { maskNonCode } from '../../js-ts-semantic-scope-use-def-scan.js';
|
|
4
|
+
|
|
5
|
+
function classStaticBlockRuntimeRecordsForImport(imported, semanticIndex, publicKeys = new Set()) {
|
|
6
|
+
const sourceText = nativeImportSourceText(imported);
|
|
7
|
+
if (typeof sourceText !== 'string' || !sourceText.includes('static')) return [];
|
|
8
|
+
const sourcePath = imported?.sourcePath ?? imported?.nativeSource?.sourcePath ?? imported?.nativeAst?.sourcePath;
|
|
9
|
+
const sourceHash = imported?.nativeSource?.sourceHash ?? imported?.nativeAst?.sourceHash ?? imported?.sourceHash;
|
|
10
|
+
const language = imported?.language ?? imported?.nativeSource?.language ?? imported?.nativeAst?.language;
|
|
11
|
+
const publicNames = new Set((semanticIndex?.symbols ?? []).filter((symbol) => symbol?.kind === 'export').map((symbol) => symbol.name));
|
|
12
|
+
return classStaticBlockRecords(sourceText, sourcePath).map((block) => {
|
|
13
|
+
const publicContract = block.exported || publicNames.has(block.className) || publicKeys.has(runtimePublicKey(sourcePath, block.className)) || undefined;
|
|
14
|
+
const runtimeOrderEvidence = classStaticBlockRuntimeOrderEvidence(block);
|
|
15
|
+
const signatureHash = hashSemanticValue({
|
|
16
|
+
kind: 'frontier.lang.projectClassStaticBlockRuntimeRegionSignature.v1',
|
|
17
|
+
className: block.className,
|
|
18
|
+
ordinal: block.ordinal,
|
|
19
|
+
runtimeOrderEvidence,
|
|
20
|
+
text: block.text
|
|
21
|
+
});
|
|
22
|
+
const id = `runtime_region_class_static_${idFragment(hashSemanticValue([sourcePath, block.className, block.ordinal, block.start, block.end]))}`;
|
|
23
|
+
return compactRecord({
|
|
24
|
+
id,
|
|
25
|
+
key: ['class-static-block', sourcePath ?? 'memory', block.className, block.ordinal].join('#'),
|
|
26
|
+
regionKind: 'effect',
|
|
27
|
+
runtimeKind: 'class-static-block',
|
|
28
|
+
runtimeKinds: ['class-static-block'],
|
|
29
|
+
sourcePath,
|
|
30
|
+
sourceHash,
|
|
31
|
+
sourceSpan: sourceSpanForBlock(block, sourcePath, sourceHash),
|
|
32
|
+
precision: 'block',
|
|
33
|
+
spanKind: 'class-static-block',
|
|
34
|
+
symbolName: block.className,
|
|
35
|
+
symbolKind: 'class',
|
|
36
|
+
line: block.line,
|
|
37
|
+
ordinal: block.ordinal,
|
|
38
|
+
runtimeOrderEvidence,
|
|
39
|
+
signatureHash,
|
|
40
|
+
publicContract,
|
|
41
|
+
evidenceIds: uniqueStrings([`class-static-block:${sourcePath}:${block.className}:${block.ordinal}`])
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function classStaticBlockRecords(sourceText, sourcePath) {
|
|
47
|
+
const masked = maskNonCode(sourceText).code;
|
|
48
|
+
const lineStarts = lineStartsFor(sourceText);
|
|
49
|
+
const records = [];
|
|
50
|
+
const classPattern = /\b(export\s+)?(?:abstract\s+)?class\s+([A-Za-z_$][\w$]*)[^{]*\{/g;
|
|
51
|
+
for (const match of masked.matchAll(classPattern)) {
|
|
52
|
+
const classOpen = masked.indexOf('{', match.index);
|
|
53
|
+
const classClose = matchingBraceIndex(masked, classOpen);
|
|
54
|
+
if (classOpen < 0 || classClose === undefined) continue;
|
|
55
|
+
const body = masked.slice(classOpen + 1, classClose);
|
|
56
|
+
let ordinal = 0;
|
|
57
|
+
for (const staticMatch of body.matchAll(/\bstatic\s*\{/g)) {
|
|
58
|
+
const start = classOpen + 1 + staticMatch.index;
|
|
59
|
+
const open = masked.indexOf('{', start);
|
|
60
|
+
const end = matchingBraceIndex(masked, open);
|
|
61
|
+
if (open < 0 || end === undefined || end > classClose) continue;
|
|
62
|
+
ordinal += 1;
|
|
63
|
+
const location = lineColumnAt(lineStarts, start);
|
|
64
|
+
records.push(compactRecord({
|
|
65
|
+
sourcePath,
|
|
66
|
+
className: match[2],
|
|
67
|
+
exported: Boolean(match[1]),
|
|
68
|
+
ordinal,
|
|
69
|
+
start,
|
|
70
|
+
end: end + 1,
|
|
71
|
+
line: location.line,
|
|
72
|
+
column: location.column,
|
|
73
|
+
text: sourceText.slice(start, end + 1),
|
|
74
|
+
statementCount: classStaticBlockStatementCount(sourceText.slice(open + 1, end))
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return records;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function classStaticBlockRuntimeOrderEvidence(block) {
|
|
82
|
+
return compactRecord({
|
|
83
|
+
schema: 'frontier.lang.runtimeOrderEvidence.v1',
|
|
84
|
+
source: 'lexical-source-scan',
|
|
85
|
+
runtimeScope: 'class-static-initialization',
|
|
86
|
+
regionKind: 'effect',
|
|
87
|
+
runtimeKinds: ['class-static-block'],
|
|
88
|
+
line: block.line,
|
|
89
|
+
runtimeOrderIndex: block.ordinal,
|
|
90
|
+
classStaticBlockOrder: [compactRecord({
|
|
91
|
+
kind: 'class-static-block',
|
|
92
|
+
className: block.className,
|
|
93
|
+
ordinal: block.ordinal,
|
|
94
|
+
line: block.line,
|
|
95
|
+
statementCount: block.statementCount,
|
|
96
|
+
text: normalizeText(block.text)
|
|
97
|
+
})]
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function sourceSpanForBlock(block, sourcePath, sourceHash) {
|
|
102
|
+
const starts = lineStartsFor(block.text);
|
|
103
|
+
const endLine = block.line + starts.length - 1;
|
|
104
|
+
const lastLineStart = starts[starts.length - 1] ?? 0;
|
|
105
|
+
return {
|
|
106
|
+
sourceId: sourceHash,
|
|
107
|
+
path: sourcePath,
|
|
108
|
+
startLine: block.line,
|
|
109
|
+
endLine,
|
|
110
|
+
startColumn: block.column,
|
|
111
|
+
endColumn: endLine === block.line ? block.column + block.text.length : block.text.length - lastLineStart + 1
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function classStaticBlockStatementCount(body) {
|
|
116
|
+
return String(body ?? '').split(';').map((part) => part.trim()).filter(Boolean).length;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function matchingBraceIndex(text, open) {
|
|
120
|
+
if (open < 0) return undefined;
|
|
121
|
+
let depth = 0;
|
|
122
|
+
for (let index = open; index < text.length; index += 1) {
|
|
123
|
+
if (text[index] === '{') depth += 1;
|
|
124
|
+
else if (text[index] === '}' && --depth === 0) return index;
|
|
125
|
+
}
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function lineStartsFor(sourceText) {
|
|
130
|
+
const starts = [0];
|
|
131
|
+
for (let index = 0; index < String(sourceText).length; index += 1) {
|
|
132
|
+
if (sourceText[index] === '\n') starts.push(index + 1);
|
|
133
|
+
}
|
|
134
|
+
return starts;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function lineColumnAt(lineStarts, offset) {
|
|
138
|
+
let lineIndex = 0;
|
|
139
|
+
while (lineIndex + 1 < lineStarts.length && lineStarts[lineIndex + 1] <= offset) lineIndex += 1;
|
|
140
|
+
return { line: lineIndex + 1, column: offset - lineStarts[lineIndex] + 1 };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function runtimePublicKey(sourcePath, symbolName) { return sourcePath && symbolName ? `${sourcePath}\0${symbolName}` : undefined; }
|
|
144
|
+
function nativeImportSourceText(imported) { return imported?.metadata?.sourcePreservation?.sourceText ?? imported?.nativeSource?.metadata?.sourcePreservation?.sourceText ?? imported?.nativeAst?.metadata?.sourcePreservation?.sourceText ?? imported?.sourceText; }
|
|
145
|
+
function normalizeText(value) { return String(value ?? '').replace(/\s+/g, ' ').trim(); }
|
|
146
|
+
function compactRecord(record) { return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined)); }
|
|
147
|
+
|
|
148
|
+
export { classStaticBlockRuntimeRecordsForImport };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
function compilerAdvancedTypeMetadata(value) {
|
|
2
|
+
const advancedTypeShapes = arrayValue(value.advancedTypeShapes);
|
|
3
|
+
const typeReferenceTargets = arrayValue(value.typeReferenceTargets);
|
|
4
|
+
const counts = {
|
|
5
|
+
advancedTypeShapeCount: numberValue(value.advancedTypeShapeCount) ?? advancedTypeShapes.length,
|
|
6
|
+
typeReferenceTargetCount: numberValue(value.typeReferenceTargetCount) ?? typeReferenceTargets.length,
|
|
7
|
+
conditionalTypeCount: numberValue(value.conditionalTypeCount) ?? countKind(advancedTypeShapes, 'conditional-type'),
|
|
8
|
+
mappedTypeCount: numberValue(value.mappedTypeCount) ?? countKind(advancedTypeShapes, 'mapped-type'),
|
|
9
|
+
indexedAccessTypeCount: numberValue(value.indexedAccessTypeCount) ?? countKind(advancedTypeShapes, 'indexed-access-type'),
|
|
10
|
+
keyofTypeOperatorCount: numberValue(value.keyofTypeOperatorCount) ?? countKind(advancedTypeShapes, 'keyof-type-operator'),
|
|
11
|
+
templateLiteralTypeCount: numberValue(value.templateLiteralTypeCount) ?? countKind(advancedTypeShapes, 'template-literal-type'),
|
|
12
|
+
inferTypeCount: numberValue(value.inferTypeCount) ?? countKind(advancedTypeShapes, 'infer-type'),
|
|
13
|
+
unionTypeCount: numberValue(value.unionTypeCount) ?? countKind(advancedTypeShapes, 'union-type'),
|
|
14
|
+
intersectionTypeCount: numberValue(value.intersectionTypeCount) ?? countKind(advancedTypeShapes, 'intersection-type'),
|
|
15
|
+
tupleTypeCount: numberValue(value.tupleTypeCount) ?? countKind(advancedTypeShapes, 'tuple-type')
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
counts,
|
|
19
|
+
record: compactRecord({
|
|
20
|
+
advancedTypeShapeCount: counts.advancedTypeShapeCount || undefined,
|
|
21
|
+
advancedTypeShapeKinds: value.advancedTypeShapeKinds ?? nonEmptyArray(uniqueStrings(advancedTypeShapes.map((shape) => shape.kind))),
|
|
22
|
+
typeReferenceTargetCount: counts.typeReferenceTargetCount || undefined,
|
|
23
|
+
conditionalTypeCount: counts.conditionalTypeCount || undefined,
|
|
24
|
+
mappedTypeCount: counts.mappedTypeCount || undefined,
|
|
25
|
+
indexedAccessTypeCount: counts.indexedAccessTypeCount || undefined,
|
|
26
|
+
keyofTypeOperatorCount: counts.keyofTypeOperatorCount || undefined,
|
|
27
|
+
templateLiteralTypeCount: counts.templateLiteralTypeCount || undefined,
|
|
28
|
+
inferTypeCount: counts.inferTypeCount || undefined,
|
|
29
|
+
unionTypeCount: counts.unionTypeCount || undefined,
|
|
30
|
+
intersectionTypeCount: counts.intersectionTypeCount || undefined,
|
|
31
|
+
tupleTypeCount: counts.tupleTypeCount || undefined,
|
|
32
|
+
advancedTypeShapes: nonEmptyArray(advancedTypeShapes),
|
|
33
|
+
typeReferenceTargets: nonEmptyArray(typeReferenceTargets)
|
|
34
|
+
})
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function countKind(records, kind) { return records.filter((record) => record.kind === kind).length; }
|
|
39
|
+
function arrayValue(value) { return Array.isArray(value) ? value : []; }
|
|
40
|
+
function compactRecord(record) { return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined)); }
|
|
41
|
+
function numberValue(value) { return Number.isFinite(value) ? value : undefined; }
|
|
42
|
+
function nonEmptyArray(value) { return Array.isArray(value) && value.length ? value : undefined; }
|
|
43
|
+
function uniqueStrings(values) { return [...new Set(values.filter((value) => typeof value === 'string' && value.length > 0))]; }
|
|
44
|
+
|
|
45
|
+
export { compilerAdvancedTypeMetadata };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { hashSemanticValue } from '@shapeshift-labs/frontier-lang-kernel';
|
|
2
|
+
|
|
3
|
+
function compilerCallableSignatureEquivalenceRecord(value, counts, sourceBinding = {}) {
|
|
4
|
+
if (!requiresCallableSignatureProof(counts)) return { reasonCodes: [] };
|
|
5
|
+
const checkerEvidence = callableSignatureCheckerEvidence(value, counts, sourceBinding);
|
|
6
|
+
const missingSignals = missingCallableSignatureEquivalenceSignals(value, counts, checkerEvidence, sourceBinding);
|
|
7
|
+
const reasonCodes = callableSignatureReasonCodes(counts, missingSignals);
|
|
8
|
+
const canProve = missingSignals.length === 0;
|
|
9
|
+
const callSignatureSetHash = canProve && counts.callSignatureCount > 0 ? hashSemanticValue({ kind: 'frontier.lang.typescript.compilerCallSignatureSetEquivalence.v1', callSignatures: canonicalSignatureRecords(value.callSignatures) }) : undefined;
|
|
10
|
+
const constructSignatureSetHash = canProve && counts.constructSignatureCount > 0 ? hashSemanticValue({ kind: 'frontier.lang.typescript.compilerConstructSignatureSetEquivalence.v1', constructSignatures: canonicalSignatureRecords(value.constructSignatures) }) : undefined;
|
|
11
|
+
const proof = compactRecord({
|
|
12
|
+
kind: callableSignatureProofKind(counts),
|
|
13
|
+
status: canProve ? 'passed' : 'failed',
|
|
14
|
+
proofLevel: callableSignatureProofLevel(counts),
|
|
15
|
+
checkerInvariant: callableSignatureCheckerInvariant(counts, sourceBinding),
|
|
16
|
+
requiredSignals: callableSignatureRequiredSignals(counts, sourceBinding),
|
|
17
|
+
missingSignals: nonEmptyArray(missingSignals),
|
|
18
|
+
reasonCodes: nonEmptyArray(reasonCodes),
|
|
19
|
+
callSignatureSetHash,
|
|
20
|
+
constructSignatureSetHash,
|
|
21
|
+
sourcePath: sourceBinding.sourcePath,
|
|
22
|
+
sourceHash: sourceBinding.sourceHash,
|
|
23
|
+
sourceBoundPublicApi: sourceBinding.publicContract === true || undefined,
|
|
24
|
+
callSignatureCount: counts.callSignatureCount || undefined,
|
|
25
|
+
constructSignatureCount: counts.constructSignatureCount || undefined,
|
|
26
|
+
evidenceIds: counts.evidenceIds,
|
|
27
|
+
autoMergeClaim: false,
|
|
28
|
+
semanticEquivalenceClaim: false
|
|
29
|
+
});
|
|
30
|
+
return { status: canProve ? 'compiler-backed-equivalent' : 'unsupported', reasonCodes: canProve ? [] : reasonCodes, callSignatureSetHash, constructSignatureSetHash, proof, checkerEvidence };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function requiresCallableSignatureProof(counts) { return counts.callSignatureCount > 0 || counts.constructSignatureCount > 0; }
|
|
34
|
+
function callableSignatureProofKind(counts) {
|
|
35
|
+
if (counts.callSignatureCount > 0 && counts.constructSignatureCount > 0) return 'typescript-checker-public-api-callable-and-construct-signature-shape-equivalence';
|
|
36
|
+
return counts.constructSignatureCount > 0 ? 'typescript-checker-public-api-construct-signature-shape-equivalence' : 'typescript-checker-public-api-call-signature-shape-equivalence';
|
|
37
|
+
}
|
|
38
|
+
function callableSignatureProofLevel(counts) {
|
|
39
|
+
const levels = [counts.callSignatureCount > 0 ? 'call-signature-set' : undefined, counts.constructSignatureCount > 0 ? 'construct-signature-set' : undefined].filter(Boolean);
|
|
40
|
+
return `typescript-checker-public-api-${levels.join('-and-')}`;
|
|
41
|
+
}
|
|
42
|
+
function callableSignatureCheckerInvariant(counts, sourceBinding = {}) {
|
|
43
|
+
return [
|
|
44
|
+
sourceBinding.publicContract === true ? 'public API source path/hash bound' : undefined,
|
|
45
|
+
counts.callSignatureCount > 0 ? 'call signatures/returns/parameters complete' : undefined,
|
|
46
|
+
counts.constructSignatureCount > 0 ? 'construct signatures/returns/parameters complete' : undefined
|
|
47
|
+
].filter(Boolean).join('; ');
|
|
48
|
+
}
|
|
49
|
+
function callableSignatureRequiredSignals(counts, sourceBinding = {}) {
|
|
50
|
+
return [
|
|
51
|
+
sourceBinding.publicContract === true ? 'compiler-public-api-source-path' : undefined,
|
|
52
|
+
sourceBinding.publicContract === true ? 'compiler-public-api-source-hash' : undefined,
|
|
53
|
+
counts.callSignatureCount > 0 ? 'compiler-call-signature-count' : undefined,
|
|
54
|
+
counts.callSignatureCount > 0 ? 'compiler-call-signature-texts' : undefined,
|
|
55
|
+
counts.callSignatureCount > 0 ? 'compiler-call-signature-return-type-texts' : undefined,
|
|
56
|
+
counts.callSignatureCount > 0 ? 'compiler-call-signature-parameter-type-texts' : undefined,
|
|
57
|
+
counts.constructSignatureCount > 0 ? 'compiler-construct-signature-count' : undefined,
|
|
58
|
+
counts.constructSignatureCount > 0 ? 'compiler-construct-signature-texts' : undefined,
|
|
59
|
+
counts.constructSignatureCount > 0 ? 'compiler-construct-signature-return-type-texts' : undefined,
|
|
60
|
+
counts.constructSignatureCount > 0 ? 'compiler-construct-signature-parameter-type-texts' : undefined
|
|
61
|
+
].filter(Boolean);
|
|
62
|
+
}
|
|
63
|
+
function callableSignatureReasonCodes(counts, missingSignals = []) {
|
|
64
|
+
return uniqueStrings([
|
|
65
|
+
counts.callSignatureCount > 0 ? 'typescript-public-call-signature-shape-equivalence-unproven' : undefined,
|
|
66
|
+
counts.constructSignatureCount > 0 ? 'typescript-public-construct-signature-shape-equivalence-unproven' : undefined,
|
|
67
|
+
...missingSignals.map((signal) => `typescript-${signal}-missing`)
|
|
68
|
+
]);
|
|
69
|
+
}
|
|
70
|
+
function missingCallableSignatureEquivalenceSignals(value, counts, checkerEvidence = callableSignatureCheckerEvidence(value, counts), sourceBinding = {}) {
|
|
71
|
+
const missing = [];
|
|
72
|
+
if (sourceBinding.publicContract === true && !checkerEvidence.sourcePath) missing.push('compiler-public-api-source-path');
|
|
73
|
+
if (sourceBinding.publicContract === true && !checkerEvidence.sourceHash) missing.push('compiler-public-api-source-hash');
|
|
74
|
+
if (counts.callSignatureCount > 0 && checkerEvidence.callSignatureTexts.length !== counts.callSignatureCount) missing.push('compiler-call-signature-count');
|
|
75
|
+
if (counts.callSignatureCount > 0 && checkerEvidence.callSignatureTexts.some((text) => !text)) missing.push('compiler-call-signature-texts');
|
|
76
|
+
if (counts.callSignatureCount > 0 && checkerEvidence.callReturnTypeTexts.some((text) => !text)) missing.push('compiler-call-signature-return-type-texts');
|
|
77
|
+
if (counts.callSignatureCount > 0 && !signaturesHaveParameterTypes(value.callSignatures)) missing.push('compiler-call-signature-parameter-type-texts');
|
|
78
|
+
if (counts.constructSignatureCount > 0 && checkerEvidence.constructSignatureTexts.length !== counts.constructSignatureCount) missing.push('compiler-construct-signature-count');
|
|
79
|
+
if (counts.constructSignatureCount > 0 && checkerEvidence.constructSignatureTexts.some((text) => !text)) missing.push('compiler-construct-signature-texts');
|
|
80
|
+
if (counts.constructSignatureCount > 0 && checkerEvidence.constructReturnTypeTexts.some((text) => !text)) missing.push('compiler-construct-signature-return-type-texts');
|
|
81
|
+
if (counts.constructSignatureCount > 0 && !signaturesHaveParameterTypes(value.constructSignatures)) missing.push('compiler-construct-signature-parameter-type-texts');
|
|
82
|
+
return uniqueStrings(missing);
|
|
83
|
+
}
|
|
84
|
+
function callableSignatureCheckerEvidence(value, counts, sourceBinding = {}) {
|
|
85
|
+
const callSignatures = arrayValue(value.callSignatures), constructSignatures = arrayValue(value.constructSignatures);
|
|
86
|
+
return compactRecord({
|
|
87
|
+
sourcePath: sourceBinding.sourcePath,
|
|
88
|
+
sourceHash: sourceBinding.sourceHash,
|
|
89
|
+
sourceBoundPublicApi: sourceBinding.publicContract === true || undefined,
|
|
90
|
+
callSignatureCount: counts.callSignatureCount || undefined,
|
|
91
|
+
constructSignatureCount: counts.constructSignatureCount || undefined,
|
|
92
|
+
callSignatureTexts: callSignatures.map((signature) => signature.signatureText),
|
|
93
|
+
callReturnTypeTexts: callSignatures.map((signature) => signature.returnTypeText),
|
|
94
|
+
callParameterTypeTexts: callSignatures.map((signature) => arrayValue(signature.parameters).map((parameter) => parameter.typeText)),
|
|
95
|
+
constructSignatureTexts: constructSignatures.map((signature) => signature.signatureText),
|
|
96
|
+
constructReturnTypeTexts: constructSignatures.map((signature) => signature.returnTypeText),
|
|
97
|
+
constructParameterTypeTexts: constructSignatures.map((signature) => arrayValue(signature.parameters).map((parameter) => parameter.typeText))
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function signaturesHaveParameterTypes(signatures) { return arrayValue(signatures).every((signature) => arrayValue(signature.parameters).every((parameter) => Boolean(parameter.typeText))); }
|
|
101
|
+
function canonicalSignatureRecords(signatures) { return arrayValue(signatures).map((signature) => compactRecord({ ...signature, parameters: nonEmptyArray(arrayValue(signature.parameters).map(({ flags: _flags, ...parameter }) => parameter)) })); }
|
|
102
|
+
function arrayValue(value) { return Array.isArray(value) ? value : []; }
|
|
103
|
+
function compactRecord(record) { return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined)); }
|
|
104
|
+
function nonEmptyArray(value) { return Array.isArray(value) && value.length ? value : undefined; }
|
|
105
|
+
function uniqueStrings(values) { return [...new Set(values.filter((value) => typeof value === 'string' && value.length > 0))]; }
|
|
106
|
+
|
|
107
|
+
export { callableSignatureCheckerEvidence, callableSignatureProofKind, callableSignatureReasonCodes, callableSignatureRequiredSignals, compilerCallableSignatureEquivalenceRecord, missingCallableSignatureEquivalenceSignals, requiresCallableSignatureProof };
|