@@ -160,7 +160,7 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
160
160
/// - Returns: the rewritten node
161
161
\( node. apiAttributes ( ) ) \
162
162
open func visit(_ node: \( node. kind. syntaxType) ) -> \( node. kind. syntaxType) {
163
- return visitChildren(node)
163
+ return visitChildren(node._syntaxNode)?.cast( \( node . kind . syntaxType ) .self) ?? node
164
164
}
165
165
"""
166
166
)
@@ -172,7 +172,7 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
172
172
/// - Returns: the rewritten node
173
173
\( node. apiAttributes ( ) ) \
174
174
open func visit(_ node: \( node. kind. syntaxType) ) -> \( node. baseType. syntaxBaseName) {
175
- return \( node. baseType. syntaxBaseName) (visitChildren(node) )
175
+ return \( node. baseType. syntaxBaseName) (visitChildren(node._syntaxNode)?.cast( \( node . kind . syntaxType ) .self) ?? node )
176
176
}
177
177
"""
178
178
)
@@ -302,9 +302,7 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
302
302
303
303
DeclSyntax (
304
304
"""
305
- private func visitChildren<SyntaxType: SyntaxProtocol>(
306
- _ node: SyntaxType
307
- ) -> SyntaxType {
305
+ private func visitChildren(_ node: Syntax) -> Syntax? {
308
306
// Walk over all children of this node and rewrite them. Don't store any
309
307
// rewritten nodes until the first non-`nil` value is encountered. When this
310
308
// happens, retrieve all previous syntax nodes from the parent node to
@@ -320,11 +318,9 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
320
318
// with 'Syntax'
321
319
var rewrittens: ContiguousArray<RetainedSyntaxArena> = []
322
320
323
- let syntaxNode = node._syntaxNode
324
-
325
321
// Incrementing i manually is faster than using .enumerated()
326
322
var childIndex = 0
327
- for (raw, info) in RawSyntaxChildren(syntaxNode ) {
323
+ for (raw, info) in RawSyntaxChildren(node ) {
328
324
defer { childIndex += 1 }
329
325
330
326
guard let child = raw, viewMode.shouldTraverse(node: child) else {
@@ -333,7 +329,7 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
333
329
}
334
330
335
331
// Build the Syntax node to rewrite
336
- var childNode = nodeFactory.create(parent: syntaxNode , raw: child, absoluteInfo: info)
332
+ var childNode = nodeFactory.create(parent: node , raw: child, absoluteInfo: info)
337
333
338
334
dispatchVisit(&childNode)
339
335
if childNode.raw.id != child.id {
@@ -365,11 +361,11 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
365
361
newLayout.deallocate()
366
362
// 'withExtendedLifetime' to keep 'SyntaxArena's of them alive until here.
367
363
return withExtendedLifetime(rewrittens) {
368
- Syntax(raw: newRaw, rawNodeArena: arena).cast(SyntaxType.self)
364
+ Syntax(raw: newRaw, rawNodeArena: arena)
369
365
}
370
366
} else {
371
367
// No child node was rewritten. So no need to change this node as well.
372
- return node
368
+ return nil
373
369
}
374
370
}
375
371
"""
0 commit comments