Skip to content

Commit c5900c7

Browse files
committed
Fix compiling of strict lookup in compat mode
Fixes #2149
1 parent b10cec2 commit c5900c7

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

lib/handlebars/compiler/javascript-compiler.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,9 @@ function strictLookup(requireTerminal, compiler, parts, startPartIndex, type) {
11751175
stack = compiler.nameLookup(stack, parts[i], type);
11761176
}
11771177

1178-
if (requireTerminal) {
1178+
// If compat mode already consumed all parts via depthedLookup, skip the strict terminal check
1179+
// since the stack already holds the resolved value, not an object to look the property up on.
1180+
if (requireTerminal && startPartIndex <= len) {
11791181
return [
11801182
compiler.aliasable('container.strict'),
11811183
'(',

spec/strict.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,22 @@ describe('strict', function () {
121121
});
122122
});
123123

124+
describe('strict and compat mode', function () {
125+
it('GH-2149: should render correctly when block context is a boolean', function () {
126+
expectTemplate('{{#foo}}Hello {{bar}}{{/foo}}')
127+
.withCompileOptions({ strict: true, compat: true })
128+
.withInput({ foo: true, bar: 'World' })
129+
.toCompileTo('Hello World');
130+
});
131+
132+
it('GH-2149: should render correctly when looking up a property on each item', function () {
133+
expectTemplate('{{#each items}}{{name}}{{/each}}')
134+
.withCompileOptions({ strict: true, compat: true })
135+
.withInput({ items: [{ name: 'Hello' }] })
136+
.toCompileTo('Hello');
137+
});
138+
});
139+
124140
describe('assume objects', function () {
125141
it('should ignore missing property', function () {
126142
expectTemplate('{{hello}}')

0 commit comments

Comments
 (0)