File tree 2 files changed +32
-1
lines changed
Sources/SwiftSyntaxMacroExpansion
Tests/SwiftSyntaxMacroExpansionTest
2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -462,7 +462,8 @@ private func expandBodyMacro(
462
462
conformanceList: nil ,
463
463
in: context,
464
464
indentationWidth: indentationWidth
465
- )
465
+ ) ,
466
+ !expanded. isEmpty
466
467
else {
467
468
return nil
468
469
}
Original file line number Diff line number Diff line change @@ -125,4 +125,34 @@ 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
+ print(42)
147
+ }
148
+ """ ,
149
+ expandedSource: """
150
+ func f() {
151
+ print(42)
152
+ }
153
+ """ ,
154
+ diagnostics: [ ] ,
155
+ macros: [ " EmptyBody " : EmptyBodyMacro . self]
156
+ )
157
+ }
128
158
}
You can’t perform that action at this time.
0 commit comments