@@ -1309,14 +1309,15 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
1309
1309
1310
1310
if isNestedInPostfixIfConfig ( node: Syntax ( node) ) {
1311
1311
let breakToken : Token
1312
- let previousToken = node. parent? . parent? . previousToken
1312
+ let currentIfConfigDecl = node. parent? . parent? . as ( IfConfigDeclSyntax . self)
1313
+ let tokenBeforeCurrentIfConfigDecl = currentIfConfigDecl? . previousToken
1313
1314
1314
- if previousToken ? . parent ? . parent ? . parent ? . parent ? . syntaxNodeType == IfConfigClauseSyntax . self ||
1315
- previousToken ? . text == " } " {
1315
+ if isNestedInIfConfig ( Syntax ( tokenBeforeCurrentIfConfigDecl ) ) ||
1316
+ tokenBeforeCurrentIfConfigDecl ? . text == " } " {
1316
1317
breakToken = . break( . reset)
1317
1318
} else {
1318
1319
breakToken = . break
1319
- before ( node . parent ? . parent ? . as ( IfConfigDeclSyntax . self ) ? . poundEndif, tokens: [ . break] )
1320
+ before ( currentIfConfigDecl ? . poundEndif, tokens: [ . break] )
1320
1321
}
1321
1322
1322
1323
before (
@@ -3525,6 +3526,9 @@ private func isNestedInPostfixIfConfig(node: Syntax) -> Bool {
3525
3526
var this : Syntax ? = node
3526
3527
3527
3528
while this? . parent != nil {
3529
+ // This guard handles the situation where a type with its own modifiers
3530
+ // is nested inside of an if config. That type should not count as being
3531
+ // in a postfix if config because its entire body is inside the if config.
3528
3532
if this? . is ( TupleExprElementSyntax . self) == true {
3529
3533
return false
3530
3534
}
@@ -3540,6 +3544,20 @@ private func isNestedInPostfixIfConfig(node: Syntax) -> Bool {
3540
3544
return false
3541
3545
}
3542
3546
3547
+ private func isNestedInIfConfig( node: Syntax ) -> Bool {
3548
+ var this : Syntax ? = node
3549
+
3550
+ while this? . parent != nil {
3551
+ if this? . is ( IfConfigClauseSyntax . self) == true {
3552
+ return true
3553
+ }
3554
+
3555
+ this = this? . parent
3556
+ }
3557
+
3558
+ return false
3559
+ }
3560
+
3543
3561
extension Syntax {
3544
3562
/// Creates a pretty-printable token stream for the provided Syntax node.
3545
3563
func makeTokenStream( configuration: Configuration , operatorContext: OperatorContext ) -> [ Token ] {
0 commit comments