Skip to content

Commit 7d04ed8

Browse files
committed
Merge pull request swiftlang#1518 from stevapple/else-spacing
Add whitespace before `else`
1 parent 31b7753 commit 7d04ed8

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
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`):

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)