@@ -450,17 +450,17 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
450450 override func visit( _ node: AccessorDeclSyntax ) -> SyntaxVisitorContinueKind {
451451 arrangeAttributeList ( node. attributes)
452452
453- if let asyncKeyword = node. asyncKeyword {
454- if node. throwsKeyword != nil {
453+ if let asyncKeyword = node. effectSpecifiers ? . asyncSpecifier {
454+ if node. effectSpecifiers ? . throwsSpecifier != nil {
455455 before ( asyncKeyword, tokens: . break, . open)
456456 } else {
457457 before ( asyncKeyword, tokens: . break)
458458 }
459459 }
460460
461- if let throwsKeyword = node. throwsKeyword {
462- before ( node. throwsKeyword , tokens: . break)
463- if node. asyncKeyword != nil {
461+ if let throwsKeyword = node. effectSpecifiers ? . throwsSpecifier {
462+ before ( node. effectSpecifiers ? . throwsSpecifier , tokens: . break)
463+ if node. effectSpecifiers ? . asyncSpecifier != nil {
464464 after ( throwsKeyword, tokens: . close)
465465 }
466466 }
@@ -1132,9 +1132,9 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
11321132 }
11331133 }
11341134
1135- before ( node. asyncKeyword , tokens: . break)
1136- before ( node. throwsTok , tokens: . break)
1137- if let asyncKeyword = node. asyncKeyword , let throwsTok = node. throwsTok {
1135+ before ( node. effectSpecifiers ? . asyncSpecifier , tokens: . break)
1136+ before ( node. effectSpecifiers ? . throwsSpecifier , tokens: . break)
1137+ if let asyncKeyword = node. effectSpecifiers ? . asyncSpecifier , let throwsTok = node. effectSpecifiers ? . throwsSpecifier {
11381138 before ( asyncKeyword, tokens: . open)
11391139 after ( throwsTok, tokens: . close)
11401140 }
@@ -1256,7 +1256,16 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
12561256 }
12571257
12581258 override func visit( _ node: ReturnClauseSyntax ) -> SyntaxVisitorContinueKind {
1259- after ( node. arrow, tokens: . space)
1259+ if node. parent? . is ( FunctionTypeSyntax . self) ?? false {
1260+ // `FunctionTypeSyntax` used to not use `ReturnClauseSyntax` and had
1261+ // slightly different formatting behavior than the normal
1262+ // `ReturnClauseSyntax`. To maintain the previous formatting behavior,
1263+ // add a special case.
1264+ before ( node. arrow, tokens: . break)
1265+ before ( node. returnType. firstToken, tokens: . break)
1266+ } else {
1267+ after ( node. arrow, tokens: . space)
1268+ }
12601269
12611270 // Member type identifier is used when the return type is a member of another type. Add a group
12621271 // here so that the base, dot, and member type are kept together when they fit.
@@ -1500,10 +1509,8 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
15001509 override func visit( _ node: FunctionTypeSyntax ) -> SyntaxVisitorContinueKind {
15011510 after ( node. leftParen, tokens: . break( . open, size: 0 ) , . open)
15021511 before ( node. rightParen, tokens: . break( . close, size: 0 ) , . close)
1503- before ( node. asyncKeyword, tokens: . break)
1504- before ( node. throwsOrRethrowsKeyword, tokens: . break)
1505- before ( node. arrow, tokens: . break)
1506- before ( node. returnType. firstToken, tokens: . break)
1512+ before ( node. effectSpecifiers? . asyncSpecifier, tokens: . break)
1513+ before ( node. effectSpecifiers? . throwsSpecifier, tokens: . break)
15071514 return . visitChildren
15081515 }
15091516
@@ -1723,10 +1730,10 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
17231730 }
17241731
17251732 override func visit( _ node: FunctionSignatureSyntax ) -> SyntaxVisitorContinueKind {
1726- before ( node. asyncOrReasyncKeyword , tokens: . break)
1727- before ( node. throwsOrRethrowsKeyword , tokens: . break)
1728- if let asyncOrReasyncKeyword = node. asyncOrReasyncKeyword ,
1729- let throwsOrRethrowsKeyword = node. throwsOrRethrowsKeyword
1733+ before ( node. effectSpecifiers ? . asyncSpecifier , tokens: . break)
1734+ before ( node. effectSpecifiers ? . throwsSpecifier , tokens: . break)
1735+ if let asyncOrReasyncKeyword = node. effectSpecifiers ? . asyncSpecifier ,
1736+ let throwsOrRethrowsKeyword = node. effectSpecifiers ? . throwsSpecifier
17301737 {
17311738 before ( asyncOrReasyncKeyword, tokens: . open)
17321739 after ( throwsOrRethrowsKeyword, tokens: . close)
@@ -1868,7 +1875,7 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
18681875 override func visit( _ node: ArrowExprSyntax ) -> SyntaxVisitorContinueKind {
18691876 // The break before the `throws` keyword is inserted at the `InfixOperatorExpr` level so that it
18701877 // is placed in the correct relative position to the group surrounding the "operator".
1871- after ( node. throwsToken , tokens: . break)
1878+ after ( node. effectSpecifiers ? . throwsSpecifier , tokens: . break)
18721879 return . visitChildren
18731880 }
18741881
0 commit comments