From ff3cc7930e9fd4bfb2f89a6fd7bcd0ed2b196f19 Mon Sep 17 00:00:00 2001 From: David Majda Date: Fri, 23 Sep 2016 06:30:52 +0200 Subject: [PATCH] CSS Example: Move null filtering from extractList to buildList This makes extractList identical to the same function in other grammars and makes it so that nulls are dealt with in only one function (until now, they were dealt with both in extractList and buildList). The refactoring should be safe as extractList isn't by itself used in contexts where it can be passed a list containing nulls. --- examples/css.pegjs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/css.pegjs b/examples/css.pegjs index ceba571..1199cff 100644 --- a/examples/css.pegjs +++ b/examples/css.pegjs @@ -23,13 +23,12 @@ } function extractList(list, index) { - return list - .map(function(element) { return element[index]; }) - .filter(function(element) { return element !== null; }); + return list.map(function(element) { return element[index]; }); } function buildList(head, tail, index) { - return (head !== null ? [head] : []).concat(extractList(tail, index)); + return [head].concat(extractList(tail, index)) + .filter(function(element) { return element !== null; }); } function buildExpression(head, tail) {