Whilst doing some cleanup of some Aura Components for Summer 16, I was creating a JS function in my helper. I had wanted to add some default values to that function using the new ES6 Default Parameter Value Spec. Like so:
myFunction = function (param1 = "this", param2 = "that"){ ... }
Meaning that if I invoked this like
helper.myFunction(); > param1 = "this" > param2 = "that" helper.myFunction("what is"); > param1 = "what is" > param2 = "that"
No luck. I get an error when I attempt to save the component on the server as such:
ERROR: 0Ad240000008RPA: org.auraframework.util.json.JsonStreamReader$JsonStreamParseException: Expected ‘,’ or ‘)’ [64, 30]: ‘=’
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
I have just bumped in this issue and I would like to share my findings.
The following syntax is still not supported (you’ll get a JsonStreamParseException
):
myFunction = function (param1 = "this", param2 = "that")
However, if you write it this way (without spaces around the equal signs), the default parameter values work fine:
myFunction = function (param1="this", param2="that")
I hope this will help someone.
Method 2
It turns out Lightning Components are using a version of closure compiler that is incompatible with this syntax currently. So as of Summer 16, certain syntax that is ES6 compliant will not work with Lightning Components.
I found this out through raising an issue with the aura open source framework repo in github.
Note: this is not an issue in Lightning Web Components
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0