Skip to content

Commit be00757

Browse files
MartinMagajus
andauthored
feat: add support for ParenthesizedExpression in filter function (#27)
Co-authored-by: Gajus Kuizinas <gajus@gajus.com>
1 parent 111b640 commit be00757

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

src/internalFilter.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,16 @@ export const internalFilter = <T extends Object>(
257257
});
258258
}
259259

260+
if (ast.type === 'ParenthesizedExpression') {
261+
return internalFilter(
262+
ast.expression,
263+
rows,
264+
resultFast,
265+
path,
266+
highlights,
267+
);
268+
}
269+
260270
if (!ast.left) {
261271
throw new Error('Expected left to be defined.');
262272
}

test/liqe/filter.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ const persons: readonly Person[] = [
6060
phoneNumber: '404-050-2611',
6161
subscribed: true,
6262
},
63+
{
64+
height: 150,
65+
name: 'foo bar',
66+
nick: 'old dog',
67+
},
68+
{
69+
height: 194,
70+
name: 'fox',
71+
nick: 'quick fox',
72+
},
6373
];
6474

6575
const testQuery = test.macro((t, expectedResultNames: string[]) => {
@@ -90,14 +100,14 @@ test('height:[200 TO 225]', testQuery, ['robert', 'noah']);
90100
test('height:[200 TO 225}', testQuery, ['robert']);
91101
test('height:{220 TO 225}', testQuery, []);
92102

93-
test('NOT David', testQuery, ['john', 'mike', 'robert', 'noah']);
94-
test('-David', testQuery, ['john', 'mike', 'robert', 'noah']);
103+
test('NOT David', testQuery, ['john', 'mike', 'robert', 'noah', 'foo bar', 'fox']);
104+
test('-David', testQuery, ['john', 'mike', 'robert', 'noah', 'foo bar', 'fox']);
95105
test('David OR John', testQuery, ['david', 'john', 'noah']);
96106
test('Noah AND John', testQuery, ['noah']);
97107
test('John AND NOT Noah', testQuery, ['john']);
98-
test('David OR NOT John', testQuery, ['david', 'mike', 'robert']);
108+
test('David OR NOT John', testQuery, ['david', 'mike', 'robert', 'foo bar', 'fox']);
99109
test('John AND -Noah', testQuery, ['john']);
100-
test('David OR -John', testQuery, ['david', 'mike', 'robert']);
110+
test('David OR -John', testQuery, ['david', 'mike', 'robert', 'foo bar', 'fox']);
101111

102112
test('name:David OR John', testQuery, ['david', 'john', 'noah']);
103113

@@ -131,3 +141,9 @@ test('phoneNumber:"404-050-2611"', testQuery, ['noah']);
131141
test('phoneNumber:404', testQuery, ['noah']);
132142

133143
test('balance:364', testQuery, ['noah']);
144+
145+
test('(David)', testQuery, ['david']);
146+
test('(name:david OR name:john)', testQuery, ['david', 'john']);
147+
test('(name:"foo bar" AND nick:"quick fox") OR name:fox', testQuery, ['fox']);
148+
test('(name:fox OR name:"foo bar" AND nick:"old dog")', testQuery, ['foo bar']);
149+
test('(name:fox OR (name:"foo bar" AND nick:"old dog"))', testQuery, ['fox', 'foo bar']);

0 commit comments

Comments
 (0)