Skip to content

Commit 58ef942

Browse files
committed
Migrate CallToTrailingClosures from with syntax of SwiftSyntax to setters
1 parent 713f08f commit 58ef942

File tree

1 file changed

+16
-30
lines changed

1 file changed

+16
-30
lines changed

Sources/SwiftRefactor/CallToTrailingClosures.swift

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ extension FunctionCallExprSyntax {
6969
// Trailing comma won't exist any more, move its trivia to the end of
7070
// the closure instead
7171
if let comma = arg.trailingComma {
72-
closure = closure.with(\.trailingTrivia, closure.trailingTrivia.merging(triviaOf: comma))
72+
closure.trailingTrivia = closure.trailingTrivia.merging(triviaOf: comma)
7373
}
7474
closures.append((arg, closure))
7575
}
@@ -80,13 +80,10 @@ extension FunctionCallExprSyntax {
8080

8181
// First trailing closure won't have label/colon. Transfer their trivia.
8282
var trailingClosure = closures.first!.closure
83-
.with(
84-
\.leadingTrivia,
85-
Trivia()
86-
.merging(triviaOf: closures.first!.original.label)
87-
.merging(triviaOf: closures.first!.original.colon)
88-
.merging(closures.first!.closure.leadingTrivia)
89-
)
83+
trailingClosure.leadingTrivia = Trivia()
84+
.merging(triviaOf: closures.first!.original.label)
85+
.merging(triviaOf: closures.first!.original.colon)
86+
.merging(closures.first!.closure.leadingTrivia)
9087
let additionalTrailingClosures = closures.dropFirst().map {
9188
MultipleTrailingClosureElementSyntax(
9289
label: $0.original.label ?? .wildcardToken(),
@@ -101,47 +98,36 @@ extension FunctionCallExprSyntax {
10198
// last comma otherwise. Makes sure to keep the trivia of any removed node.
10299
var argList = Array(arguments.dropLast(closures.count))
103100
if argList.isEmpty {
104-
converted =
105-
converted
106-
.with(\.leftParen, nil)
107-
.with(\.rightParen, nil)
101+
converted.leftParen = nil
102+
converted.rightParen = nil
108103

109104
// No left paren any more, right paren is handled below since it makes
110105
// sense to keep its trivia of the end of the call, regardless of whether
111106
// it was removed or not.
112107
if let leftParen = leftParen {
113-
trailingClosure = trailingClosure.with(
114-
\.leadingTrivia,
115-
Trivia()
116-
.merging(triviaOf: leftParen)
117-
.merging(trailingClosure.leadingTrivia)
118-
)
108+
trailingClosure.leadingTrivia = Trivia()
109+
.merging(triviaOf: leftParen)
110+
.merging(trailingClosure.leadingTrivia)
119111
}
120112
} else {
121113
let last = argList.last!
122114
if let comma = last.trailingComma {
123-
converted =
124-
converted
125-
.with(\.rightParen, TokenSyntax.rightParenToken(trailingTrivia: Trivia().merging(triviaOf: comma)))
115+
converted.rightParen = TokenSyntax.rightParenToken(trailingTrivia: Trivia().merging(triviaOf: comma))
126116
}
127-
argList[argList.count - 1] =
128-
last
129-
.with(\.trailingComma, nil)
117+
argList[argList.count - 1] = last.with(\.trailingComma, nil)
130118
}
131119

132120
// Update arguments and trailing closures
133-
converted =
134-
converted
135-
.with(\.arguments, LabeledExprListSyntax(argList))
136-
.with(\.trailingClosure, trailingClosure)
121+
converted.arguments = LabeledExprListSyntax(argList)
122+
converted.trailingClosure = trailingClosure
137123
if !additionalTrailingClosures.isEmpty {
138-
converted = converted.with(\.additionalTrailingClosures, MultipleTrailingClosureElementListSyntax(additionalTrailingClosures))
124+
converted.additionalTrailingClosures = MultipleTrailingClosureElementListSyntax(additionalTrailingClosures)
139125
}
140126

141127
// The right paren either doesn't exist any more, or is before all the
142128
// trailing closures. Moves its trivia to the end of the converted call.
143129
if let rightParen = rightParen {
144-
converted = converted.with(\.trailingTrivia, converted.trailingTrivia.merging(triviaOf: rightParen))
130+
converted.trailingTrivia = converted.trailingTrivia.merging(triviaOf: rightParen)
145131
}
146132

147133
return converted

0 commit comments

Comments
 (0)