Skip to content

Commit 1280cae

Browse files
authored
Merge branch 'swiftlang:main' into upgrade-dont-repeat-type-in-static-properties
2 parents 7496b30 + b268009 commit 1280cae

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift

+8
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,12 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
13271327
}
13281328

13291329
override func visit(_ node: MacroExpansionDeclSyntax) -> SyntaxVisitorContinueKind {
1330+
arrangeAttributeList(node.attributes)
1331+
1332+
before(
1333+
node.trailingClosure?.leftBrace,
1334+
tokens: .break(.same, newlines: .elective(ignoresDiscretionary: true)))
1335+
13301336
arrangeFunctionCallArgumentList(
13311337
node.arguments,
13321338
leftDelimiter: node.leftParen,
@@ -1453,6 +1459,8 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
14531459
}
14541460

14551461
override func visit(_ node: IfConfigDeclSyntax) -> SyntaxVisitorContinueKind {
1462+
// there has to be a break after an #endif
1463+
after(node.poundEndif, tokens: .break(.same, size: 0))
14561464
return .visitChildren
14571465
}
14581466

Tests/SwiftFormatTests/PrettyPrint/IfConfigTests.swift

+26
Original file line numberDiff line numberDiff line change
@@ -531,4 +531,30 @@ final class IfConfigTests: PrettyPrintTestCase {
531531
"""
532532
assertPrettyPrintEqual(input: input, expected: input, linelength: 45)
533533
}
534+
535+
func testNestedPoundIfInSwitchStatement() {
536+
let input =
537+
"""
538+
switch self {
539+
#if os(iOS) || os(tvOS) || os(watchOS)
540+
case .a:
541+
return 40
542+
#if os(iOS) || os(tvOS)
543+
case .e:
544+
return 30
545+
#endif
546+
#if os(iOS)
547+
case .g:
548+
return 2
549+
#endif
550+
#endif
551+
default:
552+
return nil
553+
}
554+
555+
"""
556+
var configuration = Configuration.forTesting
557+
configuration.indentConditionalCompilationBlocks = false
558+
assertPrettyPrintEqual(input: input, expected: input, linelength: 45, configuration: configuration)
559+
}
534560
}

Tests/SwiftFormatTests/PrettyPrint/MacroCallTests.swift

+12
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,16 @@ final class MacroCallTests: PrettyPrintTestCase {
114114

115115
assertPrettyPrintEqual(input: input, expected: expected, linelength: 45)
116116
}
117+
118+
func testMacroDeclWithAttributesAndArguments() {
119+
let input = """
120+
@nonsenseAttribute
121+
@available(iOS 17.0, *)
122+
#Preview("Name") {
123+
EmptyView()
124+
}
125+
126+
"""
127+
assertPrettyPrintEqual(input: input, expected: input, linelength: 45)
128+
}
117129
}

0 commit comments

Comments
 (0)