From 7f580a4e1d6f081566f3b51387319be790304fd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Fri, 24 Jun 2022 15:25:47 +0200 Subject: [PATCH] [IMP] compiler: add support for binary operators --- src/compiler/inline_expressions.ts | 5 ++--- tests/compiler/inline_expressions.test.ts | 7 +++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/compiler/inline_expressions.ts b/src/compiler/inline_expressions.ts index cca8c2f49..21fcfcde9 100644 --- a/src/compiler/inline_expressions.ts +++ b/src/compiler/inline_expressions.ts @@ -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; diff --git a/tests/compiler/inline_expressions.test.ts b/tests/compiler/inline_expressions.test.ts index 06f71c8a5..b375da9f1 100644 --- a/tests/compiler/inline_expressions.test.ts +++ b/tests/compiler/inline_expressions.test.ts @@ -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"); + }); });