Skip to content

Commit

Permalink
Merge pull request #249 from eslint/issue247
Browse files Browse the repository at this point in the history
Fix: Object rest/spread in assign (fixes #247)
  • Loading branch information
nzakas committed Feb 2, 2016
2 parents 3ebeb31 + ecfe4c8 commit 609f0a2
Show file tree
Hide file tree
Showing 8 changed files with 1,213 additions and 2 deletions.
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"browserify": "^7.0.0",
"chai": "^1.10.0",
"eslint": "^2.0.0-beta.1",
"eslint-config-eslint": "^2.0.0",
"eslint-config-eslint": "^3.0.0",
"eslint-release": "^0.2.0",
"esprima": "latest",
"esprima-fb": "^8001.2001.0-dev-harmony-fb",
Expand Down
Loading

0 comments on commit 609f0a2

Please sign in to comment.