@shapeshift-labs/frontier-lang-compiler 0.2.140 → 0.2.142

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
@@ -200,11 +200,12 @@ interface, type, class, or object member additions. Existing class/object method
200
200
  or property body edits inside the declared member region are preserved for
201
201
  semantic replay while added members are neutralized; object member additions are
202
202
  re-emitted with safe commas when both sides add final properties.
203
- If staged whole-declaration replay cannot verify because head changed a sibling
204
- member inside the same declaration, `safeMergeJsTsSource` retries the direct
205
- semantic edit projection and admits the merge only when replay still verifies
206
- cleanly. That direct retry can project onto the staged top-level merge output,
207
- so safe import/declaration additions are preserved alongside the sibling edit.
203
+ When head changed an existing sibling declaration or sibling member,
204
+ `safeMergeJsTsSource` prefers the direct semantic edit projection over a
205
+ neutralized staged projection, and admits the merge only when replay still
206
+ verifies cleanly. That direct path projects onto a staged top-level output with
207
+ head declaration changes replayed first, so safe import/declaration additions
208
+ are preserved without dropping the head-side sibling edit.
208
209
 
209
210
  Project-level JS/TS safe merges compose the same file-level gates across a
210
211
  base/worker/head file set. They preserve head-only files, admit worker-only
@@ -295,6 +296,9 @@ Public contract regions include `apiSurfaceKind`, `signatureHash`, and
295
296
  For `export * from './module.js'`, project graphs fan out re-export identities
296
297
  for each named export in the resolved target document and omit `default`, which
297
298
  matches JavaScript module semantics.
299
+ Output graph admission can use those expanded identities to accept disjoint
300
+ export-star additions while blocking incompatible duplicate exported names as
301
+ `project-output-re-export-identity-conflict`.
298
302
 
299
303
  When using `createTypeScriptCompilerNativeImporterAdapter`,
300
304
  `createEstreeNativeImporterAdapter`, or `createBabelNativeImporterAdapter`,
