throw an error when destructuring a null or undefined value on an empty object pattern - fixes #681
This commit is contained in:
@@ -53,7 +53,8 @@ File.helpers = [
|
||||
"extends",
|
||||
"get",
|
||||
"set",
|
||||
"class-call-check"
|
||||
"class-call-check",
|
||||
"object-destructuring-empty"
|
||||
];
|
||||
|
||||
File.validOptions = [
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
(function (obj) {
|
||||
if (obj == null) throw new TypeError("Cannot destructure undefined");
|
||||
});
|
||||
@@ -66,6 +66,12 @@ var pushAssignmentPattern = function (opts, nodes, pattern, parentId) {
|
||||
};
|
||||
|
||||
var pushObjectPattern = function (opts, nodes, pattern, parentId) {
|
||||
if (!pattern.properties.length) {
|
||||
nodes.push(t.expressionStatement(
|
||||
t.callExpression(opts.file.addHelper("object-destructuring-empty"), [parentId])
|
||||
));
|
||||
}
|
||||
|
||||
for (var i = 0; i < pattern.properties.length; i++) {
|
||||
var prop = pattern.properties[i];
|
||||
if (t.isSpreadProperty(prop)) {
|
||||
|
||||
Reference in New Issue
Block a user