Skip to content

Commit 493a8c3

Browse files
committed
Add whitespace before else
1 parent eff37e3 commit 493a8c3

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public let KEYWORDS: [KeywordSpec] = [
122122
KeywordSpec("do", isLexerClassified: true),
123123
KeywordSpec("dynamic"),
124124
KeywordSpec("each"),
125-
KeywordSpec("else", isLexerClassified: true, requiresTrailingSpace: true),
125+
KeywordSpec("else", isLexerClassified: true, requiresLeadingSpace: true, requiresTrailingSpace: true),
126126
KeywordSpec("enum", isLexerClassified: true, requiresTrailingSpace: true),
127127
KeywordSpec("escaping"),
128128
KeywordSpec("exclusivity"),

Sources/SwiftBasicFormat/generated/BasicFormat.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ open class BasicFormat: SyntaxRewriter {
198198
return true
199199
case .keyword(.`catch`):
200200
return true
201+
case .keyword(.`else`):
202+
return true
201203
case .keyword(.`in`):
202204
return true
203205
case .keyword(.`where`):

Sources/SwiftSyntax/generated/SyntaxCollections.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,8 +2387,7 @@ public struct ClosureParameterListSyntax: SyntaxCollection, SyntaxHashable {
23872387

23882388
public let _syntaxNode: Syntax
23892389

2390-
@_spi(RawSyntax)
2391-
public var layoutView: RawSyntaxLayoutView {
2390+
private var layoutView: RawSyntaxLayoutView {
23922391
data.raw.layoutView!
23932392
}
23942393

@@ -2420,7 +2419,7 @@ public struct ClosureParameterListSyntax: SyntaxCollection, SyntaxHashable {
24202419

24212420
/// The number of elements, `present` or `missing`, in this collection.
24222421
public var count: Int {
2423-
return raw.layoutView!.children.count
2422+
return layoutView.children.count
24242423
}
24252424

24262425
/// Creates a new `ClosureParameterListSyntax` by replacing the underlying layout with
@@ -4689,8 +4688,7 @@ public struct EnumCaseParameterListSyntax: SyntaxCollection, SyntaxHashable {
46894688

46904689
public let _syntaxNode: Syntax
46914690

4692-
@_spi(RawSyntax)
4693-
public var layoutView: RawSyntaxLayoutView {
4691+
private var layoutView: RawSyntaxLayoutView {
46944692
data.raw.layoutView!
46954693
}
46964694

@@ -4722,7 +4720,7 @@ public struct EnumCaseParameterListSyntax: SyntaxCollection, SyntaxHashable {
47224720

47234721
/// The number of elements, `present` or `missing`, in this collection.
47244722
public var count: Int {
4725-
return raw.layoutView!.children.count
4723+
return layoutView.children.count
47264724
}
47274725

47284726
/// Creates a new `EnumCaseParameterListSyntax` by replacing the underlying layout with

Tests/SwiftSyntaxBuilderTest/IfStmtTests.swift

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,26 @@ final class IfStmtTests: XCTestCase {
4545
}
4646
"""
4747
),
48+
#line: (
49+
ExprSyntax(
50+
"""
51+
if foo == x {
52+
return foo
53+
}
54+
else {
55+
return bar
56+
}
57+
"""
58+
).cast(IfExprSyntax.self),
59+
"""
60+
if foo == x {
61+
return foo
62+
}
63+
else {
64+
return bar
65+
}
66+
"""
67+
),
4868
#line: (
4969
try IfExprSyntax("if foo == x") { StmtSyntax("return foo") },
5070
"""
@@ -62,7 +82,7 @@ final class IfStmtTests: XCTestCase {
6282
"""
6383
if foo == x {
6484
return foo
65-
}else {
85+
} else {
6686
return bar
6787
}
6888
"""
@@ -72,7 +92,7 @@ final class IfStmtTests: XCTestCase {
7292
"""
7393
if foo == x {
7494
return foo
75-
}else if foo == z {
95+
} else if foo == z {
7696
return baz
7797
}
7898
"""

0 commit comments

Comments
 (0)