@akanjs/language 3.2.0-rc.17 → 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/index.js CHANGED
@@ -109,6 +109,38 @@ ${at.file}` : null;
109
109
  return node.fields ? { ...node, fields: node.fields.map(({ digest: _field, ...field }) => field) } : node;
110
110
  }
111
111
  }
112
+ // pkgs/akanjs/common/facetBarrel.ts
113
+ var barrelFacetDirs = ["ui", "webkit", "srvkit", "common", "plugin"];
114
+ var sourceFilePattern = /\.(ts|tsx)$/;
115
+ var excludedFilePattern = /(^index\.tsx?$|\.d\.ts$|\.(test|spec)\.(ts|tsx)$|\.css$|\.scss$|\.sass$)/;
116
+ var pascalCasePattern = /^[A-Z][A-Za-z0-9]*$/;
117
+ var camelCasePattern = /^[a-z][A-Za-z0-9]*$/;
118
+ var letterRankOf = (char) => char.toLowerCase().charCodeAt(0) * 2 + (char === char.toLowerCase() ? 1 : 0);
119
+ var digitRunAt = (name, idx) => /^\d+/.exec(name.slice(idx))?.[0] ?? "";
120
+ var compareExportNames = (a, b) => {
121
+ for (let idx = 0;idx < a.length && idx < b.length; ) {
122
+ const [runA, runB] = [digitRunAt(a, idx), digitRunAt(b, idx)];
123
+ if (runA && runB && runA !== runB)
124
+ return runA.length - runB.length || (runA < runB ? -1 : 1);
125
+ if (runA && runB)
126
+ idx += runA.length;
127
+ else if (runA || runB)
128
+ return runA ? -1 : 1;
129
+ else if (a.charAt(idx) !== b.charAt(idx))
130
+ return letterRankOf(a.charAt(idx)) - letterRankOf(b.charAt(idx));
131
+ else
132
+ idx++;
133
+ }
134
+ return a.length - b.length;
135
+ };
136
+ var facetBarrelNamesOf = (facet, files, dirs) => {
137
+ const nameCasePattern = facet === "ui" ? pascalCasePattern : camelCasePattern;
138
+ return [
139
+ ...files.filter((file) => sourceFilePattern.test(file) && !excludedFilePattern.test(file)).map((file) => file.replace(sourceFilePattern, "")),
140
+ ...dirs.filter((dir) => !dir.startsWith("."))
141
+ ].filter((name) => nameCasePattern.test(name)).sort(compareExportNames);
142
+ };
143
+
112
144
  // pkgs/@akanjs/language/escapeRegExp.ts
113
145
  var regExpSpecials = /[\\^$.*+?()[\]{}|]/g;
114
146
  var escapeRegExp = (text) => text.replace(regExpSpecials, (special) => `\\${special}`);
@@ -390,7 +422,7 @@ var ownerOf = (relativePath) => {
390
422
  const [root, name] = relativePath.split("/");
391
423
  return (root === "apps" || root === "libs") && name ? `${root}/${name}` : null;
392
424
  };
393
- var createFactReader = (ts, ast) => {
425
+ var syntaxReaderOf = (ts, ast) => {
394
426
  const spanOf = (source, node) => {
395
427
  const start = node.getStart(source);
396
428
  const end = node.getEnd();
@@ -448,6 +480,74 @@ var createFactReader = (ts, ast) => {
448
480
  const node = keyName(property);
449
481
  return name && node ? [{ name, span: spanOf(source, node), extent: extentOf(source, property) }] : [];
450
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) => {
451
551
  const sliceKeysOf = (source, builder, made, model) => (returnedObject(builder)?.properties ?? []).flatMap((property) => {
452
552
  if (!ts.isPropertyAssignment(property))
453
553
  return [];
@@ -466,23 +566,30 @@ var createFactReader = (ts, ast) => {
466
566
  }
467
567
  ];
468
568
  });
469
- const verbReaderOf = (parameter) => {
470
- const verbs = new Map;
471
- if (parameter && ts.isObjectBindingPattern(parameter.name))
472
- for (const element of parameter.name.elements) {
473
- const verb = element.propertyName ?? element.name;
474
- if (ts.isIdentifier(verb) && ts.isIdentifier(element.name))
475
- verbs.set(element.name.text, verb.text);
476
- }
477
- const holder = parameter && ts.isIdentifier(parameter.name) ? parameter.name.text : null;
478
- return (callee) => {
479
- if (callee && ts.isIdentifier(callee))
480
- return verbs.get(callee.text) ?? null;
481
- if (callee && ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression) && callee.expression.text === holder)
482
- return callee.name.text;
483
- return null;
484
- };
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
+ });
485
589
  };
590
+ return { sliceKeysOf, endpointKeysOf };
591
+ };
592
+ var jobKeyReaderOf = (ts, ast, { spanOf, extentOf, unwrap, returnedObject, chainOf, verbReaderOf }) => {
486
593
  const numberOf = (expression) => {
487
594
  const value = unwrap(expression);
488
595
  if (ts.isNumericLiteral(value))
@@ -555,6 +662,9 @@ var createFactReader = (ts, ast) => {
555
662
  ];
556
663
  });
557
664
  };
665
+ return { internalKeysOf };
666
+ };
667
+ var serviceReaderOf = (ts, ast, { spanOf, extentOf, returnedObject, guardNameOf, chainOf, verbReaderOf }) => {
558
668
  const plugsOf = (source, builder) => {
559
669
  const verbOf = verbReaderOf(builder?.parameters[0]);
560
670
  return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
@@ -580,27 +690,17 @@ var createFactReader = (ts, ast) => {
580
690
  visit(source);
581
691
  return bindings;
582
692
  };
583
- const endpointKeysOf = (source, builder, made, model) => {
584
- const verbOf = verbReaderOf(builder?.parameters[0]);
585
- return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
586
- if (!ts.isPropertyAssignment(property))
587
- return [];
588
- const name = ast.nodeName(property.name);
589
- if (!name)
590
- return [];
591
- const { root, methods } = chainOf(property.initializer);
592
- return [
593
- {
594
- name,
595
- span: spanOf(source, property.name),
596
- extent: extentOf(source, property),
597
- verb: root ? verbOf(root.expression) : null,
598
- guards: root ? guardsIn(source, optionObjectOf(root), made, `${model}.${name}`) : [],
599
- argCount: methods.filter((method) => argMethods.has(method)).length
600
- }
601
- ];
602
- });
603
- };
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 }) => {
604
704
  const filterQueriesOf = (source, builder) => {
605
705
  const query = returnedObject(builder)?.properties.find((property) => ts.isPropertyAssignment(property) && ast.nodeName(property.name) === "query")?.initializer;
606
706
  return query && ts.isObjectLiteralExpression(query) ? objectKeys(source, query) : [];
@@ -638,48 +738,18 @@ var createFactReader = (ts, ast) => {
638
738
  return [];
639
739
  return list.elements.flatMap((element) => ts.isStringLiteralLike(element) ? [element.text] : []);
640
740
  };
641
- const methodsOf = (source, statement) => statement.members.flatMap((member) => {
642
- if (!ts.isMethodDeclaration(member) || !member.body)
643
- return [];
644
- const name = ast.nodeName(member.name);
645
- if (!name || ts.getModifiers(member)?.some(({ kind }) => kind === ts.SyntaxKind.StaticKeyword))
646
- return [];
647
- return [{ name, span: spanOf(source, member.name), extent: extentOf(source, member) }];
648
- });
649
- const importsOf = (statement) => {
650
- const { importClause, moduleSpecifier } = statement;
651
- if (!importClause || !ts.isStringLiteral(moduleSpecifier))
652
- return [];
653
- const from = moduleSpecifier.text;
654
- const bindings = importClause.namedBindings;
655
- return [
656
- ...importClause.name ? [{ name: importClause.name.text, imported: "default", from }] : [],
657
- ...bindings && ts.isNamespaceImport(bindings) ? [{ name: bindings.name.text, imported: "*", from }] : [],
658
- ...bindings && ts.isNamedImports(bindings) ? bindings.elements.map((element) => ({
659
- name: element.name.text,
660
- imported: (element.propertyName ?? element.name).text,
661
- from
662
- })) : []
663
- ];
664
- };
665
- const docOf = (source, node) => {
666
- const { text } = source;
667
- const ranges = ts.getLeadingCommentRanges(text, node.getFullStart()) ?? [];
668
- const comments = [];
669
- let end = node.getStart(source);
670
- for (const range of [...ranges].reverse()) {
671
- if ((text.slice(range.end, end).match(/\n/g)?.length ?? 0) > 1)
672
- break;
673
- comments.unshift(text.slice(range.pos, range.end));
674
- end = range.pos;
675
- }
676
- const lines = comments.flatMap((comment) => comment.split(`
677
- `)).map((line) => line.trim().replace(/^\/\*\*?|\*\/$/g, "").replace(/^(?:\/\/[?*!]?|\*)/, "").replace(/\{@link\s+([^}\s|]+)[^}]*\}/g, "$1").trim()).filter((line) => line && !/^(?:biome-ignore|eslint-|@ts-)/.test(line));
678
- return lines.length ? lines.join(" ") : null;
679
- };
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);
680
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);
681
752
  const lowerFirst = (text) => text.charAt(0).toLowerCase() + text.slice(1);
682
- const importsIn = (source) => source.statements.filter(ts.isImportDeclaration).flatMap(importsOf);
683
753
  const read = (source, owner) => {
684
754
  const imports = importsIn(source);
685
755
  const madeInPlace = [];
@@ -779,7 +849,9 @@ var aliasPattern = /^@(apps|libs)\/([^/]+)/;
779
849
  var maxMapDepth = 4;
780
850
  var identifierPattern = /^[\p{ID_Start}$_][\p{ID_Continue}$\u200c\u200d]*$/u;
781
851
  var starExportPattern = /export\s*\*\s*from\s*["']([^"']+)["']/g;
852
+ var facetEntryPattern = new RegExp(`^((?:apps|libs)/[^/]+/(${barrelFacetDirs.map(escapeRegExp).join("|")}))/([^/]+)(/)?`);
782
853
  var exportingPatternOf = (name) => new RegExp(`export\\s*\\{(?:[^}]*?[\\s,])?${escapeRegExp(name)}(?![\\w$])`);
854
+ var exportMentioningPatternOf = (name) => new RegExp(`export\\s[^;]*?(?<![\\w$])${escapeRegExp(name)}(?![\\w$])`);
783
855
  var declaringPatternOf = (name, isAnyBinding) => {
784
856
  const escaped = escapeRegExp(name);
785
857
  const braced = "\\{(?:[^}]*?[\\s,])?";
@@ -802,8 +874,11 @@ class GuardResolver {
802
874
  #declarations = new Map;
803
875
  #starExports = new Map;
804
876
  #moduleExports = new Map;
877
+ #fileStars = new Map;
878
+ #starReach = new Map;
805
879
  #ownerFiles = null;
806
880
  #modules = null;
881
+ #barrels = null;
807
882
  constructor(source, routes) {
808
883
  this.#source = source;
809
884
  this.#routes = routes;
@@ -931,7 +1006,7 @@ ${name}`, guard);
931
1006
  const own = this.#nearest(candidates.filter((other) => other.owner === from), ({ site }) => site.fileName, near);
