diff --git a/lib/util.js b/lib/util.js index 22deac1d..54d68bf7 100644 --- a/lib/util.js +++ b/lib/util.js @@ -1488,17 +1488,19 @@ exports.topMost = function (pile, accessors) { accessors = [accessors]; } for (const member of pile) { - candidate = member[accessors[0]]; - for (let i = 1; i < accessors.length; i++){ + if (member) { + candidate = member[accessors[0]]; + for (let i = 1; i < accessors.length; i++){ + if (candidate) { + candidate = candidate[accessors[i]] + } else { + continue; + } + } if (candidate) { - candidate = candidate[accessors[i]] - } else { - continue; + break; } } - if (candidate) { - break; - } } return candidate; -} +};