[jira] [Commented] (JEXL-307) Variable redeclaration option

2020-06-11 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


Changeset: 066919bec45d8d65dcf2f7d8f1ad890efeb4b6e1
Author:henrib 
Date:  2020-06-11 16:41
Message:   JEXL-307: commented templates throw NPE due to missing expected scope

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> Project: Commons JEXL
>  Issue Type: New Feature
>Affects Versions: 3.1
>Reporter: Dmitri Blinov
>Assignee: Henri Biestro
>Priority: Major
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2020-02-08 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


Changeset: aaaf8424def2f4aff85fe80cc5a7efc7d5df12ff
Author:henrib 
Date:  2020-02-08 11:21
Message:   JEXL-307: added another test

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> Project: Commons JEXL
>  Issue Type: New Feature
>Affects Versions: 3.1
>Reporter: Dmitri Blinov
>Assignee: Henri Biestro
>Priority: Major
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2020-02-08 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


The context is null; try:
{code:java}
...
JexlContext jc = new MapContext();
jc.set("x", 11);
Object result = script.execute(jc); // a context where 'x' is defined
...{code}

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> Project: Commons JEXL
>  Issue Type: New Feature
>Affects Versions: 3.1
>Reporter: Dmitri Blinov
>Assignee: Henri Biestro
>Priority: Major
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2020-02-07 Thread Dmitri Blinov (Jira)


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

Dmitri Blinov commented on JEXL-307:


