Skip to content

Commit 97a05cc

Browse files
authored
Merge pull request #1294 from kimdv/kimdv/add-missing-unexpected-after
Add missing parameter
2 parents f7667e1 + 5a6b41a commit 97a05cc

File tree

8 files changed

+145
-189
lines changed

8 files changed

+145
-189
lines changed

CodeGeneration/Sources/SyntaxSupport/Node.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,14 @@ public class Node {
117117
isOptional: true,
118118
collectionElementName: unexpectedName
119119
),
120-
child,
120+
child
121121
]
122-
}
122+
} + (children.last != nil ? [Child(
123+
name: "UnexpectedAfter\(children.last!.name)",
124+
kind: "UnexpectedNodes",
125+
isOptional: true,
126+
collectionElementName: "UnexpectedAfter\(children.last!.name)"
127+
)] : [])
123128
}
124129

125130
self.nonUnexpectedChildren = children.filter { !$0.isUnexpectedNodes }

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxTraitsFile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ let syntaxTraitsFile = SourceFileSyntax {
2828
}
2929
}
3030

31-
ExtensionDeclSyntax("public extension \(trait.traitName)Syntax") {
31+
ExtensionDeclSyntax("public extension \(raw: trait.traitName)Syntax") {
3232
FunctionDeclSyntax("""
3333
/// Without this function, the `with` function defined on `SyntaxProtocol`
3434
/// does not work on existentials of this protocol type.

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntaxbuilder/BuildableNodesFile.swift

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,8 @@ private func createConvenienceInitializer(node: Node) -> InitializerDeclSyntax?
7474
} else {
7575
produceExpr = ExprSyntax(FunctionCallExprSyntax("\(raw: child.swiftName)Builder()"))
7676
}
77-
let defaultArgument = ClosureExprSyntax {
78-
if child.type.isOptional {
79-
NilLiteralExprSyntax()
80-
} else {
81-
FunctionCallExprSyntax("\(builderInitializableType.syntax)([])")
82-
}
83-
}
8477
builderParameters.append(FunctionParameterSyntax(
85-
"@\(builderInitializableType.resultBuilderBaseName) \(child.swiftName)Builder: () -> \(builderInitializableType.syntax) = \(defaultArgument)",
78+
"@\(builderInitializableType.resultBuilderBaseName) \(child.swiftName)Builder: () -> \(builderInitializableType.syntax)",
8679
for: .functionParameters
8780
))
8881
} else {
@@ -103,7 +96,7 @@ private func createConvenienceInitializer(node: Node) -> InitializerDeclSyntax?
10396

10497
return InitializerDeclSyntax(
10598
leadingTrivia: .docLineComment("/// A convenience initializer that allows initializing syntax collections using result builders") + .newline,
106-
modifiers: [DeclModifierSyntax(name: .keyword(.public))],
99+
modifiers: [DeclModifierSyntax(leadingTrivia: .newline, name: .keyword(.public))],
107100
signature: FunctionSignatureSyntax(
108101
input: ParameterClauseSyntax {
109102
FunctionParameterSyntax("leadingTrivia: Trivia? = nil", for: .functionParameters)

Sources/SwiftParser/Lexer/Cursor.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,6 @@ extension Lexer.Cursor {
12981298
}
12991299

13001300
mutating func lexHexNumber() -> Lexer.Result {
1301-
let tokStart = self
13021301
// We assume we're starting from the 'x' in a '0x...' floating-point literal.
13031302
let zeroConsumed = self.advance(matching: "0")
13041303
let xConsumed = self.advance(matching: "x")

Sources/SwiftSyntaxBuilder/generated/BuildableNodes.swift

Lines changed: 129 additions & 172 deletions
Large diffs are not rendered by default.

Tests/SwiftParserTest/DeclarationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ final class DeclarationTests: XCTestCase {
11831183
substructure: Syntax(
11841184
SourceFileSyntax(
11851185
CodeBlockItemListSyntax {
1186-
MacroExpansionDeclSyntax(macro: "expand")
1186+
MacroExpansionDeclSyntax(macro: "expand") {}
11871187
}
11881188
)
11891189
)

Tests/SwiftSyntaxBuilderTest/FunctionTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ final class FunctionTests: XCTestCase {
335335
}
336336

337337
func testParensEmittedForArgumentAndTrailingClosure() {
338-
let buildable = FunctionCallExprSyntax(callee: ExprSyntax("test"), trailingClosure: ClosureExprSyntax()) {
338+
let buildable = FunctionCallExprSyntax(callee: ExprSyntax("test"), trailingClosure: ClosureExprSyntax {}) {
339339
TupleExprElementSyntax(expression: ExprSyntax("42"))
340340
}
341341
AssertBuildResult(buildable, "test(42) {\n}")

Tests/SwiftSyntaxBuilderTest/StructTests.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ final class StructTests: XCTestCase {
4545
.carriageReturns(1),
4646
],
4747
structKeyword: .keyword(.struct),
48-
identifier: "CarriateReturnsStruct"
48+
identifier: "CarriateReturnsStruct",
49+
members: MemberDeclBlockSyntax(members: [])
4950
)
5051
let carriageReturnFormFeedsStruct = StructDeclSyntax(
5152
leadingTrivia: [
@@ -55,7 +56,8 @@ final class StructTests: XCTestCase {
5556
.carriageReturnLineFeeds(1),
5657
],
5758
structKeyword: .keyword(.struct),
58-
identifier: "CarriageReturnFormFeedsStruct"
59+
identifier: "CarriageReturnFormFeedsStruct",
60+
members: MemberDeclBlockSyntax(members: [])
5961
)
6062
let testStruct = try StructDeclSyntax("public struct TestStruct") {
6163
nestedStruct

0 commit comments

Comments
 (0)