Skip to content

Commit

Permalink
Fix: Object rest/spread in assign (fixes #247)
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas committed Feb 2, 2016
1 parent 3ebeb31 commit ea6261e
Show file tree
Hide file tree
Showing 7 changed files with 1,212 additions and 1 deletion.
29 changes: 29 additions & 0 deletions espree.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,35 @@ pp.extend("parseTopLevel", function(parseTopLevel) {
};
});

pp.extend("toAssignable", function(toAssignable) {

return /** @this acorn.Parser */ function(node, isBinding) {

if (extra.ecmaFeatures.experimentalObjectRestSpread &&
node.type === "ObjectExpression"
) {
node.type = "ObjectPattern";

for (var i = 0; i < node.properties.length; i++) {
var prop = node.properties[i];

if (prop.type === "ExperimentalSpreadProperty") {
prop.type = "ExperimentalRestProperty";
} else if (prop.kind !== "init") {
this.raise(prop.key.start, "Object pattern can't contain getter or setter");
} else {
this.toAssignable(prop.value, isBinding);
}
}

return node;
} else {
return toAssignable.call(this, node, isBinding);
}
};

});

/**
* Method to parse an object rest or object spread.
* @returns {ASTNode} The node representing object rest or object spread.
Expand Down
Loading

0 comments on commit ea6261e

Please sign in to comment.