Get a better error for compile(falsy)
This commit is contained in:
@@ -1035,6 +1035,10 @@ Handlebars.JavaScriptCompiler = function() {};
|
|||||||
})(Handlebars.Compiler, Handlebars.JavaScriptCompiler);
|
})(Handlebars.Compiler, Handlebars.JavaScriptCompiler);
|
||||||
|
|
||||||
Handlebars.precompile = function(string, options) {
|
Handlebars.precompile = function(string, options) {
|
||||||
|
if (typeof string !== 'string') {
|
||||||
|
throw new Handlebars.Exception("You must pass a string to Handlebars.compile. You passed " + string);
|
||||||
|
}
|
||||||
|
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
var ast = Handlebars.parse(string);
|
var ast = Handlebars.parse(string);
|
||||||
@@ -1043,6 +1047,10 @@ Handlebars.precompile = function(string, options) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Handlebars.compile = function(string, options) {
|
Handlebars.compile = function(string, options) {
|
||||||
|
if (typeof string !== 'string') {
|
||||||
|
throw new Handlebars.Exception("You must pass a string to Handlebars.compile. You passed " + string);
|
||||||
|
}
|
||||||
|
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
var compiled;
|
var compiled;
|
||||||
|
|||||||
@@ -1245,3 +1245,9 @@ test("bug reported by @fat where lambdas weren't being properly resolved", funct
|
|||||||
var output = "<strong>This is a slightly more complicated blah.</strong>.\n\nCheck this out:\n\n<ul>\n\n<li class=one>@fat</li>\n\n<li class=two>@dhg</li>\n\n<li class=three>@sayrer</li>\n</ul>.\n\n";
|
var output = "<strong>This is a slightly more complicated blah.</strong>.\n\nCheck this out:\n\n<ul>\n\n<li class=one>@fat</li>\n\n<li class=two>@dhg</li>\n\n<li class=three>@sayrer</li>\n</ul>.\n\n";
|
||||||
shouldCompileTo(string, data, output);
|
shouldCompileTo(string, data, output);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("Passing falsy values to Handlebars.compile throws an error", function() {
|
||||||
|
shouldThrow(function() {
|
||||||
|
CompilerContext.compile(null);
|
||||||
|
}, "You must pass a string to Handlebars.compile. You passed null");
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user