summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2015-04-13 21:18:53 -0500
committerkpdecker <kpdecker@gmail.com>2015-04-13 21:18:53 -0500
commitdfd141cd3566c52c271c7470ff690fa6ace6f548 (patch)
tree0729215dc4afd922dc8b7b9e672f6a2a194f0c21
parent37a664bf6438bde0ee827a68da4cbd95a21cf52e (diff)
downloadhandlebars.js-dfd141cd3566c52c271c7470ff690fa6ace6f548.zip
handlebars.js-dfd141cd3566c52c271c7470ff690fa6ace6f548.tar.gz
handlebars.js-dfd141cd3566c52c271c7470ff690fa6ace6f548.tar.bz2
Allow undefined and null in helper names
-rw-r--r--spec/basic.js14
-rw-r--r--spec/javascript-compiler.js2
-rw-r--r--spec/parser.js4
-rw-r--r--src/handlebars.yy4
4 files changed, 21 insertions, 3 deletions
diff --git a/spec/basic.js b/spec/basic.js
index 11002e4..e634d41 100644
--- a/spec/basic.js
+++ b/spec/basic.js
@@ -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() {
diff --git a/spec/javascript-compiler.js b/spec/javascript-compiler.js
index f47ddeb..fb78658 100644
--- a/spec/javascript-compiler.js
+++ b/spec/javascript-compiler.js
@@ -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() {
diff --git a/spec/parser.js b/spec/parser.js
index 6f5a660..d799e08 100644
--- a/spec/parser.js
+++ b/spec/parser.js
@@ -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");
});
diff --git a/src/handlebars.yy b/src/handlebars.yy
index d724578..01ef7fb 100644
--- a/src/handlebars.yy
+++ b/src/handlebars.yy
@@ -83,8 +83,6 @@ partial
param
: helperName -> $1
| sexpr -> $1
- | UNDEFINED -> new yy.UndefinedLiteral(yy.locInfo(@$))
- | NULL -> new yy.NullLiteral(yy.locInfo(@$))
;
sexpr
@@ -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