932
1007
  if (own)
933
1008
  return own;
934
- const reexport = from && depth < maxMapDepth ? this.reexportOf(from, name, near) : null;
1009
+ const reexport = from && depth < maxMapDepth ? this.#reexportOf(from, name, near) : null;
935
1010
  if (reexport)
936
1011
  return this.#factoryAt(factories, reexport.local, reexport.site, depth + 1);
937
1012
  return from && near ? this.#throughStar(candidates, from, name, near) : undefined;
@@ -969,13 +1044,13 @@ ${name}`, guard);
969
1044
  const visible = isBase ? undefined : declared.find((other) => this.visible(other.owner, site.owner));
970
1045
  return visible ? { guard: visible } : { name, from };
971
1046
  }
972
- const reexport = from && depth < maxMapDepth ? this.reexportOf(from, name, near) : null;
1047
+ const reexport = from && depth < maxMapDepth ? this.#reexportOf(from, name, near) : null;
973
1048
  if (reexport)
974
1049
  return this.#findGuard(reexport.local, reexport.site, depth + 1, isBase);
975
1050
  const reached = from && near ? this.#throughStar(declared, from, name, near) : undefined;
976
1051
  return reached ? { guard: reached } : { name, from };
977
1052
  }
978
- reexportOf(owner, name, near) {
1053
+ #reexportOf(owner, name, near) {
979
1054
  const key = `${owner}
