From a77e462105ce90634ee6a5537eb34aa013ecdea6 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 3 Dec 2016 15:55:37 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20#2402=20make=20sure=20a=20given=20elemen?= =?UTF-8?q?t=20isn=E2=80=99t=20undefined=20before=20accessing=20properties?= =?UTF-8?q?=20(#2403)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/util.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) 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; -} +};