syntax error on empty variable tag
This commit is contained in:
@@ -23,6 +23,10 @@ _None_
|
|||||||
[Ilya Puchka](https://github.com/ilyapuchka)
|
[Ilya Puchka](https://github.com/ilyapuchka)
|
||||||
[#254](https://github.com/stencilproject/Stencil/pull/254)
|
[#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
|
### Internal Changes
|
||||||
|
|
||||||
- `Token` type converted to struct to allow computing token components only once.
|
- `Token` type converted to struct to allow computing token components only once.
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ enum Filter: FilterType {
|
|||||||
switch self {
|
switch self {
|
||||||
case let .simple(filter):
|
case let .simple(filter):
|
||||||
if !arguments.isEmpty {
|
if !arguments.isEmpty {
|
||||||
throw TemplateSyntaxError("cannot invoke filter with an argument")
|
throw TemplateSyntaxError("Can't invoke filter with an argument")
|
||||||
}
|
}
|
||||||
return try filter(value)
|
return try filter(value)
|
||||||
case let .arguments(filter):
|
case let .arguments(filter):
|
||||||
|
|||||||
@@ -84,7 +84,10 @@ public class VariableNode: NodeType {
|
|||||||
elseExpression = nil
|
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)
|
return VariableNode(variable: filter, token: token, condition: condition, elseExpression: elseExpression)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -133,6 +133,11 @@ final class EnvironmentTests: XCTestCase {
|
|||||||
token: "name|unknown"
|
token: "name|unknown"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
it("reports error in variable tag") {
|
||||||
|
self.template = "{{ }}"
|
||||||
|
try self.expectError(reason: "Missing variable name", token: " ")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testRenderingError() {
|
func testRenderingError() {
|
||||||
@@ -153,7 +158,7 @@ final class EnvironmentTests: XCTestCase {
|
|||||||
|
|
||||||
it("reports passing argument to simple filter") {
|
it("reports passing argument to simple filter") {
|
||||||
self.template = "{{ name|uppercase:5 }}"
|
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") {
|
it("reports rendering error in custom tag") {
|
||||||
|
|||||||
Reference in New Issue
Block a user