remove invalid ObjectPattern destructuring assignment

This commit is contained in:
Sebastian McKenzie
2014-11-10 00:18:01 +11:00
parent 9989b89b92
commit 7adc919bb6
4 changed files with 6 additions and 24 deletions

View File

@@ -11,21 +11,7 @@ var buildVariableAssign = function (kind, id, init) {
}
};
var normalise = function (node) {
if (t.isParenthesizedExpression(node)) {
return node.expression;
} else {
return node;
}
};
var isPattern = function (node) {
return t.isPattern(normalise(node));
};
var push = function (kind, nodes, elem, parentId) {
elem = normalise(elem);
if (t.isObjectPattern(elem)) {
pushObjectPattern(kind, nodes, elem, parentId);
} else if (t.isArrayPattern(elem)) {
@@ -42,7 +28,7 @@ var pushObjectPattern = function (kind, nodes, pattern, parentId) {
var pattern2 = prop.value;
var patternId2 = t.memberExpression(parentId, prop.key);
if (isPattern(pattern2)) {
if (t.isPattern(pattern2)) {
push(kind, nodes, pattern2, patternId2);
} else {
nodes.push(buildVariableAssign(kind, pattern2, patternId2));
@@ -94,7 +80,7 @@ exports.ForOfStatement = function (node, parent, file, scope) {
if (!t.isVariableDeclaration(declar)) return;
var pattern = declar.declarations[0].id;
if (!isPattern(pattern)) return;
if (!t.isPattern(pattern)) return;
var key = t.identifier(file.generateUid("ref", scope));
node.left = t.variableDeclaration(declar.kind, [
@@ -117,7 +103,7 @@ exports.Function = function (node, parent, file, scope) {
var hasDestructuring = false;
node.params = node.params.map(function (pattern) {
if (!isPattern(pattern)) return pattern;
if (!t.isPattern(pattern)) return pattern;
hasDestructuring = true;
var parentId = t.identifier(file.generateUid("ref", scope));
@@ -146,7 +132,7 @@ exports.ExpressionStatement = function (node, parent, file, scope) {
var expr = node.expression;
if (expr.type !== "AssignmentExpression") return;
if (!isPattern(expr.left)) return;
if (!t.isPattern(expr.left)) return;
var nodes = [];
@@ -167,7 +153,7 @@ exports.VariableDeclaration = function (node, parent, file, scope) {
var hasPattern = false;
_.each(node.declarations, function (declar) {
if (isPattern(declar.id)) {
if (t.isPattern(declar.id)) {
hasPattern = true;
return false;
}