diff --git a/Sources/Node.swift b/Sources/Node.swift index df27fb4a..33862112 100644 --- a/Sources/Node.swift +++ b/Sources/Node.swift @@ -71,15 +71,9 @@ public class VariableNode: NodeType { if hasToken("if", at: 1) { let components = components.suffix(from: 2) - #if swift(<5.0) - let elseIndex = components.index(of: "else") - #else - let elseIndex = components.firstIndex(of: "else") - #endif - - if let safeElseIndex = elseIndex { - condition = try parser.compileExpression(components: Array(components.prefix(upTo: safeElseIndex)), token: token) - let elseToken = components.suffix(from: safeElseIndex.advanced(by: 1)).joined(separator: " ") + if let elseIndex = components.firstIndex(of: "else") { + condition = try parser.compileExpression(components: Array(components.prefix(upTo: elseIndex)), token: token) + let elseToken = components.suffix(from: elseIndex.advanced(by: 1)).joined(separator: " ") elseExpression = try parser.compileResolvable(elseToken, containedIn: token) } else { condition = try parser.compileExpression(components: Array(components), token: token) diff --git a/Sources/_SwiftSupport.swift b/Sources/_SwiftSupport.swift index 24413505..1faa5e47 100644 --- a/Sources/_SwiftSupport.swift +++ b/Sources/_SwiftSupport.swift @@ -36,3 +36,11 @@ public extension Variable { } } #endif + +#if !swift(>=4.1) +extension ArraySlice where Element: Equatable { + func firstIndex(of element: Element) -> Int? { + return index(of: element) + } +} +#endif