File tree Expand file tree Collapse file tree 2 files changed +48
-37
lines changed
Sources/SwiftFormatPrettyPrint
Tests/SwiftFormatPrettyPrintTests Expand file tree Collapse file tree 2 files changed +48
-37
lines changed Original file line number Diff line number Diff line change @@ -1308,11 +1308,22 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
1308
1308
}
1309
1309
1310
1310
if isNestedInPostfixIfConfig ( node: Syntax ( node) ) {
1311
+ let breakToken : Token
1312
+ let previousToken = node. parent? . parent? . previousToken
1313
+
1314
+ if previousToken? . parent? . parent? . parent? . parent? . syntaxNodeType == IfConfigClauseSyntax . self ||
1315
+ previousToken? . text == " } " {
1316
+ breakToken = . break( . reset)
1317
+ } else {
1318
+ breakToken = . break
1319
+ before ( node. parent? . parent? . as ( IfConfigDeclSyntax . self) ? . poundEndif, tokens: [ . break] )
1320
+ }
1321
+
1311
1322
before (
1312
1323
node. firstToken,
1313
1324
tokens: [
1314
1325
. printerControl( kind: . enableBreaking) ,
1315
- . break ( . reset ) ,
1326
+ breakToken ,
1316
1327
]
1317
1328
)
1318
1329
} else if let condition = node. condition {
Original file line number Diff line number Diff line change @@ -247,10 +247,10 @@ final class IfConfigTests: PrettyPrintTestCase {
247
247
"""
248
248
VStack {
249
249
Text( " something " )
250
- #if os(iOS)
251
- .iOSSpecificModifier()
252
- #endif
253
- .commonModifier()
250
+ #if os(iOS)
251
+ .iOSSpecificModifier()
252
+ #endif
253
+ .commonModifier()
254
254
}
255
255
256
256
"""
@@ -277,13 +277,13 @@ final class IfConfigTests: PrettyPrintTestCase {
277
277
"""
278
278
VStack {
279
279
Text( " something " )
280
- #if os(iOS)
281
- .iOSSpecificModifier()
282
- .anotherModifier()
283
- .anotherAnotherModifier()
284
- #endif
285
- .commonModifier()
286
- .anotherCommonModifier()
280
+ #if os(iOS)
281
+ .iOSSpecificModifier()
282
+ .anotherModifier()
283
+ .anotherAnotherModifier()
284
+ #endif
285
+ .commonModifier()
286
+ .anotherCommonModifier()
287
287
}
288
288
289
289
"""
@@ -311,14 +311,14 @@ final class IfConfigTests: PrettyPrintTestCase {
311
311
"""
312
312
VStack {
313
313
Text( " something " )
314
- #if os(iOS) || os(watchOS)
315
- #if os(iOS)
316
- .iOSModifier()
317
- #else
318
- .watchOSModifier()
314
+ #if os(iOS) || os(watchOS)
315
+ #if os(iOS)
316
+ .iOSModifier()
317
+ #else
318
+ .watchOSModifier()
319
+ #endif
320
+ .iOSAndWatchOSModifier()
319
321
#endif
320
- .iOSAndWatchOSModifier()
321
- #endif
322
322
}
323
323
324
324
"""
@@ -343,10 +343,10 @@ final class IfConfigTests: PrettyPrintTestCase {
343
343
"""
344
344
VStack {
345
345
textView
346
- #if os(iOS)
347
- .iOSSpecificModifier()
348
- #endif
349
- .commonModifier()
346
+ #if os(iOS)
347
+ .iOSSpecificModifier()
348
+ #endif
349
+ .commonModifier()
350
350
}
351
351
352
352
"""
@@ -406,9 +406,9 @@ final class IfConfigTests: PrettyPrintTestCase {
406
406
"""
407
407
EmptyView()
408
408
.padding([.vertical])
409
- #if os(iOS)
410
- .iOSSpecificModifier()
411
- #endif
409
+ #if os(iOS)
410
+ .iOSSpecificModifier()
411
+ #endif
412
412
.commonModifier()
413
413
414
414
"""
@@ -438,17 +438,17 @@ final class IfConfigTests: PrettyPrintTestCase {
438
438
"""
439
439
EmptyView()
440
440
.padding([.vertical])
441
- #if os(iOS)
442
- .iOSSpecificModifier(
443
- SpecificType()
444
- .onChanged { _ in
445
- // do things
446
- }
447
- .onEnded { _ in
448
- // do things
449
- }
450
- )
451
- #endif
441
+ #if os(iOS)
442
+ .iOSSpecificModifier(
443
+ SpecificType()
444
+ .onChanged { _ in
445
+ // do things
446
+ }
447
+ .onEnded { _ in
448
+ // do things
449
+ }
450
+ )
451
+ #endif
452
452
453
453
"""
454
454
You can’t perform that action at this time.
0 commit comments