@shapeshift-labs/frontier-lang-compiler 0.2.125 → 0.2.127
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/dist/internal/index-impl/semanticIndexFromNativeDeclarations.js +1 -0
- package/dist/internal/index-impl/typeScriptModuleDeclarationEntries.js +4 -0
- package/dist/js-ts-safe-merge-analyze.js +11 -0
- package/dist/js-ts-safe-merge-context.js +1 -0
- package/dist/js-ts-safe-merge-ledger-validation.js +12 -0
- package/dist/js-ts-safe-merge-parse-declarations.js +58 -1
- package/dist/js-ts-safe-project-merge.js +1 -0
- package/package.json +1 -1
|
@@ -245,6 +245,7 @@ function publicContractRegionForDeclaration(declaration, ownershipRegion, module
|
|
|
245
245
|
function reExportIdentityForDeclaration(declaration, input, documentId, relationId, ownershipRegion, moduleEdge) {
|
|
246
246
|
if (!moduleEdge?.isReExport && !declaration.reExport) return undefined;
|
|
247
247
|
const bindingCount = Number(declaration.nativeNode?.metadata?.bindingCount ?? declaration.metadata?.bindingCount ?? 0);
|
|
248
|
+
if (declaration.symbolKind === 'module' && declaration.metadata?.namespaceReExport) return undefined;
|
|
248
249
|
if (declaration.symbolKind === 'module' && !declaration.exportStar && !declaration.metadata?.exportStar && bindingCount > 1) return undefined;
|
|
249
250
|
const identityId = hashSemanticValue([relationId, declaration.symbolId, declaration.exportedName ?? declaration.metadata?.exportedName, declaration.importedName ?? declaration.metadata?.importedName, declaration.localName ?? declaration.metadata?.localName]);
|
|
250
251
|
const stableId = bindingCount > 1 ? idFragment(identityId) : idFragment(relationId);
|
|
@@ -39,17 +39,20 @@ function exportDeclarationEntries(node, nativeNodeId, input) {
|
|
|
39
39
|
const typeOnly = Boolean(node.isTypeOnly);
|
|
40
40
|
const exportStar = moduleSpecifier && !node.exportClause;
|
|
41
41
|
const bindings = exportClauseBindings(node.exportClause, { typeOnly, reExport: Boolean(moduleSpecifier) });
|
|
42
|
+
const namespaceReExport = Boolean(moduleSpecifier && bindings.some((binding) => binding.exportKind === 'namespace-reexport'));
|
|
42
43
|
return [
|
|
43
44
|
...(moduleSpecifier ? importModuleEntries(input, nativeNodeId, moduleSpecifier, 'ExportFromDeclaration', reExportImportBindings(bindings, exportStar), {
|
|
44
45
|
typeOnly,
|
|
45
46
|
reexport: true,
|
|
46
47
|
exportStar,
|
|
48
|
+
namespaceReExport,
|
|
47
49
|
importKind: exportStar ? 'reexport' : 'reexport'
|
|
48
50
|
}) : []),
|
|
49
51
|
...exportModuleEntries(input, nativeNodeId, moduleSpecifier, bindings, {
|
|
50
52
|
typeOnly,
|
|
51
53
|
exportStar,
|
|
52
54
|
reExport: Boolean(moduleSpecifier),
|
|
55
|
+
namespaceReExport,
|
|
53
56
|
exportKind: exportStar ? 'export-star' : 'named'
|
|
54
57
|
})
|
|
55
58
|
];
|
|
@@ -269,6 +272,7 @@ function moduleMetadata(scan, bindings, metadata) {
|
|
|
269
272
|
sideEffectOnly: metadata.sideEffectOnly,
|
|
270
273
|
reexport: metadata.reexport,
|
|
271
274
|
reExport: metadata.reExport,
|
|
275
|
+
namespaceReExport: metadata.namespaceReExport,
|
|
272
276
|
exportStar: metadata.exportStar,
|
|
273
277
|
publicContract: metadata.reExport || metadata.exportKind
|
|
274
278
|
});
|
|
@@ -200,6 +200,7 @@ function validateCrossSideAddedNames(workerPlan, headPlan, context) {
|
|
|
200
200
|
const nameKey = `${entry.kind}:${name}`;
|
|
201
201
|
const headEntry = headEntriesByName.get(nameKey);
|
|
202
202
|
if (headEntry) {
|
|
203
|
+
if (shouldDeferReExportNameConflict(entry, headEntry, context)) continue;
|
|
203
204
|
const typeAliasConflict = entry.declarationInfo?.declarationKind === 'type'
|
|
204
205
|
|| headEntry.declarationInfo?.declarationKind === 'type';
|
|
205
206
|
addConflict(context, {
|
|
@@ -216,6 +217,16 @@ function validateCrossSideAddedNames(workerPlan, headPlan, context) {
|
|
|
216
217
|
}
|
|
217
218
|
}
|
|
218
219
|
|
|
220
|
+
function shouldDeferReExportNameConflict(left, right, context) {
|
|
221
|
+
return context.deferReExportIdentityConflictsToProjectGraph === true
|
|
222
|
+
&& isReExportEntry(left)
|
|
223
|
+
&& isReExportEntry(right);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function isReExportEntry(entry) {
|
|
227
|
+
return entry?.kind === 'export' && entry.declarationInfo?.reExport === true;
|
|
228
|
+
}
|
|
229
|
+
|
|
219
230
|
function validateCrossSideImportAdditions(workerPlan, headPlan, context) {
|
|
220
231
|
for (const [key, workerAdditions] of workerPlan.importAdditions) {
|
|
221
232
|
const headAdditions = headPlan.importAdditions.get(key) ?? [];
|
|
@@ -5,6 +5,7 @@ export function createMergeContext(input) {
|
|
|
5
5
|
id: String(input.id ?? 'js_ts_safe_merge'),
|
|
6
6
|
sourcePath: input.sourcePath,
|
|
7
7
|
language: input.language ?? 'typescript',
|
|
8
|
+
deferReExportIdentityConflictsToProjectGraph: input.deferReExportIdentityConflictsToProjectGraph === true,
|
|
8
9
|
conflicts: [],
|
|
9
10
|
blockedGateIds: new Set(),
|
|
10
11
|
gateReasonCodes: new Map()
|
|
@@ -24,6 +24,7 @@ export function validateLedgerUniqueness(ledger, context) {
|
|
|
24
24
|
const nameKey = `${entry.kind}:${name}`;
|
|
25
25
|
const existing = nameOwners.get(nameKey);
|
|
26
26
|
if (existing) {
|
|
27
|
+
if (shouldDeferMergedReExportNameConflict(ledger, existing, entry, context)) continue;
|
|
27
28
|
addConflict(context, {
|
|
28
29
|
code: JsTsSafeMergeConflictCodes.duplicateName,
|
|
29
30
|
gateId: JsTsSafeMergeGateIds.uniqueNames,
|
|
@@ -65,6 +66,17 @@ function validateUniqueImportSpecifiers(entry, side, context) {
|
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
|
|
69
|
+
function shouldDeferMergedReExportNameConflict(ledger, left, right, context) {
|
|
70
|
+
return ledger.label === 'merged'
|
|
71
|
+
&& context.deferReExportIdentityConflictsToProjectGraph === true
|
|
72
|
+
&& isReExportEntry(left)
|
|
73
|
+
&& isReExportEntry(right);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function isReExportEntry(entry) {
|
|
77
|
+
return entry?.kind === 'export' && entry.declarationInfo?.reExport === true;
|
|
78
|
+
}
|
|
79
|
+
|
|
68
80
|
export function indexBaseLedger(base, context) {
|
|
69
81
|
const entriesByKey = new Map();
|
|
70
82
|
for (const entry of base.entries) entriesByKey.set(entry.key, entry);
|
|
@@ -19,7 +19,7 @@ export function classifyStatement(text, start, end) {
|
|
|
19
19
|
if (unsupported) return { unsupported, text, start, end };
|
|
20
20
|
return {
|
|
21
21
|
kind: declarationInfo.kind,
|
|
22
|
-
key:
|
|
22
|
+
key: declarationLedgerKey(declarationInfo),
|
|
23
23
|
text,
|
|
24
24
|
start,
|
|
25
25
|
end,
|
|
@@ -126,6 +126,50 @@ function parseDeclarationInfo(text) {
|
|
|
126
126
|
const defaultClass = trimmed.match(/^export\s+default\s+(?:abstract\s+)?class(?:\s+([A-Za-z_$][\w$]*))?\b/);
|
|
127
127
|
if (defaultClass) return { kind: 'declaration', names: ['default'], declarationKind: 'class', exported: true, defaultExport: true };
|
|
128
128
|
|
|
129
|
+
const namespaceReExport = trimmed.match(/^export\s+(type\s+)?\*\s+as\s+([A-Za-z_$][\w$]*)\s+from\s+(['"])([^'"]+)\3\s*;?$/);
|
|
130
|
+
if (namespaceReExport) {
|
|
131
|
+
return {
|
|
132
|
+
kind: 'export',
|
|
133
|
+
names: [namespaceReExport[2]],
|
|
134
|
+
declarationKind: 're-export-namespace',
|
|
135
|
+
exported: true,
|
|
136
|
+
typeOnly: Boolean(namespaceReExport[1]),
|
|
137
|
+
reExport: true,
|
|
138
|
+
moduleSpecifier: namespaceReExport[4],
|
|
139
|
+
namespace: namespaceReExport[2]
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const starReExport = trimmed.match(/^export\s+(type\s+)?\*\s+from\s+(['"])([^'"]+)\2\s*;?$/);
|
|
144
|
+
if (starReExport) {
|
|
145
|
+
return {
|
|
146
|
+
kind: 'export',
|
|
147
|
+
names: [],
|
|
148
|
+
declarationKind: 're-export-star',
|
|
149
|
+
exported: true,
|
|
150
|
+
typeOnly: Boolean(starReExport[1]),
|
|
151
|
+
reExport: true,
|
|
152
|
+
moduleSpecifier: starReExport[3],
|
|
153
|
+
exportStar: true
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const namedReExport = trimmed.match(/^export\s+(type\s+)?\{([\s\S]+)\}\s+from\s+(['"])([^'"]+)\3\s*;?$/);
|
|
158
|
+
if (namedReExport) {
|
|
159
|
+
const names = splitCommaList(namedReExport[2]).map((part) => parseExportSpecifierName(part)).filter(Boolean);
|
|
160
|
+
const expectedCount = splitCommaList(namedReExport[2]).filter((part) => part.trim()).length;
|
|
161
|
+
if (names.length !== expectedCount || names.length === 0) return undefined;
|
|
162
|
+
return {
|
|
163
|
+
kind: 'export',
|
|
164
|
+
names,
|
|
165
|
+
declarationKind: 're-export-list',
|
|
166
|
+
exported: true,
|
|
167
|
+
typeOnly: Boolean(namedReExport[1]),
|
|
168
|
+
reExport: true,
|
|
169
|
+
moduleSpecifier: namedReExport[4]
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
129
173
|
const namedExport = trimmed.match(/^export\s+(type\s+)?\{([\s\S]+)\}\s*;?$/);
|
|
130
174
|
if (namedExport) {
|
|
131
175
|
const names = splitCommaList(namedExport[2]).map((part) => parseExportSpecifierName(part)).filter(Boolean);
|
|
@@ -154,6 +198,19 @@ function parseDeclarationInfo(text) {
|
|
|
154
198
|
return undefined;
|
|
155
199
|
}
|
|
156
200
|
|
|
201
|
+
function declarationLedgerKey(declarationInfo) {
|
|
202
|
+
if (declarationInfo.reExport) {
|
|
203
|
+
return [
|
|
204
|
+
declarationInfo.kind,
|
|
205
|
+
declarationInfo.declarationKind,
|
|
206
|
+
declarationInfo.moduleSpecifier ?? '',
|
|
207
|
+
declarationInfo.typeOnly ? 'type' : 'value',
|
|
208
|
+
declarationInfo.exportStar ? '*' : declarationInfo.names.join('|')
|
|
209
|
+
].join(':');
|
|
210
|
+
}
|
|
211
|
+
return `${declarationInfo.kind}:${declarationInfo.names.join('|')}`;
|
|
212
|
+
}
|
|
213
|
+
|
|
157
214
|
function unsupportedDeclarationPolicy(text, declarationInfo) {
|
|
158
215
|
const trimmed = text.trim();
|
|
159
216
|
if (/^\s*@/m.test(text)) {
|
|
@@ -111,6 +111,7 @@ function mergeProjectFile(file, input, projectId) {
|
|
|
111
111
|
const result = safeMergeJsTsSource({
|
|
112
112
|
...input,
|
|
113
113
|
...context,
|
|
114
|
+
deferReExportIdentityConflictsToProjectGraph: input.includeProjectGraphDelta === true,
|
|
114
115
|
id: `${projectId}_${safeId(file.sourcePath)}`,
|
|
115
116
|
baseSourceText: base,
|
|
116
117
|
workerSourceText: worker,
|
package/package.json
CHANGED