Handle all potential literal values

Adds support for literal helper names in a few missing cases such as block expressions and subexpressions.
This commit is contained in:
kpdecker
2015-02-09 23:54:46 -06:00
parent 07f27843dc
commit 39121cf8f5
3 changed files with 35 additions and 24 deletions
+9 -5
View File
@@ -110,6 +110,8 @@ Compiler.prototype = {
},
BlockStatement: function(block) {
transformLiteralToPath(block);
var program = block.program,
inverse = block.inverse;
@@ -172,7 +174,6 @@ Compiler.prototype = {
},
MustacheStatement: function(mustache) {
transformLiteralToPath(mustache);
this.SubExpression(mustache);
if(mustache.escaped && !this.options.noEscape) {
@@ -191,6 +192,7 @@ Compiler.prototype = {
CommentStatement: function() {},
SubExpression: function(sexpr) {
transformLiteralToPath(sexpr);
var type = this.classifySexpr(sexpr);
if (type === 'simple') {
@@ -487,9 +489,11 @@ function argEquals(a, b) {
}
}
function transformLiteralToPath(mustache) {
if (mustache.path.type.match(/Literal$/)) {
var literal = mustache.path;
mustache.path = { type: 'PathExpression', original: String(literal.original), parts: [String(literal.original)], depth: 0, data: false };
function transformLiteralToPath(sexpr) {
if (!sexpr.path.parts) {
var literal = sexpr.path;
// Casting to string here to make false and 0 literal values play nicely with the rest
// of the system.
sexpr.path = new AST.PathExpression(false, 0, [literal.original+''], literal.original+'', literal.log);
}
}