@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,314 @@
|
|
|
1
|
+
const EnvironmentPackageConditions = Object.freeze([
|
|
2
|
+
'browser',
|
|
3
|
+
'node',
|
|
4
|
+
'development',
|
|
5
|
+
'production',
|
|
6
|
+
'worker',
|
|
7
|
+
'workerd',
|
|
8
|
+
'deno',
|
|
9
|
+
'bun',
|
|
10
|
+
'react-native'
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
function exportTargetsForValue(value, conditions, condition) {
|
|
14
|
+
if (!value) return [];
|
|
15
|
+
if (typeof value === 'string') return [{ path: value, condition }];
|
|
16
|
+
if (Array.isArray(value)) return value.flatMap((entry) => exportTargetsForValue(entry, conditions, condition));
|
|
17
|
+
if (!isRecord(value)) return [];
|
|
18
|
+
return conditions.flatMap((key) => exportTargetsForValue(value[key], conditions, key));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function exportMapMatch(exportsValue, subpath) {
|
|
22
|
+
if (!isRecord(exportsValue) || !Object.keys(exportsValue).some((key) => key.startsWith('.'))) return subpath === '.' ? { key: '.', value: exportsValue } : undefined;
|
|
23
|
+
if (Object.prototype.hasOwnProperty.call(exportsValue, subpath)) return { key: subpath, value: exportsValue[subpath] };
|
|
24
|
+
for (const [pattern, target] of Object.entries(exportsValue)) {
|
|
25
|
+
const capture = patternCapture(subpath, pattern);
|
|
26
|
+
if (capture !== undefined) return { key: pattern, value: replaceTargetCapture(target, capture) };
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function packageConditions(moduleResolution = {}, sourcePath, packageContext, edgeMetadata) {
|
|
32
|
+
return prioritizeConditions(
|
|
33
|
+
moduleResolution.packageExportConditions ?? moduleResolution.conditions ?? ['types', 'import', 'module', 'require', 'default'],
|
|
34
|
+
packageConditionPreferences(sourcePath, moduleResolution, packageContext, edgeMetadata)
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function packageRuntimeConditionAmbiguity(value, moduleResolution, sourcePath, packageContext, edgeMetadata) {
|
|
39
|
+
if (packageRuntimeConditionEvidence(moduleResolution, sourcePath, packageContext, edgeMetadata).packageRuntimeCondition) return undefined;
|
|
40
|
+
const conditions = new Set(packageConditions(moduleResolution, sourcePath, packageContext, edgeMetadata));
|
|
41
|
+
if (!conditions.has('import') || !conditions.has('require')) return undefined;
|
|
42
|
+
const runtimeTargets = packageRuntimeTargetsForValue(value, conditions);
|
|
43
|
+
if (!runtimeTargets.import.size || !runtimeTargets.require.size) return undefined;
|
|
44
|
+
return sameSet(runtimeTargets.import, runtimeTargets.require) ? undefined : 'import|require';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function packageEnvironmentConditionAmbiguity(value, moduleResolution, sourcePath, packageContext, edgeMetadata) {
|
|
48
|
+
if (packageEnvironmentConditionEvidence(moduleResolution, edgeMetadata).packageEnvironmentCondition) return undefined;
|
|
49
|
+
const conditions = new Set(packageConditions(moduleResolution, sourcePath, packageContext, edgeMetadata));
|
|
50
|
+
const environmentTargets = packageEnvironmentTargetsForValue(value, conditions);
|
|
51
|
+
const present = Object.entries(environmentTargets).filter(([, targets]) => targets.size);
|
|
52
|
+
if (present.length < 2) return undefined;
|
|
53
|
+
const first = present[0][1];
|
|
54
|
+
return present.every(([, targets]) => sameSet(first, targets))
|
|
55
|
+
? undefined
|
|
56
|
+
: present.map(([condition]) => condition).join('|');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function packageRuntimeConditionEvidence(moduleResolution = {}, sourcePath, packageContext, edgeMetadata) {
|
|
60
|
+
const edgeCondition = packageRuntimeConditionFromEdge(edgeMetadata);
|
|
61
|
+
const extensionCondition = packageRuntimeConditionFromExtension(sourcePath);
|
|
62
|
+
const packageType = packageTypeForSource(moduleResolution, sourcePath, packageContext);
|
|
63
|
+
const packageTypeCondition = packageType === 'module' ? 'import' : packageType === 'commonjs' ? 'require' : undefined;
|
|
64
|
+
if (edgeCondition) {
|
|
65
|
+
const conflict = edgeCondition.conflictsWithSource && (
|
|
66
|
+
extensionCondition && extensionCondition !== edgeCondition.packageRuntimeCondition ||
|
|
67
|
+
packageTypeCondition && packageTypeCondition !== edgeCondition.packageRuntimeCondition
|
|
68
|
+
);
|
|
69
|
+
if (conflict) return compactRecord({
|
|
70
|
+
packageRuntimeConditionEvidenceSource: 'conflict',
|
|
71
|
+
packageRuntimeConditionEdgeKind: edgeCondition.packageRuntimeConditionEdgeKind,
|
|
72
|
+
packageRuntimeConditionCandidates: uniqueStrings([edgeCondition.packageRuntimeCondition, extensionCondition, packageTypeCondition]),
|
|
73
|
+
packageRuntimeConditionReasonCode: 'package-runtime-condition-conflict-missing',
|
|
74
|
+
packageRuntimeConditionConflict: true,
|
|
75
|
+
packageType
|
|
76
|
+
});
|
|
77
|
+
if (edgeCondition.preferred || !extensionCondition && !packageTypeCondition) return compactRecord({ ...edgeCondition, packageType });
|
|
78
|
+
}
|
|
79
|
+
const hostAmbiguity = edgeCondition ? undefined : packageRuntimeHostConditionAmbiguity(edgeMetadata, packageType);
|
|
80
|
+
if (hostAmbiguity) return hostAmbiguity;
|
|
81
|
+
if (extensionCondition) return { packageRuntimeCondition: extensionCondition, packageRuntimeConditionEvidenceSource: 'source-extension', packageType };
|
|
82
|
+
if (packageTypeCondition) return { packageRuntimeCondition: packageTypeCondition, packageRuntimeConditionEvidenceSource: 'package-type', packageType };
|
|
83
|
+
return {};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function packageEnvironmentConditionEvidence(moduleResolution = {}, edgeMetadata = {}) {
|
|
87
|
+
const condition = stringValue(
|
|
88
|
+
edgeMetadata.packageEnvironmentCondition ??
|
|
89
|
+
moduleResolution.packageEnvironmentCondition ??
|
|
90
|
+
moduleResolution.environmentCondition
|
|
91
|
+
);
|
|
92
|
+
return condition ? {
|
|
93
|
+
packageEnvironmentCondition: condition,
|
|
94
|
+
packageEnvironmentConditionEvidenceSource: edgeMetadata.packageEnvironmentCondition ? 'edge-metadata' : 'module-resolution'
|
|
95
|
+
} : {};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function packageRuntimeTargetsForValue(value, conditions) {
|
|
99
|
+
const result = { import: new Set(), require: new Set() };
|
|
100
|
+
collectPackageRuntimeTargets(value, conditions, result);
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function packageEnvironmentTargetsForValue(value, conditions) {
|
|
105
|
+
const result = Object.fromEntries(EnvironmentPackageConditions.map((condition) => [condition, new Set()]));
|
|
106
|
+
collectPackageEnvironmentTargets(value, conditions, result);
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function collectPackageRuntimeTargets(value, conditions, result) {
|
|
111
|
+
if (Array.isArray(value)) {
|
|
112
|
+
for (const entry of value) collectPackageRuntimeTargets(entry, conditions, result);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (!isRecord(value)) return;
|
|
116
|
+
for (const [condition, target] of Object.entries(value)) {
|
|
117
|
+
if (!conditions.has(condition)) continue;
|
|
118
|
+
if (condition === 'import' || condition === 'require') {
|
|
119
|
+
for (const entry of exportTargetsForValue(target, [...conditions], condition)) result[condition].add(entry.path);
|
|
120
|
+
} else {
|
|
121
|
+
collectPackageRuntimeTargets(target, conditions, result);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function collectPackageEnvironmentTargets(value, conditions, result) {
|
|
127
|
+
if (Array.isArray(value)) {
|
|
128
|
+
for (const entry of value) collectPackageEnvironmentTargets(entry, conditions, result);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (!isRecord(value)) return;
|
|
132
|
+
for (const [condition, target] of Object.entries(value)) {
|
|
133
|
+
if (!conditions.has(condition)) continue;
|
|
134
|
+
if (result[condition]) {
|
|
135
|
+
for (const entry of exportTargetsForValue(target, [...conditions], condition)) result[condition].add(entry.path);
|
|
136
|
+
} else {
|
|
137
|
+
collectPackageEnvironmentTargets(target, conditions, result);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function packageConditionPreferences(sourcePath, moduleResolution, packageContext, edgeMetadata) {
|
|
143
|
+
const environmentCondition = packageEnvironmentConditionEvidence(moduleResolution, edgeMetadata).packageEnvironmentCondition;
|
|
144
|
+
const runtimeCondition = packageRuntimeConditionEvidence(
|
|
145
|
+
moduleResolution,
|
|
146
|
+
sourcePath,
|
|
147
|
+
packageContext,
|
|
148
|
+
edgeMetadata
|
|
149
|
+
).packageRuntimeCondition;
|
|
150
|
+
const runtimePreferences = runtimeCondition === 'require'
|
|
151
|
+
? ['require', 'node', 'default']
|
|
152
|
+
: runtimeCondition === 'import'
|
|
153
|
+
? ['import', 'module', 'default']
|
|
154
|
+
: [];
|
|
155
|
+
return uniqueStrings([environmentCondition, ...runtimePreferences]);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function packageRuntimeConditionFromEdge(edgeMetadata = {}) {
|
|
159
|
+
const hostKind = edgeMetadata.hostDependencyKind;
|
|
160
|
+
if (edgeMetadata.importKind === 'import-meta-resolve' || !edgeMetadata.importKind && hostKind === 'import-meta-resolve') return edgeCondition('import', 'host-import-resolve', 'package-runtime-condition-edge-host-resolve-evidence', true, false);
|
|
161
|
+
if (edgeMetadata.importKind === 'require-resolve' || !edgeMetadata.importKind && hostKind === 'require-resolve') return edgeCondition('require', 'host-require-resolve', 'package-runtime-condition-edge-host-resolve-evidence', true, true);
|
|
162
|
+
if (edgeMetadata.importKind === 'commonjs-require' || !edgeMetadata.importKind && edgeMetadata.commonJs) return edgeCondition('require', 'commonjs-require', 'package-runtime-condition-edge-require-evidence', true, true);
|
|
163
|
+
if (edgeMetadata.commonJs && commonJsHelperImportKind(edgeMetadata.importKind)) return edgeCondition('require', commonJsHelperEdgeKind(edgeMetadata), 'package-runtime-condition-edge-require-evidence', true, true);
|
|
164
|
+
if (edgeMetadata.importKind === 'dynamic-import' || !edgeMetadata.importKind && edgeMetadata.dynamicImport) return edgeCondition('import', 'dynamic-import', 'package-runtime-condition-edge-dynamic-import-evidence', true, false);
|
|
165
|
+
if (staticImportKind(edgeMetadata.importKind)) return edgeCondition('import', `static-${edgeMetadata.importKind}`, 'package-runtime-condition-edge-import-evidence', false, false);
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function packageRuntimeHostConditionAmbiguity(edgeMetadata = {}, packageType) {
|
|
170
|
+
const hostKind = edgeMetadata.hostDependencyKind;
|
|
171
|
+
if (!hostKind) return undefined;
|
|
172
|
+
return compactRecord({
|
|
173
|
+
packageRuntimeConditionEvidenceSource: 'host-runtime-ambiguous',
|
|
174
|
+
packageRuntimeConditionEdgeKind: `host-${hostKind}`,
|
|
175
|
+
packageRuntimeConditionReasonCode: 'package-runtime-condition-host-ambiguous-missing',
|
|
176
|
+
packageType
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function edgeCondition(packageRuntimeCondition, packageRuntimeConditionEdgeKind, packageRuntimeConditionReasonCode, preferred, conflictsWithSource) {
|
|
181
|
+
return {
|
|
182
|
+
packageRuntimeCondition,
|
|
183
|
+
packageRuntimeConditionEvidenceSource: 'edge-kind',
|
|
184
|
+
packageRuntimeConditionEdgeKind,
|
|
185
|
+
packageRuntimeConditionReasonCode,
|
|
186
|
+
preferred,
|
|
187
|
+
conflictsWithSource
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function staticImportKind(importKind) {
|
|
192
|
+
return importKind === 'module' ||
|
|
193
|
+
importKind === 'side-effect' ||
|
|
194
|
+
importKind === 'reexport' ||
|
|
195
|
+
importKind === 'namespace-reexport' ||
|
|
196
|
+
importKind === 'default' ||
|
|
197
|
+
importKind === 'namespace' ||
|
|
198
|
+
importKind === 'named' ||
|
|
199
|
+
importKind === 'type-named' ||
|
|
200
|
+
importKind === 'type-default' ||
|
|
201
|
+
importKind === 'type-reexport';
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function commonJsHelperImportKind(importKind) {
|
|
205
|
+
return importKind === 'default' ||
|
|
206
|
+
importKind === 'namespace' ||
|
|
207
|
+
importKind === 'reexport' ||
|
|
208
|
+
importKind === 'namespace-reexport';
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function commonJsHelperEdgeKind(edgeMetadata) {
|
|
212
|
+
const helper = typeof edgeMetadata.interopHelper === 'string'
|
|
213
|
+
? edgeMetadata.interopHelper.replace(/^__/, '')
|
|
214
|
+
: edgeMetadata.importKind;
|
|
215
|
+
return `commonjs-helper-${helper}`;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function packageRuntimeConditionFromExtension(sourcePath) {
|
|
219
|
+
const path = String(sourcePath ?? '');
|
|
220
|
+
if (/\.(?:cjs|cts)$/.test(path)) return 'require';
|
|
221
|
+
if (/\.(?:mjs|mts)$/.test(path)) return 'import';
|
|
222
|
+
return undefined;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function packageTypeForSource(moduleResolution = {}, sourcePath, packageContext) {
|
|
226
|
+
return normalizePackageType(
|
|
227
|
+
packageContext?.packageType ?? packageContext?.type ??
|
|
228
|
+
packageTypeByRoot(moduleResolution.packageTypeByRoot, sourcePath) ??
|
|
229
|
+
packageTypeByRoot(moduleResolution.packageTypes, sourcePath) ??
|
|
230
|
+
moduleResolution.packageType ?? moduleResolution.type
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function packageTypeByRoot(typeMap, sourcePath) {
|
|
235
|
+
if (!isRecord(typeMap)) return undefined;
|
|
236
|
+
const normalizedSource = normalizeProjectPath(sourcePath);
|
|
237
|
+
return Object.entries(typeMap)
|
|
238
|
+
.map(([root, value]) => ({ root: normalizeProjectPath(root), value }))
|
|
239
|
+
.filter((entry) => pathInsideRoot(normalizedSource, entry.root))
|
|
240
|
+
.sort((left, right) => right.root.length - left.root.length)[0]?.value;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function normalizePackageType(value) {
|
|
244
|
+
const type = typeof value === 'string' ? value : value?.type ?? value?.packageType;
|
|
245
|
+
return type === 'module' || type === 'commonjs' ? type : undefined;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function sameSet(left, right) {
|
|
249
|
+
if (left.size !== right.size) return false;
|
|
250
|
+
for (const value of left) if (!right.has(value)) return false;
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function uniqueStrings(values) {
|
|
255
|
+
return [...new Set(values.filter((value) => typeof value === 'string' && value))];
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function stringValue(value) {
|
|
259
|
+
return typeof value === 'string' && value.length ? value : undefined;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function prioritizeConditions(conditions, preferred) {
|
|
263
|
+
const entries = Array.isArray(conditions) ? conditions : [conditions];
|
|
264
|
+
const normalized = entries.map((entry) => String(entry)).filter(Boolean);
|
|
265
|
+
if (!preferred.length) return normalized;
|
|
266
|
+
const preferredSet = new Set(preferred);
|
|
267
|
+
return [
|
|
268
|
+
...preferred.filter((condition) => normalized.includes(condition)),
|
|
269
|
+
...normalized.filter((condition) => !preferredSet.has(condition))
|
|
270
|
+
];
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function isRecord(value) { return value && typeof value === 'object' && !Array.isArray(value); }
|
|
274
|
+
|
|
275
|
+
function compactRecord(record) { return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined)); }
|
|
276
|
+
|
|
277
|
+
function replaceTargetCapture(target, capture) {
|
|
278
|
+
if (typeof target === 'string') return target.replace('*', capture);
|
|
279
|
+
if (Array.isArray(target)) return target.map((entry) => replaceTargetCapture(entry, capture));
|
|
280
|
+
if (!isRecord(target)) return target;
|
|
281
|
+
return Object.fromEntries(Object.entries(target).map(([key, value]) => [key, replaceTargetCapture(value, capture)]));
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function normalizeProjectPath(path) {
|
|
285
|
+
const parts = [];
|
|
286
|
+
for (const part of String(path ?? '').split('/')) {
|
|
287
|
+
if (!part || part === '.') continue;
|
|
288
|
+
if (part === '..') parts.pop(); else parts.push(part);
|
|
289
|
+
}
|
|
290
|
+
return parts.join('/');
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function patternCapture(value, pattern) {
|
|
294
|
+
if (pattern === value) return '';
|
|
295
|
+
if (!String(pattern).includes('*')) return undefined;
|
|
296
|
+
const [prefix, suffix = ''] = String(pattern).split('*');
|
|
297
|
+
if (!String(value).startsWith(prefix) || !String(value).endsWith(suffix)) return undefined;
|
|
298
|
+
return String(value).slice(prefix.length, String(value).length - suffix.length);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function pathInsideRoot(sourcePath, root) {
|
|
302
|
+
if (!root) return true;
|
|
303
|
+
return sourcePath === root || sourcePath.startsWith(`${root}/`);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export {
|
|
307
|
+
exportMapMatch,
|
|
308
|
+
exportTargetsForValue,
|
|
309
|
+
packageConditions,
|
|
310
|
+
packageEnvironmentConditionAmbiguity,
|
|
311
|
+
packageEnvironmentConditionEvidence,
|
|
312
|
+
packageRuntimeConditionAmbiguity,
|
|
313
|
+
packageRuntimeConditionEvidence
|
|
314
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
function resolveReExportIdentityImportTargets(importEdges = [], reExportIdentities = []) {
|
|
2
|
+
const identityMatches = reExportIdentityTargetIndex(reExportIdentities);
|
|
3
|
+
const edgeById = new Map(importEdges.map((edge) => [edge.id, edge]));
|
|
4
|
+
return importEdges.map((edge) => {
|
|
5
|
+
if (edge?.resolvedTargetSymbolId || !edge?.targetDocumentId || !projectImportTargetName(edge)) return edge;
|
|
6
|
+
const matches = identityMatches.get(`${edge.targetDocumentId}\0${projectImportTargetName(edge)}`) ?? [];
|
|
7
|
+
if (matches.length !== 1 || !matches[0].originSymbolId) return edge;
|
|
8
|
+
return resolvedReExportImportEdge(edge, matches[0], edgeById.get(matches[0].relationId));
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function reExportIdentityTargetIndex(reExportIdentities = []) {
|
|
13
|
+
const result = new Map();
|
|
14
|
+
for (const identity of reExportIdentities) {
|
|
15
|
+
if (!identity?.sourceDocumentId || !identity.exportedName) continue;
|
|
16
|
+
const key = `${identity.sourceDocumentId}\0${identity.exportedName}`;
|
|
17
|
+
result.set(key, [...(result.get(key) ?? []), identity]);
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function resolvedReExportImportEdge(edge, identity, relationEdge) {
|
|
23
|
+
return {
|
|
24
|
+
...edge,
|
|
25
|
+
resolvedTargetSymbolId: identity.originSymbolId,
|
|
26
|
+
reExportResolved: true,
|
|
27
|
+
reExportResolutionKind: identity.isExportStar ? 'export-star' : 're-export-identity',
|
|
28
|
+
reExportIdentityId: identity.id,
|
|
29
|
+
reExportRelationId: identity.relationId,
|
|
30
|
+
reExportSourcePath: identity.sourcePath,
|
|
31
|
+
reExportModuleSpecifier: identity.moduleSpecifier,
|
|
32
|
+
reExportTargetSourcePath: relationEdge?.resolvedModulePath,
|
|
33
|
+
reExportTargetDocumentId: relationEdge?.targetDocumentId
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function projectImportTargetName(edge) {
|
|
38
|
+
if (edge?.importKind === 'side-effect' || edge?.importKind === 'namespace' || edge?.importKind === 'module') return undefined;
|
|
39
|
+
const name = edge?.importedName ?? edge?.localName ?? edge?.exportedName;
|
|
40
|
+
return name && name !== '*' ? String(name) : undefined;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { resolveReExportIdentityImportTargets };
|
|
@@ -15,7 +15,9 @@ export function reExportIdentityRecord(identity, edge, resolveDocumentExportSymb
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export function isReExportImportEdge(edge) {
|
|
18
|
-
|
|
18
|
+
if (edge.exportStar === true) return true;
|
|
19
|
+
if (edge.importKind !== 'reexport' && edge.importKind !== 'namespace-reexport') return false;
|
|
20
|
+
return Boolean(edge.importedName || edge.exportedName || edge.namespace || edge.localName);
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
export function reExportIdentityInputFromEdge(edge, id) {
|
|
@@ -25,6 +27,11 @@ export function reExportIdentityInputFromEdge(edge, id) {
|
|
|
25
27
|
sourcePath: edge.sourcePath,
|
|
26
28
|
sourceHash: edge.sourceHash,
|
|
27
29
|
moduleSpecifier: edge.moduleSpecifier,
|
|
30
|
+
hasImportAttributes: edge.hasImportAttributes,
|
|
31
|
+
importAttributeCount: edge.importAttributeCount,
|
|
32
|
+
importAttributeKeys: edge.importAttributeKeys,
|
|
33
|
+
importAttributeHash: edge.importAttributeHash,
|
|
34
|
+
importAttributes: edge.importAttributes,
|
|
28
35
|
symbolId: edge.targetSymbolId,
|
|
29
36
|
relationId: edge.id,
|
|
30
37
|
publicContract: edge.publicContract
|
|
@@ -41,6 +48,11 @@ export function exportStarReExportIdentityRecords(edge, targetExports) {
|
|
|
41
48
|
sourcePath: edge.sourcePath,
|
|
42
49
|
sourceHash: edge.sourceHash,
|
|
43
50
|
moduleSpecifier: edge.moduleSpecifier,
|
|
51
|
+
hasImportAttributes: edge.hasImportAttributes,
|
|
52
|
+
importAttributeCount: edge.importAttributeCount,
|
|
53
|
+
importAttributeKeys: edge.importAttributeKeys,
|
|
54
|
+
importAttributeHash: edge.importAttributeHash,
|
|
55
|
+
importAttributes: edge.importAttributes,
|
|
44
56
|
symbolId: edge.targetSymbolId,
|
|
45
57
|
relationId: edge.id,
|
|
46
58
|
importedName: symbol.name,
|
|
@@ -53,6 +65,48 @@ export function exportStarReExportIdentityRecords(edge, targetExports) {
|
|
|
53
65
|
}));
|
|
54
66
|
}
|
|
55
67
|
|
|
68
|
+
export function commonJsAliasReExportIdentityRecords(importEdges, exportEdges, resolveDocumentExportSymbolId) {
|
|
69
|
+
const requireAliases = new Map();
|
|
70
|
+
for (const edge of importEdges ?? []) {
|
|
71
|
+
if (edge.importKind !== 'commonjs-require' || !edge.localName || !edge.targetDocumentId || !edge.moduleSpecifier) continue;
|
|
72
|
+
requireAliases.set(commonJsAliasKey(edge.sourceDocumentId, edge.localName), edge);
|
|
73
|
+
}
|
|
74
|
+
return (exportEdges ?? []).flatMap((edge) => {
|
|
75
|
+
if (!edge.exportedName || edge.moduleSpecifier) return [];
|
|
76
|
+
const member = commonJsAliasMember(edge.localName);
|
|
77
|
+
const importEdge = member ? requireAliases.get(commonJsAliasKey(edge.sourceDocumentId, member.alias)) : undefined;
|
|
78
|
+
if (!importEdge) return [];
|
|
79
|
+
return [compactRecord({
|
|
80
|
+
id: `reexport_commonjs_alias_${idFragment(edge.id)}_${idFragment(importEdge.id)}_${idFragment(member.importedName)}`,
|
|
81
|
+
sourceDocumentId: edge.sourceDocumentId,
|
|
82
|
+
sourcePath: edge.sourcePath,
|
|
83
|
+
sourceHash: edge.sourceHash,
|
|
84
|
+
moduleSpecifier: importEdge.moduleSpecifier,
|
|
85
|
+
symbolId: edge.targetSymbolId,
|
|
86
|
+
relationId: edge.id,
|
|
87
|
+
importRelationId: importEdge.id,
|
|
88
|
+
importedName: member.importedName,
|
|
89
|
+
exportedName: edge.exportedName,
|
|
90
|
+
localName: edge.localName,
|
|
91
|
+
originSymbolId: resolveDocumentExportSymbolId(importEdge.targetDocumentId, member.importedName),
|
|
92
|
+
exportedSymbolId: resolveDocumentExportSymbolId(edge.sourceDocumentId, edge.exportedName) ?? edge.targetSymbolId,
|
|
93
|
+
localSymbolId: edge.targetSymbolId,
|
|
94
|
+
commonJs: true,
|
|
95
|
+
reExport: true,
|
|
96
|
+
publicContract: edge.publicContract
|
|
97
|
+
})];
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function commonJsAliasMember(localName) {
|
|
102
|
+
const match = String(localName ?? '').match(/^([A-Za-z_$][\w$]*)\.([A-Za-z_$][\w$]*)$/);
|
|
103
|
+
return match ? { alias: match[1], importedName: match[2] } : undefined;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function commonJsAliasKey(sourceDocumentId, alias) {
|
|
107
|
+
return `${sourceDocumentId ?? ''}\u0000${alias}`;
|
|
108
|
+
}
|
|
109
|
+
|
|
56
110
|
function idFragment(value) {
|
|
57
111
|
return String(value ?? '').toLowerCase().replace(/[^a-z0-9]+/g, '_').replace(/^_+|_+$/g, '').slice(0, 80) || 'id';
|
|
58
112
|
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { hashSemanticValue } from '@shapeshift-labs/frontier-lang-kernel';
|
|
2
|
+
import { idFragment, uniqueStrings } from '../../native-import-utils.js';
|
|
3
|
+
import { semanticEffectRegionRecordsForImport } from '../../semantic-import-effect-regions.js';
|
|
4
|
+
import { importMetaHostContextEvidence } from '../../semantic-import-runtime-import-meta-evidence.js';
|
|
5
|
+
import { resourceManagementRuntimeRegionRecordsForImport } from '../../semantic-import-runtime-resource-management-evidence.js';
|
|
6
|
+
import { classStaticBlockRuntimeRecordsForImport } from './projectSymbolGraphClassStaticBlocks.js';
|
|
7
|
+
|
|
8
|
+
function createProjectRuntimeRegionRecords(semanticIndex, imports, publicContractRegions) {
|
|
9
|
+
const publicKeys = publicRuntimeSymbolKeys(publicContractRegions);
|
|
10
|
+
return uniqueRecords(imports.flatMap((imported) => runtimeRegionsForImport(imported, publicKeys)));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function runtimeRegionsForImport(imported, publicKeys) {
|
|
14
|
+
const semanticIndex = imported?.semanticIndex ?? imported?.universalAst?.semanticIndex;
|
|
15
|
+
const symbolsById = new Map((semanticIndex?.symbols ?? []).map((symbol) => [symbol.id, symbol]));
|
|
16
|
+
const publicNames = new Set((semanticIndex?.symbols ?? []).filter((symbol) => symbol?.kind === 'export').map((symbol) => symbol.name));
|
|
17
|
+
const sourceText = nativeImportSourceText(imported);
|
|
18
|
+
const semanticRuntimeRecords = semanticEffectRegionRecordsForImport(imported, semanticIndex).ownershipRegions.map((region) => {
|
|
19
|
+
const subject = symbolsById.get(region.metadata?.subjectId);
|
|
20
|
+
const expressionText = sourceTextForSpan(sourceText, region.sourceSpan);
|
|
21
|
+
const runtimeOrderEvidence = importMetaHostContextEvidence(expressionText, region.metadata?.runtimeOrderEvidence);
|
|
22
|
+
const signatureHash = hashSemanticValue({
|
|
23
|
+
kind: 'frontier.lang.projectRuntimeRegionSignature',
|
|
24
|
+
regionKind: region.regionKind,
|
|
25
|
+
factKinds: region.metadata?.factKinds,
|
|
26
|
+
spanKind: region.metadata?.spanKind,
|
|
27
|
+
runtimeOrderEvidence,
|
|
28
|
+
expressionText
|
|
29
|
+
});
|
|
30
|
+
const runtimeRecordId = `runtime_region_${idFragment(region.id)}_${idFragment(hashSemanticValue({
|
|
31
|
+
kind: 'frontier.lang.projectRuntimeRegionRecordId',
|
|
32
|
+
key: region.key,
|
|
33
|
+
regionKind: region.regionKind,
|
|
34
|
+
runtimeKinds: region.metadata?.factKinds,
|
|
35
|
+
line: region.metadata?.factLine,
|
|
36
|
+
ordinal: region.metadata?.occurrenceOrdinal
|
|
37
|
+
}))}`;
|
|
38
|
+
return compactRecord({
|
|
39
|
+
id: runtimeRecordId,
|
|
40
|
+
key: region.key,
|
|
41
|
+
regionKind: region.regionKind,
|
|
42
|
+
runtimeKind: region.metadata?.factKinds?.[0] ?? region.regionKind,
|
|
43
|
+
runtimeKinds: region.metadata?.factKinds,
|
|
44
|
+
sourcePath: region.sourcePath,
|
|
45
|
+
sourceHash: region.sourceHash,
|
|
46
|
+
sourceSpan: region.sourceSpan,
|
|
47
|
+
precision: region.precision,
|
|
48
|
+
spanKind: region.metadata?.spanKind,
|
|
49
|
+
symbolId: region.metadata?.subjectId,
|
|
50
|
+
symbolName: subject?.name ?? region.metadata?.subjectName,
|
|
51
|
+
symbolKind: subject?.kind,
|
|
52
|
+
line: region.metadata?.factLine,
|
|
53
|
+
ordinal: region.metadata?.occurrenceOrdinal,
|
|
54
|
+
runtimeOrderEvidence,
|
|
55
|
+
signatureHash,
|
|
56
|
+
publicContract: publicKeys.has(runtimePublicKey(region.sourcePath, subject?.name ?? region.metadata?.subjectName))
|
|
57
|
+
|| publicNames.has(subject?.name) || undefined,
|
|
58
|
+
factIds: region.metadata?.factIds,
|
|
59
|
+
evidenceIds: uniqueStrings((region.metadata?.factIds ?? []).map((id) => `fact:${id}`))
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
return [
|
|
63
|
+
...semanticRuntimeRecords,
|
|
64
|
+
...resourceManagementRuntimeRegionRecordsForImport(imported, semanticIndex, publicKeys),
|
|
65
|
+
...classStaticBlockRuntimeRecordsForImport(imported, semanticIndex, publicKeys)
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function publicRuntimeSymbolKeys(regions = []) {
|
|
70
|
+
return new Set(regions.flatMap((region) => [
|
|
71
|
+
runtimePublicKey(region.sourcePath, region.symbolName),
|
|
72
|
+
runtimePublicKey(region.sourcePath, region.exportedName)
|
|
73
|
+
]).filter(Boolean));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function runtimePublicKey(sourcePath, symbolName) {
|
|
77
|
+
return sourcePath && symbolName ? `${sourcePath}\0${symbolName}` : undefined;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function nativeImportSourceText(imported) {
|
|
81
|
+
return imported?.metadata?.sourcePreservation?.sourceText
|
|
82
|
+
?? imported?.nativeSource?.metadata?.sourcePreservation?.sourceText
|
|
83
|
+
?? imported?.nativeAst?.metadata?.sourcePreservation?.sourceText
|
|
84
|
+
?? imported?.universalAst?.metadata?.sourcePreservation?.sourceText
|
|
85
|
+
?? imported?.sourceText;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function sourceTextForSpan(sourceText, span) {
|
|
89
|
+
if (!sourceText || !span?.startLine || !span?.endLine) return undefined;
|
|
90
|
+
const lines = String(sourceText).split(/\r\n|\n|\r/).slice(span.startLine - 1, span.endLine);
|
|
91
|
+
if (!lines.length) return undefined;
|
|
92
|
+
lines[0] = lines[0].slice(Math.max(0, (span.startColumn ?? 1) - 1));
|
|
93
|
+
lines[lines.length - 1] = lines[lines.length - 1].slice(0, Math.max(0, (span.endColumn ?? 1) - 1));
|
|
94
|
+
return lines.join('\n');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function compactRecord(record) { return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined)); }
|
|
98
|
+
function uniqueRecords(records) {
|
|
99
|
+
const seen = new Set();
|
|
100
|
+
return records.filter((record) => {
|
|
101
|
+
const key = record.id ?? JSON.stringify(record);
|
|
102
|
+
if (seen.has(key)) return false;
|
|
103
|
+
seen.add(key);
|
|
104
|
+
return true;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export { createProjectRuntimeRegionRecords };
|