@shapeshift-labs/frontier-lang-compiler 0.2.113 → 0.2.114

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 CHANGED
@@ -238,6 +238,11 @@ console.log(project.outputProjectSymbolGraph.importEdges[0].packageName); // "@p
238
238
  console.log(project.outputProjectSymbolGraph.importEdges[0].packageExportCondition); // "import"
239
239
  ```
240
240
 
241
+ Named re-export identities also include symbol links when the project graph has
242
+ enough evidence. For `export { thing as renamedThing } from './thing.js'`,
243
+ `reExportIdentities[]` records the source module, imported/exported names,
244
+ `originSymbolId`, `exportedSymbolId`, and `localSymbolId`.
245
+
241
246
  High-risk native features also have explicit evidence policies. These policies are advisory in this package: they tell a swarm or admission queue what evidence is missing without silently changing the existing readiness classification.
242
247
 
243
248
  ```js
@@ -138,10 +138,10 @@ export interface NativeProjectSymbolGraphReExportIdentityRecord {
138
138
  readonly localName?: string;
139
139
  readonly namespace?: string;
140
140
  readonly isTypeOnly?: boolean;
141
- readonly symbolId?: string;
141
+ readonly symbolId?: string; readonly originSymbolId?: string;
142
+ readonly exportedSymbolId?: string; readonly localSymbolId?: string;
142
143
  readonly relationId?: string;
143
- readonly ownershipRegionId?: string;
144
- readonly ownershipRegionKey?: string;
144
+ readonly ownershipRegionId?: string; readonly ownershipRegionKey?: string;
145
145
  readonly publicContract?: boolean;
146
146
  readonly factId?: string;
147
147
  }
@@ -1,6 +1,7 @@
1
1
  import{idFragment,uniqueByEvidenceId,uniqueByLossId,uniqueStrings}from'../../native-import-utils.js';import{createDocument,createPatch,createUniversalAstEnvelope}from'@shapeshift-labs/frontier-lang-kernel';
2
2
  import{createNativeImportResultContract}from'./createNativeImportResultContract.js';import{createProjectImportAdmissionRecord}from'./createProjectImportAdmissionRecord.js';import{mergeSemanticIndexes}from'./mergeSemanticIndexes.js';import{summarizeNativeImportLosses}from'./summarizeNativeImportLosses.js';import{summarizeProjectSourcePreservation}from'./summarizeProjectSourcePreservation.js';
