@@ -718,13 +718,23 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
718718 after ( node. unknownAttr? . lastToken, tokens: . space)
719719 after ( node. label. lastToken, tokens: . break( . reset, size: 0 ) , . break( . open) , . open)
720720
721- // If switch/case labels were configured to be indented, insert an extra `close` break after the
722- // case body to match the `open` break above
721+ // If switch/case labels were configured to be indented, insert an extra `close` break after
722+ // the case body to match the `open` break above
723723 var afterLastTokenTokens : [ Token ] = [ . break( . close, size: 0 ) , . close]
724724 if config. indentSwitchCaseLabels {
725725 afterLastTokenTokens. append ( . break( . close, size: 0 ) )
726726 }
727- after ( node. lastToken, tokens: afterLastTokenTokens)
727+
728+ // If the case contains statements, add the closing tokens after the last token of the case.
729+ // Otherwise, add the closing tokens before the next case (or the end of the switch) to have the
730+ // same effect. If instead the opening and closing tokens were omitted completely in the absence
731+ // of statements, comments within the empty case would be incorrectly indented to the same level
732+ // as the case label.
733+ if node. label. lastToken != node. lastToken {
734+ after ( node. lastToken, tokens: afterLastTokenTokens)
735+ } else {
736+ before ( node. nextToken, tokens: afterLastTokenTokens)
737+ }
728738
729739 return . visitChildren
730740 }
0 commit comments