diff --git a/CHANGELOG.md b/CHANGELOG.md index 586f7a14e3..c42b6f67e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.12.8 + + * Temporarily forbid `AssignmentExpression` destructuring outside of `ExpressionStatement`. + # 1.12.7 * Update to latest `acorn-6to5`. diff --git a/lib/6to5/transformation/transformers/destructuring.js b/lib/6to5/transformation/transformers/destructuring.js index 67690661e5..a1fb9627df 100644 --- a/lib/6to5/transformation/transformers/destructuring.js +++ b/lib/6to5/transformation/transformers/destructuring.js @@ -146,6 +146,12 @@ exports.ExpressionStatement = function (node, parent, file, scope) { return nodes; }; +exports.AssignmentExpression = function (node, parent, file) { + if (parent.type === "ExpressionStatement") return; + if (!t.isPattern(node.left)) return; + throw file.errorWithNode(node, "AssignmentExpression destructuring outside of a ExpressionStatement is forbidden due to current limitations"); +}; + exports.VariableDeclaration = function (node, parent, file, scope) { if (t.isForInStatement(parent) || t.isForOfStatement(parent)) return; diff --git a/test/fixtures/transformation/destructuring/assignment-expression/actual.js b/test/fixtures/transformation/destructuring/assignment-expression/actual.js new file mode 100644 index 0000000000..2ebf93ff16 --- /dev/null +++ b/test/fixtures/transformation/destructuring/assignment-expression/actual.js @@ -0,0 +1 @@ +console.log([x] = [123]); diff --git a/test/fixtures/transformation/destructuring/assignment-expression/options.json b/test/fixtures/transformation/destructuring/assignment-expression/options.json new file mode 100644 index 0000000000..d0680c1c5d --- /dev/null +++ b/test/fixtures/transformation/destructuring/assignment-expression/options.json @@ -0,0 +1,3 @@ +{ + "throws": "AssignmentExpression destructuring outside of a ExpressionStatement is forbidden due to current limitations" +} diff --git a/test/fixtures/transformation/destructuring/assignment/actual.js b/test/fixtures/transformation/destructuring/assignment-statement/actual.js similarity index 100% rename from test/fixtures/transformation/destructuring/assignment/actual.js rename to test/fixtures/transformation/destructuring/assignment-statement/actual.js diff --git a/test/fixtures/transformation/destructuring/assignment/expected.js b/test/fixtures/transformation/destructuring/assignment-statement/expected.js similarity index 100% rename from test/fixtures/transformation/destructuring/assignment/expected.js rename to test/fixtures/transformation/destructuring/assignment-statement/expected.js