Skip to content

Commit

Permalink
Allow undefined and null in helper names
Browse files Browse the repository at this point in the history
  • Loading branch information
kpdecker committed Apr 14, 2015
1 parent 37a664b commit dfd141c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
14 changes: 14 additions & 0 deletions spec/basic.js
Expand Up @@ -74,6 +74,20 @@ describe("basic context", function() {
}
},
'true true object');
shouldCompileTo('{{undefined}}',
{
undefined: function() {
return 'undefined!';
}
},
'undefined!');
shouldCompileTo('{{null}}',
{
null: function() {
return 'null!';
}
},
'null!');
});

it("newlines", function() {
Expand Down
2 changes: 1 addition & 1 deletion spec/javascript-compiler.js
Expand Up @@ -23,7 +23,7 @@ describe('javascript-compiler api', function() {
// Tests nameLookup dot vs. bracket behavior. Bracket is required in certain cases
// to avoid errors in older browsers.
it('should handle reserved words', function() {
shouldCompileTo("{{foo}} {{~[null]~}}", { foo: "food" }, "food");
shouldCompileTo("{{foo}} {{~null~}}", { foo: "food" }, "food");
});
});
describe('#compilerInfo', function() {
Expand Down
4 changes: 4 additions & 0 deletions spec/parser.js
Expand Up @@ -58,6 +58,10 @@ describe('parser', function() {
equals(ast_for("{{foo false}}"), "{{ PATH:foo [BOOLEAN{false}] }}\n");
});

it('parses mustaches with undefined and null paths', function() {
equals(ast_for("{{undefined}}"), "{{ UNDEFINED [] }}\n");
equals(ast_for("{{null}}"), "{{ NULL [] }}\n");
});
it('parses mustaches with undefined and null parameters', function() {
equals(ast_for("{{foo undefined null}}"), "{{ PATH:foo [UNDEFINED, NULL] }}\n");
});
Expand Down
4 changes: 2 additions & 2 deletions src/handlebars.yy
Expand Up @@ -83,8 +83,6 @@ partial
param
: helperName -> $1
| sexpr -> $1
| UNDEFINED -> new yy.UndefinedLiteral(yy.locInfo(@$))
| NULL -> new yy.NullLiteral(yy.locInfo(@$))
;

sexpr
Expand All @@ -109,6 +107,8 @@ helperName
| STRING -> new yy.StringLiteral($1, yy.locInfo(@$))
| NUMBER -> new yy.NumberLiteral($1, yy.locInfo(@$))
| BOOLEAN -> new yy.BooleanLiteral($1, yy.locInfo(@$))
| UNDEFINED -> new yy.UndefinedLiteral(yy.locInfo(@$))
| NULL -> new yy.NullLiteral(yy.locInfo(@$))
;

partialName
Expand Down

0 comments on commit dfd141c

Please sign in to comment.