File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
Sources/SwiftSyntaxMacroExpansion
Tests/SwiftSyntaxMacroExpansionTest Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -462,7 +462,8 @@ private func expandBodyMacro(
462462 conformanceList: nil ,
463463 in: context,
464464 indentationWidth: indentationWidth
465- )
465+ ) ,
466+ !expanded. isEmpty
466467 else {
467468 return nil
468469 }
Original file line number Diff line number Diff line change @@ -125,4 +125,34 @@ final class BodyMacroTests: XCTestCase {
125125 indentationWidth: indentationWidth
126126 )
127127 }
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+ }
128158}
You can’t perform that action at this time.
0 commit comments