Skip to content

Commit

Permalink
fix on redeclared import path issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sleygin committed Aug 25, 2024
1 parent 3dec19e commit ddaedad
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,20 +264,22 @@ func getLastImportPart(srcPackageImport string) string {
}

func getSrcPackageAlias(imports []*ast.ImportSpec, srcPackageImport string) string {
var srcPackageImportAlias string
lastSrcPackagePart := getLastImportPart(srcPackageImport)

for _, imp := range imports {
var partToCompare string
if imp.Name != nil {
continue
partToCompare = imp.Name.Name
} else {
partToCompare = getLastImportPart(imp.Path.Value)
}

lastSrcPackagePart := getLastImportPart(srcPackageImport)
lastImpPart := getLastImportPart(imp.Path.Value)
if lastImpPart == lastSrcPackagePart {
srcPackageImportAlias = "__" + lastSrcPackagePart
if partToCompare == lastSrcPackagePart {
return "__" + lastSrcPackagePart
}
}

return srcPackageImportAlias
return ""
}

func makeImports(imports []*ast.ImportSpec) []string {
Expand Down

0 comments on commit ddaedad

Please sign in to comment.