@kubb/ast 5.0.0-beta.45 → 5.0.0-beta.47

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.45",
3
+ "version": "5.0.0-beta.47",
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
@@ -667,7 +667,24 @@ export function createFile<TMeta extends object = object>(input: UserFileNode<TM
667
667
  .filter(Boolean)
668
668
  .join('\n\n')
669
669
  const resolvedExports = input.exports?.length ? combineExports(input.exports) : []
670
- const resolvedImports = input.imports?.length ? combineImports(input.imports, resolvedExports, source || undefined) : []
670
+ const combinedImports = input.imports?.length ? combineImports(input.imports, resolvedExports, source || undefined) : []
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: 'group'`/`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 `mode: 'group'` 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
+ })
671
688
  const resolvedSources = input.sources?.length ? combineSources(input.sources) : []
672
689
 
673
690
  return {