@akanjs/language 3.2.0-rc.18 → 3.2.0-rc.19
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/guardResolver.d.ts +2 -0
- package/index.cjs +235 -105
- package/index.js +235 -105
- package/package.json +1 -1
- package/server.js +235 -105
package/index.js
CHANGED
|
@@ -422,7 +422,7 @@ var ownerOf = (relativePath) => {
|
|
|
422
422
|
const [root, name] = relativePath.split("/");
|
|
423
423
|
return (root === "apps" || root === "libs") && name ? `${root}/${name}` : null;
|
|
424
424
|
};
|
|
425
|
-
var
|
|
425
|
+
var syntaxReaderOf = (ts, ast) => {
|
|
426
426
|
const spanOf = (source, node) => {
|
|
427
427
|
const start = node.getStart(source);
|
|
428
428
|
const end = node.getEnd();
|
|
@@ -480,6 +480,74 @@ var createFactReader = (ts, ast) => {
|
|
|
480
480
|
const node = keyName(property);
|
|
481
481
|
return name && node ? [{ name, span: spanOf(source, node), extent: extentOf(source, property) }] : [];
|
|
482
482
|
});
|
|
483
|
+
const verbReaderOf = (parameter) => {
|
|
484
|
+
const verbs = new Map;
|
|
485
|
+
if (parameter && ts.isObjectBindingPattern(parameter.name))
|
|
486
|
+
for (const element of parameter.name.elements) {
|
|
487
|
+
const verb = element.propertyName ?? element.name;
|
|
488
|
+
if (ts.isIdentifier(verb) && ts.isIdentifier(element.name))
|
|
489
|
+
verbs.set(element.name.text, verb.text);
|
|
490
|
+
}
|
|
491
|
+
const holder = parameter && ts.isIdentifier(parameter.name) ? parameter.name.text : null;
|
|
492
|
+
return (callee) => {
|
|
493
|
+
if (callee && ts.isIdentifier(callee))
|
|
494
|
+
return verbs.get(callee.text) ?? null;
|
|
495
|
+
if (callee && ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression) && callee.expression.text === holder)
|
|
496
|
+
return callee.name.text;
|
|
497
|
+
return null;
|
|
498
|
+
};
|
|
499
|
+
};
|
|
500
|
+
return {
|
|
501
|
+
spanOf,
|
|
502
|
+
extentOf,
|
|
503
|
+
unwrap,
|
|
504
|
+
moduleRefOf,
|
|
505
|
+
returnedObject,
|
|
506
|
+
builderOf,
|
|
507
|
+
guardNameOf,
|
|
508
|
+
optionObjectOf,
|
|
509
|
+
chainOf,
|
|
510
|
+
keyName,
|
|
511
|
+
objectKeys,
|
|
512
|
+
verbReaderOf
|
|
513
|
+
};
|
|
514
|
+
};
|
|
515
|
+
var sourceReaderOf = (ts) => {
|
|
516
|
+
const importsOf = (statement) => {
|
|
517
|
+
const { importClause, moduleSpecifier } = statement;
|
|
518
|
+
if (!importClause || !ts.isStringLiteral(moduleSpecifier))
|
|
519
|
+
return [];
|
|
520
|
+
const from = moduleSpecifier.text;
|
|
521
|
+
const bindings = importClause.namedBindings;
|
|
522
|
+
return [
|
|
523
|
+
...importClause.name ? [{ name: importClause.name.text, imported: "default", from }] : [],
|
|
524
|
+
...bindings && ts.isNamespaceImport(bindings) ? [{ name: bindings.name.text, imported: "*", from }] : [],
|
|
525
|
+
...bindings && ts.isNamedImports(bindings) ? bindings.elements.map((element) => ({
|
|
526
|
+
name: element.name.text,
|
|
527
|
+
imported: (element.propertyName ?? element.name).text,
|
|
528
|
+
from
|
|
529
|
+
})) : []
|
|
530
|
+
];
|
|
531
|
+
};
|
|
532
|
+
const docOf = (source, node) => {
|
|
533
|
+
const { text } = source;
|
|
534
|
+
const ranges = ts.getLeadingCommentRanges(text, node.getFullStart()) ?? [];
|
|
535
|
+
const comments = [];
|
|
536
|
+
let end = node.getStart(source);
|
|
537
|
+
for (const range of [...ranges].reverse()) {
|
|
538
|
+
if ((text.slice(range.end, end).match(/\n/g)?.length ?? 0) > 1)
|
|
539
|
+
break;
|
|
540
|
+
comments.unshift(text.slice(range.pos, range.end));
|
|
541
|
+
end = range.pos;
|
|
542
|
+
}
|
|
543
|
+
const lines = comments.flatMap((comment) => comment.split(`
|
|
544
|
+
`)).map((line) => line.trim().replace(/^\/\*\*?|\*\/$/g, "").replace(/^(?:\/\/[?*!]?|\*)/, "").replace(/\{@link\s+([^}\s|]+)[^}]*\}/g, "$1").trim()).filter((line) => line && !/^(?:biome-ignore|eslint-|@ts-)/.test(line));
|
|
545
|
+
return lines.length ? lines.join(" ") : null;
|
|
546
|
+
};
|
|
547
|
+
const importsIn = (source) => source.statements.filter(ts.isImportDeclaration).flatMap(importsOf);
|
|
548
|
+
return { docOf, importsIn };
|
|
549
|
+
};
|
|
550
|
+
var signalKeyReaderOf = (ts, ast, { spanOf, extentOf, returnedObject, optionObjectOf, chainOf, verbReaderOf }, guardsIn) => {
|
|
483
551
|
const sliceKeysOf = (source, builder, made, model) => (returnedObject(builder)?.properties ?? []).flatMap((property) => {
|
|
484
552
|
if (!ts.isPropertyAssignment(property))
|
|
485
553
|
return [];
|
|
@@ -498,23 +566,30 @@ var createFactReader = (ts, ast) => {
|
|
|
498
566
|
}
|
|
499
567
|
];
|
|
500
568
|
});
|
|
501
|
-
const
|
|
502
|
-
const
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
569
|
+
const endpointKeysOf = (source, builder, made, model) => {
|
|
570
|
+
const verbOf = verbReaderOf(builder?.parameters[0]);
|
|
571
|
+
return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
|
|
572
|
+
if (!ts.isPropertyAssignment(property))
|
|
573
|
+
return [];
|
|
574
|
+
const name = ast.nodeName(property.name);
|
|
575
|
+
if (!name)
|
|
576
|
+
return [];
|
|
577
|
+
const { root, methods } = chainOf(property.initializer);
|
|
578
|
+
return [
|
|
579
|
+
{
|
|
580
|
+
name,
|
|
581
|
+
span: spanOf(source, property.name),
|
|
582
|
+
extent: extentOf(source, property),
|
|
583
|
+
verb: root ? verbOf(root.expression) : null,
|
|
584
|
+
guards: root ? guardsIn(source, optionObjectOf(root), made, `${model}.${name}`) : [],
|
|
585
|
+
argCount: methods.filter((method) => argMethods.has(method)).length
|
|
586
|
+
}
|
|
587
|
+
];
|
|
588
|
+
});
|
|
517
589
|
};
|
|
590
|
+
return { sliceKeysOf, endpointKeysOf };
|
|
591
|
+
};
|
|
592
|
+
var jobKeyReaderOf = (ts, ast, { spanOf, extentOf, unwrap, returnedObject, chainOf, verbReaderOf }) => {
|
|
518
593
|
const numberOf = (expression) => {
|
|
519
594
|
const value = unwrap(expression);
|
|
520
595
|
if (ts.isNumericLiteral(value))
|
|
@@ -587,6 +662,9 @@ var createFactReader = (ts, ast) => {
|
|
|
587
662
|
];
|
|
588
663
|
});
|
|
589
664
|
};
|
|
665
|
+
return { internalKeysOf };
|
|
666
|
+
};
|
|
667
|
+
var serviceReaderOf = (ts, ast, { spanOf, extentOf, returnedObject, guardNameOf, chainOf, verbReaderOf }) => {
|
|
590
668
|
const plugsOf = (source, builder) => {
|
|
591
669
|
const verbOf = verbReaderOf(builder?.parameters[0]);
|
|
592
670
|
return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
|
|
@@ -612,27 +690,17 @@ var createFactReader = (ts, ast) => {
|
|
|
612
690
|
visit(source);
|
|
613
691
|
return bindings;
|
|
614
692
|
};
|
|
615
|
-
const
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
name,
|
|
627
|
-
span: spanOf(source, property.name),
|
|
628
|
-
extent: extentOf(source, property),
|
|
629
|
-
verb: root ? verbOf(root.expression) : null,
|
|
630
|
-
guards: root ? guardsIn(source, optionObjectOf(root), made, `${model}.${name}`) : [],
|
|
631
|
-
argCount: methods.filter((method) => argMethods.has(method)).length
|
|
632
|
-
}
|
|
633
|
-
];
|
|
634
|
-
});
|
|
635
|
-
};
|
|
693
|
+
const methodsOf = (source, statement) => statement.members.flatMap((member) => {
|
|
694
|
+
if (!ts.isMethodDeclaration(member) || !member.body)
|
|
695
|
+
return [];
|
|
696
|
+
const name = ast.nodeName(member.name);
|
|
697
|
+
if (!name || ts.getModifiers(member)?.some(({ kind }) => kind === ts.SyntaxKind.StaticKeyword))
|
|
698
|
+
return [];
|
|
699
|
+
return [{ name, span: spanOf(source, member.name), extent: extentOf(source, member) }];
|
|
700
|
+
});
|
|
701
|
+
return { plugsOf, adaptorBindingsIn, methodsOf };
|
|
702
|
+
};
|
|
703
|
+
var constantReaderOf = (ts, ast, { spanOf, extentOf, unwrap, returnedObject, chainOf, keyName, objectKeys }) => {
|
|
636
704
|
const filterQueriesOf = (source, builder) => {
|
|
637
705
|
const query = returnedObject(builder)?.properties.find((property) => ts.isPropertyAssignment(property) && ast.nodeName(property.name) === "query")?.initializer;
|
|
638
706
|
return query && ts.isObjectLiteralExpression(query) ? objectKeys(source, query) : [];
|
|
@@ -670,48 +738,18 @@ var createFactReader = (ts, ast) => {
|
|
|
670
738
|
return [];
|
|
671
739
|
return list.elements.flatMap((element) => ts.isStringLiteralLike(element) ? [element.text] : []);
|
|
672
740
|
};
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
return [{ name, span: spanOf(source, member.name), extent: extentOf(source, member) }];
|
|
680
|
-
});
|
|
681
|
-
const importsOf = (statement) => {
|
|
682
|
-
const { importClause, moduleSpecifier } = statement;
|
|
683
|
-
if (!importClause || !ts.isStringLiteral(moduleSpecifier))
|
|
684
|
-
return [];
|
|
685
|
-
const from = moduleSpecifier.text;
|
|
686
|
-
const bindings = importClause.namedBindings;
|
|
687
|
-
return [
|
|
688
|
-
...importClause.name ? [{ name: importClause.name.text, imported: "default", from }] : [],
|
|
689
|
-
...bindings && ts.isNamespaceImport(bindings) ? [{ name: bindings.name.text, imported: "*", from }] : [],
|
|
690
|
-
...bindings && ts.isNamedImports(bindings) ? bindings.elements.map((element) => ({
|
|
691
|
-
name: element.name.text,
|
|
692
|
-
imported: (element.propertyName ?? element.name).text,
|
|
693
|
-
from
|
|
694
|
-
})) : []
|
|
695
|
-
];
|
|
696
|
-
};
|
|
697
|
-
const docOf = (source, node) => {
|
|
698
|
-
const { text } = source;
|
|
699
|
-
const ranges = ts.getLeadingCommentRanges(text, node.getFullStart()) ?? [];
|
|
700
|
-
const comments = [];
|
|
701
|
-
let end = node.getStart(source);
|
|
702
|
-
for (const range of [...ranges].reverse()) {
|
|
703
|
-
if ((text.slice(range.end, end).match(/\n/g)?.length ?? 0) > 1)
|
|
704
|
-
break;
|
|
705
|
-
comments.unshift(text.slice(range.pos, range.end));
|
|
706
|
-
end = range.pos;
|
|
707
|
-
}
|
|
708
|
-
const lines = comments.flatMap((comment) => comment.split(`
|
|
709
|
-
`)).map((line) => line.trim().replace(/^\/\*\*?|\*\/$/g, "").replace(/^(?:\/\/[?*!]?|\*)/, "").replace(/\{@link\s+([^}\s|]+)[^}]*\}/g, "$1").trim()).filter((line) => line && !/^(?:biome-ignore|eslint-|@ts-)/.test(line));
|
|
710
|
-
return lines.length ? lines.join(" ") : null;
|
|
711
|
-
};
|
|
741
|
+
return { constantOf, enumValuesOf, filterQueriesOf };
|
|
742
|
+
};
|
|
743
|
+
var createFactReader = (ts, ast) => {
|
|
744
|
+
const syntax = syntaxReaderOf(ts, ast);
|
|
745
|
+
const { spanOf, extentOf, unwrap, moduleRefOf, returnedObject, builderOf, chainOf, objectKeys } = syntax;
|
|
746
|
+
const { docOf, importsIn } = sourceReaderOf(ts);
|
|
712
747
|
const { guardsIn, guardsOf } = createGuardFactReader(ts, ast, { spanOf, extentOf, unwrap, docOf });
|
|
748
|
+
const { sliceKeysOf, endpointKeysOf } = signalKeyReaderOf(ts, ast, syntax, guardsIn);
|
|
749
|
+
const { internalKeysOf } = jobKeyReaderOf(ts, ast, syntax);
|
|
750
|
+
const { plugsOf, adaptorBindingsIn, methodsOf } = serviceReaderOf(ts, ast, syntax);
|
|
751
|
+
const { constantOf, enumValuesOf, filterQueriesOf } = constantReaderOf(ts, ast, syntax);
|
|
713
752
|
const lowerFirst = (text) => text.charAt(0).toLowerCase() + text.slice(1);
|
|
714
|
-
const importsIn = (source) => source.statements.filter(ts.isImportDeclaration).flatMap(importsOf);
|
|
715
753
|
const read = (source, owner) => {
|
|
716
754
|
const imports = importsIn(source);
|
|
717
755
|
const madeInPlace = [];
|
|
@@ -813,6 +851,7 @@ var identifierPattern = /^[\p{ID_Start}$_][\p{ID_Continue}$\u200c\u200d]*$/u;
|
|
|
813
851
|
var starExportPattern = /export\s*\*\s*from\s*["']([^"']+)["']/g;
|
|
814
852
|
var facetEntryPattern = new RegExp(`^((?:apps|libs)/[^/]+/(${barrelFacetDirs.map(escapeRegExp).join("|")}))/([^/]+)(/)?`);
|
|
815
853
|
var exportingPatternOf = (name) => new RegExp(`export\\s*\\{(?:[^}]*?[\\s,])?${escapeRegExp(name)}(?![\\w$])`);
|
|
854
|
+
var exportMentioningPatternOf = (name) => new RegExp(`export\\s[^;]*?(?<![\\w$])${escapeRegExp(name)}(?![\\w$])`);
|
|
816
855
|
var declaringPatternOf = (name, isAnyBinding) => {
|
|
817
856
|
const escaped = escapeRegExp(name);
|
|
818
857
|
const braced = "\\{(?:[^}]*?[\\s,])?";
|
|
@@ -835,6 +874,8 @@ class GuardResolver {
|
|
|
835
874
|
#declarations = new Map;
|
|
836
875
|
#starExports = new Map;
|
|
837
876
|
#moduleExports = new Map;
|
|
877
|
+
#fileStars = new Map;
|
|
878
|
+
#starReach = new Map;
|
|
838
879
|
#ownerFiles = null;
|
|
839
880
|
#modules = null;
|
|
840
881
|
#barrels = null;
|
|
@@ -1192,27 +1233,78 @@ ${name}`;
|
|
|
1192
1233
|
const cached = this.#moduleExports.get(key);
|
|
1193
1234
|
if (cached)
|
|
1194
1235
|
return cached;
|
|
1195
|
-
const found = { named: null, stars:
|
|
1196
|
-
const
|
|
1236
|
+
const found = { named: null, stars: [], isLocal: false };
|
|
1237
|
+
const stars = new Set(this.#barrelAt(path));
|
|
1197
1238
|
for (const fileName of this.#modulesAt(path)) {
|
|
1198
1239
|
const text = this.#source.readText(fileName);
|
|
1199
1240
|
if (text === undefined)
|
|
1200
1241
|
continue;
|
|
1201
|
-
const named = identifierPattern.test(name) &&
|
|
1242
|
+
const named = text.includes(name) && identifierPattern.test(name) && exportingPatternOf(name).test(text) ? this.#reexportIn(this.#source.parse(fileName, text), name) : null;
|
|
1202
1243
|
if (named) {
|
|
1203
1244
|
found.named = { ...named, fileName };
|
|
1204
|
-
found.stars = [];
|
|
1205
1245
|
break;
|
|
1206
1246
|
}
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
found.stars.push(target);
|
|
1247
|
+
if (text.includes(name) && exportMentioningPatternOf(name).test(text) && this.#exportsLocally(this.#source.parse(fileName, text), name)) {
|
|
1248
|
+
found.isLocal = true;
|
|
1249
|
+
break;
|
|
1211
1250
|
}
|
|
1251
|
+
for (const target of this.#starsIn(fileName, text))
|
|
1252
|
+
stars.add(target);
|
|
1212
1253
|
}
|
|
1254
|
+
if (!found.named && !found.isLocal)
|
|
1255
|
+
found.stars = [...stars];
|
|
1213
1256
|
this.#moduleExports.set(key, found);
|
|
1214
1257
|
return found;
|
|
1215
1258
|
}
|
|
1259
|
+
#exportsLocally(source, name) {
|
|
1260
|
+
const { ts } = this.#source;
|
|
1261
|
+
const binds = (node) => ts.isIdentifier(node) ? node.text === name : node.elements.some((element) => !ts.isOmittedExpression(element) && binds(element.name));
|
|
1262
|
+
return source.statements.some((statement) => {
|
|
1263
|
+
if (ts.isExportDeclaration(statement))
|
|
1264
|
+
return !statement.moduleSpecifier && !statement.isTypeOnly && !!statement.exportClause && ts.isNamedExports(statement.exportClause) && statement.exportClause.elements.some((element) => !element.isTypeOnly && element.name.text === name);
|
|
1265
|
+
const modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) ?? [] : [];
|
|
1266
|
+
if (!modifiers.some(({ kind }) => kind === ts.SyntaxKind.ExportKeyword) || modifiers.some(({ kind }) => kind === ts.SyntaxKind.DefaultKeyword))
|
|
1267
|
+
return false;
|
|
1268
|
+
if (ts.isVariableStatement(statement))
|
|
1269
|
+
return statement.declarationList.declarations.some((declaration) => binds(declaration.name));
|
|
1270
|
+
return (ts.isClassDeclaration(statement) || ts.isFunctionDeclaration(statement) || ts.isEnumDeclaration(statement) || ts.isModuleDeclaration(statement) || ts.isImportEqualsDeclaration(statement)) && !!statement.name && ts.isIdentifier(statement.name) && statement.name.text === name;
|
|
1271
|
+
});
|
|
1272
|
+
}
|
|
1273
|
+
mentionsAlong(path, name) {
|
|
1274
|
+
return this.#starReachOf(path).some((text) => text.includes(name));
|
|
1275
|
+
}
|
|
1276
|
+
#starReachOf(path) {
|
|
1277
|
+
const cached = this.#starReach.get(path);
|
|
1278
|
+
if (cached)
|
|
1279
|
+
return cached;
|
|
1280
|
+
const paths = new Set([path]);
|
|
1281
|
+
const texts = [];
|
|
1282
|
+
for (const at of paths) {
|
|
1283
|
+
for (const next of this.#barrelAt(at) ?? [])
|
|
1284
|
+
paths.add(next);
|
|
1285
|
+
for (const fileName of this.#modulesAt(at)) {
|
|
1286
|
+
const text = this.#source.readText(fileName) ?? "";
|
|
1287
|
+
texts.push(text);
|
|
1288
|
+
for (const next of this.#starsIn(fileName, text))
|
|
1289
|
+
paths.add(next);
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
this.#starReach.set(path, texts);
|
|
1293
|
+
return texts;
|
|
1294
|
+
}
|
|
1295
|
+
#starsIn(fileName, text) {
|
|
1296
|
+
const cached = this.#fileStars.get(fileName);
|
|
1297
|
+
if (cached)
|
|
1298
|
+
return cached;
|
|
1299
|
+
const found = [];
|
|
1300
|
+
for (const [, specifier = ""] of text.matchAll(starExportPattern)) {
|
|
1301
|
+
const target = this.pathOfSpecifier(fileName, specifier);
|
|
1302
|
+
if (target !== null)
|
|
1303
|
+
found.push(target);
|
|
1304
|
+
}
|
|
1305
|
+
this.#fileStars.set(fileName, found);
|
|
1306
|
+
return found;
|
|
1307
|
+
}
|
|
1216
1308
|
#modulesAt(path) {
|
|
1217
1309
|
if (!this.#modules) {
|
|
1218
1310
|
this.#modules = new Map;
|
|
@@ -1304,6 +1396,9 @@ ${name}`;
|
|
|
1304
1396
|
var packageOf = (specifier) => specifier.split("/").slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
|
|
1305
1397
|
var packageKeyOf = ({ name, from }) => `${packageOf(from)}
|
|
1306
1398
|
${name}`;
|
|
1399
|
+
var exportedKeyOf = (item) => ("fact" in item) ? item.id : ("local" in item) ? `${item.local}
|
|
1400
|
+
` : packageKeyOf(item);
|
|
1401
|
+
var isPackageExport = (item) => ("from" in item);
|
|
1307
1402
|
|
|
1308
1403
|
class AdaptorResolver {
|
|
1309
1404
|
#source;
|
|
@@ -1312,6 +1407,7 @@ class AdaptorResolver {
|
|
|
1312
1407
|
#adaptors = new Map;
|
|
1313
1408
|
#plugs = new Map;
|
|
1314
1409
|
#serviceFields = new Set;
|
|
1410
|
+
#exported = new Map;
|
|
1315
1411
|
constructor(source, resolver, sink) {
|
|
1316
1412
|
this.#source = source;
|
|
1317
1413
|
this.#resolver = resolver;
|
|
@@ -1394,33 +1490,66 @@ ${field}`))
|
|
|
1394
1490
|
return own.find((adaptor) => adaptor.fileName === fileName) ?? first;
|
|
1395
1491
|
if (own.length === 1)
|
|
1396
1492
|
return first;
|
|
1397
|
-
const exported = this.#exportedAt(name, path
|
|
1493
|
+
const exported = this.#exportedAt(name, path).filter((item) => first || !isPackageExport(item));
|
|
1398
1494
|
const [only] = exported;
|
|
1399
1495
|
if (only)
|
|
1400
|
-
return exported.length === 1 ? only : null;
|
|
1496
|
+
return exported.length === 1 && !("local" in only) ? only : null;
|
|
1401
1497
|
return first ? null : undefined;
|
|
1402
1498
|
}
|
|
1403
|
-
#exportedAt(name, path
|
|
1499
|
+
#exportedAt(name, path) {
|
|
1404
1500
|
const key = `${path}
|
|
1405
1501
|
${name}`;
|
|
1406
|
-
|
|
1502
|
+
const cached = this.#exported.get(key);
|
|
1503
|
+
if (cached)
|
|
1504
|
+
return cached;
|
|
1505
|
+
if (!this.#resolver.mentionsAlong(path, name)) {
|
|
1506
|
+
this.#exported.set(key, []);
|
|
1407
1507
|
return [];
|
|
1408
|
-
|
|
1409
|
-
const
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1508
|
+
}
|
|
1509
|
+
const reached = new Map;
|
|
1510
|
+
const seen = new Set;
|
|
1511
|
+
const pending = [[name, path]];
|
|
1512
|
+
for (let next = pending.pop();next; next = pending.pop()) {
|
|
1513
|
+
const [wanted, at] = next;
|
|
1514
|
+
if (seen.has(`${at}
|
|
1515
|
+
${wanted}`))
|
|
1516
|
+
continue;
|
|
1517
|
+
seen.add(`${at}
|
|
1518
|
+
${wanted}`);
|
|
1519
|
+
for (const item of this.#bindingAt(wanted, at, pending))
|
|
1520
|
+
reached.set(exportedKeyOf(item), item);
|
|
1521
|
+
}
|
|
1522
|
+
const found = [...reached.values()];
|
|
1523
|
+
this.#exported.set(key, found);
|
|
1524
|
+
return found;
|
|
1525
|
+
}
|
|
1526
|
+
#bindingAt(name, path, pending) {
|
|
1527
|
+
const here = this.#declaredAt(name, path);
|
|
1413
1528
|
if (here.length)
|
|
1414
1529
|
return here;
|
|
1415
|
-
const { named, stars } = this.#resolver.exportsAt(path, name);
|
|
1416
|
-
if (
|
|
1417
|
-
return [{
|
|
1530
|
+
const { named, stars, isLocal } = this.#resolver.exportsAt(path, name);
|
|
1531
|
+
if (isLocal)
|
|
1532
|
+
return [{ local: path }];
|
|
1533
|
+
if (named?.from === null) {
|
|
1534
|
+
const local = this.#declaredAt(named.name, path);
|
|
1535
|
+
return local.length ? local : [{ local: path }];
|
|
1536
|
+
}
|
|
1418
1537
|
if (named) {
|
|
1419
|
-
const target =
|
|
1420
|
-
|
|
1538
|
+
const target = this.#resolver.pathOfSpecifier(named.fileName, named.from);
|
|
1539
|
+
if (target === null)
|
|
1540
|
+
return [{ name: named.name === "default" ? name : named.name, from: named.from }];
|
|
1541
|
+
pending.push([named.name, target]);
|
|
1542
|
+
return [];
|
|
1421
1543
|
}
|
|
1422
|
-
const
|
|
1423
|
-
|
|
1544
|
+
for (const star of stars)
|
|
1545
|
+
pending.push([name, star]);
|
|
1546
|
+
return [];
|
|
1547
|
+
}
|
|
1548
|
+
#declaredAt(name, path) {
|
|
1549
|
+
return (this.#adaptors.get(name) ?? []).filter((adaptor) => {
|
|
1550
|
+
const module = this.#source.relative(adaptor.fileName).replace(/\.tsx?$/, "");
|
|
1551
|
+
return module === path || module === `${path}/index`;
|
|
1552
|
+
});
|
|
1424
1553
|
}
|
|
1425
1554
|
#packageAdaptorOf(name, specifier) {
|
|
1426
1555
|
if (frameworkPattern.test(specifier))
|
|
@@ -1431,14 +1560,15 @@ ${name}`;
|
|
|
1431
1560
|
#packageShimOf(owner, name, near) {
|
|
1432
1561
|
if (!near)
|
|
1433
1562
|
return null;
|
|
1434
|
-
const shims = this.#exportedAt(name, near
|
|
1563
|
+
const shims = this.#exportedAt(name, near).filter(isPackageExport);
|
|
1435
1564
|
const [shim] = shims;
|
|
1436
1565
|
if (shim)
|
|
1437
1566
|
return shims.length === 1 ? shim : null;
|
|
1438
1567
|
const { packages, paths } = this.#resolver.starExportsOf(owner, near);
|
|
1439
1568
|
const [only] = packages;
|
|
1440
|
-
|
|
1441
|
-
|
|
1569
|
+
if (!only || new Set(packages.map(packageOf)).size !== 1)
|
|
1570
|
+
return null;
|
|
1571
|
+
return paths.some((path) => this.#resolver.declaresAt(path, name)) ? null : { name, from: only };
|
|
1442
1572
|
}
|
|
1443
1573
|
#nodeOf({ fact, owner, fileName, id }) {
|
|
1444
1574
|
const detail = fact.refName ? [fact.refName] : [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akanjs/language",
|
|
3
|
-
"version": "3.2.0-rc.
|
|
3
|
+
"version": "3.2.0-rc.19",
|
|
4
4
|
"description": "Editor-independent Akan.js language core: resolves derived names (slices, queries, CRUD, form setters) back to the source key that produced them.",
|
|
5
5
|
"sourceType": "module",
|
|
6
6
|
"type": "module",
|