make it illegal to have a rest on a setter

This commit is contained in:
Sebastian McKenzie
2015-03-07 01:32:03 +11:00
parent 35c49dbef7
commit 8ad678e5bc
5 changed files with 19 additions and 2 deletions

View File

@@ -10,6 +10,7 @@ export var messages = {
undeclaredVariable: "Reference to undeclared variable $1",
undeclaredVariableSuggestion: "Reference to undeclared variable $1 - did you mean $2?",
settersInvalidParamLength: "Setters must have exactly one parameter",
settersNoRest: "Setters aren't allowed to have a rest",
noAssignmentsInForHead: "No assignments allowed in for-in/of head",
expectedMemberExpressionOrIdentifier: "Expected type MemeberExpression or Identifier",
invalidParentForThisNode: "We don't know how to handle this node within the current parent - please open an issue",

View File

@@ -3,6 +3,7 @@ export default {
_validation: require("./internal/validation"),
"validation.undeclaredVariableCheck": require("./validation/undeclared-variable-check"),
"validation.react": require("./validation/react"),
// this goes at the start so we only transform the original user code

View File

@@ -12,8 +12,15 @@ export function ForOfStatement(node, parent, scope, file) {
export { ForOfStatement as ForInStatement };
export function Property(node, parent, scope, file) {
if (node.kind === "set" && node.value.params.length !== 1) {
throw file.errorWithNode(node.value, messages.get("settersInvalidParamLength"));
if (node.kind === "set") {
if (node.value.params.length !== 1) {
throw file.errorWithNode(node.value, messages.get("settersInvalidParamLength"));
}
var first = node.value.params[0];
if (t.isRestElement(first)) {
throw file.errorWithNode(first, messages.get("settersNoRest"));
}
}
}