Skip to content

Commit db7fd99

Browse files
committed
Simplify lookupLabeledStmtsHelper.
1 parent a00c922 commit db7fd99

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Sources/SwiftLexicalScopes/Scope.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@ extension Scope {
5151

5252
/// Given syntax node position, returns all available labeled statements.
5353
func lookupLabeledStmts(at syntax: SyntaxProtocol) -> [LabeledStmtSyntax] {
54-
return lookupLabeledStmtsHelper(at: syntax.parent, accumulator: [])
54+
return lookupLabeledStmtsHelper(at: syntax.parent)
5555
}
5656

5757
/// Helper method to recursively collect labeled statements from the syntax node's parents.
58-
private func lookupLabeledStmtsHelper(at syntax: Syntax?, accumulator: [LabeledStmtSyntax]) -> [LabeledStmtSyntax] {
59-
guard let syntax, !syntax.is(MemberBlockSyntax.self) else { return accumulator }
58+
private func lookupLabeledStmtsHelper(at syntax: Syntax?) -> [LabeledStmtSyntax] {
59+
guard let syntax, !syntax.is(MemberBlockSyntax.self) else { return [] }
6060
if let labeledStmtSyntax = syntax.as(LabeledStmtSyntax.self) {
61-
return lookupLabeledStmtsHelper(at: labeledStmtSyntax.parent, accumulator: accumulator + [labeledStmtSyntax])
61+
return [labeledStmtSyntax] + lookupLabeledStmtsHelper(at: labeledStmtSyntax.parent)
6262
} else {
63-
return lookupLabeledStmtsHelper(at: syntax.parent, accumulator: accumulator)
63+
return lookupLabeledStmtsHelper(at: syntax.parent)
6464
}
6565
}
6666

0 commit comments

Comments
 (0)