The following test case fails with - *_variable 'x' is undefined_*
{code:java}
@Test
public void testCapturedShaded() throws Exception {
JexlFeatures f = new JexlFeatures();
f.lexical(true);
JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
JexlScript script = jexl.createScript("{var x = 10; } var a = 
function(var b) {for (var q : 1 ..10) {return x + b}}; a(32)");
JexlContext jc = new MapContext();
jc.set("x", 11);
Object result = script.execute(null);
Assert.assertEquals(result, 43);
}
{code}
The expected behaviour is to resolve context variable 'x'

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> Project: Commons JEXL
>  Issue Type: New Feature
>Affects Versions: 3.1
>Reporter: Dmitri Blinov
>Assignee: Henri Biestro
>Priority: Major
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2020-01-21 Thread Dmitri Blinov (Jira)


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

Dmitri Blinov commented on JEXL-307:


And one more thing... hoisted variables are not resolved in nested blocks - 
_*variable 'x' is undefined*_
{code:java}
@Test
public void testHoisted() throws Exception {
JexlFeatures f = new JexlFeatures();
f.lexical(true);
JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
JexlScript script = jexl.createScript("var x = 10; var a = function(var 
b) {for (var q : 1 ..10) {return x + b}}; a(32)");
JexlContext jc = new MapContext();
Object result = script.execute(null);
Assert.assertEquals(result, 42);
}
 {code}
If the lexical feature is switched off everything works OK.

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2020-01-20 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


Changeset: f0942719bf96487596fa71f0b7fdcc1d004c34e0
Author:henrib 
Date:  2020-01-20 17:12
Message:   JEXL-307: fixing regression, parameter declaration under lexical 
feature

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2020-01-20 Thread Dmitri Blinov (Jira)


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

Dmitri Blinov commented on JEXL-307:


It seems I have found a nasty regression - the code below fails with _*x: 
variable is already defined*_
{code:java}
@Test
public void testNamed() throws Exception {
JexlFeatures f = new JexlFeatures();
f.lexical(true);
JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
JexlScript script = jexl.createScript("var i = function(x, y, z) 
{return x + y + z}; i(20,20,2)");
JexlContext jc = new MapContext();
Object result = script.execute(jc);
Assert.assertEquals(result, 42);
}
{code}
If the lexical feature is switched *off* everything works OK.

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2020-01-16 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


Changeset: 8f78f4580341ca2edf17c0eae1cf9f36f39c28f5
Author:henrib 
Date:  2020-01-16 14:35
Message:   JEXL-307: better detection of shaded variables

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2020-01-14 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


Changeset: 9d1898392323ead2b26040f1f3cf23ee5e4570f7
Author:henrib 
Date:  2020-01-14 11:05
Message:   JEXL-307: refactored test

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2020-01-07 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


Changeset: 55ba9f5f5ca4a76883ea5ccff0f54a2b3d770470
Author:henrib 
Date:  2019-12-20 13:15
Message:   JEXL-307: fix features being lost during parsing

Changeset: 0d0e58305b87cfe8fe26aa8c8abcf8c351917abd
Author:henrib 
Date:  2020-01-07 15:08
Message:   JEXL-307: fix usage of outer defined var in inner block

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-12-18 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


Changeset: 676448c88b58ed49a97f7284d5dcee57258da08f
Author:henrib 
Date:  2019-12-18 16:59
Message:   JEXL-307: nitpicking on options handling

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-12-11 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


Changeset: 805b5c6b121e7a7cdd866fe2888b243a79b8cda6
Author:henrib 
Date:  2019-12-11 22:35
Message:   JEXL-307: javadoc typo

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-12-11 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


Changeset: 7cbcc66519325d23bb16ee6e2da63c9030ef7923
Author:henrib 
Date:  2019-12-11 22:27
Message:   JEXL-307: added lexical shade flag to features, aligned with options 
semantics

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-12-10 Thread Dmitri Blinov (Jira)


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

Dmitri Blinov commented on JEXL-307:


Options are OK. The test case to illustrate the problem is this
{code:java}
@Test
public void testLexical6a1() throws Exception {
String str = "i = 0; { var i = 32; }; i";
JexlFeatures f = new JexlFeatures();
f.lexical(true);
JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
JexlScript e = jexl.createScript(str);
JexlContext ctxt = new MapContext();
Object o = e.execute(ctxt);
Assert.assertEquals(0, o);
}{code}
The above test case fails with - variable is not defined. I understand the 
intention was good - to check for variables that are out of scope. But in 
practice it has become a severe restriction, with no way to disable.

Compare it with existing test case, which is OK and is an example of what I 
wish we could somehow achieve with lexical *feature* enabled.
{code:java}
@Test
public void testLexical6a() throws Exception {
String str = "i = 0; { var i = 32; }; i";
JexlEngine jexl = new JexlBuilder().strict(true).lexical(true).create();
JexlScript e = jexl.createScript(str);
JexlContext ctxt = new MapContext();
Object o = e.execute(ctxt);
Assert.assertEquals(0, o);
} {code}
I'm not in favor of creating as much additional features as possible. If we 
could just *align* behaviour of lexical feature with that of lexical option, 
there would be no need for a new feature to disable that variable check.

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-12-10 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


We already have 2 options, lexical and lexicalShade; the former deals with 
definition scope rules, the latter deals with local variable definitions 
shading global ones. At least, this is the intent.

These are option flags (as in JexlOptions); the lexical feature (as in 
JexlFeatures) will fail parsing on variable redefinition only.

What am I missing ? Test case will help :)

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-12-06 Thread Dmitri Blinov (Jira)


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

Dmitri Blinov commented on JEXL-307:


Now that everything works as expected I wonder whether it is possible to 
decouple undeclared variable check in lexical mode from lexical mode itself. 
Can we make undeclared variable check a separate JEXL feature? The problem is 
that now, when lexical feature is enabled, once the variable with the name 
'foo' has been declared, there is no way to access context variable with the 
same name, which requires to completely rewrite and check whole script - this 
addes up additional migration pains.

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-12-03 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


Changeset: 0d51930407eed691e11dc2767f34ef5df6cbf4b8
Author:henrib 
Date:  2019-12-03 22:08
Message:   JEXL-307: fixed lexical feature handling of variable scope in for 
units (take 3)

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-12-03 Thread Dmitri Blinov (Jira)


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

Dmitri Blinov commented on JEXL-307:


Maybe I do not fully understand what the lexical feature is all about, but from 
the previous test case I've learned the idea was to control the access to 
undeclared local variables. If I'm right, then the following test case should 
also pass, but it doesn't.
{code:java}
@Test
public void testForVariable() throws Exception {
JexlFeatures f = new JexlFeatures();
f.lexical(true);
JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
try {
JexlScript script = jexl.createScript("for(var x : 1..3) { var c = 
0}; return x");
Assert.fail("Should not have been parsed");
} catch (Exception ex) {
   // OK
}
}
 {code}

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-12-02 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


Changeset: 53e5e77cc9ec42c96840c8f4ae04dc500e0baf63
Author:henrib 
Date:  2019-12-02 17:09
Message:   JEXL-307: fixed lexical feature handling of variable scope in 
for/lambda units

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-29 Thread Dmitri Blinov (Jira)


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

Dmitri Blinov commented on JEXL-307:


The following test fails with *undefined variable x* in most inner block;
{code:java}
@Test
public void testInnerAccess() throws Exception {
JexlFeatures f = new JexlFeatures();
f.lexical(true);
JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
JexlScript script = jexl.createScript("var x = 32; (()->{ for(var x : 
null) { var c = 0; {return x; }} })();");
}
{code}
Interestingly, the next test case passes successfully
{code:java}
@Test
public void testInnerAccess() throws Exception {
JexlEngine jexl = new JexlBuilder().strict(true).lexical(true).create();
JexlScript script = jexl.createScript("var x = 32; (()->{ for(var x : 
null) { var c = 0; {return x; }} })();");
}
{code}

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-28 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


