@shapeshift-labs/frontier-lang-parser 0.3.61 → 0.3.62
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/index.js +5 -0
- package/dist/source-syntax-children.js +20 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -303,12 +303,17 @@ function readTypeFields(body) {
|
|
|
303
303
|
}
|
|
304
304
|
function readVariants(body) {
|
|
305
305
|
const variants = [];
|
|
306
|
+
const seenNames = new Set();
|
|
307
|
+
const seenIds = new Set();
|
|
306
308
|
const re = /^\s*variant\s+([A-Za-z_$][\w$]*)(.*)$/gm;
|
|
307
309
|
let match;
|
|
308
310
|
while ((match = re.exec(body))) {
|
|
309
311
|
const fields = readVariantPayloadFields(match[2] ?? '', match[1], parseTypeExpression);
|
|
310
312
|
if (fields === null) continue;
|
|
311
313
|
const id = /@id\(\s*["']([^"']+)["']\s*\)/.exec(match[2] ?? '')?.[1];
|
|
314
|
+
const variantId = id ?? `type_variant_${safeId(match[1])}`;
|
|
315
|
+
if (seenNames.has(match[1]) || seenIds.has(variantId)) continue;
|
|
316
|
+
seenNames.add(match[1]); seenIds.add(variantId);
|
|
312
317
|
variants.push({ ...(id ? { id } : {}), name: match[1], ...(fields?.length ? { fields } : {}) });
|
|
313
318
|
}
|
|
314
319
|
return variants.length ? variants : undefined;
|
|
@@ -24,18 +24,35 @@ export function readSourceSyntaxChildren(source, block, options = {}) {
|
|
|
24
24
|
|
|
25
25
|
function readTypeSyntaxChildren(source, block, options) {
|
|
26
26
|
const children = [];
|
|
27
|
+
const seenVariantNames = new Set();
|
|
28
|
+
const seenVariantIds = new Set();
|
|
27
29
|
for (const line of readBodyLines(source, block)) {
|
|
28
30
|
if (!line.text || line.text.startsWith('#')) continue;
|
|
29
31
|
const variant = /^variant\s+([A-Za-z_$][\w$]*)(.*)$/.exec(line.text);
|
|
30
32
|
if (!variant) continue;
|
|
31
33
|
const [, name, rest] = variant;
|
|
32
34
|
const payload = inspectVariantPayload(rest ?? '', inspectTypeExpressionSyntax);
|
|
35
|
+
const id = idFrom(rest, `type_variant_${safeId(name)}`);
|
|
36
|
+
let recognized = payload.ok;
|
|
37
|
+
let reason = payload.ok ? undefined : payload.reason;
|
|
38
|
+
if (recognized && seenVariantNames.has(name)) {
|
|
39
|
+
recognized = false;
|
|
40
|
+
reason = 'duplicate-type-variant-name';
|
|
41
|
+
}
|
|
42
|
+
if (recognized && seenVariantIds.has(id)) {
|
|
43
|
+
recognized = false;
|
|
44
|
+
reason = 'duplicate-type-variant-id';
|
|
45
|
+
}
|
|
46
|
+
if (recognized) {
|
|
47
|
+
seenVariantNames.add(name);
|
|
48
|
+
seenVariantIds.add(id);
|
|
49
|
+
}
|
|
33
50
|
children.push(cleanRecord({
|
|
34
51
|
kind: 'typeVariant',
|
|
35
52
|
rowKind: 'variant',
|
|
36
53
|
normalizedRowKind: 'variant',
|
|
37
54
|
name,
|
|
38
|
-
id
|
|
55
|
+
id,
|
|
39
56
|
header: line.text,
|
|
40
57
|
startOffset: line.startOffset,
|
|
41
58
|
endOffset: line.endOffset,
|
|
@@ -46,8 +63,8 @@ function readTypeSyntaxChildren(source, block, options) {
|
|
|
46
63
|
moduleId: block.moduleId,
|
|
47
64
|
moduleName: block.moduleName,
|
|
48
65
|
sourceSpan: sourceSpan(source, block, line.startOffset, line.endOffset, options),
|
|
49
|
-
recognized
|
|
50
|
-
reason
|
|
66
|
+
recognized,
|
|
67
|
+
reason,
|
|
51
68
|
fieldCount: payload.fieldCount,
|
|
52
69
|
fieldIds: payload.fieldIds
|
|
53
70
|
}));
|