this is another ES6 feature that's really unfriendly to implement in Espruino's parser, because you don't actually know whether [a,b,c] is an array or a destructuring assignment until you get to the = sign.
I can vividly see that... because you try to resolve every '(sub)expression' as soon as possible. For the simplest solution - (plain) variable references - It would require to keep a prallel array with the references and when the = shows throw either away and continue processing accordingly. An optimization could be by having a first level of array construction with simple value object references only - no functions and other ('complex') objects - and have an earlier decision of continuing with array build process... what would then either throw an error when hitting the = sign or keep going and 'emptying' the result stack onto the references kept in the array. (...as seen from my interpreter-illiterate 'frog perspective'.) I guess the detection of wether the array element - in the anonymous array (and that is the only array type it would work) - is a plain var reference or something else is the challenge... --- Resolution of the encountered array element(s) is postponed until a non-simple-value-object-reference (variable) his hit or the array closes.
PS: Did 'vote' on the ES6 wishlist. It is all very relative due to the nature of Espruino.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I can vividly see that... because you try to resolve every '(sub)expression' as soon as possible. For the simplest solution - (plain) variable references - It would require to keep a prallel array with the references and when the
=
shows throw either away and continue processing accordingly. An optimization could be by having a first level of array construction with simple value object references only - no functions and other ('complex') objects - and have an earlier decision of continuing with array build process... what would then either throw an error when hitting the=
sign or keep going and 'emptying' the result stack onto the references kept in the array. (...as seen from my interpreter-illiterate 'frog perspective'.) I guess the detection of wether the array element - in the anonymous array (and that is the only array type it would work) - is a plain var reference or something else is the challenge... --- Resolution of the encountered array element(s) is postponed until a non-simple-value-object-reference (variable) his hit or the array closes.PS: Did 'vote' on the ES6 wishlist. It is all very relative due to the nature of Espruino.