Skip to content

Commit

Permalink
Improve robustness when continuing parsing after recoverable errors.
Browse files Browse the repository at this point in the history
Setter properties or methods without parameters cause a recoverable error, hence subsequent code has to be made robust against plugins that override `raiseRecoverable` to continue parsing.
  • Loading branch information
xiemaisi authored and marijnh committed Aug 4, 2016
1 parent 693c5fe commit 28cbcbc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,10 @@ pp.parsePropertyValue = function(prop, isPattern, isGenerator, startPos, startLo
this.raiseRecoverable(start, "getter should have no params")
else
this.raiseRecoverable(start, "setter should have exactly one param")
} else {
if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params")
}
if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params")
} else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
if (this.keywords.test(prop.key.name) ||
(this.strict ? this.reservedWordsStrictBind : this.reservedWords).test(prop.key.name) ||
Expand Down
5 changes: 3 additions & 2 deletions src/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,10 @@ pp.parseClass = function(node, isStatement) {
this.raiseRecoverable(start, "getter should have no params")
else
this.raiseRecoverable(start, "setter should have exactly one param")
} else {
if (method.kind === "set" && method.value.params[0].type === "RestElement")
this.raise(method.value.params[0].start, "Setter cannot use rest params")
}
if (method.kind === "set" && method.value.params[0].type === "RestElement")
this.raise(method.value.params[0].start, "Setter cannot use rest params")
}
}
node.body = this.finishNode(classBody, "ClassBody")
Expand Down

0 comments on commit 28cbcbc

Please sign in to comment.