diff --git a/.editorconfig b/.editorconfig index b9d48d491..d69dc778c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,6 +5,9 @@ indent_size = 2 insert_final_newline = true trim_trailing_whitespace = true +[spec/expected/*.js] +insert_final_newline = false + [*.yml] indent_size = 2 insert_final_newline = true diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js index 7762412ef..8f437cda4 100644 --- a/lib/handlebars/compiler/javascript-compiler.js +++ b/lib/handlebars/compiler/javascript-compiler.js @@ -308,7 +308,7 @@ JavaScriptCompiler.prototype = { if (appendOnly) { if (bufferStart) { - bufferStart.prepend('return '); + bufferStart.prepend('return ""+'); bufferEnd.add(';'); } else if (!sourceSeen) { this.source.push('return "";'); diff --git a/package-lock.json b/package-lock.json index 325c28e09..cfc881c36 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "handlebars", - "version": "4.7.7", + "version": "4.7.8", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "handlebars", - "version": "4.7.7", + "version": "4.7.8", "license": "MIT", "dependencies": { "minimist": "^1.2.5", @@ -24,7 +24,6 @@ "babel-runtime": "^5.1.10", "benchmark": "~1.0", "chai": "^4.2.0", - "chai-diff": "^1.0.1", "concurrently": "^5.0.0", "dirty-chai": "^2.0.1", "dtslint": "^0.5.5", @@ -2700,18 +2699,6 @@ "node": ">=4" } }, - "node_modules/chai-diff": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/chai-diff/-/chai-diff-1.0.1.tgz", - "integrity": "sha1-bGaJRwDYDNkDUKtORANiXU9TocE=", - "dev": true, - "dependencies": { - "diff": "^2.2.1" - }, - "peerDependencies": { - "chai": ">= 3.0" - } - }, "node_modules/chalk": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", @@ -4127,15 +4114,6 @@ "node": ">=0.4.0" } }, - "node_modules/diff": { - "version": "2.2.3", - "resolved": "https://registry.npmjs.org/diff/-/diff-2.2.3.tgz", - "integrity": "sha1-YOr9DSjukG5Oj/ClLBIpUhAzv5k=", - "dev": true, - "engines": { - "node": ">=0.3.1" - } - }, "node_modules/diff-sequences": { "version": "27.4.0", "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-27.4.0.tgz", @@ -17452,15 +17430,6 @@ "type-detect": "^4.0.5" } }, - "chai-diff": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/chai-diff/-/chai-diff-1.0.1.tgz", - "integrity": "sha1-bGaJRwDYDNkDUKtORANiXU9TocE=", - "dev": true, - "requires": { - "diff": "^2.2.1" - } - }, "chalk": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", @@ -18606,12 +18575,6 @@ } } }, - "diff": { - "version": "2.2.3", - "resolved": "https://registry.npmjs.org/diff/-/diff-2.2.3.tgz", - "integrity": "sha1-YOr9DSjukG5Oj/ClLBIpUhAzv5k=", - "dev": true - }, "diff-sequences": { "version": "27.4.0", "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-27.4.0.tgz", diff --git a/package.json b/package.json index 463c01dac..e7e3126de 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,6 @@ "babel-runtime": "^5.1.10", "benchmark": "~1.0", "chai": "^4.2.0", - "chai-diff": "^1.0.1", "concurrently": "^5.0.0", "dirty-chai": "^2.0.1", "dtslint": "^0.5.5", diff --git a/spec/expected/bom.amd.js b/spec/expected/bom.amd.js index 906989feb..38842be40 100644 --- a/spec/expected/bom.amd.js +++ b/spec/expected/bom.amd.js @@ -1,6 +1,6 @@ define(['handlebars.runtime'], function(Handlebars) { - Handlebars = Handlebars["default"]; var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {}; - return templates['bom'] = template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { - return "a"; - },"useData":true}); - }); \ No newline at end of file + Handlebars = Handlebars["default"]; var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {}; +return templates['bom'] = template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { + return "a"; +},"useData":true}); +}); \ No newline at end of file diff --git a/spec/expected/empty.amd.simple.js b/spec/expected/empty.amd.simple.js index b4014bb83..7b2bb3163 100644 --- a/spec/expected/empty.amd.simple.js +++ b/spec/expected/empty.amd.simple.js @@ -1,3 +1,3 @@ {"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { - return ""; -},"useData":true} \ No newline at end of file + return ""; +},"useData":true} diff --git a/spec/expected/handlebar.path.amd.js b/spec/expected/handlebar.path.amd.js index b3aa1f08a..72a95ffb6 100644 --- a/spec/expected/handlebar.path.amd.js +++ b/spec/expected/handlebar.path.amd.js @@ -1,6 +1,6 @@ define(['some-path/handlebars.runtime'], function(Handlebars) { - Handlebars = Handlebars["default"]; var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {}; - return templates['empty'] = template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { - return ""; - },"useData":true}); - }); \ No newline at end of file + Handlebars = Handlebars["default"]; var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {}; +return templates['empty'] = template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { + return ""; +},"useData":true}); +}); \ No newline at end of file diff --git a/spec/expected/help.menu.txt b/spec/expected/help.menu.txt index 834f4afe2..35e566e37 100644 --- a/spec/expected/help.menu.txt +++ b/spec/expected/help.menu.txt @@ -1,6 +1,5 @@ Precompile handlebar templates. Usage: handlebars [template|directory]... - Options: -f, --output Output File [string] --map Source Map File [string] @@ -22,4 +21,4 @@ Options: -e, --extension Template extension. [string] [default: "handlebars"] -b, --bom Removes the BOM (Byte Order Mark) from the beginning of the templates. [boolean] -v, --version Prints the current compiler version [boolean] - --help Outputs this message [boolean] \ No newline at end of file + --help Outputs this message [boolean] diff --git a/spec/expected/namespace.amd.js b/spec/expected/namespace.amd.js index cdd91f0df..662baaaad 100644 --- a/spec/expected/namespace.amd.js +++ b/spec/expected/namespace.amd.js @@ -1,10 +1,10 @@ define(['handlebars.runtime'], function(Handlebars) { - Handlebars = Handlebars["default"]; var template = Handlebars.template, templates = someNameSpace = someNameSpace || {}; - templates['empty'] = template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { - return ""; - },"useData":true}); - templates['empty'] = template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { - return ""; - },"useData":true}); - return templates; - }); \ No newline at end of file + Handlebars = Handlebars["default"]; var template = Handlebars.template, templates = someNameSpace = someNameSpace || {}; +templates['empty'] = template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { + return ""; +},"useData":true}); +templates['empty'] = template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { + return ""; +},"useData":true}); +return templates; +}); \ No newline at end of file diff --git a/spec/expected/non.default.extension.amd.js b/spec/expected/non.default.extension.amd.js index 264499a7c..84b1cfd1d 100644 --- a/spec/expected/non.default.extension.amd.js +++ b/spec/expected/non.default.extension.amd.js @@ -1,6 +1,6 @@ define(['handlebars.runtime'], function(Handlebars) { - Handlebars = Handlebars["default"]; var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {}; - return templates['non.default.extension'] = template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { - return "
This is a test
"; - },"useData":true}); - }); \ No newline at end of file + Handlebars = Handlebars["default"]; var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {}; +return templates['non.default.extension'] = template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { + return "
This is a test
"; +},"useData":true}); +}); \ No newline at end of file diff --git a/spec/expected/non.empty.amd.known.helper.js b/spec/expected/non.empty.amd.known.helper.js index 75c81cdce..edb61872b 100644 --- a/spec/expected/non.empty.amd.known.helper.js +++ b/spec/expected/non.empty.amd.known.helper.js @@ -1,24 +1,25 @@ define(['handlebars.runtime'], function(Handlebars) { -Handlebars = Handlebars["default"]; var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {}; + Handlebars = Handlebars["default"]; var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {}; return templates['known.helpers'] = template({"1":function(container,depth0,helpers,partials,data) { -var stack1, lookupProperty = container.lookupProperty || function(parent, propertyName) { -if (Object.prototype.hasOwnProperty.call(parent, propertyName)) { -return parent[propertyName]; -} -return undefined -}; -return "
Some known helper
\n" -+ ((stack1 = lookupProperty(helpers,"anotherHelper").call(depth0 != null ? depth0 : (container.nullContext || {}),true,{"name":"anotherHelper","hash":{},"fn":container.program(2, data, 0),"inverse":container.noop,"data":data,"loc":{"start":{"line":3,"column":4},"end":{"line":5,"column":22}}})) != null ? stack1 : ""); + var stack1, lookupProperty = container.lookupProperty || function(parent, propertyName) { + if (Object.prototype.hasOwnProperty.call(parent, propertyName)) { + return parent[propertyName]; + } + return undefined + }; + + return ""+"
Some known helper
\n" + + ((stack1 = lookupProperty(helpers,"anotherHelper").call(depth0 != null ? depth0 : (container.nullContext || {}),true,{"name":"anotherHelper","hash":{},"fn":container.program(2, data, 0),"inverse":container.noop,"data":data,"loc":{"start":{"line":3,"column":4},"end":{"line":5,"column":22}}})) != null ? stack1 : ""); },"2":function(container,depth0,helpers,partials,data) { -return "
Another known helper
\n"; + return "
Another known helper
\n"; },"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { -var stack1, lookupProperty = container.lookupProperty || function(parent, propertyName) { -if (Object.prototype.hasOwnProperty.call(parent, propertyName)) { -return parent[propertyName]; -} -return undefined -}; -return ((stack1 = lookupProperty(helpers,"someHelper").call(depth0 != null ? depth0 : (container.nullContext || {}),true,{"name":"someHelper","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":15}}})) != null ? stack1 : ""); + var stack1, lookupProperty = container.lookupProperty || function(parent, propertyName) { + if (Object.prototype.hasOwnProperty.call(parent, propertyName)) { + return parent[propertyName]; + } + return undefined + }; + + return ""+((stack1 = lookupProperty(helpers,"someHelper").call(depth0 != null ? depth0 : (container.nullContext || {}),true,{"name":"someHelper","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":15}}})) != null ? stack1 : ""); },"useData":true}); -}); - \ No newline at end of file +}); \ No newline at end of file diff --git a/spec/expected/partial.template.js b/spec/expected/partial.template.js index e73aaa1d7..f223a7d46 100644 --- a/spec/expected/partial.template.js +++ b/spec/expected/partial.template.js @@ -1,6 +1,6 @@ define(['handlebars.runtime'], function(Handlebars) { - Handlebars = Handlebars["default"]; var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {}; - return Handlebars.partials['partial.template'] = template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { - return "
Test Partial
"; - },"useData":true}); - }); \ No newline at end of file + Handlebars = Handlebars["default"]; var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {}; +return Handlebars.partials['partial.template'] = template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { + return "
Test Partial
"; +},"useData":true}); +}); \ No newline at end of file diff --git a/spec/javascript-compiler.js b/spec/javascript-compiler.js index ed2dc8c56..f3191aa04 100644 --- a/spec/javascript-compiler.js +++ b/spec/javascript-compiler.js @@ -34,6 +34,7 @@ describe('javascript-compiler api', function() { .toCompileTo('food'); }); }); + describe('#compilerInfo', function() { var $superCheck, $superInfo; beforeEach(function() { @@ -58,6 +59,7 @@ describe('javascript-compiler api', function() { .toCompileTo('food '); }); }); + describe('buffer', function() { var $superAppend, $superCreate; beforeEach(function() { @@ -116,4 +118,13 @@ describe('javascript-compiler api', function() { }); }); }); + + describe('options', function() { + it('should append `noEscape` statements as string', function() { + expectTemplate('{{a}}{{b}}') + .withCompileOptions({ noEscape: true }) + .withInput({ a: 1, b: 1 }) + .toCompileTo('11'); + }); + }); }); diff --git a/tasks/test-bin.js b/tasks/test-bin.js index 58dfab042..2fc1f6a34 100644 --- a/tasks/test-bin.js +++ b/tasks/test-bin.js @@ -4,7 +4,6 @@ const os = require('os'); const path = require('path'); const chai = require('chai'); -chai.use(require('chai-diff')); const expect = chai.expect; const testCases = [ @@ -192,11 +191,9 @@ module.exports = function(grunt) { fs.unlinkSync(outputLocation); } - expect(normalizedOutput).not.to.be.differentFrom( + expect(normalizedOutput).to.be.equal( normalizedExpectedOutput, - { - relaxedSpace: true - } + `Failed on ${expectedOutputSpec}` ); } ); @@ -226,7 +223,7 @@ function addPathToNodeJs(pathEnvironment) { function normalizeCrlf(string) { if (typeof string === 'string') { - return string.replace(/\r\n/g, '\n'); + return string.replace(/\r\n/g, '\n').trim(); } return string; }