fix(if): Allow operator use

This commit is contained in:
Kyle Fuller
2016-11-30 17:12:41 +00:00
parent 98edad3566
commit d024da5567
3 changed files with 30 additions and 3 deletions

View File

@@ -1,5 +1,13 @@
# Stencil Changelog # Stencil Changelog
## Master
### Bug Fixes
- Fixes an issue where using `{% if %}` statements which use operators would
throw a syntax error.
## 0.7.0 ## 0.7.0
### Breaking ### Breaking

View File

@@ -167,9 +167,6 @@ class IfNode : NodeType {
class func parse(_ parser: TokenParser, token: Token) throws -> NodeType { class func parse(_ parser: TokenParser, token: Token) throws -> NodeType {
var components = token.components() var components = token.components()
guard components.count == 2 else {
throw TemplateSyntaxError("'if' statements should use the following 'if condition' `\(token.contents)`.")
}
components.removeFirst() components.removeFirst()
var trueNodes = [NodeType]() var trueNodes = [NodeType]()
var falseNodes = [NodeType]() var falseNodes = [NodeType]()

View File

@@ -27,6 +27,28 @@ func testIfNode() {
try expect(falseNode?.text) == "false" try expect(falseNode?.text) == "false"
} }
$0.it("can parse an if with complex expression") {
let tokens: [Token] = [
.block(value: "if value == \"test\" and not name"),
.text(value: "true"),
.block(value: "else"),
.text(value: "false"),
.block(value: "endif")
]
let parser = TokenParser(tokens: tokens, namespace: Namespace())
let nodes = try parser.parse()
let node = nodes.first as? IfNode
let trueNode = node?.trueNodes.first as? TextNode
let falseNode = node?.falseNodes.first as? TextNode
try expect(nodes.count) == 1
try expect(node?.trueNodes.count) == 1
try expect(trueNode?.text) == "true"
try expect(node?.falseNodes.count) == 1
try expect(falseNode?.text) == "false"
}
$0.it("can parse an ifnot block") { $0.it("can parse an ifnot block") {
let tokens: [Token] = [ let tokens: [Token] = [
.block(value: "ifnot value"), .block(value: "ifnot value"),