Skip to content

Commit 30dbf04

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

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/handlebars/compiler/javascript-compiler.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,9 @@ JavaScriptCompiler.prototype = {
537537

538538
resolvePath: function(type, parts, i, falsy, strict) {
539539
if (this.options.strict || this.options.assumeObjects) {
540-
this.push(strictLookup(this.options.strict && strict, this, parts, type));
540+
this.push(
541+
strictLookup(this.options.strict && strict, this, parts, i, type)
542+
);
541543
return;
542544
}
543545

@@ -1261,9 +1263,8 @@ JavaScriptCompiler.isValidJavaScriptVariableName = function(name) {
12611263
);
12621264
};
12631265

1264-
function strictLookup(requireTerminal, compiler, parts, type) {
1266+
function strictLookup(requireTerminal, compiler, parts, i, type) {
12651267
let stack = compiler.popStack(),
1266-
i = 0,
12671268
len = parts.length;
12681269
if (requireTerminal) {
12691270
len--;

spec/builtins.js

+9
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)