Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handlebars.compile() does not modify "options" anymore #1349

Merged
merged 1 commit into from
May 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/handlebars/compiler/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Compiler.prototype = {
for (let name in knownHelpers) {
/* istanbul ignore else */
if (name in knownHelpers) {
options.knownHelpers[name] = knownHelpers[name];
this.options.knownHelpers[name] = knownHelpers[name];
}
}
}
Expand Down Expand Up @@ -488,6 +488,7 @@ export function compile(input, options = {}, env) {
throw new Exception('You must pass a string or Handlebars AST to Handlebars.compile. You passed ' + input);
}

options = Object.assign({}, options);
if (!('data' in options)) {
options.data = true;
}
Expand Down
12 changes: 12 additions & 0 deletions spec/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ describe('compiler', function() {
it('can pass through an empty string', function() {
equal(Handlebars.compile('')(), '');
});

it('should not modify the options.data property(GH-1327)', function() {
var options = {data: [{a: 'foo'}, {a: 'bar'}]};
Handlebars.compile('{{#each data}}{{@index}}:{{a}} {{/each}}', options)();
equal(JSON.stringify(options, 0, 2), JSON.stringify({data: [{a: 'foo'}, {a: 'bar'}]}, 0, 2));
});

it('should not modify the options.knownHelpers property(GH-1327)', function() {
var options = {knownHelpers: {}};
Handlebars.compile('{{#each data}}{{@index}}:{{a}} {{/each}}', options)();
equal(JSON.stringify(options, 0, 2), JSON.stringify({knownHelpers: {}}, 0, 2));
});
});

describe('#precompile', function() {
Expand Down