Test compilation of literal values in mustaches
This commit is contained in:
@@ -172,7 +172,11 @@ Compiler.prototype = {
|
||||
},
|
||||
|
||||
MustacheStatement: function(mustache) {
|
||||
this.SubExpression(mustache);
|
||||
if (!mustache.path.type.match(/Literal$/)) {
|
||||
this.SubExpression(mustache);
|
||||
} else {
|
||||
this.accept(mustache.path);
|
||||
}
|
||||
|
||||
if(mustache.escaped && !this.options.noEscape) {
|
||||
this.opcode('appendEscaped');
|
||||
|
||||
@@ -229,4 +229,20 @@ describe("basic context", function() {
|
||||
CompilerContext.compile(string);
|
||||
}, Error);
|
||||
});
|
||||
|
||||
it("pass string literals", function() {
|
||||
shouldCompileTo('{{"foo"}}', {}, "foo", "works with strings");
|
||||
shouldCompileTo('{{"foo"}}', { foo: "bar" }, "foo", "uses the provided string instead of lookup in the context object");
|
||||
});
|
||||
|
||||
it("pass number literals", function() {
|
||||
shouldCompileTo("{{12}}", {}, "12", "works with numbers");
|
||||
shouldCompileTo("{{12}}", { "12": "bar" }, "12", "uses the provided number instead of lookup in the context object");
|
||||
});
|
||||
|
||||
it("pass boolean literals", function() {
|
||||
shouldCompileTo("{{true}}", {}, "true", "works with true");
|
||||
shouldCompileTo("{{true}}", { "true": "foo" }, "true", "uses the primitive true instead of lookup in the context object");
|
||||
shouldCompileTo("{{false}}", { "false": "foo" }, "false", "uses the primitive false instead of lookup in the context object");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user