Skip to content

Commit fa34bdb

Browse files
committed
Accept a String for the expression in FunctionCallExpr(calledExpression:) convenience initializer
1 parent 4057450 commit fa34bdb

File tree

6 files changed

+17
-17
lines changed

6 files changed

+17
-17
lines changed

Sources/SwiftSyntaxBuilder/ConvenienceInitializers.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ extension FunctionCallExpr {
9696
/// instead of having to wrap them in a `TupleExprElementList`.
9797
/// The presence of the parenthesis will be inferred based on the presence of arguments and the trailing closure.
9898
public init(
99-
calledExpression: ExprSyntaxProtocol,
99+
callee: String,
100100
trailingClosure: ClosureExprSyntax? = nil,
101101
additionalTrailingClosures: MultipleTrailingClosureElementList? = nil,
102102
@TupleExprElementListBuilder argumentList: () -> TupleExprElementList = { [] }
103103
) {
104104
let argumentList = argumentList()
105105
let shouldOmitParens = argumentList.isEmpty && trailingClosure != nil
106106
self.init(
107-
calledExpression: calledExpression,
107+
calledExpression: Expr(callee),
108108
leftParen: shouldOmitParens ? nil : .leftParen,
109109
argumentList: argumentList,
110110
rightParen: shouldOmitParens ? nil : .rightParen,
@@ -295,7 +295,7 @@ extension VariableDecl {
295295
PatternBinding(
296296
pattern: name,
297297
typeAnnotation: type,
298-
accessor: .codeBlock(CodeBlock(statements: accessor()))
298+
accessor: .getter(CodeBlock(statements: accessor()))
299299
)
300300
}
301301
}

Tests/SwiftSyntaxBuilderTest/CollectionNodeFlatteningTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ final class CollectionNodeFlatteningTests: XCTestCase {
2121

2222
@CodeBlockItemListBuilder
2323
func buildInnerCodeBlockItemList() -> CodeBlockItemList {
24-
FunctionCallExpr(calledExpression: Expr("innerBuilder"))
24+
FunctionCallExpr(callee: "innerBuilder")
2525
}
2626

2727
@CodeBlockItemListBuilder
2828
func buildOuterCodeBlockItemList() -> CodeBlockItemList {
29-
FunctionCallExpr(calledExpression: Expr("outerBuilder"))
29+
FunctionCallExpr(callee: "outerBuilder")
3030

3131
buildInnerCodeBlockItemList()
3232
}
3333

3434
let codeBlock = CodeBlock(leadingTrivia: leadingTrivia) {
35-
FunctionCallExpr(calledExpression: Expr("outsideBuilder"))
35+
FunctionCallExpr(callee: "outsideBuilder")
3636
buildOuterCodeBlockItemList()
3737
}
3838

Tests/SwiftSyntaxBuilderTest/DoStmtTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ final class DoStmtTests: XCTestCase {
1818
func testDoStmt() {
1919
let buildable = DoStmt(
2020
body: CodeBlock(statementsBuilder: {
21-
TryExpr(expression: FunctionCallExpr(calledExpression: MemberAccessExpr(base: "a", name: "b")))
21+
TryExpr(expression: FunctionCallExpr(callee: "a.b"))
2222
}),
2323
catchClauses: [
2424
CatchClause(CatchItemList {
2525
CatchItem(pattern: Pattern("Error1"))
2626
CatchItem(pattern: Pattern("Error2"))
2727
}) {
28-
FunctionCallExpr(calledExpression: Expr("print")) {
28+
FunctionCallExpr(callee: "print") {
2929
TupleExprElement(expression: StringLiteralExpr(content: "Known error"))
3030
}
3131
},
@@ -36,7 +36,7 @@ final class DoStmtTests: XCTestCase {
3636
ThrowStmt(expression: MemberAccessExpr(base: "Error4", name: "error3"))
3737
},
3838
CatchClause {
39-
FunctionCallExpr(calledExpression: Expr("print")) {
39+
FunctionCallExpr(callee: "print") {
4040
TupleExprElement(expression: "error")
4141
}
4242
}

Tests/SwiftSyntaxBuilderTest/ExtensionDeclTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final class ExtensionDeclTests: XCTestCase {
1919
let keywords = ["associatedtype", "class"].map { keyword -> VariableDecl in
2020
// We need to use `CodeBlock` here to ensure there is braces around.
2121
let body = CodeBlock {
22-
FunctionCallExpr(calledExpression: MemberAccessExpr("TokenSyntax.\(keyword)Keyword"))
22+
FunctionCallExpr(callee: "TokenSyntax.\(keyword)Keyword")
2323
}
2424

2525
return VariableDecl(

Tests/SwiftSyntaxBuilderTest/FunctionTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ final class FunctionTests: XCTestCase {
3535
}
3636

3737
func testArguments() {
38-
let buildable = FunctionCallExpr(calledExpression: Expr("test")) {
38+
let buildable = FunctionCallExpr(callee: "test") {
3939
for param in (1...5) {
4040
TupleExprElement(label: param.isMultiple(of: 2) ? "p\(param)" : nil, expression: "value\(param)")
4141
}
@@ -44,24 +44,24 @@ final class FunctionTests: XCTestCase {
4444
}
4545

4646
func testParensEmittedForNoArgumentsAndNoTrailingClosure() {
47-
let buildable = FunctionCallExpr(calledExpression: Expr("test"))
47+
let buildable = FunctionCallExpr(callee: "test")
4848
AssertBuildResult(buildable, "test()")
4949
}
5050

5151
func testParensEmittedForArgumentAndTrailingClosure() {
52-
let buildable = FunctionCallExpr(calledExpression: Expr("test"), trailingClosure: ClosureExpr()) {
52+
let buildable = FunctionCallExpr(callee: "test", trailingClosure: ClosureExpr()) {
5353
TupleExprElement(expression: "42")
5454
}
5555
AssertBuildResult(buildable, "test(42) {\n}")
5656
}
5757

5858
func testParensOmittedForNoArgumentsAndTrailingClosure() {
5959
let closure = ClosureExpr(statementsBuilder: {
60-
FunctionCallExpr(calledExpression: Expr("f")) {
60+
FunctionCallExpr(callee: "f") {
6161
TupleExprElement(expression: "a")
6262
}
6363
})
64-
let buildable = FunctionCallExpr(calledExpression: Expr("test"), trailingClosure: closure)
64+
let buildable = FunctionCallExpr(callee: "test", trailingClosure: closure)
6565

6666
AssertBuildResult(
6767
buildable,

Tests/SwiftSyntaxBuilderTest/IfStmtTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ final class IfStmtTests: XCTestCase {
3030
// Use the convenience initializer from IfStmtConvenienceInitializers
3131
// with an else branch expressed by a second trailing closure.
3232
let buildable = IfStmt(conditions: ConditionElementList { BooleanLiteralExpr(true) }) {
33-
FunctionCallExpr(calledExpression: Expr("print")) {
33+
FunctionCallExpr(callee: "print") {
3434
TupleExprElement(expression: StringLiteralExpr(content: "Hello from the if-branch!"))
3535
}
3636
} elseBody: {
37-
FunctionCallExpr(calledExpression: Expr("print")) {
37+
FunctionCallExpr(callee: "print") {
3838
TupleExprElement(expression: StringLiteralExpr(content: "Hello from the else-branch!"))
3939
}
4040
}

0 commit comments

Comments
 (0)