@@ -20,23 +20,14 @@ import { idFragment, uniqueStrings } from './native-import-utils.js';
20
20
  function semanticEditFallbackResult(input, topLevelResult) {
21
21
  if (!shouldTrySemanticEditFallback(topLevelResult)) return topLevelResult;
22
22
  const stagedFallback = createStagedTopLevelSemanticFallback(input, topLevelResult);
23
- let selectedFallback = stagedFallback;
24
- let artifacts = createSemanticEditFallbackArtifacts(input, topLevelResult, stagedFallback);
25
- if (stagedFallback && artifacts.status !== 'verified') {
26
- const directFallback = stagedFallback.directProjectionHeadSourceText && stagedFallback.safeTopLevelChanges > 0
27
- ? { ...stagedFallback, projectionMode: 'direct' }
28
- : undefined;
29
- const directArtifacts = createSemanticEditFallbackArtifacts(input, topLevelResult, directFallback);
30
- if (directArtifacts.status === 'verified') {
31
- artifacts = directArtifacts;
32
- selectedFallback = directFallback;
33
- } else if (directFallback) {
34
- const plainDirectArtifacts = createSemanticEditFallbackArtifacts(input, topLevelResult, undefined);
35
- if (plainDirectArtifacts.status === 'verified') {
36
- artifacts = plainDirectArtifacts;
37
- selectedFallback = undefined;
38
- }
39
- }
23
+ const candidates = semanticFallbackCandidates(stagedFallback);
24
+ let selectedFallback = candidates[0];
25
+ let artifacts = createSemanticEditFallbackArtifacts(input, topLevelResult, selectedFallback);
26
+ for (const candidate of candidates.slice(1)) {
27
+ if (artifacts.status === 'verified') break;
28
+ const nextArtifacts = createSemanticEditFallbackArtifacts(input, topLevelResult, candidate);
29
+ if (nextArtifacts.status === 'verified') selectedFallback = candidate;
30
+ artifacts = nextArtifacts.status === 'verified' ? nextArtifacts : artifacts;
40
31
  }
41
32
  if (artifacts.status !== 'verified') return semanticEditFallbackBlockedResult(input, topLevelResult, artifacts);
42
33
  const resultBase = selectedFallback?.stagedTopLevelResult ?? topLevelResult;
@@ -83,6 +74,16 @@ function semanticEditFallbackResult(input, topLevelResult) {
83
74
  };
84
75
  }
85
76
 
77
+ function semanticFallbackCandidates(stagedFallback) {
78
+ if (!stagedFallback) return [undefined];
79
+ const headChanged = (stagedFallback.neutralization?.summary?.headChangedExistingDeclarations ?? 0) > 0;
80
+ const directFallback = stagedFallback.directProjectionHeadSourceText && (headChanged || stagedFallback.safeTopLevelChanges > 0)
81
+ ? { ...stagedFallback, projectionMode: 'direct' }
82
+ : undefined;
83
+ if (headChanged) return directFallback ? [directFallback, undefined] : [undefined];
84
+ return directFallback ? [stagedFallback, directFallback, undefined] : [stagedFallback];
85
+ }
86
+
86
87
  function createSemanticEditFallbackArtifacts(input, topLevelResult, stagedFallback) {
87
88
  try {
88
89
  const id = String(input.id ?? topLevelResult.id ?? 'js_ts_safe_merge');
@@ -1,3 +1,4 @@
1
+ import { hashSemanticValue } from '@shapeshift-labs/frontier-lang-kernel';
1
2
  import { compactRecord } from './js-ts-safe-merge-context.js';
2
3
  import { projectGraphDeltaConflicts } from './js-ts-safe-project-merge-graph-delta-conflicts.js';
3
4
 
@@ -25,7 +26,8 @@ function outputProjectGraphConflicts(projectSymbolGraph) {
25
26
  return [
26
27
  ...limitConflicts,
27
28
  ...[...missingModuleGroups.values()].map(projectGraphMissingImportConflict),
28
- ...[...missingSymbolGroups.values()].map(projectGraphMissingTargetConflict)
29
+ ...[...missingSymbolGroups.values()].map(projectGraphMissingTargetConflict),
30
+ ...duplicateReExportIdentityConflicts(projectSymbolGraph?.reExportIdentities)
29
31
  ];
30
32
  }
31
33
 
@@ -94,6 +96,83 @@ function projectImportTargetName(edge) {
94
96
  return String(name);
95
97
  }
96
98
 
99
+ function duplicateReExportIdentityConflicts(records = []) {
100
+ const groups = new Map();
101
+ for (const record of records) {
102
+ const key = reExportIdentityKey(record);
103
+ if (!key) continue;
104
+ const group = groups.get(key) ?? [];
105
+ group.push(record);
106
+ groups.set(key, group);
107
+ }
108
+ return [...groups.entries()]
109
+ .filter(([, group]) => new Set(group.map(reExportIdentityFingerprint)).size > 1)
110
+ .map(([identityKey, group]) => projectGraphDuplicateReExportIdentityConflict(identityKey, group));
111
+ }
112
+
113
+ function projectGraphDuplicateReExportIdentityConflict(identityKey, group) {
114
+ const record = group[0] ?? {};
115
+ return {
116
+ code: 'project-output-re-export-identity-conflict',
117
+ gateId: 'project-symbol-graph',
118
+ message: `Output project graph exposes incompatible re-export identity ${JSON.stringify(identityKey)}.`,
119
+ sourcePath: record.sourcePath,
120
+ details: compactRecord({
121
+ reasonCode: 'project-output-re-export-identity-conflict',
122
+ conflictKey: `project-output-re-export-identity#${identityKey}`,
123
+ identityKey,
124
+ sourcePath: record.sourcePath,
125
+ exportedName: record.exportedName,
126
+ records: group.map(reExportIdentityDetails)
127
+ })
128
+ };
129
+ }
130
+
131
+ function reExportIdentityKey(record) {
132
+ return stableKey([
133
+ 're-export-identity',
134
+ record?.sourcePath,
135
+ record?.exportedName ?? record?.localName ?? record?.namespace ?? (record?.exportStar || record?.isExportStar ? '*' : undefined)
136
+ ]);
137
+ }
138
+
139
+ function reExportIdentityFingerprint(record) {
140
+ return hashSemanticValue({
141
+ moduleSpecifier: record.moduleSpecifier,
142
+ exportedName: record.exportedName,
143
+ importedName: record.importedName,
144
+ localName: record.localName,
145
+ namespace: record.namespace,
146
+ isTypeOnly: record.isTypeOnly,
147
+ exportStar: record.exportStar,
148
+ isExportStar: record.isExportStar,
149
+ originSymbolId: record.originSymbolId,
150
+ exportedSymbolId: record.exportedSymbolId,
151
+ localSymbolId: record.localSymbolId
152
+ });
153
+ }
154
+
155
+ function reExportIdentityDetails(record) {
156
+ return compactRecord({
157
+ moduleSpecifier: record.moduleSpecifier,
158
+ exportedName: record.exportedName,
159
+ importedName: record.importedName,
160
+ localName: record.localName,
161
+ namespace: record.namespace,
162
+ isTypeOnly: record.isTypeOnly,
163
+ exportStar: record.exportStar,
164
+ isExportStar: record.isExportStar,
165
+ originSymbolId: record.originSymbolId,
166
+ exportedSymbolId: record.exportedSymbolId,
167
+ localSymbolId: record.localSymbolId
168
+ });
169
+ }
170
+
171
+ function stableKey(parts) {
172
+ const values = parts.map((part) => part === undefined || part === null ? '' : String(part));
173
+ return values.some(Boolean) ? values.join('#') : undefined;
174
+ }
175
+
97
176
  function uniqueStrings(values) {
98
177
  return [...new Set(values.filter((value) => typeof value === 'string' && value.length > 0))];
99
178
  }
@@ -111,7 +111,7 @@ function mergeProjectFile(file, input, projectId) {
111
111
  const result = safeMergeJsTsSource({
112
112
  ...input,
113
113
  ...context,
114
- deferReExportIdentityConflictsToProjectGraph: input.includeProjectGraphDelta === true,
114
+ deferReExportIdentityConflictsToProjectGraph: input.includeProjectGraphDelta === true || input.includeOutputProjectSymbolGraph === true,
115
115
  id: `${projectId}_${safeId(file.sourcePath)}`,
116
116
  baseSourceText: base,
117
117
  workerSourceText: worker,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshift-labs/frontier-lang-compiler",
3
- "version": "0.2.140",
3
+ "version": "0.2.142",
4
4
  "description": "Compiler facade for Frontier Lang source documents and language projection adapters.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",