File tree Expand file tree Collapse file tree 2 files changed +31
-4
lines changed
Sources/SwiftSyntaxMacroExpansion
Tests/SwiftSyntaxMacroExpansionTest Expand file tree Collapse file tree 2 files changed +31
-4
lines changed Original file line number Diff line number Diff line change @@ -463,15 +463,14 @@ public func collapse<Node: SyntaxProtocol>(
463
463
attachedTo declarationNode: Node ,
464
464
indentationWidth: Trivia ? = nil
465
465
) -> String {
466
- if expansions. isEmpty {
467
- return " "
468
- }
469
-
470
466
var expansions = expansions
471
467
var separator = " \n \n "
472
468
473
469
// Wrap the expansions in a set of braces.
474
470
func wrapInBraces( ) {
471
+ if expansions. isEmpty {
472
+ expansions = [ " " ]
473
+ }
475
474
// Default to 4 spaces if no indentation was passed.
476
475
// In the future, we could consider inferring the indentation width from
477
476
// the expansions to collapse.
Original file line number Diff line number Diff line change @@ -125,4 +125,32 @@ final class BodyMacroTests: XCTestCase {
125
125
indentationWidth: indentationWidth
126
126
)
127
127
}
128
+
129
+ func testEmptyBodyMacro( ) {
130
+ struct EmptyBodyMacro : BodyMacro {
131
+ public static var formatMode : FormatMode { . disabled }
132
+
133
+ public static func expansion(
134
+ of node: AttributeSyntax ,
135
+ providingBodyFor declaration: some DeclSyntaxProtocol & WithOptionalCodeBlockSyntax ,
136
+ in context: some MacroExpansionContext
137
+ ) throws -> [ CodeBlockItemSyntax ] {
138
+ return [ ]
139
+ }
140
+ }
141
+
142
+ assertMacroExpansion (
143
+ """
144
+ @EmptyBody
145
+ func f() {}
146
+ """ ,
147
+ expandedSource: """
148
+ func f() {
149
+
150
+ }
151
+ """ ,
152
+ diagnostics: [ ] ,
153
+ macros: [ " EmptyBody " : EmptyBodyMacro . self]
154
+ )
155
+ }
128
156
}
You can’t perform that action at this time.
0 commit comments