Skip to content

Commit

Permalink
Coerce noEscape-statements to a string
Browse files Browse the repository at this point in the history
Also removed `chai-diff`-dependency, since
it is unmaintained and not that useful.

Fixes #1838
  • Loading branch information
jaylinski committed Aug 29, 2023
1 parent 520e1d5 commit ca0d385
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 99 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/handlebars/compiler/javascript-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";');
Expand Down
41 changes: 2 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions spec/expected/bom.amd.js
Original file line number Diff line number Diff line change
@@ -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});
});
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});
});
4 changes: 2 additions & 2 deletions spec/expected/empty.amd.simple.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
return "";
},"useData":true}
return "";
},"useData":true}
10 changes: 5 additions & 5 deletions spec/expected/handlebar.path.amd.js
Original file line number Diff line number Diff line change
@@ -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});
});
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});
});
3 changes: 1 addition & 2 deletions spec/expected/help.menu.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
Precompile handlebar templates.
Usage: handlebars [template|directory]...

Options:
-f, --output Output File [string]
--map Source Map File [string]
Expand All @@ -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]
--help Outputs this message [boolean]
18 changes: 9 additions & 9 deletions spec/expected/namespace.amd.js
Original file line number Diff line number Diff line change
@@ -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;
});
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;
});
10 changes: 5 additions & 5 deletions spec/expected/non.default.extension.amd.js
Original file line number Diff line number Diff line change
@@ -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 "<div>This is a test</div>";
},"useData":true});
});
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 "<div>This is a test</div>";
},"useData":true});
});
39 changes: 20 additions & 19 deletions spec/expected/non.empty.amd.known.helper.js
Original file line number Diff line number Diff line change
@@ -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 " <div>Some known helper</div>\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 ""+" <div>Some known helper</div>\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 " <div>Another known helper</div>\n";
return " <div>Another known helper</div>\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});
});

});
10 changes: 5 additions & 5 deletions spec/expected/partial.template.js
Original file line number Diff line number Diff line change
@@ -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 "<div>Test Partial</div>";
},"useData":true});
});
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 "<div>Test Partial</div>";
},"useData":true});
});
11 changes: 11 additions & 0 deletions spec/javascript-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('javascript-compiler api', function() {
.toCompileTo('food');
});
});

describe('#compilerInfo', function() {
var $superCheck, $superInfo;
beforeEach(function() {
Expand All @@ -58,6 +59,7 @@ describe('javascript-compiler api', function() {
.toCompileTo('food ');
});
});

describe('buffer', function() {
var $superAppend, $superCreate;
beforeEach(function() {
Expand Down Expand Up @@ -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');
});
});
});
9 changes: 3 additions & 6 deletions tasks/test-bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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}`
);
}
);
Expand Down Expand Up @@ -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;
}

0 comments on commit ca0d385

Please sign in to comment.