Skip to content

Commit 68bb6bc

Browse files
author
Nathan Hawes
committed
Fix RawSyntax's leading/trailingTrivia computation to return nil if its outermost children don't have leading/trailing trivia
Previously if would skip over outer children that didn't have leading/trailing trivia until it found one that did. This was causing that trivia to be included twice when computing the totalLength/byteSize of the node; once in leading/trailingTrivia and again in contentlength, which only skipped the trivia of the outmost children.
1 parent 0144a2b commit 68bb6bc

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

Sources/SwiftSyntax/RawSyntax.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ extension RawSyntax {
350350
case .node(_, let layout):
351351
for child in layout {
352352
guard let child = child else { continue }
353-
guard let result = child.leadingTrivia else { continue }
353+
guard let result = child.leadingTrivia else { break }
354354
return result
355355
}
356356
return nil
@@ -364,7 +364,7 @@ extension RawSyntax {
364364
case .node(_, let layout):
365365
for child in layout.reversed() {
366366
guard let child = child else { continue }
367-
guard let result = child.trailingTrivia else { continue }
367+
guard let result = child.trailingTrivia else { break }
368368
return result
369369
}
370370
return nil

Tests/SwiftSyntaxTest/Inputs/visitor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
func foo() {
2-
func foo() {
2+
public func foo() {
33
func foo() {
44
/*Unknown token */0xG
55
}

0 commit comments

Comments
 (0)