[ 
https://issues.apache.org/jira/browse/JEXL-367?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17539002#comment-17539002
 ] 

Dmitri Blinov commented on JEXL-367:
------------------------------------

There are a couple of notes on current named function implementation, if you 
don't mind...

It seems Jexl treats named functions like expressions, not statments. This 
allows a little weird syntax like
{code:java}
    @Test
    public void testNamedFuncIsExpr() {
        String src = "var i = function foo(x) { x + x }; i(6)";
        JexlEngine jexl = createEngine();
        JexlScript script = jexl.createScript(src);
        Object result = script.execute(null);
        Assert.assertEquals(12, result);
    }
 {code}
Also, since declaring a named function means to implicitly declare a variable, 
then logically, local variable declaration feature should be checked, to see if 
we are allowed to do so in our context, for example if we are evaluating a 
simple expression.

Moreover, since we are declaring a lexical variable with named function, then I 
think, in analogy with `var` we should restrict conditional single-statement 
declarations to avoid strange errors like in example
{code:java}
    @Test
    public void testNamedFuncConditional() {
        String src = "if (false) function foo(x) { x + x }; var foo = 1";
        JexlEngine jexl = createEngine();
        JexlScript script = jexl.createScript(src);
        Object result = script.execute(null);
        Assert.assertEquals(1, result);
    }
 {code}

> Named function and fat-arrow (=>) lambda syntax
> -----------------------------------------------
>
>                 Key: JEXL-367
>                 URL: https://issues.apache.org/jira/browse/JEXL-367
>             Project: Commons JEXL
>          Issue Type: Wish
>    Affects Versions: 3.2.1
>            Reporter: Hussachai Puripunpinyo
>            Assignee: Henri Biestro
>            Priority: Major
>
> The JEXL code surprisingly looks a lot like Javascript. I think this change 
> is a good transition for folks to update the code, and it's pretty fine if 
> they can tolerate using the deprecate syntax and don't mind seeing a warning 
> log pop up every time. 
> I'd like to propose supporting => and deprecate ->.
> The reasons are
>  - JavaScript becomes very popular and many people are familiar with it.
>  - JEXL is more like for a quick short script. In many scenarios, the target 
> audiences are not a programer. They often mistake a language as a JavaScript 
> (from my experience).
>  - JEXL syntax already looks a lot like JavaScript
>  -- var for variable declaration (Java added in Java 10, but JavaScript 
> supports this from the beginning)
>  -- The function keyword
>  -- Implicit type coercion
>  -- Ternary operator
> The proposed change.
>  * Support => in addition to ->
>  * Deprecate -> and show a warning log when it's used.



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to