@@ -253,20 +253,7 @@ extension SyntaxProtocol {
253253 /// Recursively walks through the tree to find the token semantically before
254254 /// this node.
255255 public func previousToken( viewMode: SyntaxTreeViewMode ) -> TokenSyntax ? {
256- guard let parent = self . parent else {
257- return nil
258- }
259- let siblings = parent. children ( viewMode: viewMode)
260- // `self` could be a missing node at index 0 and `viewMode` be `.sourceAccurate`.
261- // In that case `siblings` skips over the missing `self` node and has a `startIndex > 0`.
262- if siblings. startIndex < self . indexInParent {
263- for child in siblings [ ..< self . indexInParent] . reversed ( ) {
264- if let token = child. lastToken ( viewMode: viewMode) {
265- return token
266- }
267- }
268- }
269- return parent. previousToken ( viewMode: viewMode)
256+ return self . _syntaxNode. previousToken ( viewMode: viewMode)
270257 }
271258
272259 @available ( * , deprecated, message: " Use nextToken(viewMode:) instead " )
@@ -277,16 +264,7 @@ extension SyntaxProtocol {
277264 /// Recursively walks through the tree to find the next token semantically
278265 /// after this node.
279266 public func nextToken( viewMode: SyntaxTreeViewMode ) -> TokenSyntax ? {
280- guard let parent = self . parent else {
281- return nil
282- }
283- let siblings = parent. children ( viewMode: viewMode)
284- for child in siblings [ siblings. index ( after: self . indexInParent) ... ] {
285- if let token = child. firstToken ( viewMode: viewMode) {
286- return token
287- }
288- }
289- return parent. nextToken ( viewMode: viewMode)
267+ return self . _syntaxNode. nextToken ( viewMode: viewMode)
290268 }
291269
292270 @available ( * , deprecated, message: " Use firstToken(viewMode: .sourceAccurate) instead " )
@@ -296,17 +274,7 @@ extension SyntaxProtocol {
296274
297275 /// Returns the first token node that is part of this syntax node.
298276 public func firstToken( viewMode: SyntaxTreeViewMode ) -> TokenSyntax ? {
299- guard viewMode. shouldTraverse ( node: raw) else { return nil }
300- if let token = _syntaxNode. as ( TokenSyntax . self) {
301- return token
302- }
303-
304- for child in children ( viewMode: viewMode) {
305- if let token = child. firstToken ( viewMode: viewMode) {
306- return token
307- }
308- }
309- return nil
277+ return self . _syntaxNode. firstToken ( viewMode: viewMode)
310278 }
311279
312280 @available ( * , deprecated, message: " Use lastToken(viewMode: .sourceAccurate) instead " )
@@ -316,17 +284,7 @@ extension SyntaxProtocol {
316284
317285 /// Returns the last token node that is part of this syntax node.
318286 public func lastToken( viewMode: SyntaxTreeViewMode ) -> TokenSyntax ? {
319- guard viewMode. shouldTraverse ( node: raw) else { return nil }
320- if let token = _syntaxNode. as ( TokenSyntax . self) {
321- return token
322- }
323-
324- for child in children ( viewMode: viewMode) . reversed ( ) {
325- if let tok = child. lastToken ( viewMode: viewMode) {
326- return tok
327- }
328- }
329- return nil
287+ return self . _syntaxNode. lastToken ( viewMode: viewMode)
330288 }
331289
332290 /// Sequence of tokens that are part of this Syntax node.
0 commit comments