Skip to content

Commit 95f5aa6

Browse files
Replace joined(separator:) in collapse with custom logic to avoid adding unnecessary separators
1 parent bd5dc8d commit 95f5aa6

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Sources/SwiftSyntaxMacroExpansion/MacroExpansion.swift

+11-1
Original file line numberDiff line numberDiff line change
@@ -528,5 +528,15 @@ public func collapse<Node: SyntaxProtocol>(
528528
break
529529
}
530530

531-
return expansions.joined(separator: separator)
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)