Test compilation of literal values in mustaches

This commit is contained in:
Marcio Junior
2015-02-07 18:23:03 -02:00
parent f857471cc8
commit 5cc326d425
2 changed files with 21 additions and 1 deletions
+5 -1
View File
@@ -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');
+16
View File
@@ -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");
});
});