TomFrost / Jexl

Javascript Expression Language: Powerful context-based expression parser and evaluator
MIT License
559 stars 90 forks source link

Minus is not interpreted properly... #97

Open OlivierB-OB opened 3 years ago

OlivierB-OB commented 3 years ago

Hi @TomFrost

Minus is not interpreted properly...

[1, 2, 3] => OK https://czosel.github.io/jexl-playground/#/?input=%5B1%2C%202%2C%203%5D

[-1, 2, 3] => OK https://czosel.github.io/jexl-playground/#/?input=%5B-1%2C%202%2C%203%5D

[-1, -2, 3] => Error: Token - (binaryOp) unexpected in expression: [-1, - https://czosel.github.io/jexl-playground/#/?input=%5B-1%2C%20-2%2C%203%5D

Same issue with functions like: min(1, -2, 3)

OlivierB-OB commented 3 years ago

Hi @TomFrost

If I'm not mistaken in the file /lib/Lexer.js

The variable minusNegatesAfter should also contains 'comma'... const minusNegatesAfter = [ 'binaryOp', 'unaryOp', 'openParen', 'openBracket', 'question', 'colon' ]

prafullkulkarni commented 2 years ago

Hi @TomFrost

Do you have any update on this issue, please?

TomFrost commented 2 years ago

Hi, sorry for the late response on this! Spot-on diagnosis -- I'll look to include this in the next release.

Dossar commented 2 years ago

@TomFrost Opened a pull request (https://github.com/TomFrost/Jexl/pull/122) with the suggested change from @OlivierB-OB