[IMP] compiler: add better support for "in" and "new" operators

Previously, the support for the "in" operator was iffy, and "new" was
not supported at all, "in" would fail when checking if a nested property
was in something else, as the leading space would be stripped, and "new"
would fail because the following space would be stripped.

This commit fixes that by preserving the significant whitespace where
necessary.
This commit is contained in:
Samuel Degueldre
2022-05-18 16:06:52 +02:00
committed by Géry Debongnie
parent 4c77132ae2
commit d917af4614
2 changed files with 15 additions and 4 deletions
+7 -1
View File
@@ -135,7 +135,7 @@ describe("expression evaluation", () => {
expect(compileExpr("color === 'black'")).toBe("ctx['color']==='black'");
expect(compileExpr("'li_'+item")).toBe("'li_'+ctx['item']");
expect(compileExpr("state.val > 1")).toBe("ctx['state'].val>1");
expect(compileExpr("a in b")).toBe("ctx['a']in ctx['b']");
expect(compileExpr("a in b")).toBe("ctx['a'] in ctx['b']");
});
test("boolean operations", () => {
@@ -215,4 +215,10 @@ describe("expression evaluation", () => {
expect(compileExpr("[a, {b, c},d]")).toBe("[ctx['a'],{b:ctx['b'],c:ctx['c']},ctx['d']]");
expect(compileExpr("{a:[b, {c, d: e}]}")).toBe("{a:[ctx['b'],{c:ctx['c'],d:ctx['e']}]}");
});
test("preserving spaces where needed for text operators", () => {
expect(compileExpr("new Date()")).toBe("new Date()");
expect(compileExpr("a.c in b")).toBe("ctx['a'].c in ctx['b']");
expect(compileExpr("typeof val")).toBe("typeof ctx['val']");
});
});