diff --git a/CHANGELOG.md b/CHANGELOG.md index e418af9..2326ca8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Stencil Changelog +## Master + +### Bug Fixes + +- Fixes an issue where using `{% if %}` statements which use operators would + throw a syntax error. + + ## 0.7.0 ### Breaking diff --git a/Sources/IfTag.swift b/Sources/IfTag.swift index d48622e..c962a61 100644 --- a/Sources/IfTag.swift +++ b/Sources/IfTag.swift @@ -167,9 +167,6 @@ class IfNode : NodeType { class func parse(_ parser: TokenParser, token: Token) throws -> NodeType { var components = token.components() - guard components.count == 2 else { - throw TemplateSyntaxError("'if' statements should use the following 'if condition' `\(token.contents)`.") - } components.removeFirst() var trueNodes = [NodeType]() var falseNodes = [NodeType]() diff --git a/Tests/StencilTests/IfNodeSpec.swift b/Tests/StencilTests/IfNodeSpec.swift index cfb6052..cbd160e 100644 --- a/Tests/StencilTests/IfNodeSpec.swift +++ b/Tests/StencilTests/IfNodeSpec.swift @@ -27,6 +27,28 @@ func testIfNode() { 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") { let tokens: [Token] = [ .block(value: "ifnot value"),