commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henri Biestro (Jira)" <>
Subject [jira] [Commented] (JEXL-307) Variable redeclaration option
Date Tue, 01 Oct 2019 13:54:00 GMT


Henri Biestro commented on JEXL-307:

Of course, the behaviour wrt local variables / parameters is what you describe (besides your
penultimate example which is not allowed for the same reason the 2nd is not, if or no-if or
for or while). 

I'll restate we only have 2 scopes today; global variables (JexlContext) and local variables
whose scope is the whole function/lambda after their point of declaration. Locals so far have
the weak(er) Javascript-like 'var' semantic. The idea is to allow turning gracefully to a
'let'-like one (aka lexical scope) without adding yet another keyword. Pretty much the same
rules Java or C apply wrt to local variable definition in this mode. The solution will *not*
change any existing behaviour, current code under current configuration will run the same

Setting the lexical feature - at JexlEngine construction time - and/or the lexical option
- plus at script evaluation time - will trigger the new semantic on variable scopes. Using
the option, it will be even possible to turn it on/off in the script itself through a pragma.

This allows existing users dealing with huge scripts to easily control the pace of deploying
this lexical semantic.

> Variable redeclaration option
> -----------------------------
>                 Key: JEXL-307
>                 URL:
>             Project: Commons JEXL
>          Issue Type: New Feature
>    Affects Versions: 3.1
>            Reporter: Dmitri Blinov
>            Assignee: Henri Biestro
>            Priority: Minor
>             Fix For: 3.2
> As of now, JEXL allows a script writer to redeclare a local variable during script evaluation.
> {code:java}
> var a = 1; var a = 2;{code}
> This may lead to potential errors with misspelled names and clashed variables. Checking
for already defined variable is a common feature of many languages. This feature can be implemented
in JEXL as an additional option of JexlFeatures class, enabled by default, thus allowing compatibility
with existing code.

This message was sent by Atlassian Jira

View raw message