@sprig-and-prose/sprig-universe 0.4.2 → 0.4.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sprig-and-prose/sprig-universe",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "type": "module",
5
5
  "description": "Minimal universe parser for sprig",
6
6
  "main": "src/index.js",
@@ -670,31 +670,21 @@ function bindParentsAndKinds(index, normalizedDecls) {
670
670
  * @param {ScopeKey} scopeKey
671
671
  * @returns {string}
672
672
  */
673
- function resolveKind(spelledKind, scopeKey) {
673
+ function resolveKind(spelledKind, declId) {
674
674
  const baseKinds = ['universe', 'anthology', 'series', 'book', 'chapter', 'concept', 'relates', 'relationship', 'repository', 'reference'];
675
675
  if (baseKinds.includes(spelledKind)) {
676
676
  return spelledKind;
677
677
  }
678
678
 
679
- // Walk up scope chain to find alias
680
- let currentScope = scopeKey;
681
- while (currentScope) {
682
- const aliasTable = aliasTablesByScope.get(currentScope);
679
+ // Walk up syntactic parent chain to find alias
680
+ let currentDeclId = declId;
681
+ while (currentDeclId) {
682
+ const decl = declMap.get(currentDeclId);
683
+ const aliasTable = decl?.aliases;
683
684
  if (aliasTable && aliasTable.has(spelledKind)) {
684
685
  return aliasTable.get(spelledKind);
685
686
  }
686
-
687
- // Move to parent scope (extract parent from scope key)
688
- if (currentScope.startsWith('series:')) {
689
- // Parent would be anthology or universe - need to find it
690
- break; // For now, just check current scope
691
- } else if (currentScope.startsWith('anthology:')) {
692
- // Parent is universe
693
- const universeName = currentScope.split(':')[1];
694
- currentScope = `universe:${universeName}`;
695
- } else {
696
- break;
697
- }
687
+ currentDeclId = decl?.syntacticParentId;
698
688
  }
699
689
 
700
690
  return 'unknown';
@@ -702,7 +692,7 @@ function bindParentsAndKinds(index, normalizedDecls) {
702
692
 
703
693
  // First pass: resolve kinds
704
694
  for (const [declId, info] of declIndex.entries()) {
705
- const resolvedKind = resolveKind(info.kindSpelled, info.scopeKey);
695
+ const resolvedKind = resolveKind(info.kindSpelled, declId);
706
696
  info.kindResolved = resolvedKind;
707
697
 
708
698
  if (resolvedKind === 'unknown' && !['relates', 'relationshipDecl', 'repository', 'referenceDecl'].includes(info.kindSpelled)) {
@@ -814,13 +804,19 @@ function bindParentsAndKinds(index, normalizedDecls) {
814
804
 
815
805
  // Build children lists from resolved parent map, preserving source order
816
806
  const childrenByParent = new Map();
807
+ const childrenSeenByParent = new Map();
817
808
  for (const decl of normalizedDecls) {
818
809
  const info = declIndex.get(decl.id);
819
810
  if (!info || !info.parentDeclId) continue;
820
811
  if (!childrenByParent.has(info.parentDeclId)) {
821
812
  childrenByParent.set(info.parentDeclId, []);
813
+ childrenSeenByParent.set(info.parentDeclId, new Set());
814
+ }
815
+ const seen = childrenSeenByParent.get(info.parentDeclId);
816
+ if (!seen.has(decl.id)) {
817
+ childrenByParent.get(info.parentDeclId).push(decl.id);
818
+ seen.add(decl.id);
822
819
  }
823
- childrenByParent.get(info.parentDeclId).push(decl.id);
824
820
  }
825
821
 
826
822
  for (const bound of boundDecls) {