Skip to content

Commit b14ff4a

Browse files
arturmakarankajaylinski
authored andcommitted
Fix compiling of each block params in strict mode
Fixes #1820 Closes #1821
1 parent e0de1d9 commit b14ff4a

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/handlebars/compiler/javascript-compiler.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,9 @@ JavaScriptCompiler.prototype = {
535535

536536
resolvePath: function(type, parts, i, falsy, strict) {
537537
if (this.options.strict || this.options.assumeObjects) {
538-
this.push(strictLookup(this.options.strict && strict, this, parts, type));
538+
this.push(
539+
strictLookup(this.options.strict && strict, this, parts, i, type)
540+
);
539541
return;
540542
}
541543

@@ -1152,9 +1154,8 @@ JavaScriptCompiler.isValidJavaScriptVariableName = function(name) {
11521154
);
11531155
};
11541156

1155-
function strictLookup(requireTerminal, compiler, parts, type) {
1157+
function strictLookup(requireTerminal, compiler, parts, i, type) {
11561158
let stack = compiler.popStack(),
1157-
i = 0,
11581159
len = parts.length;
11591160
if (requireTerminal) {
11601161
len--;

spec/builtins.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,15 @@ describe('builtin helpers', function() {
324324
);
325325
});
326326

327+
it('each with block params and strict compilation', function() {
328+
expectTemplate(
329+
'{{#each goodbyes as |value index|}}{{index}}. {{value.text}}!{{/each}}'
330+
)
331+
.withCompileOptions({ strict: true })
332+
.withInput({ goodbyes: [{ text: 'goodbye' }, { text: 'Goodbye' }] })
333+
.toCompileTo('0. goodbye!1. Goodbye!');
334+
});
335+
327336
it('each object with @index', function() {
328337
expectTemplate(
329338
'{{#each goodbyes}}{{@index}}. {{text}}! {{/each}}cruel {{world}}!'

0 commit comments

Comments
 (0)