support SpreadElement in destructuring - fixes #128
This commit is contained in:
parent
b3206d94a6
commit
f8e8cd3979
@ -40,7 +40,15 @@ var pushArrayPattern = function (kind, nodes, pattern, parentId) {
|
||||
_.each(pattern.elements, function (elem, i) {
|
||||
if (!elem) return;
|
||||
|
||||
var newPatternId = t.memberExpression(parentId, t.literal(i), true);
|
||||
var newPatternId;
|
||||
|
||||
if (t.isSpreadElement(elem)) {
|
||||
newPatternId = t.callExpression(t.memberExpression(parentId, t.identifier("slice")), [t.literal(i)]);
|
||||
elem = elem.argument;
|
||||
} else {
|
||||
newPatternId = t.memberExpression(parentId, t.literal(i), true);
|
||||
}
|
||||
|
||||
push(kind, nodes, elem, newPatternId);
|
||||
});
|
||||
};
|
||||
|
||||
5
test/fixtures/transformation/destructuring/spread/actual.js
vendored
Normal file
5
test/fixtures/transformation/destructuring/spread/actual.js
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
var isSorted = ([x, y, ...wow]) => {
|
||||
if (!zs.length) return true
|
||||
if (y > x) return isSorted(zs)
|
||||
return false
|
||||
};
|
||||
11
test/fixtures/transformation/destructuring/spread/expected.js
vendored
Normal file
11
test/fixtures/transformation/destructuring/spread/expected.js
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
var isSorted = function (_ref) {
|
||||
var x = _ref[0];
|
||||
var y = _ref[1];
|
||||
var wow = _ref.slice(2);
|
||||
|
||||
if (!zs.length) return true;
|
||||
if (y > x) return isSorted(zs);
|
||||
return false;
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user