Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "Expected left to be defined." error in filter function for parenthesized expressions #27

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/internalFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,16 @@ export const internalFilter = <T extends Object>(
});
}

if (ast.type === 'ParenthesizedExpression') {
return internalFilter(
ast.expression,
rows,
resultFast,
path,
highlights,
);
}

if (!ast.left) {
throw new Error('Expected left to be defined.');
}
Expand Down
24 changes: 20 additions & 4 deletions test/liqe/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ const persons: readonly Person[] = [
phoneNumber: '404-050-2611',
subscribed: true,
},
{
height: 150,
name: 'foo bar',
nick: 'old dog',
},
{
height: 194,
name: 'fox',
nick: 'quick fox',
},
];

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

test('NOT David', testQuery, ['john', 'mike', 'robert', 'noah']);
test('-David', testQuery, ['john', 'mike', 'robert', 'noah']);
test('NOT David', testQuery, ['john', 'mike', 'robert', 'noah', 'foo bar', 'fox']);
test('-David', testQuery, ['john', 'mike', 'robert', 'noah', 'foo bar', 'fox']);
test('David OR John', testQuery, ['david', 'john', 'noah']);
test('Noah AND John', testQuery, ['noah']);
test('John AND NOT Noah', testQuery, ['john']);
test('David OR NOT John', testQuery, ['david', 'mike', 'robert']);
test('David OR NOT John', testQuery, ['david', 'mike', 'robert', 'foo bar', 'fox']);
test('John AND -Noah', testQuery, ['john']);
test('David OR -John', testQuery, ['david', 'mike', 'robert']);
test('David OR -John', testQuery, ['david', 'mike', 'robert', 'foo bar', 'fox']);

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

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

test('balance:364', testQuery, ['noah']);

test('(David)', testQuery, ['david']);
test('(name:david OR name:john)', testQuery, ['david', 'john']);
test('(name:"foo bar" AND nick:"quick fox") OR name:fox', testQuery, ['fox']);
test('(name:fox OR name:"foo bar" AND nick:"old dog")', testQuery, ['foo bar']);
test('(name:fox OR (name:"foo bar" AND nick:"old dog"))', testQuery, ['fox', 'foo bar']);
Loading