From f415189c985d1757d8b14e741855ed4fe094905b Mon Sep 17 00:00:00 2001 From: Kaz Namba Date: Wed, 18 Apr 2018 00:30:01 +0900 Subject: [PATCH] fix: always return one of items in the array Modifications on v0.1.4 fail unit tests - so fix selector.js to call callback function with one of items matched --- lib/selector.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/selector.js b/lib/selector.js index 7646af35f..c69ebf910 100644 --- a/lib/selector.js +++ b/lib/selector.js @@ -24,8 +24,12 @@ module.exports = function (content) { let part = parts[type] if (Array.isArray(part)) { - part = part.filter(p => p.attrs.hasOwnProperty(query.native ? 'native' : 'web')) - part = part[query.index] || parts[query.type] + const filtered = part.filter(p => p.attrs.hasOwnProperty(query.native ? 'native' : 'web')) + if (query.index < filtered.length) { + part = filtered[query.index] + } else { + part = part[query.index] + } } this.callback(null, part.content, part.map) }