Skip to content

Commit 3d3f31f

Browse files
committed
Re-add check for whitespace after newlines to preserve block comments in AttributeRemover
Also, added a test case that failed before this fix.
1 parent 1815d16 commit 3d3f31f

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Sources/SwiftSyntaxMacroExpansion/MacroSystem.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ private class AttributeRemover: SyntaxRewriter {
399399
if attributesToRemove.contains(attribute) {
400400
var leadingTrivia = attribute.leadingTrivia
401401
if let lastNewline = leadingTrivia.pieces.lastIndex(where: \.isNewline),
402+
leadingTrivia.pieces[lastNewline...].allSatisfy(\.isWhitespace),
402403
attribute.trailingTrivia.isEmpty,
403404
let nextToken = attribute.nextToken(viewMode: .sourceAccurate),
404405
!nextToken.leadingTrivia.isEmpty

Tests/SwiftSyntaxMacroExpansionTest/AttributeRemoverTests.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,22 @@ final class AttributeRemoverTests: XCTestCase {
196196
)
197197
}
198198

199+
func testAttributeNewlineBlockCommentEmpty() {
200+
assertMacroExpansion(
201+
"""
202+
@State
203+
/*doc comment*/@Test
204+
var x: Int
205+
""",
206+
expandedSource: """
207+
@State
208+
/*doc comment*/
209+
var x: Int
210+
""",
211+
macros: ["Test": NoOpPeerMacro.self]
212+
)
213+
}
214+
199215
func testEmptyBlockCommentEmpty() {
200216
assertMacroExpansion(
201217
"""

0 commit comments

Comments
 (0)