From 0ac924c6b67850003dcb221cb961afa25d5b8771 Mon Sep 17 00:00:00 2001 From: Gilles Coomans Date: Tue, 18 Apr 2017 18:43:49 +0200 Subject: [PATCH] fix(meta-api): finalise each for tests --- src/babelute.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/babelute.js b/src/babelute.js index f4bcf9c..59f609a 100644 --- a/src/babelute.js +++ b/src/babelute.js @@ -134,16 +134,17 @@ export class Babelute { */ _each(array, func) { - assert(Array.isArray(array) || array.length, '._each meta-api need an array (or iterable with bracket access) as first argument'); + assert(!array || Array.isArray(array), '._each meta-api need an array (or iterable with bracket access) as first argument'); assert(typeof func === 'function', '._each meta-api need a function as second argument'); - array.forEach((item, index) => { - const b = func(item, index); + if (array) + array.forEach((item, index) => { + const b = func(item, index); - assert(b instanceof Babelute, '._each need a function that return a babelute'); + assert(b instanceof Babelute, '._each need a function that return a babelute'); - this._lexems.push.apply(this._lexems, b._lexems); - }); + this._lexems.push.apply(this._lexems, b._lexems); + }); return this; }