@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,145 @@
|
|
|
1
|
+
function createNativeProjectModuleResolutionFromPackageManifests(input = {}) {
|
|
2
|
+
const options = Array.isArray(input) ? { manifests: input } : input;
|
|
3
|
+
const base = options.baseModuleResolution ?? options.moduleResolution ?? {};
|
|
4
|
+
const packages = { ...(base.packages ?? {}) };
|
|
5
|
+
const packageTypeByRoot = { ...(base.packageTypeByRoot ?? {}) };
|
|
6
|
+
const packageWorkspaceRootAmbiguities = { ...(base.packageWorkspaceRootAmbiguities ?? {}) };
|
|
7
|
+
const diagnostics = [];
|
|
8
|
+
const records = [];
|
|
9
|
+
for (const manifestInput of options.manifests ?? []) {
|
|
10
|
+
const parsed = packageJsonValue(manifestInput);
|
|
11
|
+
if (!parsed) {
|
|
12
|
+
diagnostics.push(diagnostic('invalid-package-json', manifestInput));
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
const root = normalizeProjectPath(manifestInput.root ?? rootFromPackageJsonPath(manifestInput.sourcePath ?? manifestInput.path));
|
|
16
|
+
const packageName = stringValue(manifestInput.packageName ?? parsed.name);
|
|
17
|
+
if (!packageName) {
|
|
18
|
+
diagnostics.push(diagnostic('missing-package-name', manifestInput, { root }));
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const packageType = normalizePackageType(manifestInput.packageType ?? manifestInput.type ?? parsed.type);
|
|
22
|
+
const existingRoots = packageWorkspaceRoots(packages[packageName], packageWorkspaceRootAmbiguities[packageName]);
|
|
23
|
+
const workspaceRoots = uniqueStrings([...existingRoots, root]);
|
|
24
|
+
const rootAmbiguous = existingRoots.length > 1 || existingRoots.length > 0 && root && !existingRoots.includes(root);
|
|
25
|
+
if (rootAmbiguous) {
|
|
26
|
+
packageWorkspaceRootAmbiguities[packageName] = workspaceRoots;
|
|
27
|
+
diagnostics.push(diagnostic('ambiguous-package-workspace-root', manifestInput, { root, packageName, existingRoot: existingRoots[0], packageWorkspaceRoots: workspaceRoots }));
|
|
28
|
+
}
|
|
29
|
+
const packageOptions = compactRecord({
|
|
30
|
+
...(packages[packageName] ?? {}),
|
|
31
|
+
root,
|
|
32
|
+
main: stringValue(parsed.main),
|
|
33
|
+
types: stringValue(parsed.types ?? parsed.typings),
|
|
34
|
+
type: packageType,
|
|
35
|
+
packageType,
|
|
36
|
+
exports: packageMapValue(parsed.exports),
|
|
37
|
+
imports: packageMapValue(parsed.imports),
|
|
38
|
+
packageWorkspaceRootAmbiguous: rootAmbiguous || undefined,
|
|
39
|
+
packageWorkspaceRoots: rootAmbiguous ? workspaceRoots : undefined,
|
|
40
|
+
packageResolutionReasonCode: rootAmbiguous ? 'package-workspace-root-ambiguous-missing' : undefined
|
|
41
|
+
});
|
|
42
|
+
packages[packageName] = packageOptions;
|
|
43
|
+
if (packageType) packageTypeByRoot[root] = packageType;
|
|
44
|
+
records.push(compactRecord({
|
|
45
|
+
packageName,
|
|
46
|
+
root,
|
|
47
|
+
sourcePath: manifestInput.sourcePath ?? manifestInput.path,
|
|
48
|
+
packageType,
|
|
49
|
+
hasExports: Object.prototype.hasOwnProperty.call(packageOptions, 'exports'),
|
|
50
|
+
hasImports: Object.prototype.hasOwnProperty.call(packageOptions, 'imports')
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
kind: 'frontier.lang.nativeProjectModuleResolutionFromPackageManifests',
|
|
55
|
+
version: 1,
|
|
56
|
+
ok: diagnostics.length === 0,
|
|
57
|
+
moduleResolution: compactRecord({
|
|
58
|
+
...base,
|
|
59
|
+
packages,
|
|
60
|
+
packageTypeByRoot,
|
|
61
|
+
packageWorkspaceRootAmbiguities: optionalRecord(packageWorkspaceRootAmbiguities),
|
|
62
|
+
packageExportConditions: options.packageExportConditions ?? base.packageExportConditions,
|
|
63
|
+
conditions: options.conditions ?? base.conditions
|
|
64
|
+
}),
|
|
65
|
+
packages: records,
|
|
66
|
+
packageCount: records.length,
|
|
67
|
+
diagnostics
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function packageJsonValue(input) {
|
|
72
|
+
const value = input.packageJson ?? input.json ?? input.packageJsonText ?? input.text;
|
|
73
|
+
if (isRecord(value)) return value;
|
|
74
|
+
if (typeof value !== 'string') return undefined;
|
|
75
|
+
try {
|
|
76
|
+
const parsed = JSON.parse(value);
|
|
77
|
+
return isRecord(parsed) ? parsed : undefined;
|
|
78
|
+
} catch {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function packageMapValue(value) {
|
|
84
|
+
if (value === null) return null;
|
|
85
|
+
if (typeof value === 'string') return value;
|
|
86
|
+
if (Array.isArray(value)) return value.map(packageMapValue).filter((entry) => entry !== undefined);
|
|
87
|
+
if (!isRecord(value)) return undefined;
|
|
88
|
+
return Object.fromEntries(
|
|
89
|
+
Object.entries(value)
|
|
90
|
+
.map(([key, entry]) => [key, packageMapValue(entry)])
|
|
91
|
+
.filter(([, entry]) => entry !== undefined)
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function diagnostic(reasonCode, input, metadata = {}) {
|
|
96
|
+
return compactRecord({
|
|
97
|
+
reasonCode,
|
|
98
|
+
sourcePath: input.sourcePath ?? input.path,
|
|
99
|
+
root: input.root,
|
|
100
|
+
packageName: input.packageName,
|
|
101
|
+
...metadata
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function stringValue(value) {
|
|
106
|
+
return typeof value === 'string' && value ? value : undefined;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function normalizePackageType(value) {
|
|
110
|
+
return value === 'module' || value === 'commonjs' ? value : undefined;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function packageWorkspaceRoots(options, ambiguousRoots) {
|
|
114
|
+
return uniqueStrings([...(Array.isArray(ambiguousRoots) ? ambiguousRoots : []), ...(Array.isArray(options?.packageWorkspaceRoots) ? options.packageWorkspaceRoots : []), options?.root]);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function uniqueStrings(values) {
|
|
118
|
+
return [...new Set(values.filter((value) => typeof value === 'string' && value))];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function rootFromPackageJsonPath(path) {
|
|
122
|
+
const normalized = normalizeProjectPath(path ?? '');
|
|
123
|
+
return normalized.endsWith('/package.json') ? normalized.slice(0, -'/package.json'.length) : '';
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function normalizeProjectPath(path) {
|
|
127
|
+
const parts = [];
|
|
128
|
+
for (const part of String(path ?? '').split('/')) {
|
|
129
|
+
if (!part || part === '.') continue;
|
|
130
|
+
if (part === '..') parts.pop(); else parts.push(part);
|
|
131
|
+
}
|
|
132
|
+
return parts.join('/');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function compactRecord(record) {
|
|
136
|
+
return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function optionalRecord(record) {
|
|
140
|
+
return Object.keys(record).length ? record : undefined;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function isRecord(value) { return value && typeof value === 'object' && !Array.isArray(value); }
|
|
144
|
+
|
|
145
|
+
export { createNativeProjectModuleResolutionFromPackageManifests };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { hashSemanticValue } from '@shapeshift-labs/frontier-lang-kernel';
|
|
2
2
|
import { countBy, idFragment, uniqueStrings } from '../../native-import-utils.js';
|
|
3
|
+
import { createParserTriviaExactnessRecord } from '../../native-source-preservation-ownership.js';
|
|
3
4
|
import {
|
|
4
5
|
detectNewlineStyle,
|
|
5
6
|
isJavaScriptTypeScriptSource,
|
|
@@ -17,7 +18,7 @@ export function createNativeSourcePreservation(options) {
|
|
|
17
18
|
const computedSourceHash = hashSemanticValue(sourceText);
|
|
18
19
|
const declaredSourceHash = options.sourceHash;
|
|
19
20
|
const sourceHash = computedSourceHash;
|
|
20
|
-
const tokensAndTrivia = scanPreservedSourceTokens(sourceText, {
|
|
21
|
+
const tokensAndTrivia = options.tokensAndTrivia ?? scanPreservedSourceTokens(sourceText, {
|
|
21
22
|
language,
|
|
22
23
|
sourcePath: options.sourcePath,
|
|
23
24
|
sourceHash,
|
|
@@ -47,13 +48,26 @@ export function createNativeSourcePreservation(options) {
|
|
|
47
48
|
const directivesByKind = countBy(directives.map((entry) => entry.kind ?? 'directive'));
|
|
48
49
|
const directiveKinds = uniqueStrings(directives.map((entry) => entry.kind ?? 'directive'));
|
|
49
50
|
const commentSpanIds = tokensAndTrivia.trivia
|
|
50
|
-
.filter((entry) => entry.kind
|
|
51
|
+
.filter((entry) => isCommentKind(entry.kind))
|
|
51
52
|
.map((entry) => entry.id)
|
|
52
53
|
.filter(Boolean);
|
|
53
54
|
const directiveSpanIds = directives
|
|
54
55
|
.map((entry) => entry.id)
|
|
55
56
|
.filter(Boolean);
|
|
56
57
|
const newline = detectNewlineStyle(sourceText);
|
|
58
|
+
const scannerEvidence = ledger ? 'frontier-lightweight-js-ts-source-ledger' : 'frontier-lightweight-lexical-scan';
|
|
59
|
+
const tokenTriviaParserEvidence = tokensAndTrivia.parserEvidence;
|
|
60
|
+
const parserEvidence = tokenTriviaParserEvidence ?? scannerEvidence;
|
|
61
|
+
const truncated = tokensAndTrivia.truncated || directiveScan.truncated || Boolean(ledger?.summary?.truncated);
|
|
62
|
+
const parserSpanCoverageProof = options.parserSpanCoverageProof ?? tokensAndTrivia.parserSpanCoverageProof;
|
|
63
|
+
const parserTriviaExactness = createParserTriviaExactnessRecord(options.parserTriviaEvidence ?? options.metadata?.parserTriviaEvidence, {
|
|
64
|
+
sourcePath: options.sourcePath,
|
|
65
|
+
sourceHash,
|
|
66
|
+
parserEvidence,
|
|
67
|
+
parserTokenTriviaEvidence: tokenTriviaParserEvidence ?? scannerEvidence,
|
|
68
|
+
parserSpanCoverageProof,
|
|
69
|
+
truncated
|
|
70
|
+
});
|
|
57
71
|
return {
|
|
58
72
|
kind: 'frontier.lang.nativeSourcePreservation',
|
|
59
73
|
version: 1,
|
|
@@ -74,7 +88,7 @@ export function createNativeSourcePreservation(options) {
|
|
|
74
88
|
tokens: tokensAndTrivia.tokens.length,
|
|
75
89
|
trivia: tokensAndTrivia.trivia.length,
|
|
76
90
|
directives: directives.length,
|
|
77
|
-
comments: tokensAndTrivia.trivia.filter((entry) => entry.kind
|
|
91
|
+
comments: tokensAndTrivia.trivia.filter((entry) => isCommentKind(entry.kind)).length,
|
|
78
92
|
whitespace: tokensAndTrivia.trivia.filter((entry) => entry.kind === 'whitespace' || entry.kind === 'newline').length,
|
|
79
93
|
...(ledger ? {
|
|
80
94
|
ledger: ledger.summary,
|
|
@@ -89,17 +103,30 @@ export function createNativeSourcePreservation(options) {
|
|
|
89
103
|
commentSpanIds,
|
|
90
104
|
directiveSpanIds,
|
|
91
105
|
exactSourceAvailable: options.includeSourceText !== false,
|
|
92
|
-
truncated
|
|
106
|
+
truncated,
|
|
107
|
+
parserTriviaExactnessStatus: parserTriviaExactness.status,
|
|
108
|
+
exactParserTrivia: parserTriviaExactness.exactParserTrivia,
|
|
109
|
+
parserSpanCoverageStatus: parserSpanCoverageProof?.status,
|
|
110
|
+
parserSpanCoverageReasonCodes: parserSpanCoverageProof?.reasonCodes,
|
|
111
|
+
parserSpanCoverageBlockReasonCodes: parserSpanCoverageProof?.blockReasonCodes,
|
|
112
|
+
parserTriviaExactnessReasonCodes: parserTriviaExactness.reasonCodes,
|
|
113
|
+
parserTriviaExactnessBlockReasonCodes: parserTriviaExactness.blockReasonCodes
|
|
93
114
|
},
|
|
94
115
|
metadata: {
|
|
95
116
|
preservation: 'source-text-token-trivia-directive-evidence',
|
|
96
|
-
tokenization: 'frontier-lightweight-lexical-scan',
|
|
117
|
+
tokenization: tokensAndTrivia.parserEvidence ?? 'frontier-lightweight-lexical-scan',
|
|
97
118
|
...(ledger ? { sourceLedger: 'frontier-lightweight-js-ts-source-ledger' } : {}),
|
|
119
|
+
...options.metadata,
|
|
120
|
+
...(parserSpanCoverageProof ? { parserSpanCoverageProof } : {}),
|
|
121
|
+
parserTriviaExactness,
|
|
98
122
|
...(declaredSourceHash ? {
|
|
99
123
|
declaredSourceHash,
|
|
100
124
|
sourceHashVerified: declaredSourceHash === computedSourceHash
|
|
101
|
-
} : {})
|
|
102
|
-
...options.metadata
|
|
125
|
+
} : {})
|
|
103
126
|
}
|
|
104
127
|
};
|
|
105
128
|
}
|
|
129
|
+
|
|
130
|
+
function isCommentKind(kind) {
|
|
131
|
+
return kind === 'comment' || kind === 'jsdoc-comment' || kind === 'block-comment';
|
|
132
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{idFragment,maxSemanticMergeReadiness,uniqueRecordsById}from'../../native-import-utils.js';import{summarizeSemanticImportDependencies}from'../../semantic-import-dependencies.js';import{createSemanticImportImpact}from'../../semantic-import-impact.js';import{summarizeSemanticImportSidecarParadigmSemantics,summarizeSemanticImportSidecarProofSpec,summarizeSemanticImportSidecarUniversalAstLayers}from'../../semantic-import-layers.js';import{semanticPatchHintForRegion,summarizeSemanticImportRegionTaxonomy}from'../../semantic-import-regions.js';import{semanticImportSidecarEntry}from'../../semantic-import-sidecar-entry.js';import{summarizeKernelSourcePreservation}from'../../semantic-import-source-preservation.js';
|
|
1
|
+
import{idFragment,maxSemanticMergeReadiness,uniqueRecordsById}from'../../native-import-utils.js';import{summarizeSemanticImportDependencies}from'../../semantic-import-dependencies.js';import{createSemanticGraphLayerSummary}from'../../semantic-import-graph-layers.js';import{createSemanticImportImpact}from'../../semantic-import-impact.js';import{summarizeSemanticImportSidecarParadigmSemantics,summarizeSemanticImportSidecarProofSpec,summarizeSemanticImportSidecarUniversalAstLayers}from'../../semantic-import-layers.js';import{semanticPatchHintForRegion,summarizeSemanticImportRegionTaxonomy}from'../../semantic-import-regions.js';import{semanticImportSidecarEntry}from'../../semantic-import-sidecar-entry.js';import{summarizeKernelSourcePreservation}from'../../semantic-import-source-preservation.js';
|
|
2
2
|
import{createSemanticImportSidecarAdmission,createSemanticImportSidecarQuality}from'./createSemanticImportSidecarAdmission.js';
|
|
3
3
|
import{summarizeNativeImportLosses}from'./summarizeNativeImportLosses.js';
|
|
4
4
|
export function createSemanticImportSidecar(importResult, options = {}) {
|
|
@@ -55,6 +55,28 @@ export function createSemanticImportSidecar(importResult, options = {}) {
|
|
|
55
55
|
},
|
|
56
56
|
readiness
|
|
57
57
|
});
|
|
58
|
+
const graphLayers = createSemanticGraphLayerSummary({
|
|
59
|
+
importResult,
|
|
60
|
+
imports,
|
|
61
|
+
importEntries,
|
|
62
|
+
symbols,
|
|
63
|
+
ownershipRegions,
|
|
64
|
+
sourceMaps,
|
|
65
|
+
sourceMapMappings,
|
|
66
|
+
sourcePreservation,
|
|
67
|
+
universalAstLayers,
|
|
68
|
+
proofSpec,
|
|
69
|
+
paradigmSemantics,
|
|
70
|
+
dependencies,
|
|
71
|
+
semanticImpact,
|
|
72
|
+
patchHints,
|
|
73
|
+
quality,
|
|
74
|
+
admission,
|
|
75
|
+
mergeCandidates,
|
|
76
|
+
losses,
|
|
77
|
+
evidence,
|
|
78
|
+
readiness
|
|
79
|
+
});
|
|
58
80
|
return {
|
|
59
81
|
kind: 'frontier.lang.semanticImportSidecar',
|
|
60
82
|
version: 1,
|
|
@@ -75,6 +97,7 @@ export function createSemanticImportSidecar(importResult, options = {}) {
|
|
|
75
97
|
proofSpec,
|
|
76
98
|
paradigmSemantics,
|
|
77
99
|
dependencies,
|
|
100
|
+
graphLayers,
|
|
78
101
|
semanticImpact,
|
|
79
102
|
patchHints,
|
|
80
103
|
quality,
|
|
@@ -125,6 +148,9 @@ export function createSemanticImportSidecar(importResult, options = {}) {
|
|
|
125
148
|
paradigmSemanticsLoweringRecords: paradigmSemantics.loweringRecords,
|
|
126
149
|
dependencyRelations: dependencies.total,
|
|
127
150
|
dependencyPredicates: dependencies.predicates,
|
|
151
|
+
graphLayers: graphLayers.summary.total,
|
|
152
|
+
graphLayersUsable: graphLayers.summary.usable,
|
|
153
|
+
graphLayerStatus: graphLayers.status,
|
|
128
154
|
semanticImpactRecords: semanticImpact.summary.total,
|
|
129
155
|
semanticImpactHighRiskRecords: semanticImpact.summary.byRisk.high ?? 0,
|
|
130
156
|
semanticImpactRequiredVerificationSteps: semanticImpact.summary.requiredVerificationSteps,
|
|
@@ -6,19 +6,21 @@ export function createTypeScriptCompilerNativeImporterAdapter(options = {}) {
|
|
|
6
6
|
language: options.language ?? 'typescript',
|
|
7
7
|
parser: options.parser ?? 'typescript-compiler-api',
|
|
8
8
|
version: options.version,
|
|
9
|
-
capabilities: uniqueStrings(['nativeAst', 'semanticIndex', 'sourceMaps', 'diagnostics', ...(options.capabilities ?? [])]),
|
|
9
|
+
capabilities: uniqueStrings(['nativeAst', 'semanticIndex', 'sourceMaps', 'diagnostics', 'tokens', 'trivia', 'parserTriviaExactness', 'compilerSymbolFacts', 'compilerTypeFacts', 'compilerReferenceGraph', ...(options.capabilities ?? [])]),
|
|
10
10
|
coverage: nativeImporterAdapterCoverage({
|
|
11
11
|
exactness: 'exact-parser-ast',
|
|
12
12
|
exactAst: true,
|
|
13
|
-
tokens:
|
|
14
|
-
trivia:
|
|
13
|
+
tokens: true,
|
|
14
|
+
trivia: true,
|
|
15
15
|
diagnostics: true,
|
|
16
16
|
sourceRanges: true,
|
|
17
17
|
generatedRanges: false,
|
|
18
18
|
semanticCoverage: declarationSemanticCoverage(),
|
|
19
19
|
notes: [
|
|
20
20
|
'Normalizes a caller-owned TypeScript SourceFile into native AST nodes and declaration-level semantic index records.',
|
|
21
|
-
'
|
|
21
|
+
'When the compiler scanner is available, SourceFile token/trivia spans become exact source-preservation evidence.',
|
|
22
|
+
'When a TypeScript checker is supplied, declaration records carry compiler symbol/type facts and reference relations for merge evidence.',
|
|
23
|
+
'Full reference resolution, control flow, and generated ranges require additional host-supplied adapter evidence.'
|
|
22
24
|
]
|
|
23
25
|
}, options.coverage),
|
|
24
26
|
supportedExtensions: options.supportedExtensions ?? ['.ts', '.tsx', '.js', '.jsx'],
|
|
@@ -42,7 +44,16 @@ export function createTypeScriptCompilerNativeImporterAdapter(options = {}) {
|
|
|
42
44
|
program,
|
|
43
45
|
typeChecker,
|
|
44
46
|
maxNodes: options.maxNodes,
|
|
45
|
-
includeTokens: options.includeTokens
|
|
47
|
+
includeTokens: options.includeTokens,
|
|
48
|
+
includeTrivia: options.includeTrivia,
|
|
49
|
+
maxTokens: options.maxTokens,
|
|
50
|
+
maxTrivia: options.maxTrivia,
|
|
51
|
+
computedEnumRuntimeValueProofs: input.options?.computedEnumRuntimeValueProofs ?? options.computedEnumRuntimeValueProofs,
|
|
52
|
+
computedEnumRuntimeValueProof: input.options?.computedEnumRuntimeValueProof ?? options.computedEnumRuntimeValueProof,
|
|
53
|
+
computedEnumRuntimeValueProofProvider: input.options?.computedEnumRuntimeValueProofProvider ?? options.computedEnumRuntimeValueProofProvider,
|
|
54
|
+
computedEnumRuntimeValueTraceProvider: input.options?.computedEnumRuntimeValueTraceProvider ?? options.computedEnumRuntimeValueTraceProvider,
|
|
55
|
+
computedEnumRuntimeValueTraces: input.options?.computedEnumRuntimeValueTraces ?? options.computedEnumRuntimeValueTraces,
|
|
56
|
+
adapterId: options.id ?? 'frontier.typescript-compiler-native-importer'
|
|
46
57
|
});
|
|
47
58
|
}
|
|
48
59
|
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { hashSemanticValue } from '@shapeshift-labs/frontier-lang-kernel';
|
|
2
|
+
|
|
3
|
+
const UNKNOWN_DYNAMIC_IMPORT_MODULE_SPECIFIER = '<dynamic-import>';
|
|
4
|
+
|
|
5
|
+
export function dynamicImportExpressionMetadata(argument, moduleSpecifier) {
|
|
6
|
+
const staticSpecifier = Boolean(moduleSpecifier && moduleSpecifier !== UNKNOWN_DYNAMIC_IMPORT_MODULE_SPECIFIER);
|
|
7
|
+
const expressionText = expressionSourceText(argument);
|
|
8
|
+
const specifierKind = dynamicImportSpecifierKind(argument, expressionText, staticSpecifier);
|
|
9
|
+
return compactRecord({
|
|
10
|
+
dynamicImportSpecifierKind: specifierKind,
|
|
11
|
+
dynamicImportExpressionText: expressionText,
|
|
12
|
+
dynamicImportExpressionHash: hashSemanticValue({ kind: specifierKind, text: expressionText ?? '', staticSpecifier }),
|
|
13
|
+
dynamicImportStaticSpecifierEvidence: staticSpecifier,
|
|
14
|
+
dynamicImportRuntimeResolutionClaim: false,
|
|
15
|
+
dynamicImportResolutionProofRequired: !staticSpecifier
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function dynamicImportExpressionEdgeFields(metadata) {
|
|
20
|
+
return compactRecord({
|
|
21
|
+
dynamicImport: metadata?.dynamicImport,
|
|
22
|
+
dynamicImportSpecifierKind: metadata?.dynamicImportSpecifierKind,
|
|
23
|
+
dynamicImportExpressionText: metadata?.dynamicImportExpressionText,
|
|
24
|
+
dynamicImportExpressionHash: metadata?.dynamicImportExpressionHash,
|
|
25
|
+
dynamicImportStaticSpecifierEvidence: metadata?.dynamicImportStaticSpecifierEvidence,
|
|
26
|
+
dynamicImportRuntimeResolutionClaim: metadata?.dynamicImportRuntimeResolutionClaim,
|
|
27
|
+
dynamicImportResolutionProofRequired: metadata?.dynamicImportResolutionProofRequired
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function dynamicImportSpecifierKind(node, text, staticSpecifier) {
|
|
32
|
+
if (staticSpecifier) return 'literal';
|
|
33
|
+
const kind = String(node?.type ?? node?.kindName ?? node?.kind ?? '');
|
|
34
|
+
if (/Template/.test(kind) || text?.startsWith('`')) return 'template';
|
|
35
|
+
if (/CallExpression/.test(kind) || node?.callee || (node?.expression && Array.isArray(node?.arguments)) || /\)\s*$/.test(text ?? '')) return 'call';
|
|
36
|
+
if (/Identifier/.test(kind) || /^[A-Za-z_$][\w$]*$/.test(text ?? '') || typeof node?.escapedText === 'string') return 'identifier';
|
|
37
|
+
if (/MemberExpression|PropertyAccessExpression|ElementAccessExpression/.test(kind) || node?.property || node?.name) return 'member';
|
|
38
|
+
if (/BinaryExpression|LogicalExpression/.test(kind) || node?.left && node?.right) return 'binary';
|
|
39
|
+
if (/ConditionalExpression/.test(kind) || node?.test && node?.consequent && node?.alternate) return 'conditional';
|
|
40
|
+
return kind ? kind.replace(/Expression$/, '').toLowerCase() : 'expression';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function expressionSourceText(node) {
|
|
44
|
+
if (!node) return undefined;
|
|
45
|
+
if (typeof node.getText === 'function') {
|
|
46
|
+
try {
|
|
47
|
+
const text = node.getText();
|
|
48
|
+
if (typeof text === 'string' && text.trim()) return text.trim();
|
|
49
|
+
} catch {}
|
|
50
|
+
}
|
|
51
|
+
if (typeof node.value === 'string') return JSON.stringify(node.value);
|
|
52
|
+
if (typeof node.raw === 'string') return node.raw;
|
|
53
|
+
if (typeof node.name === 'string') return node.name;
|
|
54
|
+
if (typeof node.escapedText === 'string') return node.escapedText;
|
|
55
|
+
if (typeof node.text === 'string') return node.text;
|
|
56
|
+
if (node.type === 'TemplateLiteral' && Array.isArray(node.quasis)) return templateLiteralText(node);
|
|
57
|
+
if (node.type === 'MemberExpression') return memberExpressionText(node);
|
|
58
|
+
if (node.type === 'CallExpression') return `${expressionSourceText(node.callee) ?? 'call'}(...)`;
|
|
59
|
+
if (node.left && node.right && node.operator) return `${expressionSourceText(node.left) ?? 'left'} ${node.operator} ${expressionSourceText(node.right) ?? 'right'}`;
|
|
60
|
+
return String(node.type ?? node.kindName ?? node.kind ?? 'expression');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function templateLiteralText(node) {
|
|
64
|
+
const parts = [];
|
|
65
|
+
for (let index = 0; index < node.quasis.length; index += 1) {
|
|
66
|
+
parts.push(node.quasis[index]?.value?.raw ?? '');
|
|
67
|
+
if (node.expressions?.[index]) parts.push('${', expressionSourceText(node.expressions[index]) ?? 'expression', '}');
|
|
68
|
+
}
|
|
69
|
+
return `\`${parts.join('')}\``;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function memberExpressionText(node) {
|
|
73
|
+
const object = expressionSourceText(node.object) ?? 'object';
|
|
74
|
+
const property = expressionSourceText(node.property) ?? 'property';
|
|
75
|
+
return node.computed ? `${object}[${property}]` : `${object}.${property}`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function compactRecord(record) {
|
|
79
|
+
return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined));
|
|
80
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { hashSemanticValue } from '@shapeshift-labs/frontier-lang-kernel';
|
|
2
|
+
|
|
3
|
+
const UNKNOWN_HOST_DEPENDENCY_MODULE_SPECIFIER = '<host-dependency>';
|
|
4
|
+
|
|
5
|
+
export function importMetaUrlDependencyMetadata(node, options = {}) {
|
|
6
|
+
if (!isNewUrlExpression(node, options)) return undefined;
|
|
7
|
+
const args = nodeArguments(node);
|
|
8
|
+
const firstArgument = args[0];
|
|
9
|
+
const secondArgument = args[1];
|
|
10
|
+
const moduleSpecifier = literalString(firstArgument);
|
|
11
|
+
if (!firstArgument || !isImportMetaUrl(secondArgument)) return undefined;
|
|
12
|
+
const expressionText = expressionTextForNode(node) ?? `new URL(${JSON.stringify(moduleSpecifier)}, import.meta.url)`;
|
|
13
|
+
return hostDependencyRecord(moduleSpecifier ?? UNKNOWN_HOST_DEPENDENCY_MODULE_SPECIFIER, 'import-meta-url', 'import.meta.url', expressionText, {
|
|
14
|
+
staticSpecifier: Boolean(moduleSpecifier)
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function hostModuleDependencyMetadata(node, options = {}) {
|
|
19
|
+
const importMetaUrl = importMetaUrlDependencyMetadata(node, options);
|
|
20
|
+
if (importMetaUrl) return [importMetaUrl];
|
|
21
|
+
if (isNewExpression(node, options)) return workerConstructorDependencyMetadata(node);
|
|
22
|
+
if (isCallExpression(node, options)) return callExpressionDependencyMetadata(node);
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function hostDependencyEdgeFields(metadata) {
|
|
27
|
+
return compactRecord({
|
|
28
|
+
hostDependency: metadata?.hostDependency,
|
|
29
|
+
hostDependencyKind: metadata?.hostDependencyKind,
|
|
30
|
+
hostDependencyBase: metadata?.hostDependencyBase,
|
|
31
|
+
hostDependencyExpressionText: metadata?.hostDependencyExpressionText,
|
|
32
|
+
hostDependencyExpressionHash: metadata?.hostDependencyExpressionHash,
|
|
33
|
+
hostDependencyStaticSpecifierEvidence: metadata?.hostDependencyStaticSpecifierEvidence,
|
|
34
|
+
hostDependencyRuntimeResolutionClaim: metadata?.hostDependencyRuntimeResolutionClaim,
|
|
35
|
+
hostDependencyResolutionProofRequired: metadata?.hostDependencyResolutionProofRequired
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function isNewUrlExpression(node, options) {
|
|
40
|
+
return isNewExpression(node, options) && expressionTextForNode(node.expression ?? node.callee) === 'URL';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function isNewExpression(node, options = {}) {
|
|
44
|
+
return nodeArguments(node).length > 0 && (options.kind === 'NewExpression' || node?.type === 'NewExpression' || node?.kindName === 'NewExpression');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function isCallExpression(node, options = {}) {
|
|
48
|
+
return nodeArguments(node).length > 0 && (options.kind === 'CallExpression' || node?.type === 'CallExpression');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function workerConstructorDependencyMetadata(node) {
|
|
52
|
+
const callee = expressionTextForNode(node.expression ?? node.callee);
|
|
53
|
+
const kind = callee === 'Worker' ? 'worker-constructor' : callee === 'SharedWorker' ? 'shared-worker-constructor' : undefined;
|
|
54
|
+
const firstArgument = nodeArguments(node)[0];
|
|
55
|
+
if (!kind || !firstArgument || isNewUrlExpression(firstArgument, {}) || expressionTextForNode(firstArgument)?.startsWith('new URL(')) return [];
|
|
56
|
+
const moduleSpecifier = literalString(firstArgument);
|
|
57
|
+
return [hostDependencyRecord(moduleSpecifier ?? UNKNOWN_HOST_DEPENDENCY_MODULE_SPECIFIER, kind, callee, expressionTextForNode(node), {
|
|
58
|
+
staticSpecifier: Boolean(moduleSpecifier)
|
|
59
|
+
})];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function callExpressionDependencyMetadata(node) {
|
|
63
|
+
const callee = expressionTextForNode(node.expression ?? node.callee);
|
|
64
|
+
const args = nodeArguments(node);
|
|
65
|
+
if (callee === 'importScripts') return args.map((argument) =>
|
|
66
|
+
hostDependencyRecord(literalString(argument) ?? UNKNOWN_HOST_DEPENDENCY_MODULE_SPECIFIER, 'worker-import-scripts', 'importScripts', expressionTextForNode(node), {
|
|
67
|
+
staticSpecifier: Boolean(literalString(argument))
|
|
68
|
+
})).filter(Boolean);
|
|
69
|
+
const first = literalString(args[0]);
|
|
70
|
+
if (!args[0]) return [];
|
|
71
|
+
if (callee === 'import.meta.resolve') return [hostDependencyRecord(first ?? UNKNOWN_HOST_DEPENDENCY_MODULE_SPECIFIER, 'import-meta-resolve', 'import.meta', expressionTextForNode(node), { staticSpecifier: Boolean(first) })];
|
|
72
|
+
if (callee === 'require.resolve') return [hostDependencyRecord(first ?? UNKNOWN_HOST_DEPENDENCY_MODULE_SPECIFIER, 'require-resolve', 'require', expressionTextForNode(node), { staticSpecifier: Boolean(first) })];
|
|
73
|
+
if (callee?.endsWith('.register') && callee.includes('serviceWorker')) return [hostDependencyRecord(first ?? UNKNOWN_HOST_DEPENDENCY_MODULE_SPECIFIER, 'service-worker-register', callee.replace(/\.register$/, ''), expressionTextForNode(node), { staticSpecifier: Boolean(first) })];
|
|
74
|
+
if (callee?.endsWith('.addModule') && /worklet/i.test(callee)) return [hostDependencyRecord(first ?? UNKNOWN_HOST_DEPENDENCY_MODULE_SPECIFIER, 'worklet-add-module', callee.replace(/\.addModule$/, ''), expressionTextForNode(node), { staticSpecifier: Boolean(first) })];
|
|
75
|
+
return [];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function nodeArguments(node) {
|
|
79
|
+
return node?.arguments && typeof node.arguments.length === 'number' ? Array.from(node.arguments) : [];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function hostDependencyRecord(moduleSpecifier, kind, base, expressionText, options = {}) {
|
|
83
|
+
const staticSpecifier = options.staticSpecifier !== false;
|
|
84
|
+
return {
|
|
85
|
+
moduleSpecifier,
|
|
86
|
+
metadata: {
|
|
87
|
+
importKind: kind,
|
|
88
|
+
hostDependency: true,
|
|
89
|
+
hostDependencyKind: kind,
|
|
90
|
+
hostDependencyBase: base,
|
|
91
|
+
hostDependencyExpressionText: expressionText,
|
|
92
|
+
hostDependencyExpressionHash: hashSemanticValue({ kind, moduleSpecifier, base, expressionText }),
|
|
93
|
+
hostDependencyStaticSpecifierEvidence: staticSpecifier,
|
|
94
|
+
hostDependencyRuntimeResolutionClaim: false,
|
|
95
|
+
hostDependencyResolutionProofRequired: !staticSpecifier
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function isImportMetaUrl(node) {
|
|
101
|
+
const text = expressionTextForNode(node);
|
|
102
|
+
if (text?.replace(/\s+/g, '') === 'import.meta.url') return true;
|
|
103
|
+
const property = propertyName(node.property ?? node.name);
|
|
104
|
+
if (property !== 'url') return false;
|
|
105
|
+
const object = node.object ?? node.expression;
|
|
106
|
+
if (String(object?.type ?? object?.kindName ?? '') === 'MetaProperty') return importMetaText(object) === 'import.meta';
|
|
107
|
+
return expressionTextForNode(object)?.replace(/\s+/g, '') === 'import.meta';
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function importMetaText(node) {
|
|
111
|
+
const meta = propertyName(node.meta);
|
|
112
|
+
const property = propertyName(node.property);
|
|
113
|
+
return meta && property ? `${meta}.${property}` : expressionTextForNode(node);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function literalString(node) {
|
|
117
|
+
if (!node) return undefined;
|
|
118
|
+
if (typeof node.value === 'string') return node.value;
|
|
119
|
+
if (node.type === 'TemplateLiteral' && (node.expressions ?? []).length === 0 && (node.quasis ?? []).length === 1) {
|
|
120
|
+
return node.quasis[0]?.value?.cooked ?? node.quasis[0]?.value?.raw;
|
|
121
|
+
}
|
|
122
|
+
if (typeof node.text === 'string' && !/^[A-Za-z_$][\w$]*$/.test(node.text)) return node.text;
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function propertyName(node) {
|
|
127
|
+
if (!node) return undefined;
|
|
128
|
+
if (typeof node === 'string') return node;
|
|
129
|
+
if (typeof node.name === 'string') return node.name;
|
|
130
|
+
if (typeof node.escapedText === 'string') return node.escapedText;
|
|
131
|
+
if (typeof node.text === 'string') return node.text;
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function expressionTextForNode(node) {
|
|
136
|
+
if (!node) return undefined;
|
|
137
|
+
if (typeof node.getText === 'function') {
|
|
138
|
+
try {
|
|
139
|
+
const text = node.getText();
|
|
140
|
+
if (typeof text === 'string' && text.trim()) return text.trim();
|
|
141
|
+
} catch {}
|
|
142
|
+
}
|
|
143
|
+
if (node.type === 'MetaProperty') return importMetaText(node);
|
|
144
|
+
if (node.type === 'MemberExpression') {
|
|
145
|
+
const object = expressionTextForNode(node.object);
|
|
146
|
+
const property = expressionTextForNode(node.property);
|
|
147
|
+
return object && property ? node.computed ? `${object}[${property}]` : `${object}.${property}` : undefined;
|
|
148
|
+
}
|
|
149
|
+
if (node.expression && node.name) {
|
|
150
|
+
const object = expressionTextForNode(node.expression);
|
|
151
|
+
const property = expressionTextForNode(node.name);
|
|
152
|
+
return object && property ? `${object}.${property}` : undefined;
|
|
153
|
+
}
|
|
154
|
+
if (node.type === 'CallExpression') return `${expressionTextForNode(node.callee) ?? 'call'}(${argumentText(node)})`;
|
|
155
|
+
if (node.expression && Array.isArray(node.arguments)) return `${expressionTextForNode(node.expression) ?? 'call'}(${argumentText(node)})`;
|
|
156
|
+
if (node.type === 'NewExpression') return `new ${expressionTextForNode(node.callee) ?? 'constructor'}(${argumentText(node)})`;
|
|
157
|
+
if (node.type === 'TemplateLiteral' && Array.isArray(node.quasis)) return templateLiteralText(node);
|
|
158
|
+
return propertyName(node);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function argumentText(node) {
|
|
162
|
+
return nodeArguments(node).map((argument) => expressionTextForNode(argument) ?? 'expression').join(', ');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function templateLiteralText(node) {
|
|
166
|
+
const parts = [];
|
|
167
|
+
for (let index = 0; index < node.quasis.length; index += 1) {
|
|
168
|
+
parts.push(node.quasis[index]?.value?.raw ?? '');
|
|
169
|
+
if (node.expressions?.[index]) parts.push('${', expressionTextForNode(node.expressions[index]) ?? 'expression', '}');
|
|
170
|
+
}
|
|
171
|
+
return `\`${parts.join('')}\``;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function compactRecord(record) {
|
|
175
|
+
return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined));
|
|
176
|
+
}
|
|
@@ -14,9 +14,8 @@ export function importNativeSource(input) {
|
|
|
14
14
|
? createNativeSourcePreservation({
|
|
15
15
|
language,
|
|
16
16
|
sourcePath,
|
|
17
|
-
sourceHash: declaredSourceHash,
|
|
18
|
-
|
|
19
|
-
metadata: { importIdPart }
|
|
17
|
+
sourceHash: declaredSourceHash, sourceText: input.sourceText,
|
|
18
|
+
parserTriviaEvidence: input.parserTriviaEvidence ?? input.nativeAst?.metadata?.parserTriviaEvidence ?? input.nativeAstMetadata?.parserTriviaEvidence, metadata: { importIdPart }
|
|
20
19
|
})
|
|
21
20
|
: undefined);
|
|
22
21
|
const lightweight = !input.nativeAst && !input.nodes && input.sourceText
|