Skip to content

Commit 8f477f3

Browse files
Replace joined(separator:) with custom logic in collapse to avoid adding unnecessary separators
1 parent e89d138 commit 8f477f3

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Sources/SwiftSyntaxMacroExpansion/MacroExpansion.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,16 @@ public func collapse<Node: SyntaxProtocol>(
527527
default:
528528
break
529529
}
530-
531-
return expansions.joined(separator: separator)
530+
531+
// Join the expansions ensuring `separator` between them.
532+
var collapsed = ""
533+
for expansion in expansions {
534+
if (collapsed.isEmpty || expansion.hasPrefix(separator)) {
535+
collapsed.append(expansion)
536+
} else {
537+
collapsed.append(separator + expansion)
538+
}
539+
}
540+
541+
return collapsed
532542
}

0 commit comments

Comments
 (0)