Skip to content

Commit b6502e5

Browse files
committed
Simplify isActive(in:) using Alex Hoppen's suggestion
1 parent f35c9e8 commit b6502e5

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

Sources/SwiftIfConfig/IfConfigEvaluation.swift

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -470,22 +470,15 @@ extension SyntaxProtocol {
470470
/// configuration options `DEBUG` and `B` are provided, but `A` is not.
471471
public func isActive(in configuration: some BuildConfiguration) throws -> Bool {
472472
var currentNode: Syntax = Syntax(self)
473-
var currentClause = currentNode.as(IfConfigClauseSyntax.self)
474-
475473
while let parent = currentNode.parent {
476474
// If the parent is an `#if` configuration, check whether our current
477475
// clause is active. If not, we're in an inactive region.
478-
if let parentIfConfig = parent.as(IfConfigDeclSyntax.self) {
479-
if try currentClause != nil && parentIfConfig.activeClause(in: configuration) != currentClause {
476+
if let ifConfigClause = currentNode.as(IfConfigClauseSyntax.self),
477+
let ifConfigDecl = ifConfigClause.parent?.as(IfConfigDeclSyntax.self)
478+
{
479+
if try ifConfigDecl.activeClause(in: configuration) != ifConfigClause {
480480
return false
481481
}
482-
483-
currentClause = nil
484-
}
485-
486-
// If the parent node is an if configuration clause, store it.
487-
if let parentClause = parent.as(IfConfigClauseSyntax.self) {
488-
currentClause = parentClause
489482
}
490483

491484
currentNode = parent

0 commit comments

Comments
 (0)