Fix: destructuring assignment with an empty array in object by zdenko · Pull Request #5000 · jashkenas/coffeescript
Conversation
While testing sub-structuring (#4995) I noticed wrong output of destructuring with an empty array in the object.
Current branch:
{a:[], b} = obj
###
var b;
obj.undefined, b = obj[1];
###Since @variable.isAssignable() in Assign returns false because of an empty array, the ::compileDestructuring is invoked.
The syntax is valid and can be output directly.
This PR:
{a:[], b} = obj
###
var b;
({
a: [],
b
} = c);
###This would be a breaking change since babel runs {a: []} through function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); }.
As an example Array.from(null) and Array.from(undefined) throws a type error, so anyone who was using it to drop keys will be screwed.
I think my comment from #4995 applies here as well.
I see no difference between {a: []} = b or {a:{}} = b. It is upon user to take care of destructuring variables.
And, I don't think anyone will be screwed, because currently, if an empty array is used in the destructuring`, you won't get correct result even if the key exists in the object.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters