Fix errors with strict lookup in compat mode (#2150)
Fixes #2149, fixes #1741
This commit is contained in:
@@ -1175,20 +1175,34 @@ function strictLookup(requireTerminal, compiler, parts, startPartIndex, type) {
|
||||
stack = compiler.nameLookup(stack, parts[i], type);
|
||||
}
|
||||
|
||||
if (requireTerminal) {
|
||||
if (!requireTerminal) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
if (startPartIndex > len) {
|
||||
// Compat mode already consumed all parts via depthedLookup; the stack
|
||||
// holds the resolved value, not an object to look the property up on.
|
||||
// Use container.strictLookup to traverse depths with a strict error on miss.
|
||||
return [
|
||||
compiler.aliasable('container.strict'),
|
||||
'(',
|
||||
stack,
|
||||
', ',
|
||||
compiler.aliasable('container.strictLookup'),
|
||||
'(depths, ',
|
||||
compiler.quotedString(parts[len]),
|
||||
', ',
|
||||
JSON.stringify(compiler.source.currentLocation),
|
||||
' )',
|
||||
];
|
||||
} else {
|
||||
return stack;
|
||||
}
|
||||
|
||||
return [
|
||||
compiler.aliasable('container.strict'),
|
||||
'(',
|
||||
stack,
|
||||
', ',
|
||||
compiler.quotedString(parts[len]),
|
||||
', ',
|
||||
JSON.stringify(compiler.source.currentLocation),
|
||||
' )',
|
||||
];
|
||||
}
|
||||
|
||||
export default JavaScriptCompiler;
|
||||
|
||||
@@ -116,6 +116,22 @@ export function template(templateSpec, env) {
|
||||
}
|
||||
return container.lookupProperty(obj, name);
|
||||
},
|
||||
strictLookup: function (depths, name, loc) {
|
||||
const len = depths.length;
|
||||
let depth;
|
||||
for (let i = 0; i < len; i++) {
|
||||
const d = depths[i];
|
||||
if (
|
||||
d &&
|
||||
(typeof d === 'object' || typeof d === 'function') &&
|
||||
name in d
|
||||
) {
|
||||
depth = d;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return container.strict(depth, name, loc);
|
||||
},
|
||||
lookupProperty: function (parent, propertyName) {
|
||||
if (Utils.isMap(parent)) {
|
||||
return parent.get(propertyName);
|
||||
|
||||
Reference in New Issue
Block a user