Skip to content

Commit

Permalink
Coerce noEscape-statements to a string
Browse files Browse the repository at this point in the history
Fixes #1838
  • Loading branch information
jaylinski committed Aug 3, 2023
1 parent 520e1d5 commit 783a1d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/handlebars/compiler/javascript-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ JavaScriptCompiler.prototype = {
if (this.isInline()) {
this.replaceStack(current => [' != null ? ', current, ' : ""']);

this.pushSource(this.appendToBuffer(this.popStack()));
this.pushSource(this.appendToBuffer([this.popStack(), '+', "''"]));
} else {
let local = this.popStack();
this.pushSource([
Expand Down
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');
});
});
});

0 comments on commit 783a1d5

Please sign in to comment.