980
1055
  ${name}
981
1056
  ${near ?? ""}`;
@@ -1132,20 +1207,24 @@ ${near}`;
1132
1207
  return cached;
1133
1208
  const found = { owners: [], packages: [], paths: [near], isOpaque: false };
1134
1209
  this.#starExports.set(key, found);
1135
- for (let idx = 0;idx < found.paths.length; idx++)
1136
- for (const fileName of this.#modulesAt(found.paths[idx] ?? ""))
1137
- for (const [, specifier = ""] of this.#source.readText(fileName)?.matchAll(starExportPattern) ?? []) {
1138
- const target = this.ownerOfSpecifier(fileName, specifier);
1139
- const path = this.pathOfSpecifier(fileName, specifier);
1140
- if (path === null && !found.packages.includes(specifier))
1141
- found.packages.push(specifier);
1142
- if (target === undefined || target === frameworkOwner || path === null)
1143
- found.isOpaque = true;
1144
- else if (!found.paths.includes(path))
1145
- found.paths.push(path);
1146
- if (target && target !== frameworkOwner && target !== owner && !found.owners.includes(target))
1147
- found.owners.push(target);
1148
- }
1210
+ const reach = (specifier, path, target) => {
1211
+ if (path === null && !found.packages.includes(specifier))
1212
+ found.packages.push(specifier);
1213
+ if (target === undefined || target === frameworkOwner || path === null)
1214
+ found.isOpaque = true;
1215
+ else if (!found.paths.includes(path))
1216
+ found.paths.push(path);
1217
+ if (target && target !== frameworkOwner && target !== owner && !found.owners.includes(target))
1218
+ found.owners.push(target);
1219
+ };
1220
+ for (let idx = 0;idx < found.paths.length; idx++) {
1221
+ const path = found.paths[idx] ?? "";
1222
+ for (const module of this.#barrelAt(path) ?? [])
1223
+ reach(module, module, ownerOf(module) ?? undefined);
1224
+ for (const fileName of this.#modulesAt(path))
1225
+ for (const [, specifier = ""] of this.#source.readText(fileName)?.matchAll(starExportPattern) ?? [])
1226
+ reach(specifier, this.pathOfSpecifier(fileName, specifier), this.ownerOfSpecifier(fileName, specifier));
1227
+ }
1149
1228
  return found;
1150
1229
  }
1151
1230
  exportsAt(path, name) {
@@ -1154,27 +1233,78 @@ ${name}`;
1154
1233
  const cached = this.#moduleExports.get(key);
1155
1234
  if (cached)
1156
1235
  return cached;
1157
- const found = { named: null, stars: [] };
1158
- const exporting = exportingPatternOf(name);
1236
+ const found = { named: null, stars: [], isLocal: false };
1237
+ const stars = new Set(this.#barrelAt(path));
1159
1238
  for (const fileName of this.#modulesAt(path)) {
1160
1239
  const text = this.#source.readText(fileName);
1161
1240
  if (text === undefined)
1162
1241
  continue;
1163
- const named = identifierPattern.test(name) && exporting.test(text) ? this.#reexportIn(this.#source.parse(fileName, text), name) : null;
1242
+ const named = text.includes(name) && identifierPattern.test(name) && exportingPatternOf(name).test(text) ? this.#reexportIn(this.#source.parse(fileName, text), name) : null;
1164
1243
  if (named) {
1165
1244
  found.named = { ...named, fileName };
1166
- found.stars = [];
1167
1245
  break;
1168
1246
  }
1169
- for (const [, specifier = ""] of text.matchAll(starExportPattern)) {
1170
- const target = this.pathOfSpecifier(fileName, specifier);
1171
- if (target !== null && !found.stars.includes(target))
1172
- 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;
1173
1250
  }
1251
+ for (const target of this.#starsIn(fileName, text))
1252
+ stars.add(target);
1174
1253
  }
1254
+ if (!found.named && !found.isLocal)
1255
+ found.stars = [...stars];
1175
1256
  this.#moduleExports.set(key, found);
1176
1257
  return found;
1177
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
+ }
1178
1308
  #modulesAt(path) {
1179
1309
  if (!this.#modules) {
1180
1310
  this.#modules = new Map;
@@ -1186,21 +1316,23 @@ ${name}`;
1186
1316
  }
1187
1317
  return this.#modules.get(path) ?? [];
1188
1318
  }
1189
- hasModule(path) {
1190
- return this.#modulesAt(path).length > 0;
1191
- }
1192
- packagesUnder(owner, folder) {
1193
- const packages = new Set;
1194
- for (const [fileName, words] of this.#filesIn(owner)) {
1195
- if (!this.#source.relative(fileName).startsWith(`${folder}/`) || !words.includes(`
1196
- export
1197
- `))
1198
- continue;
1199
- for (const [, specifier = ""] of this.#source.readText(fileName)?.matchAll(starExportPattern) ?? [])
1200
- if (this.pathOfSpecifier(fileName, specifier) === null)
1201
- packages.add(specifier);
1319
+ #barrelAt(path) {
1320
+ if (!this.#barrels) {
1321
+ const entries = new Map;
1322
+ for (const [fileName] of this.#source.files) {
1323
+ const [, folder, facet, entry, nested] = this.#source.relative(fileName).match(facetEntryPattern) ?? [];
1324
+ if (!folder || !facet || !entry)
1325
+ continue;
1326
+ const found = entries.get(folder) ?? { facet, files: new Set, dirs: new Set };
1327
+ (nested ? found.dirs : found.files).add(entry);
1328
+ entries.set(folder, found);
1329
+ }
1330
+ this.#barrels = new Map([...entries].map(([folder, { facet, files, dirs }]) => [
1331
+ folder,
1332
+ facetBarrelNamesOf(facet, [...files], [...dirs]).map((name) => `${folder}/${name}`)
1333
+ ]));
1202
1334
  }
1203
- return [...packages];
1335
+ return this.#modulesAt(path).length ? undefined : this.#barrels.get(path);
1204
1336
  }
1205
1337
  declares(owner, name) {
1206
1338
  const declaring = declaringPatternOf(name, true);
@@ -1261,7 +1393,12 @@ export
1261
1393
  }
1262
1394
 
1263
1395
  // pkgs/@akanjs/language/adaptorResolver.ts
1264
- var maxModules = 64;
1396
+ var packageOf = (specifier) => specifier.split("/").slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
1397
+ var packageKeyOf = ({ name, from }) => `${packageOf(from)}
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);
1265
1402
 
1266
1403
  class AdaptorResolver {
1267
1404
  #source;
@@ -1270,6 +1407,7 @@ class AdaptorResolver {
1270
1407
  #adaptors = new Map;
1271
1408
  #plugs = new Map;
1272
1409
  #serviceFields = new Set;
1410
+ #exported = new Map;
1273
1411
  constructor(source, resolver, sink) {
1274
1412
  this.#source = source;
1275
1413
  this.#resolver = resolver;
@@ -1352,52 +1490,85 @@ ${field}`))
1352
1490
  return own.find((adaptor) => adaptor.fileName === fileName) ?? first;
1353
1491
  if (own.length === 1)
1354
1492
  return first;
1355
- if (!this.#resolver.hasModule(path))
1356
- return own.find((adaptor) => this.#source.relative(adaptor.fileName).startsWith(`${path}/`)) ?? first;
1357
- const exported = this.#exportedAt(name, path, new Set).filter((item) => first || ("fact" in item));
1493
+ const exported = this.#exportedAt(name, path).filter((item) => first || !isPackageExport(item));
1358
1494
  const [only] = exported;
1359
1495
  if (only)
1360
- return exported.length === 1 ? only : null;
1496
+ return exported.length === 1 && !("local" in only) ? only : null;
1361
1497
  return first ? null : undefined;
1362
1498
  }
1363
- #exportedAt(name, path, seen) {
1499
+ #exportedAt(name, path) {
1364
1500
  const key = `${path}
1365
1501
  ${name}`;
1366
- if (seen.has(key) || seen.size >= maxModules)
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, []);
1367
1507
  return [];
1368
- seen.add(key);
1369
- const here = (this.#adaptors.get(name) ?? []).filter((adaptor) => {
1370
- const module = this.#source.relative(adaptor.fileName).replace(/\.tsx?$/, "");
1371
- return module === path || module === `${path}/index`;
1372
- });
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);
1373
1528
  if (here.length)
1374
1529
  return here;
1375
- const { named, stars } = this.#resolver.exportsAt(path, name);
1376
- if (named?.from && this.#resolver.pathOfSpecifier(named.fileName, named.from) === null)
1377
- return [{ name: named.name === "default" ? name : named.name, from: named.from }];
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
+ }
1378
1537
  if (named) {
1379
- const target = named.from === null ? path : this.#resolver.pathOfSpecifier(named.fileName, named.from);
1380
- return target === null ? [] : this.#exportedAt(named.name, target, seen);
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 [];
1381
1543
  }
1382
- return [...new Set(stars.flatMap((star) => this.#exportedAt(name, star, seen)))];
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
+ });
1383
1553
  }
1384
1554
  #packageAdaptorOf(name, specifier) {
1385
1555
  if (frameworkPattern.test(specifier))
1386
1556
  return this.#sink.addNode(this.#sink.key("adaptor", null, name), "adaptor", null, name, null, [frameworkOwner]).id;
1387
- const pkg = specifier.split("/").slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
1557
+ const pkg = packageOf(specifier);
1388
1558
  return this.#sink.addNode(this.#sink.key("adaptor", pkg, name), "adaptor", null, name, null, [pkg]).id;
1389
1559
  }
1390
1560
  #packageShimOf(owner, name, near) {
1391
- const reexport = this.#resolver.reexportOf(owner, name, near);
1392
- const [shim] = reexport?.site.imports ?? [];
1393
- if (reexport && shim && this.#resolver.pathOfSpecifier(reexport.site.fileName, shim.from) === null)
1394
- return { name: reexport.local === "default" ? name : reexport.local, from: shim.from };
1395
- if (reexport || !near)
1561
+ if (!near)
1396
1562
  return null;
1397
- const { packages, paths } = this.#resolver.hasModule(near) ? this.#resolver.starExportsOf(owner, near) : { packages: this.#resolver.packagesUnder(owner, near), paths: [] };
1563
+ const shims = this.#exportedAt(name, near).filter(isPackageExport);
1564
+ const [shim] = shims;
1565
+ if (shim)
1566
+ return shims.length === 1 ? shim : null;
1567
+ const { packages, paths } = this.#resolver.starExportsOf(owner, near);
1398
1568
  const [only] = packages;
1399
- const isDeclared = this.#resolver.declares(owner, name) || paths.some((path) => this.#resolver.declaresAt(path, name));
1400
- return packages.length === 1 && only && !isDeclared ? { name, from: only } : null;
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 };
1401
1572
  }
1402
1573
  #nodeOf({ fact, owner, fileName, id }) {
1403
1574
  const detail = fact.refName ? [fact.refName] : [];
@@ -1432,6 +1603,7 @@ var PAGE_ROUTE_EXPORTS = new Set([
1432
1603
  "guard"
1433
1604
  ]);
1434
1605
  var LAYOUT_ROUTE_EXPORTS = new Set([...PAGE_ROUTE_EXPORTS, "NotFound", "Error"]);
1606
+ var GENERATED_ROOT_LAYOUT_EXPORTS = new Set(["McpAppRoot", "LevelBoundary"]);
1435
1607
  var ROOT_LAYOUT_ROUTE_EXPORTS = new Set([
1436
1608
  ...LAYOUT_ROUTE_EXPORTS,
1437
1609
  "fonts",
@@ -1441,8 +1613,7 @@ var ROOT_LAYOUT_ROUTE_EXPORTS = new Set([
1441
1613
  "wsConnect",
1442
1614
  "layoutStyle",
1443
1615
  "viewport",
1444
- "McpAppRoot",
1445
- "LevelBoundary"
1616
+ ...GENERATED_ROOT_LAYOUT_EXPORTS
1446
1617
  ]);
1447
1618
  var RESERVED_ROUTE_CONFIG_EXPORTS = new Set([...ROOT_LAYOUT_ROUTE_EXPORTS].filter((name) => name !== "default" && !/^[A-Z]/.test(name)));
1448
1619
  function parseRouteModuleKey(key) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/language",
3
- "version": "3.2.0-rc.17",
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",