Changeset: 4f1a6d15e8a9a837b4e2326f74a44a8632163559
Author:henrib 
Date:  2019-11-28 17:09
Message:   JEXL-307: handle top-level lambda creation consistently

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-28 Thread Dmitri Blinov (Jira)


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

Dmitri Blinov commented on JEXL-307:


The following test case fails with undefined variable x
{code:java}
@Test
public void testParameter() throws Exception {
JexlEngine jexl = new JexlBuilder().strict(true).lexical(true).create();
JexlContext jc = new MapContext();
String strs = "var s = function(x) { for (var i : 1..3) {if (i > 2) 
return x}}; s(42)";
JexlScript s42 = jexl.createScript(strs);
Object result = s42.execute(jc);
Assert.assertEquals(42, result);
}
 {code}

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-28 Thread Dmitri Blinov (Jira)


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

Dmitri Blinov commented on JEXL-307:


I've got a regression with recent changes. For some reason the script created 
with JexlInfo fails to report declared parameters and local variables. The 
following test case illustrates this
{code:java}
@Test
public void testParameters() throws Exception {
String str = "function(u) {}";
JexlEngine jexl = new JexlBuilder().create();
JexlScript e = jexl.createScript(new JexlInfo("TestScript", 1, 1), str);
Assert.assertEquals(1, e.getParameters().length);
}   
{code}

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-19 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


Changeset: 2b63192c9485c75ea2cfff51bb6d153479a1c7ea
Author:henrib 
Date:  2019-11-19 11:42
Message:   JEXL-307: added test case on contextually exposed options

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-19 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


The story could read as: as a script developer, I need a controllable migration 
path from 3.1 to 3.2 by being able to turn the lexical/shade/antish flags 
on/off from scripts.

This can not be achieved through features since these apply at parsing time; 
this is readily achieved through pragmas. Some script devs want to manipulate 
these at runtime (through contextually exposed options and not only pragmas) so 
they can, from their end, automate +non-regression testing+ ; this feature +is+ 
considered pretty +useful+.

I'm adding a unit test to illustrate their use case. Hopefully, this will make 
you embrace the usefulness of the current design.

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-18 Thread Dmitri Blinov (Jira)


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

Dmitri Blinov commented on JEXL-307:


