Skip to content

Commit 242817b

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

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Sources/SwiftSyntaxMacroExpansion/MacroExpansion.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,14 @@ public func collapse<Node: SyntaxProtocol>(
527527
default:
528528
break
529529
}
530-
531-
return expansions.joined(separator: separator)
530+
// Join the expansions with the given separator between them.
531+
return expansions.reduce("") { (partialResult, expansion) in
532+
// We don't add the separator before the first expansion or
533+
// if the expansion already starts with the separator.
534+
if (partialResult.isEmpty || expansion.hasPrefix(separator)) {
535+
partialResult + expansion
536+
} else {
537+
partialResult + separator + expansion
538+
}
539+
}
532540
}

0 commit comments

Comments
 (0)