Skip to content

Commit d973d76

Browse files
committed
Update based on recent changes to swift-syntax main branch.
This gets swift-format building/tests passing again after the following changes: swiftlang/swift-syntax#963 (Allow postfix #if to be empty) swiftlang/swift-syntax#969 (Syntactic macro system)
1 parent 5e6c05b commit d973d76

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

Sources/SwiftFormatPrettyPrint/TokenStreamCreator.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,9 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
12291229
}
12301230

12311231
override func visit(_ node: ObjectLiteralExprSyntax) -> SyntaxVisitorContinueKind {
1232+
// TODO: Remove this; it has been subsumed by `MacroExpansionDeclSyntax`. But that feature is
1233+
// still in flux and this node type is still present in the API, even though nothing in the
1234+
// parser currently creates it.
12321235
arrangeFunctionCallArgumentList(
12331236
node.arguments,
12341237
leftDelimiter: node.leftParen,
@@ -1237,6 +1240,15 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
12371240
return .visitChildren
12381241
}
12391242

1243+
override func visit(_ node: MacroExpansionDeclSyntax) -> SyntaxVisitorContinueKind {
1244+
arrangeFunctionCallArgumentList(
1245+
node.argumentList,
1246+
leftDelimiter: node.leftParen,
1247+
rightDelimiter: node.rightParen,
1248+
forcesBreakBeforeRightDelimiter: false)
1249+
return .visitChildren
1250+
}
1251+
12401252
override func visit(_ node: ParameterClauseSyntax) -> SyntaxVisitorContinueKind {
12411253
// Prioritize keeping ") throws -> <return_type>" together. We can only do this if the function
12421254
// has arguments.
@@ -1307,7 +1319,7 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
13071319
// Unlike other code blocks, where we may want a single statement to be laid out on the same
13081320
// line as a parent construct, the content of an `#if` block must always be on its own line;
13091321
// the newline token inserted at the end enforces this.
1310-
if let lastElemTok = node.elements.lastToken {
1322+
if let lastElemTok = node.elements?.lastToken {
13111323
after(lastElemTok, tokens: .break(breakKindClose, newlines: .soft), .close)
13121324
} else {
13131325
before(tokenToOpenWith.nextToken(viewMode: .all), tokens: .break(breakKindClose, newlines: .soft), .close)

Sources/SwiftFormatRules/AlwaysUseLowerCamelCase.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public final class AlwaysUseLowerCamelCase: SyntaxLintRule {
134134
if let ifConfigDecl = member.decl.as(IfConfigDeclSyntax.self) {
135135
// Recurse into any conditional member lists and collect their test methods as well.
136136
for clause in ifConfigDecl.clauses {
137-
if let clauseMembers = clause.elements.as(MemberDeclListSyntax.self) {
137+
if let clauseMembers = clause.elements?.as(MemberDeclListSyntax.self) {
138138
collectTestMethods(from: clauseMembers, into: &set)
139139
}
140140
}

Sources/SwiftFormatRules/FileScopedDeclarationPrivacy.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ public final class FileScopedDeclarationPrivacy: SyntaxFormatRule {
109109
/// - Returns: A new `IfConfigDeclSyntax` that has possibly been rewritten.
110110
private func rewrittenIfConfigDecl(_ ifConfigDecl: IfConfigDeclSyntax) -> IfConfigDeclSyntax {
111111
let newClauses = ifConfigDecl.clauses.map { clause -> IfConfigClauseSyntax in
112-
switch clause.elements.as(SyntaxEnum.self) {
113-
case .codeBlockItemList(let codeBlockItemList):
112+
switch clause.elements?.as(SyntaxEnum.self) {
113+
case .codeBlockItemList(let codeBlockItemList)?:
114114
return clause.withElements(Syntax(rewrittenCodeBlockItems(codeBlockItemList)))
115115
default:
116116
return clause

0 commit comments

Comments
 (0)