diff options
author | Marcio Junior <marciojunior_eu@yahoo.com.br> | 2015-02-07 18:23:03 -0200 |
---|---|---|
committer | Marcio Junior <marciojunior_eu@yahoo.com.br> | 2015-02-08 19:31:38 -0200 |
commit | 5cc326d42554da8a00c69d8a8c6a71e3e6a61371 (patch) | |
tree | e8949aa270219d6bcb3861d397e3192bc7260d0f | |
parent | f857471cc8dd8dca301cd78bfef03bd774b5d4c2 (diff) | |
download | handlebars.js-5cc326d42554da8a00c69d8a8c6a71e3e6a61371.zip handlebars.js-5cc326d42554da8a00c69d8a8c6a71e3e6a61371.tar.gz handlebars.js-5cc326d42554da8a00c69d8a8c6a71e3e6a61371.tar.bz2 |
Test compilation of literal values in mustaches
-rw-r--r-- | lib/handlebars/compiler/compiler.js | 6 | ||||
-rw-r--r-- | spec/basic.js | 16 |
2 files changed, 21 insertions, 1 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index 03bf8f4..75b2c1b 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -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'); diff --git a/spec/basic.js b/spec/basic.js index 3aa1007..e19808f 100644 --- a/spec/basic.js +++ b/spec/basic.js @@ -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"); + }); }); |