Skip to content

Commit

Permalink
Code review by @djbe
Browse files Browse the repository at this point in the history
  • Loading branch information
kawoou committed Jan 30, 2019
1 parent ebb7ece commit f3f1e59
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
12 changes: 3 additions & 9 deletions Sources/Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions Sources/_SwiftSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f3f1e59

Please sign in to comment.