Skip to content

Commit 62953e7

Browse files
smmhatamijaylinski
authored andcommitted
Allow using strict and compat together
Signed-off-by: Seyed Mohammad Mahdi Hatami <[email protected]>
1 parent d3b9357 commit 62953e7

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lib/handlebars/runtime.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export function template(templateSpec, env) {
116116
// Just add water
117117
let container = {
118118
strict: function (obj, name, loc) {
119-
if (!obj || !(name in obj)) {
119+
if (!obj || (typeof obj === 'object' && !(name in obj))) {
120120
throw new Exception('"' + name + '" not defined in ' + obj, {
121121
loc: loc,
122122
});

spec/strict.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ describe('strict', function () {
4848
});
4949

5050
xt.toThrow(Error);
51-
5251
xt.withRuntimeOptions({ data: { hello: 'foo' } }).toCompileTo('foo');
5352
});
5453

@@ -87,9 +86,7 @@ describe('strict', function () {
8786

8887
it('should allow undefined hash when passed to helpers', function () {
8988
expectTemplate('{{helper value=@foo}}')
90-
.withCompileOptions({
91-
strict: true,
92-
})
89+
.withCompileOptions({ strict: true })
9390
.withHelpers({
9491
helper: function (options) {
9592
equals('value' in options.hash, true);
@@ -100,6 +97,13 @@ describe('strict', function () {
10097
.toCompileTo('success');
10198
});
10299

100+
it('should allow compat-mode combined with strict-mode', function () {
101+
expectTemplate('Foo {{bar}}')
102+
.withCompileOptions({ compat: true, strict: true })
103+
.withInput({ bar: 'baz' })
104+
.toCompileTo('Foo baz');
105+
});
106+
103107
it('should show error location on missing property lookup', function () {
104108
expectTemplate('\n\n\n {{hello}}')
105109
.withCompileOptions({ strict: true })

0 commit comments

Comments
 (0)