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

properly handle multiple subexpressions in the same hash, fixes #748 #749

Merged
merged 1 commit into from
Mar 5, 2014
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
12 changes: 6 additions & 6 deletions lib/handlebars/compiler/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ Compiler.prototype = {
},

hash: function(hash) {
var pairs = hash.pairs, pair;
var pairs = hash.pairs, i, l;

this.opcode('pushHash');

for(var i=0, l=pairs.length; i<l; i++) {
pair = pairs[i];

this.pushParam(pair[1]);
this.opcode('assignToHash', pair[0]);
for(i=0, l=pairs.length; i<l; i++) {
this.pushParam(pairs[i][1]);
}
while(i--) {
this.opcode('assignToHash', pairs[i][0]);
}
this.opcode('popHash');
},
Expand Down
7 changes: 3 additions & 4 deletions lib/handlebars/compiler/javascript-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,11 +606,10 @@ JavaScriptCompiler.prototype = {

// [assignToHash]
//
// On stack, before: value, hash, ...
// On stack, after: hash, ...
// On stack, before: value, ..., hash, ...
// On stack, after: ..., hash, ...
//
// Pops a value and hash off the stack, assigns `hash[key] = value`
// and pushes the hash back onto the stack.
// Pops a value off the stack and assigns it to the current hash
assignToHash: function(key) {
var value = this.popStack(),
context,
Expand Down
17 changes: 17 additions & 0 deletions spec/subexpressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,23 @@ describe('subexpressions', function() {
shouldCompileTo(string, [{}, helpers], "val is true");
});

it("multiple subexpressions in a hash", function() {
var string = '{{input aria-label=(t "Name") placeholder=(t "Example User")}}';

var helpers = {
input: function(options) {
var hash = options.hash;
var ariaLabel = Handlebars.Utils.escapeExpression(hash['aria-label']);
var placeholder = Handlebars.Utils.escapeExpression(hash.placeholder);
return new Handlebars.SafeString('<input aria-label="' + ariaLabel + '" placeholder="' + placeholder + '" />');
},
t: function(defaultString) {
return new Handlebars.SafeString(defaultString);
}
}
shouldCompileTo(string, [{}, helpers], '<input aria-label="Name" placeholder="Example User" />');
});

it("in string params mode,", function() {
var template = CompilerContext.compile('{{snog (blorg foo x=y) yeah a=b}}', {stringParams: true});

Expand Down