don't unpack array when the pattern contains more elements than the corresponding array expression
This commit is contained in:
parent
c3c94f0a4a
commit
0b2f1fedcb
@ -168,6 +168,7 @@ DestructuringTransformer.prototype.canUnpackArrayPattern = function (pattern, ar
|
|||||||
|
|
||||||
// pattern has less elements than the array and doesn't have a rest so some
|
// pattern has less elements than the array and doesn't have a rest so some
|
||||||
// elements wont be evaluated
|
// elements wont be evaluated
|
||||||
|
if (pattern.elements.length > arr.elements.length) return;
|
||||||
if (pattern.elements.length < arr.elements.length && !hasRest(pattern)) return false;
|
if (pattern.elements.length < arr.elements.length && !hasRest(pattern)) return false;
|
||||||
|
|
||||||
// deopt on holes
|
// deopt on holes
|
||||||
@ -418,7 +419,7 @@ exports.AssignmentExpression = function (node, parent, scope, file) {
|
|||||||
return t.toSequenceExpression(nodes, scope);
|
return t.toSequenceExpression(nodes, scope);
|
||||||
};
|
};
|
||||||
|
|
||||||
var variableDeclarationhasPattern = function (node) {
|
var variableDeclarationHasPattern = function (node) {
|
||||||
for (var i = 0; i < node.declarations.length; i++) {
|
for (var i = 0; i < node.declarations.length; i++) {
|
||||||
if (t.isPattern(node.declarations[i].id)) {
|
if (t.isPattern(node.declarations[i].id)) {
|
||||||
return true;
|
return true;
|
||||||
@ -429,7 +430,7 @@ var variableDeclarationhasPattern = function (node) {
|
|||||||
|
|
||||||
exports.VariableDeclaration = function (node, parent, scope, file) {
|
exports.VariableDeclaration = function (node, parent, scope, file) {
|
||||||
if (t.isForInStatement(parent) || t.isForOfStatement(parent)) return;
|
if (t.isForInStatement(parent) || t.isForOfStatement(parent)) return;
|
||||||
if (!variableDeclarationhasPattern(node)) return;
|
if (!variableDeclarationHasPattern(node)) return;
|
||||||
|
|
||||||
var nodes = [];
|
var nodes = [];
|
||||||
var declar;
|
var declar;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user