Please don't get me wrong, I'm very grateful for all what you have been doing, 
but as a thought - now we are adding a new option to mitigate other options. 
Options are great to be changed on the fly, for example - there is nothing 
wrong to use different calculation precision or rounding mode in one part of 
the script, thats why we did it configurable via context in 3.1. But lexical 
option is another story - in my opinion the ability to enable/disable lexical 
option is pretty much useless. May be its better to have it as a lexical 
feature with a level - runtime/syntax?

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-18 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


Changeset: 854387184da4044769669e84235d1ef4d7f8f43b
Author:henrib 
Date:  2019-11-18 17:41
Message:   JEXL-307: as a default, copy options handled of context used at 
runtime to reduce the possibility of artificially complex mistakes;  add an 
explicit flag to still allow purposeful usage
Task #JEXL-307 - Variable redeclaration option

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-18 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


You are right and this is actually true for (m)any of these flags (antish, 
lexical shade, strict arithmetic...); consequently, an unreachable/immutable 
copy of the JexlOptions will be used during execution. This will remove many 
possibilities of mistakes.

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-18 Thread Dmitri Blinov (Jira)


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

Dmitri Blinov commented on JEXL-307:


The problem is that by allowing lexical option to be dynamically 
enabled/disabled we are creating controversy that does not help in any way with 
initial intention of finding bugs. Consider the following, exaggerated and 
artificial, example
{code:java}
@Test
public void testLexicalOption() throws Exception {
JexlEngine jexl = new JexlBuilder().strict(true).lexical(true).create();
JexlEvalContext ctxt = new JexlEvalContext();
JexlOptions options = ctxt.getEngineOptions();
ctxt.set("options", options);
JexlScript script = jexl.createScript("{var x = 42;} options.lexical = 
false; x");
Object result = script.execute(ctxt);
Assert.assertNull(result);
}
 {code}
What should we expect as a result here? Until {{options.lexical = false}} we 
were in lexical mode, so one might think that once the block finished no 
variables should be visible and what't more critical - have any value. By 
allowing to change the mode on the fly, we are asking for trouble...

We may spend some more effort to try to fix this particular case, to allow 
lexical mode to coexist with non-lexical, but globally I think we should not 
mix the two. At least once we parsed the script with lexical feature enabled, 
there is no point in allowing it to be disabled via options.

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-16 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


I may be missing your actual question but just because the lexical feature is 
not equivalent to the lexical option. 

Having seen many very heavy scripts (>2000 lines) and the most common source of 
bugs, any _brand new_ solution using scripts should use the lexical feature and 
"+lexical +lexicalShade -safe +strict" options IMHO.

The lexical feature throws a *parsing* exception when a variable is redeclared 
whilst the lexical option throws exceptions at *execution* time (and that 
option can be enabled/disabled at will through the jexl.options pragma). If 
scripts are created before being used, the former fails at construction time - 
and may prevent a whole app to start -, the latter at runtime - which may fail 
some operation of that same app.

Considering any _existing_ solution using scripts, a smooth migration towards 
using 3.2 safer scripting capabilities and the implied refactoring needs to be 
achievable one script at a time; the current JEXL-307 implementation fits that 
purpose.

(Production, migration, upgrade, support, legacy, resilience, stability... 
burden vectors  :)) 

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-15 Thread Dmitri Blinov (Jira)


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

Dmitri Blinov commented on JEXL-307:


Grait, but why not to remove JexlOptions.isLexical/setLexical alltogether ?

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-14 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


Changeset: 95cc01a1528af6a6f7ce10f9a77ab39d92068537
Author:henrib 
Date:  2019-11-14 14:35
Message:   JEXL-307: ensure lexical interpretation on lexical feature

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-14 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


Good thinking, thanks.

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-13 Thread Dmitri Blinov (Jira)


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

Dmitri Blinov commented on JEXL-307:


