Skip to content

Commit

Permalink
[IMP] compiler: add support for binary operators
Browse files Browse the repository at this point in the history
  • Loading branch information
ged-odoo authored and aab-odoo committed Jun 24, 2022
1 parent c7459ef commit 7f580a4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/compiler/inline_expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ const STATIC_TOKEN_MAP: { [key: string]: TKind } = Object.assign(Object.create(n

// note that the space after typeof is relevant. It makes sure that the formatted
// expression has a space after typeof. Currently we don't support delete and void
const OPERATORS = "...,.,===,==,+,!==,!=,!,||,&&,>=,>,<=,<,?,-,*,/,%,typeof ,=>,=,;,in ,new ".split(
","
);
const OPERATORS =
"...,.,===,==,+,!==,!=,!,||,&&,>=,>,<=,<,?,-,*,/,%,typeof ,=>,=,;,in ,new ,|,&,^,~".split(",");

type Tokenizer = (expr: string) => Token | false;

Expand Down
7 changes: 7 additions & 0 deletions tests/compiler/inline_expressions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,11 @@ describe("expression evaluation", () => {
expect(compileExpr("a.c in b")).toBe("ctx['a'].c in ctx['b']");
expect(compileExpr("typeof val")).toBe("typeof ctx['val']");
});

test("binary operators", () => {
expect(compileExpr("1 | 1")).toBe("1|1");
expect(compileExpr("1 & 1")).toBe("1&1");
expect(compileExpr("1 ^ 1")).toBe("1^1");
expect(compileExpr("~1")).toBe("~1");
});
});

0 comments on commit 7f580a4

Please sign in to comment.