@@ -386,23 +386,18 @@ struct MacroSystem {
386
386
/// Removes attributes from a syntax tree while maintaining their surrounding trivia.
387
387
@_spi ( Testing)
388
388
public class AttributeRemover : SyntaxRewriter {
389
- var attributesToRemove : [ AttributeSyntax ]
390
- let attributeEquals : ( AttributeSyntax , AttributeSyntax ) -> Bool
389
+ let predicate : ( AttributeSyntax ) -> Bool
391
390
392
391
var triviaToAttachToNextToken : Trivia = Trivia ( )
393
392
394
- public init (
395
- attributesToRemove: [ AttributeSyntax ] ,
396
- attributeEquals: @escaping ( AttributeSyntax , AttributeSyntax ) -> Bool = { $0 == $1 }
397
- ) {
398
- self . attributesToRemove = attributesToRemove
399
- self . attributeEquals = attributeEquals
393
+ public init ( where predicate: @escaping ( AttributeSyntax ) -> Bool ) {
394
+ self . predicate = predicate
400
395
}
401
396
402
397
public override func visit( _ node: AttributeListSyntax ) -> AttributeListSyntax {
403
398
var filteredAttributes : [ AttributeListSyntax . Element ] = [ ]
404
399
for case . attribute( let attribute) in node {
405
- if attributesToRemove . contains ( where : { self . attributeEquals ( $0 , attribute) } ) {
400
+ if self . predicate ( attribute) {
406
401
var leadingTrivia = attribute. leadingTrivia
407
402
408
403
// Don't leave behind an empty line when the attribute being removed is on its own line,
@@ -579,7 +574,7 @@ private class MacroApplication<Context: MacroExpansionContext>: SyntaxRewriter {
579
574
580
575
let attributesToRemove = self . macroAttributes ( attachedTo: visitedNode) . map ( \. attributeNode)
581
576
582
- return AttributeRemover ( attributesToRemove : attributesToRemove) . rewrite ( visitedNode)
577
+ return AttributeRemover ( where : { attributesToRemove. contains ( $0 ) } ) . rewrite ( visitedNode)
583
578
}
584
579
585
580
return nil
0 commit comments