@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/server.js
CHANGED
|
@@ -318,7 +318,7 @@ var ownerOf = (relativePath) => {
|
|
|
318
318
|
const [root, name] = relativePath.split("/");
|
|
319
319
|
return (root === "apps" || root === "libs") && name ? `${root}/${name}` : null;
|
|
320
320
|
};
|
|
321
|
-
var
|
|
321
|
+
var syntaxReaderOf = (ts, ast) => {
|
|
322
322
|
const spanOf = (source, node) => {
|
|
323
323
|
const start = node.getStart(source);
|
|
324
324
|
const end = node.getEnd();
|
|
@@ -376,6 +376,74 @@ var createFactReader = (ts, ast) => {
|
|
|
376
376
|
const node = keyName(property);
|
|
377
377
|
return name && node ? [{ name, span: spanOf(source, node), extent: extentOf(source, property) }] : [];
|
|
378
378
|
});
|
|
379
|
+
const verbReaderOf = (parameter) => {
|
|
380
|
+
const verbs = new Map;
|
|
381
|
+
if (parameter && ts.isObjectBindingPattern(parameter.name))
|
|
382
|
+
for (const element of parameter.name.elements) {
|
|
383
|
+
const verb = element.propertyName ?? element.name;
|
|
384
|
+
if (ts.isIdentifier(verb) && ts.isIdentifier(element.name))
|
|
385
|
+
verbs.set(element.name.text, verb.text);
|
|
386
|
+
}
|
|
387
|
+
const holder = parameter && ts.isIdentifier(parameter.name) ? parameter.name.text : null;
|
|
388
|
+
return (callee) => {
|
|
389
|
+
if (callee && ts.isIdentifier(callee))
|
|
390
|
+
return verbs.get(callee.text) ?? null;
|
|
391
|
+
if (callee && ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression) && callee.expression.text === holder)
|
|
392
|
+
return callee.name.text;
|
|
393
|
+
return null;
|
|
394
|
+
};
|
|
395
|
+
};
|
|
396
|
+
return {
|
|
397
|
+
spanOf,
|
|
398
|
+
extentOf,
|
|
399
|
+
unwrap,
|
|
400
|
+
moduleRefOf,
|
|
401
|
+
returnedObject,
|
|
402
|
+
builderOf,
|
|
403
|
+
guardNameOf,
|
|
404
|
+
optionObjectOf,
|
|
405
|
+
chainOf,
|
|
406
|
+
keyName,
|
|
407
|
+
objectKeys,
|
|
408
|
+
verbReaderOf
|
|
409
|
+
};
|
|
410
|
+
};
|
|
411
|
+
var sourceReaderOf = (ts) => {
|
|
412
|
+
const importsOf = (statement) => {
|
|
413
|
+
const { importClause, moduleSpecifier } = statement;
|
|
414
|
+
if (!importClause || !ts.isStringLiteral(moduleSpecifier))
|
|
415
|
+
return [];
|
|
416
|
+
const from = moduleSpecifier.text;
|
|
417
|
+
const bindings = importClause.namedBindings;
|
|
418
|
+
return [
|
|
419
|
+
...importClause.name ? [{ name: importClause.name.text, imported: "default", from }] : [],
|
|
420
|
+
...bindings && ts.isNamespaceImport(bindings) ? [{ name: bindings.name.text, imported: "*", from }] : [],
|
|
421
|
+
...bindings && ts.isNamedImports(bindings) ? bindings.elements.map((element) => ({
|
|
422
|
+
name: element.name.text,
|
|
423
|
+
imported: (element.propertyName ?? element.name).text,
|
|
424
|
+
from
|
|
425
|
+
})) : []
|
|
426
|
+
];
|
|
427
|
+
};
|
|
428
|
+
const docOf = (source, node) => {
|
|
429
|
+
const { text } = source;
|
|
430
|
+
const ranges = ts.getLeadingCommentRanges(text, node.getFullStart()) ?? [];
|
|
431
|
+
const comments = [];
|
|
432
|
+
let end = node.getStart(source);
|
|
433
|
+
for (const range of [...ranges].reverse()) {
|
|
434
|
+
if ((text.slice(range.end, end).match(/\n/g)?.length ?? 0) > 1)
|
|
435
|
+
break;
|
|
436
|
+
comments.unshift(text.slice(range.pos, range.end));
|
|
437
|
+
end = range.pos;
|
|
438
|
+
}
|
|
439
|
+
const lines = comments.flatMap((comment) => comment.split(`
|
|
440
|
+
`)).map((line) => line.trim().replace(/^\/\*\*?|\*\/$/g, "").replace(/^(?:\/\/[?*!]?|\*)/, "").replace(/\{@link\s+([^}\s|]+)[^}]*\}/g, "$1").trim()).filter((line) => line && !/^(?:biome-ignore|eslint-|@ts-)/.test(line));
|
|
441
|
+
return lines.length ? lines.join(" ") : null;
|
|
442
|
+
};
|
|
443
|
+
const importsIn = (source) => source.statements.filter(ts.isImportDeclaration).flatMap(importsOf);
|
|
444
|
+
return { docOf, importsIn };
|
|
445
|
+
};
|
|
446
|
+
var signalKeyReaderOf = (ts, ast, { spanOf, extentOf, returnedObject, optionObjectOf, chainOf, verbReaderOf }, guardsIn) => {
|
|
379
447
|
const sliceKeysOf = (source, builder, made, model) => (returnedObject(builder)?.properties ?? []).flatMap((property) => {
|
|
380
448
|
if (!ts.isPropertyAssignment(property))
|
|
381
449
|
return [];
|
|
@@ -394,23 +462,30 @@ var createFactReader = (ts, ast) => {
|
|
|
394
462
|
}
|
|
395
463
|
];
|
|
396
464
|
});
|
|
397
|
-
const
|
|
398
|
-
const
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
465
|
+
const endpointKeysOf = (source, builder, made, model) => {
|
|
466
|
+
const verbOf = verbReaderOf(builder?.parameters[0]);
|
|
467
|
+
return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
|
|
468
|
+
if (!ts.isPropertyAssignment(property))
|
|
469
|
+
return [];
|
|
470
|
+
const name = ast.nodeName(property.name);
|
|
471
|
+
if (!name)
|
|
472
|
+
return [];
|
|
473
|
+
const { root, methods } = chainOf(property.initializer);
|
|
474
|
+
return [
|
|
475
|
+
{
|
|
476
|
+
name,
|
|
477
|
+
span: spanOf(source, property.name),
|
|
478
|
+
extent: extentOf(source, property),
|
|
479
|
+
verb: root ? verbOf(root.expression) : null,
|
|
480
|
+
guards: root ? guardsIn(source, optionObjectOf(root), made, `${model}.${name}`) : [],
|
|
481
|
+
argCount: methods.filter((method) => argMethods.has(method)).length
|
|
482
|
+
}
|
|
483
|
+
];
|
|
484
|
+
});
|
|
413
485
|
};
|
|
486
|
+
return { sliceKeysOf, endpointKeysOf };
|
|
487
|
+
};
|
|
488
|
+
var jobKeyReaderOf = (ts, ast, { spanOf, extentOf, unwrap, returnedObject, chainOf, verbReaderOf }) => {
|
|
414
489
|
const numberOf = (expression) => {
|
|
415
490
|
const value = unwrap(expression);
|
|
416
491
|
if (ts.isNumericLiteral(value))
|
|
@@ -483,6 +558,9 @@ var createFactReader = (ts, ast) => {
|
|
|
483
558
|
];
|
|
484
559
|
});
|
|
485
560
|
};
|
|
561
|
+
return { internalKeysOf };
|
|
562
|
+
};
|
|
563
|
+
var serviceReaderOf = (ts, ast, { spanOf, extentOf, returnedObject, guardNameOf, chainOf, verbReaderOf }) => {
|
|
486
564
|
const plugsOf = (source, builder) => {
|
|
487
565
|
const verbOf = verbReaderOf(builder?.parameters[0]);
|
|
488
566
|
return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
|
|
@@ -508,27 +586,17 @@ var createFactReader = (ts, ast) => {
|
|
|
508
586
|
visit(source);
|
|
509
587
|
return bindings;
|
|
510
588
|
};
|
|
511
|
-
const
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
name,
|
|
523
|
-
span: spanOf(source, property.name),
|
|
524
|
-
extent: extentOf(source, property),
|
|
525
|
-
verb: root ? verbOf(root.expression) : null,
|
|
526
|
-
guards: root ? guardsIn(source, optionObjectOf(root), made, `${model}.${name}`) : [],
|
|
527
|
-
argCount: methods.filter((method) => argMethods.has(method)).length
|
|
528
|
-
}
|
|
529
|
-
];
|
|
530
|
-
});
|
|
531
|
-
};
|
|
589
|
+
const methodsOf = (source, statement) => statement.members.flatMap((member) => {
|
|
590
|
+
if (!ts.isMethodDeclaration(member) || !member.body)
|
|
591
|
+
return [];
|
|
592
|
+
const name = ast.nodeName(member.name);
|
|
593
|
+
if (!name || ts.getModifiers(member)?.some(({ kind }) => kind === ts.SyntaxKind.StaticKeyword))
|
|
594
|
+
return [];
|
|
595
|
+
return [{ name, span: spanOf(source, member.name), extent: extentOf(source, member) }];
|
|
596
|
+
});
|
|
597
|
+
return { plugsOf, adaptorBindingsIn, methodsOf };
|
|
598
|
+
};
|
|
599
|
+
var constantReaderOf = (ts, ast, { spanOf, extentOf, unwrap, returnedObject, chainOf, keyName, objectKeys }) => {
|
|
532
600
|
const filterQueriesOf = (source, builder) => {
|
|
533
601
|
const query = returnedObject(builder)?.properties.find((property) => ts.isPropertyAssignment(property) && ast.nodeName(property.name) === "query")?.initializer;
|
|
534
602
|
return query && ts.isObjectLiteralExpression(query) ? objectKeys(source, query) : [];
|
|
@@ -566,48 +634,18 @@ var createFactReader = (ts, ast) => {
|
|
|
566
634
|
return [];
|
|
567
635
|
return list.elements.flatMap((element) => ts.isStringLiteralLike(element) ? [element.text] : []);
|
|
568
636
|
};
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
return [{ name, span: spanOf(source, member.name), extent: extentOf(source, member) }];
|
|
576
|
-
});
|
|
577
|
-
const importsOf = (statement) => {
|
|
578
|
-
const { importClause, moduleSpecifier } = statement;
|
|
579
|
-
if (!importClause || !ts.isStringLiteral(moduleSpecifier))
|
|
580
|
-
return [];
|
|
581
|
-
const from = moduleSpecifier.text;
|
|
582
|
-
const bindings = importClause.namedBindings;
|
|
583
|
-
return [
|
|
584
|
-
...importClause.name ? [{ name: importClause.name.text, imported: "default", from }] : [],
|
|
585
|
-
...bindings && ts.isNamespaceImport(bindings) ? [{ name: bindings.name.text, imported: "*", from }] : [],
|
|
586
|
-
...bindings && ts.isNamedImports(bindings) ? bindings.elements.map((element) => ({
|
|
587
|
-
name: element.name.text,
|
|
588
|
-
imported: (element.propertyName ?? element.name).text,
|
|
589
|
-
from
|
|
590
|
-
})) : []
|
|
591
|
-
];
|
|
592
|
-
};
|
|
593
|
-
const docOf = (source, node) => {
|
|
594
|
-
const { text } = source;
|
|
595
|
-
const ranges = ts.getLeadingCommentRanges(text, node.getFullStart()) ?? [];
|
|
596
|
-
const comments = [];
|
|
597
|
-
let end = node.getStart(source);
|
|
598
|
-
for (const range of [...ranges].reverse()) {
|
|
599
|
-
if ((text.slice(range.end, end).match(/\n/g)?.length ?? 0) > 1)
|
|
600
|
-
break;
|
|
601
|
-
comments.unshift(text.slice(range.pos, range.end));
|
|
602
|
-
end = range.pos;
|
|
603
|
-
}
|
|
604
|
-
const lines = comments.flatMap((comment) => comment.split(`
|
|
605
|
-
`)).map((line) => line.trim().replace(/^\/\*\*?|\*\/$/g, "").replace(/^(?:\/\/[?*!]?|\*)/, "").replace(/\{@link\s+([^}\s|]+)[^}]*\}/g, "$1").trim()).filter((line) => line && !/^(?:biome-ignore|eslint-|@ts-)/.test(line));
|
|
606
|
-
return lines.length ? lines.join(" ") : null;
|
|
607
|
-
};
|
|
637
|
+
return { constantOf, enumValuesOf, filterQueriesOf };
|
|
638
|
+
};
|
|
639
|
+
var createFactReader = (ts, ast) => {
|
|
640
|
+
const syntax = syntaxReaderOf(ts, ast);
|
|
641
|
+
const { spanOf, extentOf, unwrap, moduleRefOf, returnedObject, builderOf, chainOf, objectKeys } = syntax;
|
|
642
|
+
const { docOf, importsIn } = sourceReaderOf(ts);
|
|
608
643
|
const { guardsIn, guardsOf } = createGuardFactReader(ts, ast, { spanOf, extentOf, unwrap, docOf });
|
|
644
|
+
const { sliceKeysOf, endpointKeysOf } = signalKeyReaderOf(ts, ast, syntax, guardsIn);
|
|
645
|
+
const { internalKeysOf } = jobKeyReaderOf(ts, ast, syntax);
|
|
646
|
+
const { plugsOf, adaptorBindingsIn, methodsOf } = serviceReaderOf(ts, ast, syntax);
|
|
647
|
+
const { constantOf, enumValuesOf, filterQueriesOf } = constantReaderOf(ts, ast, syntax);
|
|
609
648
|
const lowerFirst = (text) => text.charAt(0).toLowerCase() + text.slice(1);
|
|
610
|
-
const importsIn = (source) => source.statements.filter(ts.isImportDeclaration).flatMap(importsOf);
|
|
611
649
|
const read = (source, owner) => {
|
|
612
650
|
const imports = importsIn(source);
|
|
613
651
|
const madeInPlace = [];
|
|
@@ -709,6 +747,7 @@ var identifierPattern = /^[\p{ID_Start}$_][\p{ID_Continue}$\u200c\u200d]*$/u;
|
|
|
709
747
|
var starExportPattern = /export\s*\*\s*from\s*["']([^"']+)["']/g;
|
|
710
748
|
var facetEntryPattern = new RegExp(`^((?:apps|libs)/[^/]+/(${barrelFacetDirs.map(escapeRegExp).join("|")}))/([^/]+)(/)?`);
|
|
711
749
|
var exportingPatternOf = (name) => new RegExp(`export\\s*\\{(?:[^}]*?[\\s,])?${escapeRegExp(name)}(?![\\w$])`);
|
|
750
|
+
var exportMentioningPatternOf = (name) => new RegExp(`export\\s[^;]*?(?<![\\w$])${escapeRegExp(name)}(?![\\w$])`);
|
|
712
751
|
var declaringPatternOf = (name, isAnyBinding) => {
|
|
713
752
|
const escaped = escapeRegExp(name);
|
|
714
753
|
const braced = "\\{(?:[^}]*?[\\s,])?";
|
|
@@ -731,6 +770,8 @@ class GuardResolver {
|
|
|
731
770
|
#declarations = new Map;
|
|
732
771
|
#starExports = new Map;
|
|
733
772
|
#moduleExports = new Map;
|
|
773
|
+
#fileStars = new Map;
|
|
774
|
+
#starReach = new Map;
|
|
734
775
|
#ownerFiles = null;
|
|
735
776
|
#modules = null;
|
|
736
777
|
#barrels = null;
|
|
@@ -1088,27 +1129,78 @@ ${name}`;
|
|
|
1088
1129
|
const cached = this.#moduleExports.get(key);
|
|
1089
1130
|
if (cached)
|
|
1090
1131
|
return cached;
|
|
1091
|
-
const found = { named: null, stars:
|
|
1092
|
-
const
|
|
1132
|
+
const found = { named: null, stars: [], isLocal: false };
|
|
1133
|
+
const stars = new Set(this.#barrelAt(path));
|
|
1093
1134
|
for (const fileName of this.#modulesAt(path)) {
|
|
1094
1135
|
const text = this.#source.readText(fileName);
|
|
1095
1136
|
if (text === undefined)
|
|
1096
1137
|
continue;
|
|
1097
|
-
const named = identifierPattern.test(name) &&
|
|
1138
|
+
const named = text.includes(name) && identifierPattern.test(name) && exportingPatternOf(name).test(text) ? this.#reexportIn(this.#source.parse(fileName, text), name) : null;
|
|
1098
1139
|
if (named) {
|
|
1099
1140
|
found.named = { ...named, fileName };
|
|
1100
|
-
found.stars = [];
|
|
1101
1141
|
break;
|
|
1102
1142
|
}
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
found.stars.push(target);
|
|
1143
|
+
if (text.includes(name) && exportMentioningPatternOf(name).test(text) && this.#exportsLocally(this.#source.parse(fileName, text), name)) {
|
|
1144
|
+
found.isLocal = true;
|
|
1145
|
+
break;
|
|
1107
1146
|
}
|
|
1147
|
+
for (const target of this.#starsIn(fileName, text))
|
|
1148
|
+
stars.add(target);
|
|
1108
1149
|
}
|
|
1150
|
+
if (!found.named && !found.isLocal)
|
|
1151
|
+
found.stars = [...stars];
|
|
1109
1152
|
this.#moduleExports.set(key, found);
|
|
1110
1153
|
return found;
|
|
1111
1154
|
}
|
|
1155
|
+
#exportsLocally(source, name) {
|
|
1156
|
+
const { ts } = this.#source;
|
|
1157
|
+
const binds = (node) => ts.isIdentifier(node) ? node.text === name : node.elements.some((element) => !ts.isOmittedExpression(element) && binds(element.name));
|
|
1158
|
+
return source.statements.some((statement) => {
|
|
1159
|
+
if (ts.isExportDeclaration(statement))
|
|
1160
|
+
return !statement.moduleSpecifier && !statement.isTypeOnly && !!statement.exportClause && ts.isNamedExports(statement.exportClause) && statement.exportClause.elements.some((element) => !element.isTypeOnly && element.name.text === name);
|
|
1161
|
+
const modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) ?? [] : [];
|
|
1162
|
+
if (!modifiers.some(({ kind }) => kind === ts.SyntaxKind.ExportKeyword) || modifiers.some(({ kind }) => kind === ts.SyntaxKind.DefaultKeyword))
|
|
1163
|
+
return false;
|
|
1164
|
+
if (ts.isVariableStatement(statement))
|
|
1165
|
+
return statement.declarationList.declarations.some((declaration) => binds(declaration.name));
|
|
1166
|
+
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;
|
|
1167
|
+
});
|
|
1168
|
+
}
|
|
1169
|
+
mentionsAlong(path, name) {
|
|
1170
|
+
return this.#starReachOf(path).some((text) => text.includes(name));
|
|
1171
|
+
}
|
|
1172
|
+
#starReachOf(path) {
|
|
1173
|
+
const cached = this.#starReach.get(path);
|
|
1174
|
+
if (cached)
|
|
1175
|
+
return cached;
|
|
1176
|
+
const paths = new Set([path]);
|
|
1177
|
+
const texts = [];
|
|
1178
|
+
for (const at of paths) {
|
|
1179
|
+
for (const next of this.#barrelAt(at) ?? [])
|
|
1180
|
+
paths.add(next);
|
|
1181
|
+
for (const fileName of this.#modulesAt(at)) {
|
|
1182
|
+
const text = this.#source.readText(fileName) ?? "";
|
|
1183
|
+
texts.push(text);
|
|
1184
|
+
for (const next of this.#starsIn(fileName, text))
|
|
1185
|
+
paths.add(next);
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
this.#starReach.set(path, texts);
|
|
1189
|
+
return texts;
|
|
1190
|
+
}
|
|
1191
|
+
#starsIn(fileName, text) {
|
|
1192
|
+
const cached = this.#fileStars.get(fileName);
|
|
1193
|
+
if (cached)
|
|
1194
|
+
return cached;
|
|
1195
|
+
const found = [];
|
|
1196
|
+
for (const [, specifier = ""] of text.matchAll(starExportPattern)) {
|
|
1197
|
+
const target = this.pathOfSpecifier(fileName, specifier);
|
|
1198
|
+
if (target !== null)
|
|
1199
|
+
found.push(target);
|
|
1200
|
+
}
|
|
1201
|
+
this.#fileStars.set(fileName, found);
|
|
1202
|
+
return found;
|
|
1203
|
+
}
|
|
1112
1204
|
#modulesAt(path) {
|
|
1113
1205
|
if (!this.#modules) {
|
|
1114
1206
|
this.#modules = new Map;
|
|
@@ -1200,6 +1292,9 @@ ${name}`;
|
|
|
1200
1292
|
var packageOf = (specifier) => specifier.split("/").slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
|
|
1201
1293
|
var packageKeyOf = ({ name, from }) => `${packageOf(from)}
|
|
1202
1294
|
${name}`;
|
|
1295
|
+
var exportedKeyOf = (item) => ("fact" in item) ? item.id : ("local" in item) ? `${item.local}
|
|
1296
|
+
` : packageKeyOf(item);
|
|
1297
|
+
var isPackageExport = (item) => ("from" in item);
|
|
1203
1298
|
|
|
1204
1299
|
class AdaptorResolver {
|
|
1205
1300
|
#source;
|
|
@@ -1208,6 +1303,7 @@ class AdaptorResolver {
|
|
|
1208
1303
|
#adaptors = new Map;
|
|
1209
1304
|
#plugs = new Map;
|
|
1210
1305
|
#serviceFields = new Set;
|
|
1306
|
+
#exported = new Map;
|
|
1211
1307
|
constructor(source, resolver, sink) {
|
|
1212
1308
|
this.#source = source;
|
|
1213
1309
|
this.#resolver = resolver;
|
|
@@ -1290,33 +1386,66 @@ ${field}`))
|
|
|
1290
1386
|
return own.find((adaptor) => adaptor.fileName === fileName) ?? first;
|
|
1291
1387
|
if (own.length === 1)
|
|
1292
1388
|
return first;
|
|
1293
|
-
const exported = this.#exportedAt(name, path
|
|
1389
|
+
const exported = this.#exportedAt(name, path).filter((item) => first || !isPackageExport(item));
|
|
1294
1390
|
const [only] = exported;
|
|
1295
1391
|
if (only)
|
|
1296
|
-
return exported.length === 1 ? only : null;
|
|
1392
|
+
return exported.length === 1 && !("local" in only) ? only : null;
|
|
1297
1393
|
return first ? null : undefined;
|
|
1298
1394
|
}
|
|
1299
|
-
#exportedAt(name, path
|
|
1395
|
+
#exportedAt(name, path) {
|
|
1300
1396
|
const key = `${path}
|
|
1301
1397
|
${name}`;
|
|
1302
|
-
|
|
1398
|
+
const cached = this.#exported.get(key);
|
|
1399
|
+
if (cached)
|
|
1400
|
+
return cached;
|
|
1401
|
+
if (!this.#resolver.mentionsAlong(path, name)) {
|
|
1402
|
+
this.#exported.set(key, []);
|
|
1303
1403
|
return [];
|
|
1304
|
-
|
|
1305
|
-
const
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1404
|
+
}
|
|
1405
|
+
const reached = new Map;
|
|
1406
|
+
const seen = new Set;
|
|
1407
|
+
const pending = [[name, path]];
|
|
1408
|
+
for (let next = pending.pop();next; next = pending.pop()) {
|
|
1409
|
+
const [wanted, at] = next;
|
|
1410
|
+
if (seen.has(`${at}
|
|
1411
|
+
${wanted}`))
|
|
1412
|
+
continue;
|
|
1413
|
+
seen.add(`${at}
|
|
1414
|
+
${wanted}`);
|
|
1415
|
+
for (const item of this.#bindingAt(wanted, at, pending))
|
|
1416
|
+
reached.set(exportedKeyOf(item), item);
|
|
1417
|
+
}
|
|
1418
|
+
const found = [...reached.values()];
|
|
1419
|
+
this.#exported.set(key, found);
|
|
1420
|
+
return found;
|
|
1421
|
+
}
|
|
1422
|
+
#bindingAt(name, path, pending) {
|
|
1423
|
+
const here = this.#declaredAt(name, path);
|
|
1309
1424
|
if (here.length)
|
|
1310
1425
|
return here;
|
|
1311
|
-
const { named, stars } = this.#resolver.exportsAt(path, name);
|
|
1312
|
-
if (
|
|
1313
|
-
return [{
|
|
1426
|
+
const { named, stars, isLocal } = this.#resolver.exportsAt(path, name);
|
|
1427
|
+
if (isLocal)
|
|
1428
|
+
return [{ local: path }];
|
|
1429
|
+
if (named?.from === null) {
|
|
1430
|
+
const local = this.#declaredAt(named.name, path);
|
|
1431
|
+
return local.length ? local : [{ local: path }];
|
|
1432
|
+
}
|
|
1314
1433
|
if (named) {
|
|
1315
|
-
const target =
|
|
1316
|
-
|
|
1434
|
+
const target = this.#resolver.pathOfSpecifier(named.fileName, named.from);
|
|
1435
|
+
if (target === null)
|
|
1436
|
+
return [{ name: named.name === "default" ? name : named.name, from: named.from }];
|
|
1437
|
+
pending.push([named.name, target]);
|
|
1438
|
+
return [];
|
|
1317
1439
|
}
|
|
1318
|
-
const
|
|
1319
|
-
|
|
1440
|
+
for (const star of stars)
|
|
1441
|
+
pending.push([name, star]);
|
|
1442
|
+
return [];
|
|
1443
|
+
}
|
|
1444
|
+
#declaredAt(name, path) {
|
|
1445
|
+
return (this.#adaptors.get(name) ?? []).filter((adaptor) => {
|
|
1446
|
+
const module = this.#source.relative(adaptor.fileName).replace(/\.tsx?$/, "");
|
|
1447
|
+
return module === path || module === `${path}/index`;
|
|
1448
|
+
});
|
|
1320
1449
|
}
|
|
1321
1450
|
#packageAdaptorOf(name, specifier) {
|
|
1322
1451
|
if (frameworkPattern.test(specifier))
|
|
@@ -1327,14 +1456,15 @@ ${name}`;
|
|
|
1327
1456
|
#packageShimOf(owner, name, near) {
|
|
1328
1457
|
if (!near)
|
|
1329
1458
|
return null;
|
|
1330
|
-
const shims = this.#exportedAt(name, near
|
|
1459
|
+
const shims = this.#exportedAt(name, near).filter(isPackageExport);
|
|
1331
1460
|
const [shim] = shims;
|
|
1332
1461
|
if (shim)
|
|
1333
1462
|
return shims.length === 1 ? shim : null;
|
|
1334
1463
|
const { packages, paths } = this.#resolver.starExportsOf(owner, near);
|
|
1335
1464
|
const [only] = packages;
|
|
1336
|
-
|
|
1337
|
-
|
|
1465
|
+
if (!only || new Set(packages.map(packageOf)).size !== 1)
|
|
1466
|
+
return null;
|
|
1467
|
+
return paths.some((path) => this.#resolver.declaresAt(path, name)) ? null : { name, from: only };
|
|
1338
1468
|
}
|
|
1339
1469
|
#nodeOf({ fact, owner, fileName, id }) {
|
|
1340
1470
|
const detail = fact.refName ? [fact.refName] : [];
|