File tree Expand file tree Collapse file tree 3 files changed +12
-11
lines changed Expand file tree Collapse file tree 3 files changed +12
-11
lines changed Original file line number Diff line number Diff line change @@ -144,4 +144,16 @@ PositionTests.test("Implicit") {
144
144
} )
145
145
}
146
146
147
+ PositionTests . test ( " WithoutSourceFileRoot " ) {
148
+ expectDoesNotThrow ( {
149
+ let item = SyntaxFactory . makeCodeBlockItem (
150
+ item: SyntaxFactory . makeReturnStmt (
151
+ returnKeyword: SyntaxFactory . makeToken ( . returnKeyword, presence: . present)
152
+ . withLeadingTrivia ( . newlines( 1 ) ) . withTrailingTrivia ( . newlines( 1 ) ) ,
153
+ expression: nil ) , semicolon: nil )
154
+ expectEqual ( 0 , item. position. utf8Offset)
155
+ expectEqual ( 1 , item. positionAfterSkippingLeadingTrivia. utf8Offset)
156
+ } )
157
+ }
158
+
147
159
runAllTests ( )
Original file line number Diff line number Diff line change @@ -257,13 +257,4 @@ extension RawSyntax {
257
257
piece. accumulateAbsolutePosition ( pos)
258
258
}
259
259
}
260
-
261
- var isSourceFile : Bool {
262
- switch self {
263
- case . node( let kind, _, _) :
264
- return kind == SyntaxKind . sourceFile
265
- default :
266
- return false
267
- }
268
- }
269
260
}
Original file line number Diff line number Diff line change @@ -43,7 +43,6 @@ final class SyntaxData: Equatable {
43
43
fileprivate func calculatePosition( _ initPos: AbsolutePosition ) ->
44
44
AbsolutePosition {
45
45
guard let parent = parent else {
46
- assert ( raw. isSourceFile, " cannot find SourceFileSyntax as root " )
47
46
// If this node is SourceFileSyntax, its location is the start of the file.
48
47
return initPos
49
48
}
@@ -78,7 +77,6 @@ final class SyntaxData: Equatable {
78
77
// If this node is root, the position of the next sibling is the end of
79
78
// this node.
80
79
guard let parent = parent else {
81
- assert ( raw. isSourceFile, " cannot find SourceFileSyntax as root " )
82
80
let result = self . position. copy ( )
83
81
raw. accumulateAbsolutePosition ( result)
84
82
return result
You can’t perform that action at this time.
0 commit comments