Permalink
Browse files

Adjust the error message for bad getter/setter arity

Fix #1685
Closes gh-1686
  • Loading branch information...
ariya committed Dec 22, 2016
1 parent 8060465 commit ad622c82acddb1c55b706af07741b256d4f2e086
View
@@ -1,5 +1,7 @@
// Error messages should be identical to V8.
export const Messages = {
BadGetterArity: 'Getter must not have any formal parameters',
BadSetterArity: 'Setter must have exactly one formal parameter',
ConstructorIsAsync: 'Class constructor may not be an async method',
ConstructorSpecialMethod: 'Class constructor may not be an accessor',
DeclarationMissingInitializer: 'Missing initializer in %0 declaration',
View
@@ -3036,51 +3036,34 @@ export class Parser {
parseGetterMethod(): Node.FunctionExpression {
const node = this.createNode();
this.expect('(');
this.expect(')');
const isGenerator = false;
const params = {
simple: true,
params: [],
stricted: null,
firstRestricted: null,
message: null
};
const previousAllowYield = this.context.allowYield;
this.context.allowYield = false;
const method = this.parsePropertyMethod(params);
const formalParameters = this.parseFormalParameters();
if (formalParameters.params.length > 0) {
this.tolerateError(Messages.BadGetterArity);
}
const method = this.parsePropertyMethod(formalParameters);
this.context.allowYield = previousAllowYield;
return this.finalize(node, new Node.FunctionExpression(null, params.params, method, isGenerator));
return this.finalize(node, new Node.FunctionExpression(null, formalParameters.params, method, isGenerator));
}
parseSetterMethod(): Node.FunctionExpression {
const node = this.createNode();
let options = {
simple: true,
params: [],
firstRestricted: null,
paramSet: {}
};
const isGenerator = false;
const previousAllowYield = this.context.allowYield;
this.context.allowYield = false;
this.expect('(');
if (this.match(')')) {
this.tolerateUnexpectedToken(this.lookahead);
} else {
this.parseFormalParameter(options);
const formalParameters = this.parseFormalParameters();
if (formalParameters.params.length !== 1) {
this.tolerateError(Messages.BadSetterArity);
}
this.expect(')');
const method = this.parsePropertyMethod(options);
const method = this.parsePropertyMethod(formalParameters);
this.context.allowYield = previousAllowYield;
return this.finalize(node, new Node.FunctionExpression(null, options.params, method, isGenerator));
return this.finalize(node, new Node.FunctionExpression(null, formalParameters.params, method, isGenerator));
}
parseGeneratorMethod(): Node.FunctionExpression {
@@ -0,0 +1 @@
x = { get y(z) {} }
Oops, something went wrong.

0 comments on commit ad622c8

Please sign in to comment.