EricSmekens / jsep

JavaScript Expression Parser
http://ericsmekens.github.io/jsep/
MIT License
836 stars 136 forks source link

Arrow Function plugin #147

Closed 6utt3rfly closed 3 years ago

6utt3rfly commented 3 years ago

() => x x => x (a, b) => x

Treats '=>' as a binary operator, but replaces the binary expression with the correct node type afterward

LeaVerou commented 3 years ago

What about the curly brace syntax though? a => { return 5; }? Is it out of scope?

6utt3rfly commented 3 years ago

What about the curly brace syntax though? a => { return 5; }? Is it out of scope?

That could feasibly be another plugin so curly braces could be used to return a sequence of nodes (within an arrow function or not). If both the object and arrow plugins are enabled, then it's possible to use curly braces for an object return value, like [a].map(v => ({ v })).