3
- import{createProjectModuleSymbolResolver,resolveProjectModule}from'./projectSymbolGraphModuleResolution.js';
3
+ import{createProjectDocumentExportSymbolResolver,createProjectModuleSymbolResolver,resolveProjectModule}from'./projectSymbolGraphModuleResolution.js';
4
+ import{isReExportImportEdge,reExportIdentityInputFromEdge,reExportIdentityRecord}from'./projectSymbolGraphReExports.js';
4
5
  export function createNativeProjectImportResult(input, imports) {
5
6
  const idPart = idFragment(input.id ?? input.projectRoot ?? 'native_project');
6
7
  const nodes = {};
@@ -156,6 +157,7 @@ function createProjectSymbolGraphSummary(semanticIndex, imports, input) {
156
157
  const documentsByPath = new Map(documents.filter((document) => document.path).map((document) => [document.path, document]));
157
158
  const moduleResolution = input.moduleResolution ?? input.tsconfig;
158
159
  const resolveTargetSymbolId = createProjectModuleSymbolResolver(semanticIndex?.symbols ?? [], documents);
160
+ const resolveDocumentExportSymbolId = createProjectDocumentExportSymbolResolver(semanticIndex?.symbols ?? [], documents);
159
161
  const facts = semanticIndex?.facts ?? [];
160
162
  const moduleEdgeFacts = facts.filter((fact) => fact.predicate === 'moduleEdge');
161
163
  const moduleEdgeByRelation = new Map(moduleEdgeFacts.map((fact) => [fact.subjectId, fact]));
@@ -166,22 +168,17 @@ function createProjectSymbolGraphSummary(semanticIndex, imports, input) {
166
168
  const exportEdges = relations
167
169
  .filter((relation) => relation.predicate === 'exports')
168
170
  .map((relation) => moduleEdgeRecord(relation, moduleEdgeByRelation, symbolsById, documentsById, documentsByPath, moduleResolution, resolveTargetSymbolId));
171
+ const moduleEdgeById = new Map([...importEdges, ...exportEdges].map((edge) => [edge.id, edge]));
169
172
  const reExportIdentities = uniqueRecords([
170
173
  ...facts
171
174
  .filter((fact) => fact.predicate === 'reExportIdentity' && fact.value)
172
- .map((fact) => ({ ...objectValue(fact.value), factId: fact.id })),
175
+ .map((fact) => reExportIdentityRecord(objectValue(fact.value), moduleEdgeById.get(objectValue(fact.value).relationId ?? fact.objectId), resolveDocumentExportSymbolId, { factId: fact.id })),
173
176
  ...exportEdges
174
177
  .filter((edge) => edge.isReExport)
175
- .map((edge) => compactRecord({
176
- id: `reexport_${idFragment(edge.id)}`,
177
- sourceDocumentId: edge.sourceDocumentId,
178
- sourcePath: edge.sourcePath,
179
- sourceHash: edge.sourceHash,
180
- moduleSpecifier: edge.moduleSpecifier,
181
- symbolId: edge.targetSymbolId,
182
- relationId: edge.id,
183
- publicContract: edge.publicContract
184
- }))
178
+ .map((edge) => reExportIdentityRecord(reExportIdentityInputFromEdge(edge, `reexport_${idFragment(edge.id)}`), edge, resolveDocumentExportSymbolId)),
179
+ ...importEdges
180
+ .filter((edge) => isReExportImportEdge(edge))
181
+ .map((edge) => reExportIdentityRecord(reExportIdentityInputFromEdge(edge, `reexport_${idFragment(edge.id)}`), edge, resolveDocumentExportSymbolId))
185
182
  ]);
186
183
  const publicContractRegions = uniqueRecords(facts
187
184
  .filter((fact) => fact.predicate === 'publicContractRegion' && fact.value)
@@ -17,14 +17,7 @@ export function resolveProjectModule(sourcePath, moduleSpecifier, documentsByPat
17
17
  }
18
18
 
19
19
  export function createProjectModuleSymbolResolver(symbols, documents) {
20
- const documentsByPath = new Map(documents.filter((document) => document.path).map((document) => [document.path, document]));
21
- const exportedByDocumentAndName = new Map();
22
- for (const symbol of symbols ?? []) {
23
- if (symbol?.kind !== 'export' || !symbol.name) continue;
24
- const document = documentsByPath.get(symbol.definitionSpan?.path);
25
- if (!document) continue;
26
- exportedByDocumentAndName.set(symbolKey(document.id, symbol.name), symbol);
27
- }
20
+ const exportedByDocumentAndName = projectExportSymbolMap(symbols, documents);
28
21
  return function resolveProjectModuleSymbol(edge) {
29
22
  if (!edge?.targetDocumentId) return undefined;
30
23
  const targetName = targetExportName(edge);
@@ -33,6 +26,25 @@ export function createProjectModuleSymbolResolver(symbols, documents) {
33
26
  };
34
27
  }
35
28
 
29
+ export function createProjectDocumentExportSymbolResolver(symbols, documents) {
30
+ const exportedByDocumentAndName = projectExportSymbolMap(symbols, documents);
31
+ return function resolveDocumentExportSymbol(documentId, name) {
32
+ if (!documentId || !name) return undefined;
33
+ return exportedByDocumentAndName.get(symbolKey(documentId, name))?.id;
34
+ };
35
+ }
36
+
37
+ function projectExportSymbolMap(symbols, documents) {
38
+ const documentsByPath = new Map(documents.filter((document) => document.path).map((document) => [document.path, document]));
39
+ const exportedByDocumentAndName = new Map();
40
+ for (const symbol of symbols ?? []) {
41
+ if (symbol?.kind !== 'export' || !symbol.name) continue;
42
+ const document = documentsByPath.get(symbol.definitionSpan?.path);
43
+ if (document) exportedByDocumentAndName.set(symbolKey(document.id, symbol.name), symbol);
44
+ }
45
+ return exportedByDocumentAndName;
46
+ }
47
+
36
48
  function resolveConfiguredProjectModule(moduleSpecifier, documentsByPath, moduleResolution) {
37
49
  const packageInfo = packageSpecifierInfo(moduleSpecifier);
38
50
  const candidates = configuredModuleCandidates(moduleSpecifier, moduleResolution, packageInfo);
@@ -0,0 +1,43 @@
1
+ export function reExportIdentityRecord(identity, edge, resolveDocumentExportSymbolId, extra = {}) {
2
+ const exportedName = firstString(identity.exportedName, edge?.exportedName, edge?.importedName === '*' ? undefined : (edge?.exportedName ?? edge?.importedName));
3
+ const importedName = firstString(identity.importedName, edge?.importedName);
4
+ const localName = firstString(identity.localName, edge?.localName, exportedName);
5
+ return compactRecord({
6
+ ...identity,
7
+ exportedName,
8
+ importedName,
9
+ localName,
10
+ originSymbolId: firstString(identity.originSymbolId, edge?.resolvedTargetSymbolId),
11
+ exportedSymbolId: firstString(identity.exportedSymbolId, resolveDocumentExportSymbolId(edge?.sourceDocumentId, exportedName), edge?.predicate === 'exports' ? edge?.targetSymbolId : undefined),
12
+ localSymbolId: firstString(identity.localSymbolId, edge?.targetSymbolId),
13
+ ...extra
14
+ });
15
+ }
16
+
17
+ export function isReExportImportEdge(edge) {
18
+ return edge.importKind === 'reexport' || edge.importKind === 'namespace-reexport';
19
+ }
20
+
21
+ export function reExportIdentityInputFromEdge(edge, id) {
22
+ return compactRecord({
23
+ id,
24
+ sourceDocumentId: edge.sourceDocumentId,
25
+ sourcePath: edge.sourcePath,
26
+ sourceHash: edge.sourceHash,
27
+ moduleSpecifier: edge.moduleSpecifier,
28
+ symbolId: edge.targetSymbolId,
29
+ relationId: edge.id,
30
+ publicContract: edge.publicContract
31
+ });
32
+ }
33
+
34
+ function compactRecord(record) {
35
+ return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined));
36
+ }
37
+
38
+ function firstString(...values) {
39
+ for (const value of values) {
40
+ if (value !== undefined && value !== null && String(value)) return String(value);
41
+ }
42
+ return undefined;
43
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshift-labs/frontier-lang-compiler",
3
- "version": "0.2.113",
3
+ "version": "0.2.114",
4
4
  "description": "Compiler facade for Frontier Lang source documents and language projection adapters.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",