Skip to content

Commit 64a6063

Browse files
committed
Re-add public API from Syntax.swift that was accidentally removed
1 parent d912f36 commit 64a6063

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Sources/SwiftSyntax/Syntax.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,17 @@ public extension SyntaxProtocol {
295295
return data.indexInParent
296296
}
297297

298+
/// Whether or not this node has a parent.
299+
var hasParent: Bool {
300+
return parent != nil
301+
}
302+
303+
/// Recursively walks through the tree to find the token semantically before
304+
/// this node.
305+
var previousToken: TokenSyntax? {
306+
return self.previousToken(viewMode: .sourceAccurate)
307+
}
308+
298309
/// Recursively walks through the tree to find the token semantically before
299310
/// this node.
300311
func previousToken(viewMode: SyntaxTreeViewMode) -> TokenSyntax? {
@@ -315,6 +326,12 @@ public extension SyntaxProtocol {
315326
return parent.previousToken(viewMode: viewMode)
316327
}
317328

329+
/// Recursively walks through the tree to find the next token semantically
330+
/// after this node.
331+
var nextToken: TokenSyntax? {
332+
return self.nextToken(viewMode: .sourceAccurate)
333+
}
334+
318335
/// Recursively walks through the tree to find the next token semantically
319336
/// after this node.
320337
func nextToken(viewMode: SyntaxTreeViewMode) -> TokenSyntax? {
@@ -353,6 +370,11 @@ public extension SyntaxProtocol {
353370
return nil
354371
}
355372

373+
/// Returns the last token node that is part of this syntax node.
374+
var lastToken: TokenSyntax? {
375+
return self.lastToken(viewMode: .sourceAccurate)
376+
}
377+
356378
/// Returns the last token node that is part of this syntax node.
357379
func lastToken(viewMode: SyntaxTreeViewMode) -> TokenSyntax? {
358380
guard viewMode.shouldTraverse(node: raw) else { return nil }
@@ -450,6 +472,16 @@ public extension SyntaxProtocol {
450472
}
451473
}
452474

475+
/// The length this node's leading trivia takes up spelled out in source.
476+
var leadingTriviaLength: SourceLength {
477+
return raw.leadingTriviaLength
478+
}
479+
480+
/// The length this node's trailing trivia takes up spelled out in source.
481+
var trailingTriviaLength: SourceLength {
482+
return raw.trailingTriviaLength
483+
}
484+
453485
/// Returns a new syntax node with its leading trivia replaced
454486
/// by the provided trivia.
455487
func withLeadingTrivia(_ leadingTrivia: Trivia) -> Self {

0 commit comments

Comments
 (0)