Don’t treat accessing properties within switch statements as calls (#103)

This patch fixes syntax highlighting for when a property is being switched
on, which previously would be treated as a function call with trailing
closure syntax.
This commit is contained in:
John Sundell 2020-04-16 19:52:26 +02:00 committed by GitHub
parent 8e96992997
commit 03ea9bdcbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -223,7 +223,7 @@ private extension SwiftGrammar {
var tokenType: TokenType { return .call }
private let keywordsToAvoid: Set<String>
private let callLikeKeywords: Set<String>
private let controlFlowTokens = ["if", "&&", "||", "for"]
private let controlFlowTokens = ["if", "&&", "||", "for", "switch"]
init() {
var keywordsToAvoid = keywords

View File

@ -315,6 +315,28 @@ final class StatementTests: SyntaxHighlighterTestCase {
])
}
func testSwitchStatementWithProperty() {
let components = highlighter.highlight("""
switch object.value { default: break }
""")
XCTAssertEqual(components, [
.token("switch", .keyword),
.whitespace(" "),
.plainText("object."),
.token("value", .property),
.whitespace(" "),
.plainText("{"),
.whitespace(" "),
.token("default", .keyword),
.plainText(":"),
.whitespace(" "),
.token("break", .keyword),
.whitespace(" "),
.plainText("}")
])
}
func testForStatementWithStaticProperty() {
let components = highlighter.highlight("for value in Enum.allCases { }")
@ -441,6 +463,7 @@ extension StatementTests {
("testSwitchStatementWithFallthrough", testSwitchStatementWithFallthrough),
("testSwitchStatementWithTypePatternMatching", testSwitchStatementWithTypePatternMatching),
("testSwitchStatementWithOptional", testSwitchStatementWithOptional),
("testSwitchStatementWithProperty", testSwitchStatementWithProperty),
("testForStatementWithStaticProperty", testForStatementWithStaticProperty),
("testForStatementWithContinue", testForStatementWithContinue),
("testRepeatWhileStatement", testRepeatWhileStatement),