Regarding new commit and new {{Lexical}} class which extends {{Stript}}. We 
have {{Closure}} class which also extends from {{Script}}. I haven't tested it, 
but does it mean the {{Closure}} will not support lexical feature?

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-11 Thread Dmitri Blinov (Jira)


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

Dmitri Blinov commented on JEXL-307:


Regarding Options API cleanup - what is the purpose of having lexical option 
both at context level and at parsing level? I mean its easy to get in trouble 
by, for example parsing, the script in lon-lexical mode and later executing it 
with lexical option enabled. I haven't tested this mix, but sure there will be 
unexpected results... Should we better bind this to the script whether it was 
in lexical mode or not at parsing time?

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-07 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


About EQ / NE, I believe this is part of JEXL-314 fix that got mixed up. 
Rolling back the change will probably tell...

About the copying of options, working on it; not satisfied with this part of 
the API yet.

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-07 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


Changeset: 40fd2139424f5e07cf1be149e36d2dbbc1c85436
Author:henrib 
Date:  2019-11-07 18:31
Message:   JEXL-307: clean up lexical frames after usage, fixed for-loops 
lexical handling (take 2), added method to change default options in builder, 
updated tests to resist default option switch

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-07 Thread Dmitri Blinov (Jira)


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

Dmitri Blinov commented on JEXL-307:


One more thing... 

The {{lexical}} option is not copied from JEXL instance in 
{{Options.set(JexlEngine jexl)}} and constructor {{Options(JexlOptions opts)}}

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-07 Thread Dmitri Blinov (Jira)


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

Dmitri Blinov commented on JEXL-307:


Now it basically works. 
BTW, What is the purpose of making {{EQ}} and {{NE}} operators ternary 
protected with regard to lexical handling? I have noticed the silent change in 
code...

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-05 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


Changeset: 0a9ddb9065a1c25a80b99c05bbad126845c4d16f
Author:henrib 
Date:  2019-11-05 22:41
Message:   JEXL-307: clean up lexical frames after usage, fixed template & 
for-loops lexical handling

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-04 Thread Dmitri Blinov (Jira)


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

Dmitri Blinov commented on JEXL-307:


In current implementation the example above returns 1, the value of local 
variable that should be already out of scope. The expected behaviour is to 
return 0, the value of context variable

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-04 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


Relates to the global/local shading; need to get value from context when value 
is undefined and shading false.

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-04 Thread Dmitri Blinov (Jira)


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

Dmitri Blinov commented on JEXL-307:


Now the following test case fails:
{code:java}
@Test
public void testLexical6() throws Exception {
String str = "i = 0; for (var i : [1]) i; i";
JexlEngine jexl = new JexlBuilder().strict(true).lexical(true).create();
JexlScript e = jexl.createScript(str);
JexlEvalContext ctxt = new JexlEvalContext();
JexlOptions options = ctxt.getEngineOptions();
// ensure errors will throw
options.setLexical(true);
Object o = e.execute(ctxt);
Assert.assertEquals(0, o);
}
{code}

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-04 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


Changeset: 94e6097c7bce16996e6bfb94aa4ef7a3854c115a
Author:Henri Biestro 
Date:  2019-11-04 11:31
Message:   JEXL-307: added hoisted variables stacks to solve shading and frame 
state preservation

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-02 Thread Dmitri Blinov (Jira)


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

Dmitri Blinov commented on JEXL-307:


