Skip to content

Commit

Permalink
queries: Clean up QueryTerm typing a bit by using undefined instead o…
Browse files Browse the repository at this point in the history
…f null

Signed-off-by: Kai Blin <[email protected]>
  • Loading branch information
kblin committed Aug 10, 2023
1 parent 177d6a9 commit 0601a9d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions src/models/__tests__/queries.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ describe("QueryTerm", () => {
it("stringifies only the left side of an op if the right side is invalid", () => {
const term = createOp("AND", createExpr(), new QueryTerm("expr"));
expect(term.toString()).toBe("{[alice|bob]}");
term.right = null;
term.right = undefined;
expect(term.toString()).toBe("{[alice|bob]}");
});
it("stringifies only the right side of an op if the left side is invalid", () => {
const term = createOp("AND", new QueryTerm("expr"));
expect(term.toString()).toBe("{[charlie|eve]}");
term.left = null;
term.left = undefined;
expect(term.toString()).toBe("{[charlie|eve]}");
});
});
Expand Down Expand Up @@ -132,7 +132,7 @@ describe("QueryTerm", () => {
describe("removeLeft", () => {
it("refuses to operate without a right term", () => {
const term = createOp();
term.right = null;
term.right = undefined;
expect(() => term.removeLeft()).toThrowError(QueryTermError);
});
it("creates an expr when right is an expr", () => {
Expand Down Expand Up @@ -161,7 +161,7 @@ describe("QueryTerm", () => {
describe("removeRight", () => {
it("refuses to operate without a left term", () => {
const term = createOp();
term.left = null;
term.left = undefined;
expect(() => term.removeRight()).toThrowError(QueryTermError);
});
it("creates an expr when left is an expr", () => {
Expand Down
30 changes: 15 additions & 15 deletions src/models/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,13 @@ export class QueryTerm {
termType: string;

// termType == "op"
operation: string | null = null;
left: QueryTerm | null = null;
right: QueryTerm | null = null;
operation?: string = undefined;
left?: QueryTerm = undefined;
right?: QueryTerm = undefined;

// termType == "expr"
category: string = "";
value: string | number | QueryModuleTerm | null = null;
value?: string | number | QueryModuleTerm = undefined;
filters: QueryFilter[] = [];
count: number = 1;

Expand All @@ -241,7 +241,7 @@ export class QueryTerm {
this.right = new QueryTerm("expr");

this.category = "";
this.value = null;
this.value = undefined;
this.filters.length = 0;
this.count = 1;
}
Expand All @@ -264,9 +264,9 @@ export class QueryTerm {
this.filters = this.right.filters;
this.count = this.right.count;

this.left = null;
this.right = null;
this.operation = null;
this.left = undefined;
this.right = undefined;
this.operation = undefined;
return;
}
this.operation = this.right.operation;
Expand All @@ -286,9 +286,9 @@ export class QueryTerm {
this.filters = this.left.filters;
this.count = this.left.count;

this.left = null;
this.right = null;
this.operation = null;
this.left = undefined;
this.right = undefined;
this.operation = undefined;
return;
}
this.operation = this.left.operation;
Expand Down Expand Up @@ -377,12 +377,12 @@ export class QueryTerm {

clear() {
this.termType = "expr";
this.left = null;
this.right = null;
this.operation = null;
this.left = undefined;
this.right = undefined;
this.operation = undefined;
this.category = "";
this.filters.length = 0;
this.value = null;
this.value = undefined;
this.count = 1;
}
}
Expand Down

0 comments on commit 0601a9d

Please sign in to comment.