diff options
author | kpdecker <kpdecker@gmail.com> | 2014-11-26 19:22:09 -0600 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2014-11-26 19:22:09 -0600 |
commit | 697bbe59cad06bc74a945f7e26fc0af333a01d47 (patch) | |
tree | 9d51923ba37e8960c371c67db181d33fdf63bf29 | |
parent | 2a4819d75cba7513946af5cf28ee22881561814f (diff) | |
download | handlebars.js-697bbe59cad06bc74a945f7e26fc0af333a01d47.zip handlebars.js-697bbe59cad06bc74a945f7e26fc0af333a01d47.tar.gz handlebars.js-697bbe59cad06bc74a945f7e26fc0af333a01d47.tar.bz2 |
Update literal ast nodes for new spec
-rw-r--r-- | lib/handlebars/compiler/ast.js | 15 | ||||
-rw-r--r-- | lib/handlebars/compiler/code-gen.js | 2 | ||||
-rw-r--r-- | lib/handlebars/compiler/compiler.js | 14 | ||||
-rw-r--r-- | lib/handlebars/compiler/printer.js | 12 | ||||
-rw-r--r-- | lib/handlebars/compiler/visitor.js | 6 | ||||
-rw-r--r-- | spec/string-params.js | 25 | ||||
-rw-r--r-- | spec/visitor.js | 12 |
7 files changed, 42 insertions, 44 deletions
diff --git a/lib/handlebars/compiler/ast.js b/lib/handlebars/compiler/ast.js index 26ea4ab..44b26ec 100644 --- a/lib/handlebars/compiler/ast.js +++ b/lib/handlebars/compiler/ast.js @@ -142,25 +142,22 @@ var AST = { StringNode: function(string, locInfo) { this.loc = locInfo; - this.type = "STRING"; + this.type = 'StringLiteral'; this.original = - this.string = - this.stringModeValue = string; + this.value = string; }, NumberNode: function(number, locInfo) { this.loc = locInfo; - this.type = "NUMBER"; + this.type = 'NumberLiteral'; this.original = - this.number = number; - this.stringModeValue = Number(number); + this.value = Number(number); }, BooleanNode: function(bool, locInfo) { this.loc = locInfo; - this.type = "BOOLEAN"; - this.bool = bool; - this.stringModeValue = bool === "true"; + this.type = 'BooleanLiteral'; + this.value = bool === 'true'; } }; diff --git a/lib/handlebars/compiler/code-gen.js b/lib/handlebars/compiler/code-gen.js index 30f0735..a7c1659 100644 --- a/lib/handlebars/compiler/code-gen.js +++ b/lib/handlebars/compiler/code-gen.js @@ -99,7 +99,7 @@ CodeGen.prototype = { }, quotedString: function(str) { - return '"' + str + return '"' + (str + '') .replace(/\\/g, '\\\\') .replace(/"/g, '\\"') .replace(/\n/g, '\\n') diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index ea2272a..a5acb64 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -283,16 +283,16 @@ Compiler.prototype = { this.opcode('lookupData', data, data.id.depth, data.id.parts); }, - STRING: function(string) { - this.opcode('pushString', string, string.string); + StringLiteral: function(string) { + this.opcode('pushString', string, string.value); }, - NUMBER: function(number) { - this.opcode('pushLiteral', number, number.number); + NumberLiteral: function(number) { + this.opcode('pushLiteral', number, number.value); }, - BOOLEAN: function(bool) { - this.opcode('pushLiteral', bool, bool.bool); + BooleanLiteral: function(bool) { + this.opcode('pushLiteral', bool, bool.value); }, // HELPERS @@ -338,7 +338,7 @@ Compiler.prototype = { }, pushParam: function(val) { - var stringModeValue = val.stringModeValue != null ? val.stringModeValue : ''; + var stringModeValue = val.stringModeValue || (val.value != null ? val.value : ''); if (this.stringParams) { if(val.depth) { diff --git a/lib/handlebars/compiler/printer.js b/lib/handlebars/compiler/printer.js index dac8ec2..c86f7fa 100644 --- a/lib/handlebars/compiler/printer.js +++ b/lib/handlebars/compiler/printer.js @@ -120,16 +120,16 @@ PrintVisitor.prototype.hash = function(hash) { return "HASH{" + joinedPairs.join(", ") + "}"; }; -PrintVisitor.prototype.STRING = function(string) { - return '"' + string.string + '"'; +PrintVisitor.prototype.StringLiteral = function(string) { + return '"' + string.value + '"'; }; -PrintVisitor.prototype.NUMBER = function(number) { - return "NUMBER{" + number.number + "}"; +PrintVisitor.prototype.NumberLiteral = function(number) { + return "NUMBER{" + number.value + "}"; }; -PrintVisitor.prototype.BOOLEAN = function(bool) { - return "BOOLEAN{" + bool.bool + "}"; +PrintVisitor.prototype.BooleanLiteral = function(bool) { + return "BOOLEAN{" + bool.value + "}"; }; PrintVisitor.prototype.ID = function(id) { diff --git a/lib/handlebars/compiler/visitor.js b/lib/handlebars/compiler/visitor.js index e48c9bc..a2ad7bb 100644 --- a/lib/handlebars/compiler/visitor.js +++ b/lib/handlebars/compiler/visitor.js @@ -57,9 +57,9 @@ Visitor.prototype = { this.accept(data.id); }, - STRING: function(string) {}, - NUMBER: function(number) {}, - BOOLEAN: function(bool) {}, + StringLiteral: function(string) {}, + NumberLiteral: function(number) {}, + BooleanLiteral: function(bool) {}, ID: function(id) {} }; diff --git a/spec/string-params.js b/spec/string-params.js index 2e88cf1..52ea5a8 100644 --- a/spec/string-params.js +++ b/spec/string-params.js @@ -1,3 +1,4 @@ +/*global CompilerContext */ describe('string params mode', function() { it("arguments to helpers can be retrieved from options hash in string form", function() { var template = CompilerContext.compile('{{wycats is.a slave.driver}}', {stringParams: true}); @@ -56,9 +57,9 @@ describe('string params mode', function() { var helpers = { tomdale: function(desire, noun, trueBool, falseBool, options) { - equal(options.types[0], 'STRING', "the string type is passed"); + equal(options.types[0], 'StringLiteral', "the string type is passed"); equal(options.types[1], 'ID', "the expression type is passed"); - equal(options.types[2], 'BOOLEAN', "the expression type is passed"); + equal(options.types[2], 'BooleanLiteral', "the expression type is passed"); equal(desire, "need", "the string form is passed for strings"); equal(noun, "dad.joke", "the string form is passed for expressions"); equal(trueBool, true, "raw booleans are passed through"); @@ -76,21 +77,21 @@ describe('string params mode', function() { var helpers = { tomdale: function(exclamation, options) { - equal(exclamation, "he.says"); - equal(options.types[0], "ID"); - - equal(options.hashTypes.desire, "STRING"); - equal(options.hashTypes.noun, "ID"); - equal(options.hashTypes.bool, "BOOLEAN"); - equal(options.hash.desire, "need"); - equal(options.hash.noun, "dad.joke"); + equal(exclamation, 'he.says'); + equal(options.types[0], 'ID'); + + equal(options.hashTypes.desire, 'StringLiteral'); + equal(options.hashTypes.noun, 'ID'); + equal(options.hashTypes.bool, 'BooleanLiteral'); + equal(options.hash.desire, 'need'); + equal(options.hash.noun, 'dad.joke'); equal(options.hash.bool, true); - return "Helper called"; + return 'Helper called'; } }; var result = template({}, { helpers: helpers }); - equal(result, "Helper called"); + equal(result, 'Helper called'); }); it("hash parameters get context information", function() { diff --git a/spec/visitor.js b/spec/visitor.js index 15a0f02..e6f80f3 100644 --- a/spec/visitor.js +++ b/spec/visitor.js @@ -20,14 +20,14 @@ describe('Visitor', function() { it('should traverse to stubs', function() { var visitor = new Handlebars.Visitor(); - visitor.STRING = function(string) { - equal(string.string, '2'); + visitor.StringLiteral = function(string) { + equal(string.value, '2'); }; - visitor.NUMBER = function(number) { - equal(number.stringModeValue, 1); + visitor.NumberLiteral = function(number) { + equal(number.value, 1); }; - visitor.BOOLEAN = function(bool) { - equal(bool.stringModeValue, true); + visitor.BooleanLiteral = function(bool) { + equal(bool.value, true); }; visitor.ID = function(id) { equal(id.original, 'foo.bar'); |