@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/dist/index.cjs +8 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/utils.ts +11 -1
package/package.json
CHANGED
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)
|