Add support for Swift 5.1’s opaque return types (#71)
This change adds support for the Swift 5.1 `some` keyword, which is used to declare opaque return types.
This commit is contained in:
parent
6fcb458c63
commit
d978081933
@ -52,7 +52,7 @@ private extension SwiftGrammar {
|
|||||||
"lazy", "subscript", "defer", "inout", "while",
|
"lazy", "subscript", "defer", "inout", "while",
|
||||||
"continue", "fallthrough", "repeat", "indirect",
|
"continue", "fallthrough", "repeat", "indirect",
|
||||||
"deinit", "is", "#file", "#line", "#function",
|
"deinit", "is", "#file", "#line", "#function",
|
||||||
"dynamic"
|
"dynamic", "some"
|
||||||
] as Set<String>).union(accessControlKeywords)
|
] as Set<String>).union(accessControlKeywords)
|
||||||
|
|
||||||
static let accessControlKeywords: Set<String> = [
|
static let accessControlKeywords: Set<String> = [
|
||||||
|
@ -858,6 +858,31 @@ final class DeclarationTests: SyntaxHighlighterTestCase {
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testFunctionDeclarationWithOpaqueReturnType() {
|
||||||
|
let components = highlighter.highlight(#"func make() -> some View { Text("!") }"#)
|
||||||
|
|
||||||
|
XCTAssertEqual(components, [
|
||||||
|
.token("func", .keyword),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("make()"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("->"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.token("some", .keyword),
|
||||||
|
.whitespace(" "),
|
||||||
|
.token("View", .type),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("{"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.token("Text", .type),
|
||||||
|
.plainText("("),
|
||||||
|
.token(#""!""#, .string),
|
||||||
|
.plainText(")"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("}")
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
func testIndirectEnumDeclaration() {
|
func testIndirectEnumDeclaration() {
|
||||||
let components = highlighter.highlight("""
|
let components = highlighter.highlight("""
|
||||||
indirect enum Content {
|
indirect enum Content {
|
||||||
@ -934,6 +959,7 @@ extension DeclarationTests {
|
|||||||
("testFunctionDeclarationWithPreProcessors", testFunctionDeclarationWithPreProcessors),
|
("testFunctionDeclarationWithPreProcessors", testFunctionDeclarationWithPreProcessors),
|
||||||
("testNonMutatingFunction", testNonMutatingFunction),
|
("testNonMutatingFunction", testNonMutatingFunction),
|
||||||
("testRethrowingFunctionDeclaration", testRethrowingFunctionDeclaration),
|
("testRethrowingFunctionDeclaration", testRethrowingFunctionDeclaration),
|
||||||
|
("testFunctionDeclarationWithOpaqueReturnType", testFunctionDeclarationWithOpaqueReturnType),
|
||||||
("testIndirectEnumDeclaration", testIndirectEnumDeclaration)
|
("testIndirectEnumDeclaration", testIndirectEnumDeclaration)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user