FIX: Precompiler should apply get magic too

This commit is contained in:
Robin Ward 2016-01-15 14:26:10 -05:00
parent 4bbbdd8dc4
commit 7b755c3280

View file

@ -68,27 +68,7 @@
RawHandlebars.JavaScriptCompiler.prototype.compiler = RawHandlebars.JavaScriptCompiler; RawHandlebars.JavaScriptCompiler.prototype.compiler = RawHandlebars.JavaScriptCompiler;
RawHandlebars.JavaScriptCompiler.prototype.namespace = "Discourse.EmberCompatHandlebars"; RawHandlebars.JavaScriptCompiler.prototype.namespace = "Discourse.EmberCompatHandlebars";
RawHandlebars.precompile = function(value, asObject) { function replaceGet(ast) {
var ast = Handlebars.parse(value);
var options = {
knownHelpers: {
get: true
},
data: true,
stringParams: true
};
asObject = asObject === undefined ? true : asObject;
var environment = new RawHandlebars.Compiler().compile(ast, options);
return new RawHandlebars.JavaScriptCompiler().compile(environment, options, undefined, asObject);
};
RawHandlebars.compile = function(string) {
var ast = Handlebars.parse(string);
var visitor = new Handlebars.Visitor(); var visitor = new Handlebars.Visitor();
visitor.mutating = true; visitor.mutating = true;
@ -109,6 +89,29 @@
return Handlebars.Visitor.prototype.MustacheStatement.call(this, mustache); return Handlebars.Visitor.prototype.MustacheStatement.call(this, mustache);
}; };
visitor.accept(ast); visitor.accept(ast);
}
RawHandlebars.precompile = function(value, asObject) {
var ast = Handlebars.parse(value);
replaceGet(ast);
var options = {
knownHelpers: {
get: true
},
data: true,
stringParams: true
};
asObject = asObject === undefined ? true : asObject;
var environment = new RawHandlebars.Compiler().compile(ast, options);
return new RawHandlebars.JavaScriptCompiler().compile(environment, options, undefined, asObject);
};
RawHandlebars.compile = function(string) {
var ast = Handlebars.parse(string);
replaceGet(ast);
// this forces us to rewrite helpers // this forces us to rewrite helpers
var options = { data: true, stringParams: true }; var options = { data: true, stringParams: true };