@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,307 @@
|
|
|
1
|
+
import { hashSemanticValue } from '@shapeshift-labs/frontier-lang-kernel';
|
|
2
|
+
import { idFragment } from '../../native-import-utils.js';
|
|
3
|
+
import { LexicalUseDefReasonCodes } from '../../js-ts-semantic-scope-use-def-utils.js';
|
|
4
|
+
import { resolveRelativeProjectModule } from './projectSymbolGraphModuleResolution.js';
|
|
5
|
+
|
|
6
|
+
function createScopeGraphContext(semanticIndex, imports, publicKeys) {
|
|
7
|
+
const sourceTextsByPath = new Map(imports
|
|
8
|
+
.map((imported) => [imported?.sourcePath ?? imported?.nativeSource?.sourcePath, nativeImportSourceText(imported)])
|
|
9
|
+
.filter(([sourcePath, sourceText]) => sourcePath && sourceText));
|
|
10
|
+
const documentsByPath = new Map((semanticIndex?.documents ?? [])
|
|
11
|
+
.filter((document) => document?.path)
|
|
12
|
+
.map((document) => [document.path, document]));
|
|
13
|
+
for (const imported of imports ?? []) {
|
|
14
|
+
const sourcePath = imported?.sourcePath ?? imported?.nativeSource?.sourcePath;
|
|
15
|
+
if (!sourcePath || documentsByPath.has(sourcePath)) continue;
|
|
16
|
+
documentsByPath.set(sourcePath, {
|
|
17
|
+
id: `doc_${idFragment(sourcePath)}`,
|
|
18
|
+
path: sourcePath,
|
|
19
|
+
sourceHash: imported?.nativeSource?.sourceHash ?? imported?.metadata?.sourceHash
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const importAliases = importAliasRecords(semanticIndex, documentsByPath);
|
|
23
|
+
const exportAliases = exportAliasRecords(semanticIndex, documentsByPath, sourceTextsByPath);
|
|
24
|
+
return {
|
|
25
|
+
publicKeys,
|
|
26
|
+
sourceTextsByPath,
|
|
27
|
+
importAliases,
|
|
28
|
+
exportAliases,
|
|
29
|
+
importAliasesByLocalKey: groupFirst(importAliases, (alias) => localKey(alias.sourcePath, alias.localName)),
|
|
30
|
+
exportAliasesByExportKey: groupFirst(exportAliases, (alias) => exportKey(alias.sourcePath, alias.exportedName)),
|
|
31
|
+
exportAliasesByLocalKey: groupByKey(exportAliases.filter((alias) => !alias.moduleSpecifier), (alias) => localKey(alias.sourcePath, alias.localName))
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function importAliasRecords(semanticIndex, documentsByPath) {
|
|
36
|
+
return (semanticIndex?.symbols ?? []).flatMap((symbol) => {
|
|
37
|
+
if (symbol?.kind !== 'import') return [];
|
|
38
|
+
const metadata = objectValue(symbol.metadata);
|
|
39
|
+
const sourcePath = symbol.definitionSpan?.path ?? metadata.sourcePath;
|
|
40
|
+
const moduleSpecifier = firstString(metadata.moduleSpecifier, metadata.importPath, metadata.source);
|
|
41
|
+
const localName = firstString(metadata.localName, symbol.name);
|
|
42
|
+
if (!sourcePath || !localName || !moduleSpecifier) return [];
|
|
43
|
+
const importedName = firstString(metadata.importedName, metadata.exportedName, localName);
|
|
44
|
+
const resolved = moduleSpecifier.startsWith('.')
|
|
45
|
+
? resolveRelativeProjectModule(sourcePath, moduleSpecifier, documentsByPath)
|
|
46
|
+
: undefined;
|
|
47
|
+
return [compactRecord({
|
|
48
|
+
symbolId: symbol.id,
|
|
49
|
+
sourcePath,
|
|
50
|
+
localName,
|
|
51
|
+
importedName,
|
|
52
|
+
exportedName: firstString(metadata.exportedName),
|
|
53
|
+
moduleSpecifier,
|
|
54
|
+
importKind: firstString(metadata.importKind),
|
|
55
|
+
isTypeOnly: metadata.isTypeOnly === true || metadata.typeOnly === true || undefined,
|
|
56
|
+
resolvedSourcePath: resolved?.path,
|
|
57
|
+
targetDocumentId: resolved?.documentId,
|
|
58
|
+
resolutionKind: resolved?.kind,
|
|
59
|
+
resolutionPathVariant: resolved?.resolutionPathVariant
|
|
60
|
+
})];
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function exportAliasRecords(semanticIndex, documentsByPath, sourceTextsByPath) {
|
|
65
|
+
return (semanticIndex?.symbols ?? []).flatMap((symbol) => {
|
|
66
|
+
if (symbol?.kind !== 'export') return [];
|
|
67
|
+
const metadata = objectValue(symbol.metadata);
|
|
68
|
+
const sourcePath = symbol.definitionSpan?.path ?? metadata.sourcePath;
|
|
69
|
+
const exportedName = firstString(metadata.exportedName, symbol.name);
|
|
70
|
+
if (!sourcePath || !exportedName || exportedName.startsWith('{')) return [];
|
|
71
|
+
const moduleSpecifier = firstString(metadata.moduleSpecifier, metadata.importPath, metadata.exportPath, metadata.source);
|
|
72
|
+
const resolved = moduleSpecifier?.startsWith('.')
|
|
73
|
+
? resolveRelativeProjectModule(sourcePath, moduleSpecifier, documentsByPath)
|
|
74
|
+
: undefined;
|
|
75
|
+
return [compactRecord({
|
|
76
|
+
symbolId: symbol.id,
|
|
77
|
+
sourcePath,
|
|
78
|
+
localName: firstString(metadata.localName, defaultExportLocalName(sourceTextsByPath.get(sourcePath), exportedName, moduleSpecifier), exportedName),
|
|
79
|
+
importedName: firstString(metadata.importedName, metadata.localName, exportedName),
|
|
80
|
+
exportedName,
|
|
81
|
+
exportKind: firstString(metadata.exportKind),
|
|
82
|
+
moduleSpecifier,
|
|
83
|
+
resolvedSourcePath: resolved?.path,
|
|
84
|
+
targetDocumentId: resolved?.documentId,
|
|
85
|
+
resolutionKind: resolved?.kind,
|
|
86
|
+
resolutionPathVariant: resolved?.resolutionPathVariant,
|
|
87
|
+
isTypeOnly: metadata.isTypeOnly === true || metadata.typeOnly === true || undefined
|
|
88
|
+
})];
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function attachAliasMetadata(bindings, directUseHashes, context) {
|
|
93
|
+
const bindingsByLocal = groupFirst(bindings, (binding) => localKey(binding.sourcePath, binding.name));
|
|
94
|
+
return bindings.map((binding) => {
|
|
95
|
+
const localUseHash = directUseHashes.get(binding.id);
|
|
96
|
+
const exportAliases = exportAliasesForBinding(binding, context);
|
|
97
|
+
const importAlias = binding.bindingKind === 'import'
|
|
98
|
+
? context.importAliasesByLocalKey.get(localKey(binding.sourcePath, binding.name))
|
|
99
|
+
: undefined;
|
|
100
|
+
const resolved = importAlias ? resolveImportAliasBinding(importAlias, bindingsByLocal, directUseHashes, context) : undefined;
|
|
101
|
+
const exportedNames = uniqueStrings(exportAliases.filter((alias) => alias.sourcePath === binding.sourcePath).map((alias) => alias.exportedName));
|
|
102
|
+
const reExportedNames = uniqueStrings(exportAliases.filter((alias) => alias.sourcePath !== binding.sourcePath).map((alias) => alias.exportedName));
|
|
103
|
+
const scopeUseDefReasonCodes = uniqueStrings([...(binding.scopeUseDefReasonCodes ?? []), ...(resolved?.aliasResolutionReasonCodes ?? [])]);
|
|
104
|
+
const aliasHash = exportAliases.length || importAlias ? hashSemanticValue({
|
|
105
|
+
kind: 'frontier.lang.projectScopeAliasHash',
|
|
106
|
+
binding: binding.signatureHash,
|
|
107
|
+
importAlias: aliasHashRecord(importAlias),
|
|
108
|
+
exportAliases: exportAliases.map(aliasHashRecord).sort(compareJson)
|
|
109
|
+
}) : undefined;
|
|
110
|
+
const resolvedUseHash = resolved?.resolvedBindingUseHash ? hashSemanticValue({
|
|
111
|
+
kind: 'frontier.lang.projectScopeImportResolvedUseHash',
|
|
112
|
+
binding: binding.signatureHash,
|
|
113
|
+
moduleSpecifier: importAlias.moduleSpecifier,
|
|
114
|
+
importedName: importAlias.importedName,
|
|
115
|
+
resolvedBinding: resolved.resolvedBindingSignatureHash,
|
|
116
|
+
resolvedUseHash: resolved.resolvedBindingUseHash
|
|
117
|
+
}) : undefined;
|
|
118
|
+
return compactRecord({
|
|
119
|
+
...binding,
|
|
120
|
+
localUseHash,
|
|
121
|
+
exportedNames: exportedNames.length ? exportedNames : undefined,
|
|
122
|
+
reExportedNames: reExportedNames.length ? reExportedNames : undefined,
|
|
123
|
+
aliasHash,
|
|
124
|
+
importAlias: importAlias ? true : undefined,
|
|
125
|
+
moduleSpecifier: importAlias?.moduleSpecifier,
|
|
126
|
+
importedName: importAlias?.importedName,
|
|
127
|
+
localName: importAlias?.localName,
|
|
128
|
+
importKind: importAlias?.importKind,
|
|
129
|
+
isTypeOnly: importAlias?.isTypeOnly,
|
|
130
|
+
resolvedSourcePath: importAlias?.resolvedSourcePath,
|
|
131
|
+
targetDocumentId: importAlias?.targetDocumentId,
|
|
132
|
+
resolutionKind: importAlias?.resolutionKind,
|
|
133
|
+
resolutionPathVariant: importAlias?.resolutionPathVariant,
|
|
134
|
+
...resolved,
|
|
135
|
+
aliasResolutionStatus: resolved?.aliasResolutionStatus,
|
|
136
|
+
aliasResolutionReasonCodes: resolved?.aliasResolutionReasonCodes,
|
|
137
|
+
scopeUseDefStatus: resolved?.aliasResolutionStatus === 'blocked' ? 'blocked' : binding.scopeUseDefStatus,
|
|
138
|
+
scopeUseDefReasonCodes: scopeUseDefReasonCodes.length ? scopeUseDefReasonCodes : undefined,
|
|
139
|
+
resolvedUseHash
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function resolveImportAliasBinding(importAlias, bindingsByLocal, directUseHashes, context) {
|
|
145
|
+
if (!importAlias.resolvedSourcePath || !importAlias.importedName || importAlias.importedName === '*') return undefined;
|
|
146
|
+
const origin = resolveExportOrigin(context, importAlias.resolvedSourcePath, importAlias.importedName);
|
|
147
|
+
const target = bindingsByLocal.get(localKey(origin?.sourcePath ?? importAlias.resolvedSourcePath, origin?.localName ?? importAlias.importedName));
|
|
148
|
+
if (!target) return compactRecord({
|
|
149
|
+
resolvedExportName: importAlias.importedName,
|
|
150
|
+
originSourcePath: origin?.sourcePath,
|
|
151
|
+
originExportedName: origin?.exportedName,
|
|
152
|
+
originSymbolId: origin?.symbolId,
|
|
153
|
+
aliasResolutionStatus: 'blocked',
|
|
154
|
+
aliasResolutionReasonCodes: [LexicalUseDefReasonCodes.importAliasTargetUnresolved]
|
|
155
|
+
});
|
|
156
|
+
return compactRecord({
|
|
157
|
+
resolvedExportName: importAlias.importedName,
|
|
158
|
+
originSourcePath: target.sourcePath,
|
|
159
|
+
originExportedName: origin?.exportedName,
|
|
160
|
+
originSymbolId: origin?.symbolId,
|
|
161
|
+
resolvedBindingId: target.id,
|
|
162
|
+
resolvedBindingName: target.name,
|
|
163
|
+
resolvedBindingKind: target.bindingKind,
|
|
164
|
+
resolvedBindingSignatureHash: target.signatureHash,
|
|
165
|
+
resolvedBindingUseHash: directUseHashes.get(target.id),
|
|
166
|
+
resolvedPublicOwnerName: target.publicOwnerName
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function exportAliasesForBinding(binding, context) {
|
|
171
|
+
const directAliases = context.exportAliasesByLocalKey.get(localKey(binding.sourcePath, binding.name)) ?? [];
|
|
172
|
+
const reExportAliases = context.exportAliases
|
|
173
|
+
.filter((alias) => alias.moduleSpecifier && alias.resolvedSourcePath)
|
|
174
|
+
.filter((alias) => {
|
|
175
|
+
const origin = resolveExportOrigin(context, alias.resolvedSourcePath, alias.importedName ?? alias.localName);
|
|
176
|
+
return origin?.sourcePath === binding.sourcePath && origin?.localName === binding.name;
|
|
177
|
+
});
|
|
178
|
+
const reExportImportAliases = context.importAliases
|
|
179
|
+
.filter((alias) => alias.exportedName && alias.resolvedSourcePath)
|
|
180
|
+
.filter((alias) => {
|
|
181
|
+
const origin = resolveExportOrigin(context, alias.resolvedSourcePath, alias.importedName ?? alias.localName);
|
|
182
|
+
return origin?.sourcePath === binding.sourcePath && origin?.localName === binding.name;
|
|
183
|
+
});
|
|
184
|
+
return uniqueAliasRecords([...directAliases, ...reExportAliases, ...reExportImportAliases]);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function resolveExportOrigin(context, sourcePath, exportedName, seen = new Set()) {
|
|
188
|
+
if (!sourcePath || !exportedName || exportedName === '*') return undefined;
|
|
189
|
+
const key = exportKey(sourcePath, exportedName);
|
|
190
|
+
if (seen.has(key)) return { sourcePath, localName: exportedName, exportedName };
|
|
191
|
+
seen.add(key);
|
|
192
|
+
const alias = context.exportAliasesByExportKey.get(key);
|
|
193
|
+
if (!alias) return { sourcePath, localName: exportedName, exportedName };
|
|
194
|
+
if (alias.moduleSpecifier && alias.resolvedSourcePath) {
|
|
195
|
+
return resolveExportOrigin(context, alias.resolvedSourcePath, alias.importedName ?? alias.localName, seen);
|
|
196
|
+
}
|
|
197
|
+
return { sourcePath, localName: alias.localName ?? alias.exportedName, exportedName: alias.exportedName, symbolId: alias.symbolId };
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function attachReferenceAliasMetadata(references, bindings) {
|
|
201
|
+
const bindingsById = new Map(bindings.map((binding) => [binding.id, binding]));
|
|
202
|
+
return references.map((reference) => {
|
|
203
|
+
const binding = bindingsById.get(reference.bindingId);
|
|
204
|
+
const reasonCodes = uniqueStrings([...(reference.reasonCodes ?? []), ...(binding?.aliasResolutionReasonCodes ?? [])]);
|
|
205
|
+
const resolvedUseHash = binding?.resolvedUseHash ? hashSemanticValue({
|
|
206
|
+
kind: 'frontier.lang.projectScopeReferenceResolvedUseHash',
|
|
207
|
+
reference: reference.signatureHash,
|
|
208
|
+
resolvedUseHash: binding.resolvedUseHash,
|
|
209
|
+
resolvedBindingUseHash: binding.resolvedBindingUseHash
|
|
210
|
+
}) : undefined;
|
|
211
|
+
return compactRecord({
|
|
212
|
+
...reference,
|
|
213
|
+
importAlias: binding?.importAlias,
|
|
214
|
+
moduleSpecifier: binding?.moduleSpecifier,
|
|
215
|
+
importedName: binding?.importedName,
|
|
216
|
+
resolvedSourcePath: binding?.resolvedSourcePath,
|
|
217
|
+
originSourcePath: binding?.originSourcePath,
|
|
218
|
+
resolvedExportName: binding?.resolvedExportName,
|
|
219
|
+
resolvedBindingId: binding?.resolvedBindingId,
|
|
220
|
+
resolvedBindingName: binding?.resolvedBindingName,
|
|
221
|
+
resolvedBindingUseHash: binding?.resolvedBindingUseHash,
|
|
222
|
+
aliasResolutionStatus: binding?.aliasResolutionStatus,
|
|
223
|
+
aliasResolutionReasonCodes: binding?.aliasResolutionReasonCodes,
|
|
224
|
+
status: binding?.aliasResolutionStatus ?? reference.status,
|
|
225
|
+
reasonCodes: reasonCodes.length ? reasonCodes : undefined,
|
|
226
|
+
resolvedUseHash
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function defaultExportLocalName(sourceText, exportedName, moduleSpecifier) {
|
|
232
|
+
if (exportedName !== 'default' || moduleSpecifier || typeof sourceText !== 'string') return undefined;
|
|
233
|
+
return firstString(
|
|
234
|
+
sourceText.match(/\bexport\s+default\s+(?:async\s+)?function\*?\s+([A-Za-z_$][\w$]*)/)?.[1],
|
|
235
|
+
sourceText.match(/\bexport\s+default\s+(?:abstract\s+)?class\s+([A-Za-z_$][\w$]*)/)?.[1],
|
|
236
|
+
sourceText.match(/\bexport\s+default\s+([A-Za-z_$][\w$]*)\s*;(?=\s*(?:$|\n))/)?.[1],
|
|
237
|
+
sourceText.match(/\bexport\s+default\s+([A-Za-z_$][\w$]*)\s*(?=$)/)?.[1]
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function nativeImportSourceText(imported) {
|
|
242
|
+
return imported?.metadata?.sourcePreservation?.sourceText
|
|
243
|
+
?? imported?.nativeSource?.metadata?.sourcePreservation?.sourceText
|
|
244
|
+
?? imported?.nativeAst?.metadata?.sourcePreservation?.sourceText
|
|
245
|
+
?? imported?.universalAst?.metadata?.sourcePreservation?.sourceText
|
|
246
|
+
?? imported?.sourceText;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function aliasHashRecord(alias) {
|
|
250
|
+
return alias ? JSON.stringify(compactRecord({
|
|
251
|
+
sourcePath: alias.sourcePath,
|
|
252
|
+
moduleSpecifier: alias.moduleSpecifier,
|
|
253
|
+
localName: alias.localName,
|
|
254
|
+
importedName: alias.importedName,
|
|
255
|
+
exportedName: alias.exportedName,
|
|
256
|
+
symbolId: alias.symbolId,
|
|
257
|
+
resolvedSourcePath: alias.resolvedSourcePath
|
|
258
|
+
})) : undefined;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function localKey(sourcePath, name) { return sourcePath && name ? `${sourcePath}\0${name}` : undefined; }
|
|
262
|
+
function exportKey(sourcePath, name) { return sourcePath && name ? `${sourcePath}\0${name}` : undefined; }
|
|
263
|
+
function compactRecord(record) { return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined)); }
|
|
264
|
+
function objectValue(value) { return value && typeof value === 'object' && !Array.isArray(value) ? value : {}; }
|
|
265
|
+
function compareJson(left, right) { return left < right ? -1 : left > right ? 1 : 0; }
|
|
266
|
+
function uniqueStrings(values) { return [...new Set(values.filter((value) => typeof value === 'string' && value.length > 0))]; }
|
|
267
|
+
|
|
268
|
+
function firstString(...values) {
|
|
269
|
+
for (const value of values) if (value !== undefined && value !== null && String(value)) return String(value);
|
|
270
|
+
return undefined;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function groupByKey(records, keyFn) {
|
|
274
|
+
const result = new Map();
|
|
275
|
+
for (const record of records) {
|
|
276
|
+
const key = keyFn(record);
|
|
277
|
+
if (key) result.set(key, [...(result.get(key) ?? []), record]);
|
|
278
|
+
}
|
|
279
|
+
return result;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function groupFirst(records, keyFn) {
|
|
283
|
+
const result = new Map();
|
|
284
|
+
for (const record of records) {
|
|
285
|
+
const key = keyFn(record);
|
|
286
|
+
if (key && !result.has(key)) result.set(key, record);
|
|
287
|
+
}
|
|
288
|
+
return result;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function uniqueAliasRecords(records) {
|
|
292
|
+
const seen = new Set();
|
|
293
|
+
return records.filter((record) => {
|
|
294
|
+
const key = aliasHashRecord(record);
|
|
295
|
+
if (!key || seen.has(key)) return false;
|
|
296
|
+
seen.add(key);
|
|
297
|
+
return true;
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export {
|
|
302
|
+
attachAliasMetadata,
|
|
303
|
+
attachReferenceAliasMetadata,
|
|
304
|
+
compactRecord,
|
|
305
|
+
createScopeGraphContext,
|
|
306
|
+
nativeImportSourceText
|
|
307
|
+
};
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { hashSemanticValue } from '@shapeshift-labs/frontier-lang-kernel';
|
|
2
|
+
import { idFragment } from '../../native-import-utils.js';
|
|
3
|
+
import { collectBindings } from '../../js-ts-semantic-scope-use-def-bindings.js';
|
|
4
|
+
import { createBraceDepthIndex, isPropertyAccess, likelyTypeReference, maskNonCode, tokenize } from '../../js-ts-semantic-scope-use-def-scan.js';
|
|
5
|
+
import { LexicalUseDefReasonCodes, identifierRegExp, namespaceOverlap, rangeKey } from '../../js-ts-semantic-scope-use-def-utils.js';
|
|
6
|
+
import { bindingRecords, closureCaptureEvidence, compactRecord, semanticSpanForHash, sourceSpanForRange } from './projectSymbolGraphScopeUseDefRecordBuilders.js';
|
|
7
|
+
import { nearestPublicOwnerForOffset } from './projectSymbolGraphScopeUseDefOwners.js';
|
|
8
|
+
import { readStaticMemberLiteral } from './staticMemberLiteral.js';
|
|
9
|
+
|
|
10
|
+
const jsTsKeywords = new Set('abstract as async await break case catch class const continue debugger declare default delete do else enum export extends false finally for from function if implements import in infer instanceof interface keyof let module namespace new null of package private protected public readonly return satisfies static super switch this throw true try type typeof undefined unique unknown var void while with yield'.split(' '));
|
|
11
|
+
|
|
12
|
+
function lexicalScopeRecordsForImport(sourceText, context) {
|
|
13
|
+
const masked = maskNonCode(sourceText);
|
|
14
|
+
const tokens = tokenize(masked.code).map((token, index) => ({ ...token, index, depth: 0 }));
|
|
15
|
+
const depthAt = createBraceDepthIndex(masked.code);
|
|
16
|
+
for (const token of tokens) token.depth = depthAt[token.start] ?? 0;
|
|
17
|
+
const rawBindings = collectBindings(masked.code, tokens, depthAt);
|
|
18
|
+
const bindings = bindingRecords(rawBindings, context);
|
|
19
|
+
const references = [
|
|
20
|
+
...referenceRecords(tokens, masked, bindings, context),
|
|
21
|
+
...receiverMemberReferenceRecords(masked, context)
|
|
22
|
+
];
|
|
23
|
+
return {
|
|
24
|
+
scopeBindingRecords: bindings,
|
|
25
|
+
scopeReferenceRecords: references
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function receiverMemberReferenceRecords(masked, context) {
|
|
30
|
+
const code = masked.code;
|
|
31
|
+
const records = [];
|
|
32
|
+
for (const match of code.matchAll(/\b(this|super)\b/g)) {
|
|
33
|
+
const receiver = match[1];
|
|
34
|
+
if (isPropertyAccess(code, match.index)) continue;
|
|
35
|
+
const access = receiverMemberAccess(context.sourceText ?? code, code, match.index + receiver.length);
|
|
36
|
+
if (!access) continue;
|
|
37
|
+
const publicOwner = nearestPublicOwnerForOffset(context.publicOwners, match.index);
|
|
38
|
+
if (!publicOwner) continue;
|
|
39
|
+
const writeOperation = namespaceMemberWriteOperation(code, match.index, access.accessEnd);
|
|
40
|
+
const sourceSpan = sourceSpanForRange(context, match.index, access.accessEnd);
|
|
41
|
+
const referenceKind = `${receiver}-member-${writeOperation ? 'write' : 'read'}`;
|
|
42
|
+
records.push(compactRecord({
|
|
43
|
+
id: `scope_ref_${idFragment(context.sourcePath)}_receiver_${records.length + 1}`,
|
|
44
|
+
name: receiver,
|
|
45
|
+
namespace: 'value',
|
|
46
|
+
namespaces: ['value'],
|
|
47
|
+
sourcePath: context.sourcePath,
|
|
48
|
+
sourceHash: context.sourceHash,
|
|
49
|
+
sourceSpan,
|
|
50
|
+
start: match.index,
|
|
51
|
+
end: access.accessEnd,
|
|
52
|
+
depth: 0,
|
|
53
|
+
referenceKind,
|
|
54
|
+
receiverKind: receiver,
|
|
55
|
+
memberName: access.memberName,
|
|
56
|
+
memberStart: access.memberStart,
|
|
57
|
+
memberEnd: access.memberEnd,
|
|
58
|
+
memberComputed: access.memberComputed,
|
|
59
|
+
memberLiteralKind: access.memberLiteralKind,
|
|
60
|
+
memberStaticTemplateLiteral: access.memberLiteralKind === 'static-template-literal' ? true : undefined,
|
|
61
|
+
memberOptional: access.memberOptional,
|
|
62
|
+
writeOperation,
|
|
63
|
+
publicContract: true,
|
|
64
|
+
publicOwnerName: publicOwner.name,
|
|
65
|
+
signatureHash: hashSemanticValue({
|
|
66
|
+
kind: 'frontier.lang.projectScopeReceiverMemberReference',
|
|
67
|
+
receiver,
|
|
68
|
+
memberName: access.memberName,
|
|
69
|
+
memberComputed: access.memberComputed,
|
|
70
|
+
memberOptional: access.memberOptional,
|
|
71
|
+
writeOperation,
|
|
72
|
+
publicOwnerName: publicOwner.name,
|
|
73
|
+
sourceSpan: semanticSpanForHash(sourceSpan)
|
|
74
|
+
})
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
return records;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function receiverMemberAccess(sourceText, code, receiverEnd) {
|
|
81
|
+
let index = receiverEnd;
|
|
82
|
+
while (index < code.length && /\s/.test(code[index])) index += 1;
|
|
83
|
+
let memberOptional;
|
|
84
|
+
if (code[index] === '?' && code[index + 1] === '.') {
|
|
85
|
+
memberOptional = true;
|
|
86
|
+
index += 2;
|
|
87
|
+
}
|
|
88
|
+
if (memberOptional && code[index] !== '[') return receiverDotMemberAccess(code, index, memberOptional);
|
|
89
|
+
if (code[index] === '.') return receiverDotMemberAccess(code, index + 1, memberOptional);
|
|
90
|
+
if (code[index] !== '[') return undefined;
|
|
91
|
+
return receiverComputedMemberAccess(sourceText, code, index, memberOptional);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function receiverDotMemberAccess(code, memberOffset, memberOptional) {
|
|
95
|
+
let index = memberOffset;
|
|
96
|
+
while (index < code.length && /\s/.test(code[index])) index += 1;
|
|
97
|
+
const match = /^#?[A-Za-z_$][\w$]*/.exec(code.slice(index));
|
|
98
|
+
if (!match) return undefined;
|
|
99
|
+
return { memberName: match[0], memberStart: index, memberEnd: index + match[0].length, memberOptional, accessEnd: index + match[0].length };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function receiverComputedMemberAccess(sourceText, code, open, memberOptional) {
|
|
103
|
+
const close = findMatchingBracket(code, open);
|
|
104
|
+
if (close === -1) return undefined;
|
|
105
|
+
let index = open + 1;
|
|
106
|
+
while (index < close && /\s/.test(sourceText[index])) index += 1;
|
|
107
|
+
const literal = readStaticMemberLiteral(sourceText, index, close);
|
|
108
|
+
if (!literal || !identifierRegExp.test(literal.value)) return undefined;
|
|
109
|
+
return { memberName: literal.value, memberStart: literal.start, memberEnd: literal.end, memberComputed: true, memberLiteralKind: literal.literalKind, memberOptional, accessEnd: close + 1 };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function referenceRecords(tokens, masked, bindings, context) {
|
|
113
|
+
const code = masked.code;
|
|
114
|
+
const bindingKeys = new Set(bindings.map((binding) => `${binding.start}:${binding.end}`));
|
|
115
|
+
return tokens.flatMap((token, index) => {
|
|
116
|
+
if (jsTsKeywords.has(token.value) || bindingKeys.has(rangeKey(token)) || isPropertyAccess(code, token.start)) return [];
|
|
117
|
+
const namespace = likelyTypeReference(code, tokens, index) ? 'type' : 'value';
|
|
118
|
+
const binding = nearestBinding(bindings, token, namespace);
|
|
119
|
+
if (!binding) return [];
|
|
120
|
+
const namespaceProperty = namespacePropertyAccess(code, token, binding, context);
|
|
121
|
+
const sourceSpan = sourceSpanForRange(context, token.start, token.end);
|
|
122
|
+
const semanticSpan = semanticSpanForHash(sourceSpan);
|
|
123
|
+
const publicOwner = nearestPublicOwnerForOffset(context.publicOwners, token.start);
|
|
124
|
+
const publicOwnerName = binding.publicOwnerName ?? publicOwner?.name;
|
|
125
|
+
const closureCapture = closureCaptureEvidence(token.depth, binding, publicOwnerName);
|
|
126
|
+
const templateExpression = templateExpressionRangeForOffset(masked.templateExpressionRanges, token.start);
|
|
127
|
+
const templateExpressionHash = templateExpression ? hashSemanticValue({
|
|
128
|
+
kind: 'frontier.lang.projectScopeReferenceTemplateExpression',
|
|
129
|
+
sourcePath: context.sourcePath,
|
|
130
|
+
sourceHash: context.sourceHash,
|
|
131
|
+
start: templateExpression.start,
|
|
132
|
+
end: templateExpression.end,
|
|
133
|
+
templateKind: templateExpression.templateKind,
|
|
134
|
+
templateTagText: templateExpression.templateTagText
|
|
135
|
+
}) : undefined;
|
|
136
|
+
return [compactRecord({
|
|
137
|
+
id: `scope_ref_${idFragment(context.sourcePath)}_${index + 1}`,
|
|
138
|
+
name: token.value,
|
|
139
|
+
namespace,
|
|
140
|
+
namespaces: [namespace],
|
|
141
|
+
sourcePath: context.sourcePath,
|
|
142
|
+
sourceHash: context.sourceHash,
|
|
143
|
+
sourceSpan,
|
|
144
|
+
start: token.start,
|
|
145
|
+
end: token.end,
|
|
146
|
+
depth: token.depth,
|
|
147
|
+
referenceKind: namespaceProperty?.referenceKind ?? (templateExpression ? 'template-literal-interpolation' : undefined),
|
|
148
|
+
templateLiteralInterpolation: templateExpression ? true : undefined,
|
|
149
|
+
templateExpressionStart: templateExpression?.start,
|
|
150
|
+
templateExpressionEnd: templateExpression?.end,
|
|
151
|
+
templateExpressionHash,
|
|
152
|
+
templateLiteralKind: templateExpression?.templateKind,
|
|
153
|
+
taggedTemplate: templateExpression?.templateKind === 'tagged-template' ? true : undefined,
|
|
154
|
+
templateTagText: templateExpression?.templateTagText,
|
|
155
|
+
templateTagRoot: templateExpression?.templateTagRoot,
|
|
156
|
+
templateTagMemberName: templateExpression?.templateTagMemberName,
|
|
157
|
+
templateTagStart: templateExpression?.templateTagStart,
|
|
158
|
+
templateTagEnd: templateExpression?.templateTagEnd,
|
|
159
|
+
memberName: namespaceProperty?.memberName,
|
|
160
|
+
memberStart: namespaceProperty?.memberStart,
|
|
161
|
+
memberEnd: namespaceProperty?.memberEnd,
|
|
162
|
+
memberComputed: namespaceProperty?.memberComputed,
|
|
163
|
+
memberLiteralKind: namespaceProperty?.memberLiteralKind,
|
|
164
|
+
memberStaticTemplateLiteral: namespaceProperty?.memberLiteralKind === 'static-template-literal' ? true : undefined,
|
|
165
|
+
writeOperation: namespaceProperty?.writeOperation,
|
|
166
|
+
bindingId: binding.id,
|
|
167
|
+
bindingName: binding.name,
|
|
168
|
+
bindingKind: binding.bindingKind,
|
|
169
|
+
bindingOrdinal: binding.ordinal,
|
|
170
|
+
closure: Boolean(closureCapture) || undefined,
|
|
171
|
+
closureDepthDelta: closureCapture?.closureDepthDelta,
|
|
172
|
+
closureBindingDepth: closureCapture?.closureBindingDepth,
|
|
173
|
+
closureOwnerName: closureCapture?.closureOwnerName,
|
|
174
|
+
closureCaptureHash: closureCapture?.closureCaptureHash,
|
|
175
|
+
publicContract: (binding.publicContract || Boolean(publicOwnerName)) || undefined,
|
|
176
|
+
publicOwnerName,
|
|
177
|
+
status: namespaceProperty?.status,
|
|
178
|
+
reasonCodes: namespaceProperty?.reasonCodes,
|
|
179
|
+
signatureHash: hashSemanticValue({
|
|
180
|
+
kind: 'frontier.lang.projectScopeReferenceSignature',
|
|
181
|
+
name: token.value,
|
|
182
|
+
namespace,
|
|
183
|
+
bindingId: binding.id,
|
|
184
|
+
sourceSpan: semanticSpan,
|
|
185
|
+
referenceKind: namespaceProperty?.referenceKind ?? (templateExpression ? 'template-literal-interpolation' : undefined),
|
|
186
|
+
templateExpressionHash,
|
|
187
|
+
templateKind: templateExpression?.templateKind,
|
|
188
|
+
templateTagText: templateExpression?.templateTagText,
|
|
189
|
+
memberName: namespaceProperty?.memberName,
|
|
190
|
+
memberComputed: namespaceProperty?.memberComputed,
|
|
191
|
+
writeOperation: namespaceProperty?.writeOperation,
|
|
192
|
+
closureCaptureHash: closureCapture?.closureCaptureHash,
|
|
193
|
+
closureDepthDelta: closureCapture?.closureDepthDelta,
|
|
194
|
+
closureOwnerName: closureCapture?.closureOwnerName,
|
|
195
|
+
status: namespaceProperty?.status,
|
|
196
|
+
reasonCodes: namespaceProperty?.reasonCodes
|
|
197
|
+
})
|
|
198
|
+
})];
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function templateExpressionRangeForOffset(ranges = [], offset) {
|
|
203
|
+
return ranges.filter((range) => offset >= range.start && offset < range.end).sort((left, right) => (left.end - left.start) - (right.end - right.start))[0];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function nearestBinding(bindings, token, namespace) {
|
|
207
|
+
return bindings
|
|
208
|
+
.filter((binding) => binding.name === token.value && binding.start < token.start && namespaceOverlap(binding.namespaces, [namespace]))
|
|
209
|
+
.sort((left, right) => right.start - left.start || right.depth - left.depth)[0];
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function namespacePropertyAccess(code, token, binding, context) {
|
|
213
|
+
const importAlias = context.importAliasesByLocalKey?.get(context.sourcePath && token.value ? `${context.sourcePath}\0${token.value}` : undefined);
|
|
214
|
+
if (binding.bindingKind !== 'import' || importAlias?.importKind !== 'namespace') return undefined;
|
|
215
|
+
let index = token.end;
|
|
216
|
+
while (index < code.length && /\s/.test(code[index])) index += 1;
|
|
217
|
+
if (code[index] === '.') {
|
|
218
|
+
const match = /^[A-Za-z_$][\w$]*/.exec(code.slice(index + 1).trimStart());
|
|
219
|
+
const memberStart = match ? code.indexOf(match[0], index + 1) : -1;
|
|
220
|
+
if (!match) return undefined;
|
|
221
|
+
const memberEnd = memberStart + match[0].length;
|
|
222
|
+
const writeOperation = namespaceMemberWriteOperation(code, token.start, memberEnd);
|
|
223
|
+
return writeOperation
|
|
224
|
+
? blockedNamespaceMemberWrite('namespace-property-write', { memberName: match[0], memberStart, memberEnd, writeOperation })
|
|
225
|
+
: { referenceKind: 'namespace-property-read', memberName: match[0], memberStart, memberEnd };
|
|
226
|
+
}
|
|
227
|
+
if (code[index] === '[') return namespaceComputedPropertyAccess(context.sourceText ?? code, code, token.start, index);
|
|
228
|
+
return undefined;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function namespaceComputedPropertyAccess(sourceText, code, tokenStart, open) {
|
|
232
|
+
const close = findMatchingBracket(code, open);
|
|
233
|
+
if (close === -1) return blockedNamespaceComputedPropertyAccess();
|
|
234
|
+
const writeOperation = namespaceMemberWriteOperation(code, tokenStart, close + 1);
|
|
235
|
+
let index = open + 1;
|
|
236
|
+
while (index < close && /\s/.test(sourceText[index])) index += 1;
|
|
237
|
+
const literal = readStaticMemberLiteral(sourceText, index, close);
|
|
238
|
+
if (!literal) return blockedNamespaceComputedPropertyAccess(writeOperation);
|
|
239
|
+
let afterLiteral = literal.end + 1;
|
|
240
|
+
while (afterLiteral < close && /\s/.test(sourceText[afterLiteral])) afterLiteral += 1;
|
|
241
|
+
if (afterLiteral !== close || !identifierRegExp.test(literal.value)) return blockedNamespaceComputedPropertyAccess(writeOperation);
|
|
242
|
+
if (writeOperation) {
|
|
243
|
+
return blockedNamespaceMemberWrite('namespace-computed-property-write', {
|
|
244
|
+
memberName: literal.value,
|
|
245
|
+
memberStart: literal.start,
|
|
246
|
+
memberEnd: literal.end,
|
|
247
|
+
memberComputed: true,
|
|
248
|
+
memberLiteralKind: literal.literalKind,
|
|
249
|
+
writeOperation
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
return { referenceKind: 'namespace-computed-property-read', memberName: literal.value, memberStart: literal.start, memberEnd: literal.end, memberComputed: true, memberLiteralKind: literal.literalKind };
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function blockedNamespaceComputedPropertyAccess(writeOperation) {
|
|
256
|
+
return {
|
|
257
|
+
referenceKind: writeOperation ? 'namespace-computed-property-write' : 'namespace-computed-property-read',
|
|
258
|
+
memberComputed: true,
|
|
259
|
+
writeOperation,
|
|
260
|
+
status: 'blocked',
|
|
261
|
+
reasonCodes: [
|
|
262
|
+
LexicalUseDefReasonCodes.namespaceComputedMemberUnsupported,
|
|
263
|
+
...(writeOperation ? [LexicalUseDefReasonCodes.namespaceMemberWriteUnsupported] : [])
|
|
264
|
+
]
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function blockedNamespaceMemberWrite(referenceKind, fields = {}) {
|
|
269
|
+
return {
|
|
270
|
+
referenceKind,
|
|
271
|
+
memberName: fields.memberName,
|
|
272
|
+
memberStart: fields.memberStart,
|
|
273
|
+
memberEnd: fields.memberEnd,
|
|
274
|
+
memberComputed: fields.memberComputed,
|
|
275
|
+
memberLiteralKind: fields.memberLiteralKind,
|
|
276
|
+
status: 'blocked',
|
|
277
|
+
reasonCodes: [LexicalUseDefReasonCodes.namespaceMemberWriteUnsupported],
|
|
278
|
+
writeOperation: fields.writeOperation
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function namespaceMemberWriteOperation(code, tokenStart, accessEnd) {
|
|
283
|
+
if (hasPrefixUpdateOperator(code, tokenStart)) return 'update';
|
|
284
|
+
let index = accessEnd;
|
|
285
|
+
while (index < code.length && /\s/.test(code[index])) index += 1;
|
|
286
|
+
if (code.slice(index, index + 2) === '++' || code.slice(index, index + 2) === '--') return 'update';
|
|
287
|
+
const operator = assignmentOperatorAt(code, index);
|
|
288
|
+
return operator ? 'assignment' : undefined;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function assignmentOperatorAt(code, index) {
|
|
292
|
+
for (const operator of ['>>>=', '**=', '<<=', '>>=', '&&=', '||=', '??=', '+=', '-=', '*=', '/=', '%=', '&=', '|=', '^=', '=']) {
|
|
293
|
+
if (!code.startsWith(operator, index)) continue;
|
|
294
|
+
if (operator === '=' && (code[index + 1] === '=' || code[index + 1] === '>')) return undefined;
|
|
295
|
+
return operator;
|
|
296
|
+
}
|
|
297
|
+
return undefined;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function hasPrefixUpdateOperator(code, tokenStart) {
|
|
301
|
+
let index = tokenStart - 1;
|
|
302
|
+
while (index >= 0 && /\s/.test(code[index])) index -= 1;
|
|
303
|
+
const operatorStart = index - 1;
|
|
304
|
+
const operator = code.slice(operatorStart, index + 1);
|
|
305
|
+
if (operator !== '++' && operator !== '--') return false;
|
|
306
|
+
let before = operatorStart - 1;
|
|
307
|
+
while (before >= 0 && /\s/.test(code[before])) before -= 1;
|
|
308
|
+
return before < 0 || !/[A-Za-z0-9_$)\]]/.test(code[before]);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function findMatchingBracket(code, open) {
|
|
312
|
+
let depth = 0;
|
|
313
|
+
for (let index = open; index < code.length; index += 1) {
|
|
314
|
+
if (code[index] === '[') depth += 1;
|
|
315
|
+
else if (code[index] === ']' && --depth === 0) return index;
|
|
316
|
+
}
|
|
317
|
+
return -1;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export { lexicalScopeRecordsForImport };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
function publicOwnerRanges(context, sourcePath, sourceText) {
|
|
2
|
+
return (context.sourceTextsByPath.has(sourcePath) ? context.sourceTextsByPath : new Map([[sourcePath, sourceText]]))
|
|
3
|
+
&& (context.publicOwnerRangesByPath?.get(sourcePath) ?? publicOwnerRangesFromKeys(context.publicKeys, sourcePath, sourceText));
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
function publicOwnerRangesFromKeys(publicKeys, sourcePath, sourceText) {
|
|
7
|
+
return [...publicKeys]
|
|
8
|
+
.map((key) => publicKeyParts(key))
|
|
9
|
+
.filter((parts) => parts?.sourcePath === sourcePath)
|
|
10
|
+
.map((parts) => ({ name: parts.name, range: rangeForNamedDeclaration(sourceText, parts.name) }))
|
|
11
|
+
.filter((owner) => owner.range);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function nearestPublicOwnerForOffset(publicOwners, offset) {
|
|
15
|
+
return (publicOwners ?? [])
|
|
16
|
+
.filter((owner) => owner.range.start <= offset && offset <= owner.range.end)
|
|
17
|
+
.sort((left, right) => right.range.start - left.range.start || left.range.end - right.range.end)[0];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function nearestLexicalPublicOwner(publicOwners, binding) {
|
|
21
|
+
if (binding.depth === 0) return undefined;
|
|
22
|
+
return publicOwners.filter((owner) => owner.start < binding.start && owner.depth < binding.depth)
|
|
23
|
+
.sort((left, right) => right.start - left.start)[0];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function rangeForNamedDeclaration(sourceText, name) {
|
|
27
|
+
if (!sourceText || !name) return undefined;
|
|
28
|
+
const escaped = escapeRegExp(name);
|
|
29
|
+
const declaration = new RegExp(`\\b(?:export\\s+)?(?:async\\s+)?(?:function|class|interface|type|enum|namespace|module)\\s+${escaped}\\b`, 'm').exec(sourceText);
|
|
30
|
+
if (declaration) return declarationRange(sourceText, declaration.index);
|
|
31
|
+
const variable = new RegExp(`\\b(?:export\\s+)?(?:const|let|var)\\s+${escaped}\\b`, 'm').exec(sourceText);
|
|
32
|
+
return variable ? declarationRange(sourceText, variable.index) : undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function declarationRange(sourceText, start) {
|
|
36
|
+
const nextTopLevel = /\n(?:export\s+)?(?:async\s+)?(?:function|class|interface|type|enum|namespace|module|const|let|var)\s+[A-Za-z_$][\w$]*/g;
|
|
37
|
+
nextTopLevel.lastIndex = start + 1;
|
|
38
|
+
const next = nextTopLevel.exec(sourceText);
|
|
39
|
+
return { start, end: next ? next.index : sourceText.length };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function publicKeyParts(key) {
|
|
43
|
+
const separator = String(key).indexOf('\0');
|
|
44
|
+
if (separator <= 0) return undefined;
|
|
45
|
+
return { sourcePath: String(key).slice(0, separator), name: String(key).slice(separator + 1) };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function escapeRegExp(value) { return String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); }
|
|
49
|
+
|
|
50
|
+
export { nearestLexicalPublicOwner, nearestPublicOwnerForOffset, publicOwnerRanges };
|