syntax error on empty variable tag

This commit is contained in:
Ilya Puchka
2019-01-12 22:10:21 +00:00
parent 0f18d43d9e
commit 693565ddda
4 changed files with 15 additions and 3 deletions

View File

@@ -23,6 +23,10 @@ _None_
[Ilya Puchka](https://github.com/ilyapuchka)
[#254](https://github.com/stencilproject/Stencil/pull/254)
- Throw syntax error on empty variable tags (`{{ }}`) instead `fatalError`.
[Ilya Puchka](https://github.com/ilyapuchka)
[#263](https://github.com/stencilproject/Stencil/pull/263)
### Internal Changes
- `Token` type converted to struct to allow computing token components only once.

View File

@@ -89,7 +89,7 @@ enum Filter: FilterType {
switch self {
case let .simple(filter):
if !arguments.isEmpty {
throw TemplateSyntaxError("cannot invoke filter with an argument")
throw TemplateSyntaxError("Can't invoke filter with an argument")
}
return try filter(value)
case let .arguments(filter):

View File

@@ -84,7 +84,10 @@ public class VariableNode: NodeType {
elseExpression = nil
}
let filter = try parser.compileResolvable(components[0], containedIn: token)
guard let resolvable = components.first else {
throw TemplateSyntaxError(reason: "Missing variable name", token: token)
}
let filter = try parser.compileResolvable(resolvable, containedIn: token)
return VariableNode(variable: filter, token: token, condition: condition, elseExpression: elseExpression)
}

View File

@@ -133,6 +133,11 @@ final class EnvironmentTests: XCTestCase {
token: "name|unknown"
)
}
it("reports error in variable tag") {
self.template = "{{ }}"
try self.expectError(reason: "Missing variable name", token: " ")
}
}
func testRenderingError() {
@@ -153,7 +158,7 @@ final class EnvironmentTests: XCTestCase {
it("reports passing argument to simple filter") {
self.template = "{{ name|uppercase:5 }}"
try self.expectError(reason: "cannot invoke filter with an argument", token: "name|uppercase:5")
try self.expectError(reason: "Can't invoke filter with an argument", token: "name|uppercase:5")
}
it("reports rendering error in custom tag") {