Things are getting a little bit tricky. Can we ensure that the following test 
passes ?
{code:java}
@Test
public void testLexical5() throws Exception {
JexlEngine jexl = new JexlBuilder().strict(true).create();
JexlEvalContext ctxt = new JexlEvalContext();
JexlOptions options = ctxt.getEngineOptions();
// ensure errors will throw
options.setLexical(true);
JexlScript script;
Object result;script = jexl.createScript("var x = 42; var y = 
() -> { {var x = 0}; return x; }; y()");
try {
result = script.execute(ctxt);
Assert.assertEquals(42, result);
Assert.fail();
} catch (JexlException xany) {
String ww = xany.toString();
}
}
 {code}

Maybe we can refactor the hoisted variables from local to contextual variables 
that shadow original evaluation context?

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-02 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


Changeset: 4cc3fe927a2794597650ea3df2c00c613b20acec
Author:henrib 
Date:  2019-11-02 10:45
Message:   JEXL-307: restored 3.1 var declaration behavior in non-lexical mode

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-02 Thread Dmitri Blinov (Jira)


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

Dmitri Blinov commented on JEXL-307:


The following non-lexical functionality is broken
{code:java}
@Test
public void testLexical2a() throws Exception {
JexlEngine jexl = new JexlBuilder().strict(true).create();
JexlEvalContext ctxt = new JexlEvalContext();
JexlScript script = jexl.createScript("{var x = 42}; {var x; return x; 
}");
Object result = script.execute(ctxt);
Assert.assertEquals(42, result);
}
 {code}

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-01 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


Changeset: 911180be2e527cb42aa5839991ef0a5ada621d19
Author:Henri Biestro 
Date:  2019-11-01 16:03
Message:   JEXL-307: template interpreter need lexical unit

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-01 Thread Dmitri Blinov (Jira)


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

Dmitri Blinov commented on JEXL-307:


The following test throws NPE
{code:java}
@Test
public void testLexical() throws Exception {
JexlEngine Jexl = new 
JexlBuilder().silent(false).strict(true).lexical(true).create();
JxltEngine Jxlt = Jexl.createJxltEngine();
JexlEvalContext ctxt = new JexlEvalContext(new MapContext());
JexlOptions options = ctxt.getEngineOptions();
// ensure errors will throw
options.setLexical(true);
String rpt
= "\n"
+ "\n$$var y = 1; var x = 2;"
+ "\n${x + y}"
+ "\n\n";
JxltEngine.Template t = Jxlt.createTemplate("$$", new 
StringReader(rpt));
StringWriter strw = new StringWriter();
t.evaluate(ctxt, strw);
String output = strw.toString();
String ctl = "\n\n3\n\n";
Assert.assertEquals(ctl, output);
}
{code}
 

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-01 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


Changeset: ae819a2c7cb89a50e69a056a8b8b01a49b82110d
Author:henrib 
Date:  2019-11-01 11:59
Message:   JEXL-307: test cleanup

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-11-01 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


Changeset: 32bfdc913223aac1282e9b64fdf198a1e4561dac
Author:Henri Biestro 
Date:  2019-11-01 11:17
Message:   JEXL-307: parser internal state clean up

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-10-31 Thread Dmitri Blinov (Jira)


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

Dmitri Blinov commented on JEXL-307:


The following test case fails with NPE on the second parsing

{code}
package org.apache.commons.jexl3;

import java.util.Set;

import org.junit.Assert;
import org.junit.Test;

/**
 * Test cases for lexical option and feature.
 */
public class LexicalTest extends JexlTestCase {

public LexicalTest() {
super("LexicalTest");
}

@Test
public void testLexical3() throws Exception {
JexlScript e = JEXL.createScript("var s = {}; for (var i : [1]) 
s.add(i); s");
JexlContext jc = new MapContext();
Object o = e.execute(jc);
Assert.assertEquals(Boolean.TRUE, ((Set)o).contains(1));

e = JEXL.createScript("var s = {}; for (var i : [1]) s.add(i); s");
o = e.execute(jc);
Assert.assertEquals(Boolean.TRUE, ((Set)o).contains(1));
}
{code}

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-10-29 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


Changeset: 9e8257ef6d1efec445237ab098cc654d8ba26a7c
Author:Henri Biestro 
Date:  2019-10-29 22:46
Message:   JEXL-307: declared variable default value (re)set to null

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-10-29 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


Thanks for the catch; frame needs to be cleaned up...

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-10-29 Thread Dmitri Blinov (Jira)


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

Dmitri Blinov commented on JEXL-307:


The following test case fails in lexical mode.
{code:java}
@Test
public void testLexical2() throws Exception {
JexlEngine jexl = new JexlBuilder().strict(true).create();
JexlEvalContext ctxt = new JexlEvalContext();
JexlOptions options = ctxt.getEngineOptions();
// ensure errors will throw
options.setLexical(true);

JexlScript script = jexl.createScript("{var x = 42}; {var x; return x; 
}");
try {
Object result = script.execute(ctxt);
Assert.assertNull(result);
} catch (JexlException xany) {
String ww = xany.toString();
}   
}
 {code}

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-10-03 Thread Dmitri Blinov (Jira)


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

Dmitri Blinov commented on JEXL-307:


So, if we split the task into feature #1 (Java-like local variable visibility 
scope), and feature #2 (restrict local variables from shadowing globals), 
providing each feature would be controllable independently via engine setting 
et al, then so it be.

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-10-02 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


You nailed it, the local variable *shadow* scope is the issue.

However, after a local var definition scope block, allowing the same symbol 
(aka variable name) to refer to a global might indeed _mask_ cases where the 
intent was to dereference that local (out of scope / undefined). The analogy 
with Java local/instance variable applies; it is very confusing indeed ! Good 
practise (and Java code checkers) frown upon shadowing an instance var with a 
local for the very reason it is an easy bug generator.


 We do have the opportunity to be a bit strict and make a simple rule; no local 
symbol will shadow a global var. Locals (defined or not) remain locals within a 
script.
 We may control that behaviour with another option flag (shadow) if this is 
really (really) desirable keeping in mind simplicity trumps complexity and its 
surprises... 

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-10-02 Thread Dmitri Blinov (Jira)


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

Dmitri Blinov commented on JEXL-307:


My understanding on globals with regard to this task is to keep things simple - 
we now have global variables and local variables. I think we are now discussing 
about visibility and declaration rules of *local* variables, as a result of new 
feature. So, any changes to global variables are off the table at the moment. 
In essence, if a symbol is used as a parameter or local variable in a script, 
it *shadows* a global, if such exists. This is what current implementation is 
look like, and this is how new feature IMO should work. With new feature, if a 
local comes out of its visibility scope, it simply no longer *shadows* a 
global. In my head, this is in strict analogy with java instance variables and 
local variables. Our globals are like java instance variables, and our locals 
are java local variables. Note that this is a little different from javascript 
block variable scope, where one can redeclare local variables within nested 
scope with `let` as much as he wants.

{code}
var  x = 10;
// Here x is 10
{  
  let x = 2;
  // Here x is 2
  { 
 let x = 3;
 // Here x is 3
  }
  // Here x is 2 once again
}
// Here x is 10
{code}

Since we think that 
{code}
var  x = 10;
// Here x is 10
{  
  // Error - local variable redeclaration is not allowed
  var x = 2;
}
{code}

I do not say that there is nothing good to be done with globals with respect to 
other needs, but for the sake of simplicity and understanding it is good to 
have variable model that has analogy with well-known implementation.

PS. About pragmas - what do you mean by point of impact of pragma?

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-10-02 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


1 - Not sure I fully grasped your view on globals. Your example about variable 
loop visibility does have an effect; the 'i' variable outside the loop _could_ 
be considered as a global. The current stance - shared with consultants dealing 
with huge scripts - is that a variable symbol should be either local or global 
but should *not* be allowed to be both. In essence, if a symbol is used as a 
parameter or local variable in a script, it can no longer be considered a 
global. 
2 - Hoisted variables handling as you describe seems sound.
3 - Pragmas are out-of-flow and should be considered as script meta-data. Some 
users prefer having them declared at end of script, some at start, some at 
point of impact... Better doc would help probably.

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-10-01 Thread Dmitri Blinov (Jira)


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

Dmitri Blinov commented on JEXL-307:


If new feature, through configuration on engine level, or via provided script 
compilation options, will trigger java-like local variable visibility rules, 
instead of existing ones, it would be great step in right direction. This, 
however, IMO, should not influence context variables in any way. We should be 
allowed to freely assign to new context variables from any point. So, we can 
declare that, under new option, the following is correct - every variable 
should have visibility inside the block where it is defined. Loop variables are 
visible until the end of loop:
{code:java}
for (var i : items) {}; return i;{code}
Thus the above code should raise exception - undefined variable.

Also, we need to agree what to do with hoisted variables. My vision is that 
hoisted variables should be treated like function argumens, in other words, 
they should not be allowed to be redefined. This would guarantee the evaluation 
integrity.

I'm not sure about pragmas though. The pragmas are a little underdeveloped now. 
For example, I would change the grammar to allow pragmas to be allowed only at 
the beginning of the script. Now they can be specified anywere in the middle, 
inside *if* or *while* loop, which is misleading, as they are not executed 
anyway, and their meaning relates to the whole script, not to the particular 
part. Plus, the debugger now does not reproduce them in the generated source 
code, thus they are get lost. Placing pragmas strictly at the beginning would 
allow to solve this problem, and allow them to be used for specifying any 
parsing options.

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-10-01 Thread Henri Biestro (Jira)


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

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 way. 

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: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-10-01 Thread Dmitri Blinov (Jira)


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

Dmitri Blinov commented on JEXL-307:


Right now we have three scopes for a variable - context scope, global scope and 
function scope. Context variables reside in JexlContext, global variables are 
defined during script evaluation, and the last ones are defined within 
lambdas/functions as parameters or local variables. Introduction of another 
scope - I would call it a *block scope*, is an interesting idea, but I think it 
can be split off as a separate task. There are many things to consider, as 
whether to introduce a separate keyword, for example {{let}}, for this, or if 
we can reuse {{var}}. Another consideration is compatibility. We are get used 
to context and global scope variables. I think we should not restrict 
assignments of undefined context variables as it breaks compatibility in many 
ways. For example, now it is legal to use {{for (x : items)...}}, which may 
create a context variable etc etc.

As a starter, we could solve more simple task, as whether or not to allow 
variable redefinition within the global scope or the function scope. For 
example, the following constructs should be prevented, during runtime, if 
variable redeclaration option is switched off:
{code:java}var c = 157; ...; var c = 42; {code} or 
{code:java}
var c = 157; {var c = 42; ...}
{code}
or
{code:java}
var c = 157; for (var c : items) ...
{code}
or
{code:java}
function(c) {var c = 157; ...}
{code}
or even
{code:java}
var c = 42; function(x) {var c = 157; ...}
{code}
The following constructs should be OK
{code:java}
var c = 157; if (false) {var c = 42; ...}
{code}
as well as
{code:java}
if (x) {var c = 42; ...} else {var c = 157; ...}
{code}

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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
(v8.3.4#803005)


[jira] [Commented] (JEXL-307) Variable redeclaration option

2019-09-30 Thread Henri Biestro (Jira)


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

Henri Biestro commented on JEXL-307:


This leads to a feature / option that implements a script lexical scope. The 
canonical illustration is the difference between the JavaScript 'var' and 'let' 
with respect to parameters and local variable definitions.
As a feature (JexlFeature), this 'lexical' mode will fail parsing when a 
variable/parameter redefinition is attempted in the same scope; from the point 
of definition within a block/function, a variable can not be redefined.
An an option (JexlOption), the same lexical rule applies but whether an 
exception is thrown or logged is subject to the exception handling rules in 
effect. This runtime behaviour should be easily turned on or off (driven though 
pragma for instance) so that large existing scripts libraries can be converted 
to the new semantic through managed evolution (ie one script at a time).

> Variable redeclaration option
> -
>
> Key: JEXL-307
> URL: https://issues.apache.org/jira/browse/JEXL-307
> 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 and 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
(v8.3.4#803005)