@kubb/ast 5.0.0-beta.2 → 5.0.0-beta.4

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": "@kubb/ast",
3
- "version": "5.0.0-beta.2",
3
+ "version": "5.0.0-beta.4",
4
4
  "description": "Spec-agnostic AST layer for Kubb. Defines nodes, visitor pattern, and factory functions used across codegen plugins.",
5
5
  "keywords": [
6
6
  "ast",
package/src/utils.ts CHANGED
@@ -652,6 +652,16 @@ export function combineImports(imports: Array<ImportNode>, exports: Array<Export
652
652
  const exportedNames = new Set(exports.flatMap((e) => (Array.isArray(e.name) ? e.name : e.name ? [e.name] : [])))
653
653
  const isUsed = (importName: string): boolean => !source || source.includes(importName) || exportedNames.has(importName)
654
654
 
655
+ // Memoize object import names so the same logical (propertyName, name) pair always
656
+ // reuses the same object reference — Set-based deduplication then works correctly.
657
+ const importNameMemo = new Map<string, { propertyName: string; name?: string }>()
658
+ const canonicalizeName = (n: string | { propertyName: string; name?: string }): string | { propertyName: string; name?: string } => {
659
+ if (typeof n === 'string') return n
660
+ const key = `${n.propertyName}:${n.name ?? ''}`
661
+ if (!importNameMemo.has(key)) importNameMemo.set(key, n)
662
+ return importNameMemo.get(key)!
663
+ }
664
+
655
665
  const result: Array<ImportNode> = []
656
666
  // Accumulates array-named imports keyed by `path:isTypeOnly` for name-merging
657
667
  const namedByPath = new Map<string, ImportNode>()
@@ -669,7 +679,7 @@ export function combineImports(imports: Array<ImportNode>, exports: Array<Export
669
679
  let { name } = curr
670
680
 
671
681
  if (Array.isArray(name)) {
672
- name = [...new Set(name)].filter((item) => (typeof item === 'string' ? isUsed(item) : isUsed(item.name ?? item.propertyName)))
682
+ name = [...new Set(name.map(canonicalizeName))].filter((item) => (typeof item === 'string' ? isUsed(item) : isUsed(item.name ?? item.propertyName)))
673
683
  if (!name.length) continue
674
684
 
675
685
  const key = pathTypeKey(path, isTypeOnly)