@shapeshift-labs/frontier-lang-compiler 0.2.68 → 0.2.69
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.
|
@@ -9,6 +9,10 @@ export function createUniversalAstFromDocument(document, input = {}) {
|
|
|
9
9
|
losses: input.losses,
|
|
10
10
|
evidence: input.evidence ?? [],
|
|
11
11
|
mergeCandidates: input.mergeCandidates,
|
|
12
|
+
semanticOperations: input.semanticOperations,
|
|
13
|
+
proof: input.proof ?? input.universalAstProof,
|
|
14
|
+
paradigmSemantics: input.paradigmSemantics ?? input.universalAstParadigmSemantics,
|
|
15
|
+
replayLinks: input.replayLinks,
|
|
12
16
|
layers: input.layers,
|
|
13
17
|
metadata: input.metadata
|
|
14
18
|
}), input);
|
|
@@ -30,6 +30,14 @@ export function jsImportDeclarations(input, lineNumber, trimmed) {
|
|
|
30
30
|
: [];
|
|
31
31
|
return jsImportModuleDeclarations(input, lineNumber, importPath, 'ExportFromDeclaration', bindings, { typeOnly, reexport: true, exportStar: Boolean(exportMatch[2]) });
|
|
32
32
|
}
|
|
33
|
+
const destructuredRequireMatch = trimmed.match(/^(?:const|let|var)\s+\{([^}]+)\}\s*=\s*(?:await\s+)?(require|import)\s*\(\s*(['"])([^'"]+)\3\s*\)/);
|
|
34
|
+
if (destructuredRequireMatch) {
|
|
35
|
+
const importKind = destructuredRequireMatch[2] === 'import' ? 'dynamic-import-binding' : 'commonjs-require';
|
|
36
|
+
const bindings = jsDestructuredImportBindings(destructuredRequireMatch[1], importKind);
|
|
37
|
+
if (bindings.length) {
|
|
38
|
+
return jsImportModuleDeclarations(input, lineNumber, destructuredRequireMatch[4], 'DestructuredRequireDeclaration', bindings, { destructured: true });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
33
41
|
const requireMatch = trimmed.match(/^(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*(?:await\s+)?(?:require|import)\s*\(\s*(['"])([^'"]+)\2\s*\)/);
|
|
34
42
|
if (requireMatch) return jsImportModuleDeclarations(input, lineNumber, requireMatch[3], 'CommonJsRequireDeclaration', [{
|
|
35
43
|
localName: requireMatch[1],
|
|
@@ -39,6 +47,23 @@ export function jsImportDeclarations(input, lineNumber, trimmed) {
|
|
|
39
47
|
return [];
|
|
40
48
|
}
|
|
41
49
|
|
|
50
|
+
function jsDestructuredImportBindings(raw, importKind) {
|
|
51
|
+
return String(raw ?? '')
|
|
52
|
+
.split(',')
|
|
53
|
+
.map((part) => {
|
|
54
|
+
const text = part.trim();
|
|
55
|
+
if (!text || text.startsWith('...')) return undefined;
|
|
56
|
+
const match = text.match(/^([A-Za-z_$][\w$]*|\*)\s*(?::\s*([A-Za-z_$][\w$]*))?$/);
|
|
57
|
+
if (!match) return undefined;
|
|
58
|
+
return {
|
|
59
|
+
localName: match[2] ?? match[1],
|
|
60
|
+
importedName: match[1],
|
|
61
|
+
importKind
|
|
62
|
+
};
|
|
63
|
+
})
|
|
64
|
+
.filter(Boolean);
|
|
65
|
+
}
|
|
66
|
+
|
|
42
67
|
function jsImportModuleDeclarations(input, lineNumber, importPath, languageKind, bindings = [], metadata = {}) {
|
|
43
68
|
const bindingSummaries = bindings.map((binding) => ({
|
|
44
69
|
localName: binding.localName,
|
|
@@ -55,7 +80,8 @@ function jsImportModuleDeclarations(input, lineNumber, importPath, languageKind,
|
|
|
55
80
|
...(metadata.typeOnly ? { typeOnly: true } : {}),
|
|
56
81
|
...(metadata.sideEffectOnly ? { sideEffectOnly: true } : {}),
|
|
57
82
|
...(metadata.reexport ? { reexport: true } : {}),
|
|
58
|
-
...(metadata.exportStar ? { exportStar: true } : {})
|
|
83
|
+
...(metadata.exportStar ? { exportStar: true } : {}),
|
|
84
|
+
...(metadata.destructured ? { destructured: true } : {})
|
|
59
85
|
},
|
|
60
86
|
metadata: {
|
|
61
87
|
moduleOnly: true,
|
|
@@ -33,6 +33,7 @@ function scanJavaScriptLike(input) {
|
|
|
33
33
|
let currentClass;
|
|
34
34
|
let classDepth = 0;
|
|
35
35
|
let currentObject;
|
|
36
|
+
let currentType;
|
|
36
37
|
const lexicalState = { inBlockComment: false, inTemplateString: false };
|
|
37
38
|
for (const { line, number } of lines) {
|
|
38
39
|
const scanLine = jsDeclarationScanLine(line, lexicalState);
|
|
@@ -40,6 +41,9 @@ function scanJavaScriptLike(input) {
|
|
|
40
41
|
if (!trimmed || jsCommentOnlyLine(trimmed)) continue;
|
|
41
42
|
const declarationLine = trimmed.replace(/^(?:export\s+)?(?:declare\s+)?/, '');
|
|
42
43
|
let match;
|
|
44
|
+
if (currentType && number !== currentType.startLine) {
|
|
45
|
+
pushDeclaration(jsTypeMemberDeclaration(input, number, declarationLine, currentType));
|
|
46
|
+
}
|
|
43
47
|
if (currentObject) {
|
|
44
48
|
const routeRecord = jsRouteRecordDeclaration(input, number, trimmed, currentObject);
|
|
45
49
|
if (routeRecord) {
|
|
@@ -66,13 +70,18 @@ function scanJavaScriptLike(input) {
|
|
|
66
70
|
classDepth = 0;
|
|
67
71
|
}
|
|
68
72
|
} else if ((match = declarationLine.match(/^interface\s+([A-Za-z_$][\w$]*)/))) {
|
|
69
|
-
|
|
73
|
+
const regionKind = 'type';
|
|
74
|
+
pushDeclaration(nativeDeclaration(input, number, 'InterfaceDeclaration', 'interface', match[1], {}, declarationLine.includes('{'), { regionKind }));
|
|
75
|
+
currentType = jsTypeRegionContext(match[1], declarationLine, number, regionKind, 'interface');
|
|
70
76
|
} else if ((match = declarationLine.match(/^(?:const\s+)?enum\s+([A-Za-z_$][\w$]*)/))) {
|
|
71
77
|
pushDeclaration(nativeDeclaration(input, number, 'EnumDeclaration', 'type', match[1], {}, declarationLine.includes('{')));
|
|
72
78
|
} else if ((match = declarationLine.match(/^(?:namespace|module)\s+([A-Za-z_$][\w$.]*)/))) {
|
|
73
79
|
pushDeclaration(nativeDeclaration(input, number, 'ModuleDeclaration', 'module', match[1], {}, declarationLine.includes('{')));
|
|
74
|
-
} else if ((match = declarationLine.match(/^type\s+([A-Za-z_$][\w$]*)
|
|
75
|
-
|
|
80
|
+
} else if ((match = declarationLine.match(/^type\s+([A-Za-z_$][\w$]*)(?:\s*<[^=]+>)?\s*=/))) {
|
|
81
|
+
const regionKind = 'type';
|
|
82
|
+
const hasTypeBody = declarationLine.includes('{');
|
|
83
|
+
pushDeclaration(nativeDeclaration(input, number, 'TypeAliasDeclaration', 'type', match[1], {}, hasTypeBody, { regionKind }));
|
|
84
|
+
currentType = jsTypeRegionContext(match[1], declarationLine, number, regionKind, 'type');
|
|
76
85
|
} else if ((match = declarationLine.match(/^(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*(?::\s*[^=]+)?=\s*(?:async\s*)?(?:<[^=]+>\s*)?(?:\(([^)]*)\)|([A-Za-z_$][\w$]*))\s*(?::\s*[^=]+)?=>/))) {
|
|
77
86
|
pushDeclaration(nativeDeclaration(input, number, 'VariableFunctionDeclaration', 'function', match[1], { parameters: splitParameters(match[2] ?? match[3]) }, true));
|
|
78
87
|
} else if ((match = declarationLine.match(/^(?:const|let|var)\s+([A-Za-z_$][\w$]*)\b/))) {
|
|
@@ -113,6 +122,10 @@ function scanJavaScriptLike(input) {
|
|
|
113
122
|
classDepth = 0;
|
|
114
123
|
}
|
|
115
124
|
}
|
|
125
|
+
if (currentType) {
|
|
126
|
+
if (number !== currentType.startLine) currentType.depth += jsStructureDelta(trimmed).value;
|
|
127
|
+
if (currentType.depth <= 0) currentType = undefined;
|
|
128
|
+
}
|
|
116
129
|
if (currentObject) {
|
|
117
130
|
if (number !== currentObject.startLine) currentObject.depth += jsContainerDelta(trimmed);
|
|
118
131
|
if (currentObject.depth <= 0) currentObject = undefined;
|
|
@@ -179,6 +192,53 @@ function jsStructureDelta(source) {
|
|
|
179
192
|
return { value, opened };
|
|
180
193
|
}
|
|
181
194
|
|
|
195
|
+
function jsTypeRegionContext(name, declarationLine, lineNumber, regionKind, typeKind) {
|
|
196
|
+
const depth = jsStructureDelta(declarationLine).value;
|
|
197
|
+
if (depth <= 0) return undefined;
|
|
198
|
+
return {
|
|
199
|
+
name,
|
|
200
|
+
typeKind,
|
|
201
|
+
regionKind,
|
|
202
|
+
depth,
|
|
203
|
+
startLine: lineNumber
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function jsTypeMemberDeclaration(input, lineNumber, declarationLine, context) {
|
|
208
|
+
const text = String(declarationLine ?? '').trim();
|
|
209
|
+
if (!text || /^[}\])]/.test(text) || text.startsWith('//')) return undefined;
|
|
210
|
+
let match = text.match(/^(?:readonly\s+)?(['"]?)([A-Za-z_$][\w$-]*)\1\??\s*(?:<[^({;]+>)?\s*\(([^)]*)\)\s*(?::\s*([^;,]+))?[;,]?$/);
|
|
211
|
+
if (match && !jsControlKeyword(match[2])) {
|
|
212
|
+
return nativeDeclaration(input, lineNumber, 'TypeMethodSignature', 'method', `${context.name}.${match[2]}`, {
|
|
213
|
+
owner: context.name,
|
|
214
|
+
propertyName: match[2],
|
|
215
|
+
parameters: splitParameters(match[3]),
|
|
216
|
+
returnType: match[4]?.trim(),
|
|
217
|
+
typeKind: context.typeKind
|
|
218
|
+
}, false, {
|
|
219
|
+
regionKind: jsTypeMemberRegionKind(context, match[2], text),
|
|
220
|
+
metadata: { owner: context.name, propertyName: match[2], typeKind: context.typeKind }
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
match = text.match(/^(?:readonly\s+)?(['"]?)([A-Za-z_$][\w$-]*)\1\??\s*:\s*(.+?)[;,]?$/);
|
|
224
|
+
if (!match || jsControlKeyword(match[2])) return undefined;
|
|
225
|
+
const valueType = match[3].trim();
|
|
226
|
+
const functionLike = /=>/.test(valueType) || /^\([^)]*\)\s*=>/.test(valueType);
|
|
227
|
+
return nativeDeclaration(input, lineNumber, functionLike ? 'TypeFunctionPropertySignature' : 'TypePropertySignature', functionLike ? 'function' : 'property', `${context.name}.${match[2]}`, {
|
|
228
|
+
owner: context.name,
|
|
229
|
+
propertyName: match[2],
|
|
230
|
+
valueType,
|
|
231
|
+
typeKind: context.typeKind
|
|
232
|
+
}, false, {
|
|
233
|
+
regionKind: jsTypeMemberRegionKind(context, match[2], text),
|
|
234
|
+
metadata: { owner: context.name, propertyName: match[2], typeKind: context.typeKind }
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function jsTypeMemberRegionKind(context, propertyName, source) {
|
|
239
|
+
return jsRegionKindForDeclarationName(propertyName, source) ?? (context.regionKind === 'type' ? 'property' : context.regionKind) ?? 'property';
|
|
240
|
+
}
|
|
241
|
+
|
|
182
242
|
function jsInlineClassMemberDeclarations(input, lineNumber, declarationLine, className) {
|
|
183
243
|
const open = declarationLine.indexOf('{');
|
|
184
244
|
const close = declarationLine.lastIndexOf('}');
|
package/package.json
CHANGED