Merge branch 'master' into harmony-v2.8.15
This commit is contained in:
99
lib/parse.js
99
lib/parse.js
@@ -2467,12 +2467,52 @@ function parse($TEXT, options) {
|
||||
};
|
||||
|
||||
function is_assignable(expr) {
|
||||
if (!options.strict) return true;
|
||||
if (expr instanceof AST_This) return false;
|
||||
if (expr instanceof AST_Super) return false;
|
||||
return (expr instanceof AST_PropAccess || expr instanceof AST_Symbol);
|
||||
return expr instanceof AST_PropAccess || expr instanceof AST_SymbolRef;
|
||||
};
|
||||
|
||||
function to_destructuring(node) {
|
||||
if (node instanceof AST_Object) {
|
||||
node = new AST_Destructuring({
|
||||
start: node.start,
|
||||
names: node.properties.map(to_destructuring),
|
||||
is_array: false,
|
||||
end: node.end
|
||||
});
|
||||
} else if (node instanceof AST_Array) {
|
||||
var names = [];
|
||||
|
||||
for (var i = 0; i < node.elements.length; i++) {
|
||||
// Only allow expansion as last element
|
||||
if (node.elements[i] instanceof AST_Expansion) {
|
||||
if (i + 1 !== node.elements.length) {
|
||||
token_error(node.elements[i].start, "Spread must the be last element in destructuring array");
|
||||
}
|
||||
node.elements[i].expression = to_destructuring(node.elements[i].expression);
|
||||
}
|
||||
|
||||
names.push(to_destructuring(node.elements[i]));
|
||||
}
|
||||
|
||||
node = new AST_Destructuring({
|
||||
start: node.start,
|
||||
names: names,
|
||||
is_array: true,
|
||||
end: node.end
|
||||
});
|
||||
} else if (node instanceof AST_ObjectProperty) {
|
||||
node.value = to_destructuring(node.value);
|
||||
} else if (node instanceof AST_Assign) {
|
||||
node = new AST_DefaultAssign({
|
||||
start: node.start,
|
||||
left: node.left,
|
||||
operator: "=",
|
||||
right: node.right,
|
||||
end: node.end
|
||||
});
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
// In ES6, AssignmentExpression can also be an ArrowFunction
|
||||
var maybe_assign = function(no_in) {
|
||||
var start = S.token;
|
||||
@@ -2506,56 +2546,7 @@ function parse($TEXT, options) {
|
||||
var val = S.token.value;
|
||||
|
||||
if (is("operator") && ASSIGNMENT(val)) {
|
||||
if (is_assignable(left)) {
|
||||
|
||||
var walk = function(node) {
|
||||
var newNode;
|
||||
if (node instanceof AST_Object) {
|
||||
newNode = new AST_Destructuring({
|
||||
start: node.start,
|
||||
names: node.properties.map(walk),
|
||||
is_array: false,
|
||||
end: node.end
|
||||
});
|
||||
node = newNode;
|
||||
} else if (node instanceof AST_Array) {
|
||||
var names = [];
|
||||
|
||||
for (var i = 0; i < node.elements.length; i++) {
|
||||
// Only allow expansion as last element
|
||||
if (node.elements[i] instanceof AST_Expansion) {
|
||||
if (i + 1 !== node.elements.length) {
|
||||
token_error(node.elements[i].start, "Spread must the be last element in destructuring array");
|
||||
}
|
||||
node.elements[i].expression = walk(node.elements[i].expression);
|
||||
}
|
||||
|
||||
names.push(walk(node.elements[i]));
|
||||
}
|
||||
|
||||
newNode = new AST_Destructuring({
|
||||
start: node.start,
|
||||
names: names,
|
||||
is_array: true,
|
||||
end: node.end
|
||||
});
|
||||
node = newNode;
|
||||
} else if (node instanceof AST_ObjectProperty) {
|
||||
node.value = walk(node.value);
|
||||
} else if (node instanceof AST_Assign) {
|
||||
node = new AST_DefaultAssign({
|
||||
start: node.start,
|
||||
left: node.left,
|
||||
operator: "=",
|
||||
right: node.right,
|
||||
end: node.end
|
||||
});
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
left = walk(left);
|
||||
|
||||
if (is_assignable(left) || (left = to_destructuring(left)) instanceof AST_Destructuring) {
|
||||
next();
|
||||
return new AST_Assign({
|
||||
start : start,
|
||||
|
||||
Reference in New Issue
Block a user