Skip to content

Commit d30d7e0

Browse files
committed
Adjustment for removed with<childName> functions in SwiftSyntax
1 parent cfa0d63 commit d30d7e0

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

lib/ASTGen/Sources/ASTGen/Exprs.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extension ASTGenVisitor {
2020
let tupleElement = TupleExprElementSyntax(
2121
label: nil, colon: nil, expression: ExprSyntax(trailingClosure), trailingComma: nil)
2222

23-
return visit(node.addArgument(tupleElement).withTrailingClosure(nil))
23+
return visit(node.addArgument(tupleElement).with(\.trailingClosure, nil))
2424
}
2525

2626
let args = visit(node.argumentList).rawValue

lib/ASTGen/Sources/ASTGen/Macros.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func evaluateMacro(
173173
print("not on a macro expansion node: \(token.recursiveDescription)")
174174
return -1
175175
}
176-
macroName = parentExpansion.macro.withoutTrivia().description
176+
macroName = parentExpansion.macro.text
177177
evaluatedSyntax = Syntax(try exprMacro.expansion(of: parentExpansion, in: &context))
178178

179179
// Handle expression macro. The resulting decls are wrapped in a `CodeBlockItemListSyntax`.
@@ -183,7 +183,7 @@ func evaluateMacro(
183183
return -1
184184
}
185185
let decls = try declMacro.expansion(of: parentExpansion, in: &context)
186-
macroName = parentExpansion.macro.withoutTrivia().description
186+
macroName = parentExpansion.macro.text
187187
evaluatedSyntax = Syntax(CodeBlockItemListSyntax(
188188
decls.map { CodeBlockItemSyntax(item: .decl($0)) }))
189189

@@ -212,7 +212,7 @@ func evaluateMacro(
212212
)
213213
}
214214

215-
var evaluatedSyntaxStr = evaluatedSyntax.withoutTrivia().description
215+
var evaluatedSyntaxStr = evaluatedSyntax.trimmedDescription
216216
evaluatedSyntaxStr.withUTF8 { utf8 in
217217
let evaluatedResultPtr = UnsafeMutablePointer<UInt8>.allocate(capacity: utf8.count + 1)
218218
if let baseAddress = utf8.baseAddress {
@@ -328,7 +328,7 @@ func expandAttachedMacro(
328328

329329
// Form a buffer of accessor declarations to return to the caller.
330330
evaluatedSyntaxStr = accessors.map {
331-
$0.withoutTrivia().description
331+
$0.trimmedDescription
332332
}.joined(separator: "\n\n")
333333

334334
case (let attachedMacro as MemberAttributeMacro.Type, .MemberAttribute):
@@ -351,7 +351,7 @@ func expandAttachedMacro(
351351

352352
// Form a buffer containing an attribute list to return to the caller.
353353
evaluatedSyntaxStr = attributes.map {
354-
$0.withoutTrivia().description
354+
$0.trimmedDescription
355355
}.joined(separator: " ")
356356

357357
case (let attachedMacro as MemberDeclarationMacro.Type, .SynthesizedMembers):
@@ -363,7 +363,7 @@ func expandAttachedMacro(
363363

364364
// Form a buffer of member declarations to return to the caller.
365365
evaluatedSyntaxStr = members.map {
366-
$0.withoutTrivia().description
366+
$0.trimmedDescription
367367
}.joined(separator: "\n\n")
368368

369369
default:

test/Macros/Inputs/syntax_macro_definitions.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ private func replaceFirstLabel(
1414
}
1515

1616
return tuple.replacing(
17-
childAt: 0, with: firstElement.withLabel(.identifier(newLabel)))
17+
childAt: 0, with: firstElement.with(\.label, .identifier(newLabel)))
1818
}
1919

2020
public struct ColorLiteralMacro: ExpressionMacro {
@@ -26,7 +26,7 @@ public struct ColorLiteralMacro: ExpressionMacro {
2626
)
2727
let initSyntax: ExprSyntax = ".init(\(argList))"
2828
if let leadingTrivia = macro.leadingTrivia {
29-
return initSyntax.withLeadingTrivia(leadingTrivia)
29+
return initSyntax.with(\.leadingTrivia, leadingTrivia)
3030
}
3131
return initSyntax
3232
}
@@ -38,7 +38,7 @@ public struct FileIDMacro: ExpressionMacro {
3838
) -> ExprSyntax {
3939
let fileLiteral: ExprSyntax = #""\#(raw: context.moduleName)/\#(raw: context.fileName)""#
4040
if let leadingTrivia = macro.leadingTrivia {
41-
return fileLiteral.withLeadingTrivia(leadingTrivia)
41+
return fileLiteral.with(\.leadingTrivia, leadingTrivia)
4242
}
4343
return fileLiteral
4444
}
@@ -82,7 +82,7 @@ public enum AddBlocker: ExpressionMacro {
8282
}
8383

8484
// Link the folded argument back into the tree.
85-
let node = node.withArgumentList(node.argumentList.replacing(childAt: 0, with: node.argumentList.first!.withExpression(foldedArgument.as(ExprSyntax.self)!)))
85+
let node = node.with(\.argumentList, node.argumentList.replacing(childAt: 0, with: node.argumentList.first!.with(\.expression, foldedArgument.as(ExprSyntax.self)!)))
8686

8787
class AddVisitor: SyntaxRewriter {
8888
var diagnostics: [Diagnostic] = []
@@ -102,8 +102,8 @@ public enum AddBlocker: ExpressionMacro {
102102
severity: .error
103103
),
104104
highlights: [
105-
Syntax(node.leftOperand.withoutTrivia()),
106-
Syntax(node.rightOperand.withoutTrivia())
105+
Syntax(node.leftOperand.with(\.leadingTrivia, [], \.trailingTrivia, [])),
106+
Syntax(node.rightOperand.with(\.leadingTrivia, [], \.trailingTrivia, []))
107107
],
108108
fixIts: [
109109
FixIt(
@@ -114,7 +114,7 @@ public enum AddBlocker: ExpressionMacro {
114114
),
115115
changes: [
116116
FixIt.Change.replace(
117-
oldNode: Syntax(binOp.operatorToken.withoutTrivia()),
117+
oldNode: Syntax(binOp.operatorToken),
118118
newNode: Syntax(
119119
TokenSyntax(
120120
.binaryOperator("-"),
@@ -129,9 +129,11 @@ public enum AddBlocker: ExpressionMacro {
129129
)
130130

131131
return ExprSyntax(
132-
node.withOperatorOperand(
132+
node.with(
133+
\.operatorOperand,
133134
ExprSyntax(
134-
binOp.withOperatorToken(
135+
binOp.with(
136+
\.operatorToken,
135137
binOp.operatorToken.withKind(.binaryOperator("-"))
136138
)
137139
)

0 commit comments

Comments
 (0)