@kubb/ast 5.0.0-beta.46 → 5.0.0-beta.48

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.46",
3
+ "version": "5.0.0-beta.48",
4
4
  "description": "Spec-agnostic AST layer for Kubb. Defines the node tree, visitor pattern, factory functions, and type guards used across all code generation plugins.",
5
5
  "keywords": [
6
6
  "ast",
package/src/factory.ts CHANGED
@@ -668,10 +668,23 @@ export function createFile<TMeta extends object = object>(input: UserFileNode<TM
668
668
  .join('\n\n')
669
669
  const resolvedExports = input.exports?.length ? combineExports(input.exports) : []
670
670
  const combinedImports = input.imports?.length ? combineImports(input.imports, resolvedExports, source || undefined) : []
671
- // Drop imports that resolve to the containing file itself. Consolidated output
672
- // (`mode: 'group'` and `mode: 'file'`) turns former cross-file imports into self-imports.
673
- // Bare module specifiers (`'zod'`, `'@faker-js/faker'`) never equal an absolute file path.
674
- const resolvedImports = combinedImports.filter((imp) => imp.path !== input.path)
671
+ const localNames = new Set((input.sources ?? []).map((item) => item.name).filter((name): name is string => Boolean(name)))
672
+ const nameOf = (item: string | { propertyName: string; name?: string }): string => (typeof item === 'string' ? item : (item.name ?? item.propertyName))
673
+ // Drop self-imports. Consolidating output (`mode: 'file'`) can place a symbol's
674
+ // definition and a cross-file import of it in the same file. The first pass catches imports that
675
+ // resolve to this file's own path. The second drops imports of names the file already defines,
676
+ // the case consolidation produces when the import path no longer matches `input.path`. Sources
677
+ // stay intact, so the local definition remains. Bare specifiers like `'zod'` never match a path.
678
+ const resolvedImports = combinedImports
679
+ .filter((imp) => imp.path !== input.path)
680
+ .flatMap((imp) => {
681
+ if (!Array.isArray(imp.name)) {
682
+ return typeof imp.name === 'string' && localNames.has(imp.name) ? [] : [imp]
683
+ }
684
+ const kept = imp.name.filter((item) => !localNames.has(nameOf(item)))
685
+ if (!kept.length) return []
686
+ return [kept.length === imp.name.length ? imp : { ...imp, name: kept }]
687
+ })
675
688
  const resolvedSources = input.sources?.length ? combineSources(input.sources) : []
676
689
 
677
690
  return {