diff options
Diffstat (limited to 'lib/handlebars/compiler')
-rw-r--r-- | lib/handlebars/compiler/ast.js | 16 | ||||
-rw-r--r-- | lib/handlebars/compiler/base.js | 10 | ||||
-rw-r--r-- | lib/handlebars/compiler/compiler.js | 20 | ||||
-rw-r--r-- | lib/handlebars/compiler/printer.js | 6 |
4 files changed, 30 insertions, 22 deletions
diff --git a/lib/handlebars/compiler/ast.js b/lib/handlebars/compiler/ast.js index 25abe0a..459b863 100644 --- a/lib/handlebars/compiler/ast.js +++ b/lib/handlebars/compiler/ast.js @@ -33,13 +33,10 @@ var Handlebars = require('./base'); // pass or at runtime. }; - Handlebars.AST.PartialNode = function(id, context) { - this.type = "partial"; - - // TODO: disallow complex IDs - - this.id = id; - this.context = context; + Handlebars.AST.PartialNode = function(partialName, context) { + this.type = "partial"; + this.partialName = partialName; + this.context = context; }; var verifyMatch = function(open, close) { @@ -93,6 +90,11 @@ var Handlebars = require('./base'); this.isSimple = parts.length === 1 && !this.isScoped && depth === 0; }; + Handlebars.AST.PartialNameNode = function(name) { + this.type = "PARTIAL_NAME"; + this.name = name; + }; + Handlebars.AST.DataNode = function(id) { this.type = "DATA"; this.id = id; diff --git a/lib/handlebars/compiler/base.js b/lib/handlebars/compiler/base.js index 4bb8735..5ce4222 100644 --- a/lib/handlebars/compiler/base.js +++ b/lib/handlebars/compiler/base.js @@ -12,16 +12,6 @@ Handlebars.parse = function(string) { Handlebars.print = function(ast) { return new Handlebars.PrintVisitor().accept(ast); }; - -Handlebars.logger = { - DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, level: 3, - - // override in the host environment - log: function(level, str) {} -}; - -Handlebars.log = function(level, str) { Handlebars.logger.log(level, str); }; - // END(BROWSER) module.exports = Handlebars; diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index 7578dd2..297a553 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -160,7 +160,7 @@ Handlebars.JavaScriptCompiler = function() {}; }, partial: function(partial) { - var id = partial.id; + var partialName = partial.partialName; this.usePartial = true; if(partial.context) { @@ -169,7 +169,7 @@ Handlebars.JavaScriptCompiler = function() {}; this.opcode('push', 'depth0'); } - this.opcode('invokePartial', id.original); + this.opcode('invokePartial', partialName.name); this.opcode('append'); }, @@ -1035,16 +1035,28 @@ Handlebars.JavaScriptCompiler = function() {}; })(Handlebars.Compiler, Handlebars.JavaScriptCompiler); Handlebars.precompile = function(string, options) { - options = options || {}; + if (typeof string !== 'string') { + throw new Handlebars.Exception("You must pass a string to Handlebars.compile. You passed " + string); + } + options = options || {}; + if (!('data' in options)) { + options.data = true; + } var ast = Handlebars.parse(string); var environment = new Handlebars.Compiler().compile(ast, options); return new Handlebars.JavaScriptCompiler().compile(environment, options); }; Handlebars.compile = function(string, options) { - options = options || {}; + if (typeof string !== 'string') { + throw new Handlebars.Exception("You must pass a string to Handlebars.compile. You passed " + string); + } + options = options || {}; + if (!('data' in options)) { + options.data = true; + } var compiled; function compile() { var ast = Handlebars.parse(string); diff --git a/lib/handlebars/compiler/printer.js b/lib/handlebars/compiler/printer.js index 7a42a66..853a4ca 100644 --- a/lib/handlebars/compiler/printer.js +++ b/lib/handlebars/compiler/printer.js @@ -72,7 +72,7 @@ Handlebars.PrintVisitor.prototype.mustache = function(mustache) { }; Handlebars.PrintVisitor.prototype.partial = function(partial) { - var content = this.accept(partial.id); + var content = this.accept(partial.partialName); if(partial.context) { content = content + " " + this.accept(partial.context); } return this.pad("{{> " + content + " }}"); }; @@ -111,6 +111,10 @@ Handlebars.PrintVisitor.prototype.ID = function(id) { } }; +Handlebars.PrintVisitor.prototype.PARTIAL_NAME = function(partialName) { + return "PARTIAL:" + partialName.name; +}; + Handlebars.PrintVisitor.prototype.DATA = function(data) { return "@" + data.id; }; |