Skip to content

Commit 88fcc8b

Browse files
author
Nathan Hawes
authored
Merge pull request #8 from nathawes/fix-rawsyntax-totallength-when-last-child-has-no-trailing-trivia
Fix RawSyntax's leading/trailingTrivia computation to return nil if the outermost children don't have leading/trailing trivia
2 parents 0144a2b + 68bb6bc commit 88fcc8b

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)