From e49f202fac92142de2a7b04911be7bd06378f60f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20Blo=CC=88mer?= Date: Fri, 5 Jan 2024 16:03:22 +0100 Subject: [PATCH] Upgrade to jexl 3.3 --- .../expression/GraalJsExpressionHandler.java | 1 - .../pug4j/expression/JexlExpressionHandler.java | 2 ++ .../expression/JexlExpressionHandlerTest.java | 16 +++++++++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/neuland/pug4j/expression/GraalJsExpressionHandler.java b/src/main/java/de/neuland/pug4j/expression/GraalJsExpressionHandler.java index bf53553..f642e54 100644 --- a/src/main/java/de/neuland/pug4j/expression/GraalJsExpressionHandler.java +++ b/src/main/java/de/neuland/pug4j/expression/GraalJsExpressionHandler.java @@ -14,7 +14,6 @@ import static org.graalvm.polyglot.HostAccess.newBuilder; public class GraalJsExpressionHandler extends AbstractExpressionHandler { - JexlExpressionHandler jexlExpressionHandler = new JexlExpressionHandler(); final HostAccess all = newBuilder().allowAllImplementations(true).allowPublicAccess(true).allowArrayAccess(true).allowListAccess(true).allowMapAccess(true) .targetTypeMapping(Integer.class, Object.class, null, (v) -> v) .targetTypeMapping(Long.class, Object.class, null, (v) -> v) diff --git a/src/main/java/de/neuland/pug4j/expression/JexlExpressionHandler.java b/src/main/java/de/neuland/pug4j/expression/JexlExpressionHandler.java index b93d8f6..fccf8b9 100644 --- a/src/main/java/de/neuland/pug4j/expression/JexlExpressionHandler.java +++ b/src/main/java/de/neuland/pug4j/expression/JexlExpressionHandler.java @@ -101,6 +101,8 @@ private String convertPlusPlusExpression(String expression) { private String removeVar(String expression) { expression = expression.replace("var ",";"); + expression = expression.replace("let ",";"); + expression = expression.replace("const ",";"); return expression; } diff --git a/src/test/java/de/neuland/pug4j/expression/JexlExpressionHandlerTest.java b/src/test/java/de/neuland/pug4j/expression/JexlExpressionHandlerTest.java index c05b2cc..3c90d54 100644 --- a/src/test/java/de/neuland/pug4j/expression/JexlExpressionHandlerTest.java +++ b/src/test/java/de/neuland/pug4j/expression/JexlExpressionHandlerTest.java @@ -93,11 +93,25 @@ public void testReturn() throws ExpressionException { } @Test - public void testInt() throws ExpressionException { + public void testIntVar() throws ExpressionException { jexlExpressionHandler.evaluateExpression("var count = 5; var count2 = 6;", pugModel); int count = (int) pugModel.get("count"); assertEquals(5,count); + } + @Test + public void testIntLet() throws ExpressionException { + jexlExpressionHandler.evaluateExpression("let count = 5; let count2 = 6;", pugModel); + int count = (int) pugModel.get("count"); + assertEquals(5,count); + + } + @Test + public void testIntConst() throws ExpressionException { + jexlExpressionHandler.evaluateExpression("const count = 5; const count2 = 6;", pugModel); + int count = (int) pugModel.get("count"); + assertEquals(5,count); + } @Test public void testDoubleModel() throws ExpressionException {