Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Commit

Permalink
Rename parseClassMethod to pushClassMethod
Browse files Browse the repository at this point in the history
This makes it consistent to the equivalent method for class properties,
as well as the private version (parseClassPrivateMethod).

This commit also removes one of the tests from the Test262 whitelist.
  • Loading branch information
Qantas94Heavy committed Sep 4, 2017
1 parent db7619f commit 8b5c2d5
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 55 deletions.
4 changes: 1 addition & 3 deletions scripts/test262_whitelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,6 @@ language/statements/class/definition/early-errors-class-method-await-in-formals.
language/statements/class/strict-mode/with.js(default)
language/statements/class/syntax/early-errors/class-body-has-direct-super-missing-class-heritage.js(default)
language/statements/class/syntax/early-errors/class-body-has-direct-super-missing-class-heritage.js(strict mode)
language/statements/class/syntax/early-errors/class-body-static-method-get-propname-prototype.js(default)
language/statements/class/syntax/early-errors/class-body-static-method-get-propname-prototype.js(strict mode)
language/statements/class/syntax/early-errors/class-definition-evaluation-block-duplicate-binding.js(default)
language/statements/class/syntax/early-errors/class-definition-evaluation-block-duplicate-binding.js(strict mode)
language/statements/class/syntax/early-errors/class-definition-evaluation-scriptbody-duplicate-binding.js(default)
Expand Down Expand Up @@ -1305,4 +1303,4 @@ language/statements/class/fields-wrapped-in-sc-string-literal-names.js(strict mo

language/statements/labeled/let-identifier-with-newline.js(default)
language/statements/labeled/value-yield-non-strict-escaped.js(default)
language/statements/let/syntax/escaped-let.js(default)
language/statements/let/syntax/escaped-let.js(default)
2 changes: 1 addition & 1 deletion src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -1411,12 +1411,12 @@ export default class ExpressionParser extends LValParser {
} else {
const oldInPropertyName = this.state.inPropertyName;
this.state.inPropertyName = true;
// We check if it's valid for it to be a private name when we push it.
prop.key =
this.match(tt.num) || this.match(tt.string)
? this.parseExprAtom()
: this.parseMaybePrivateName();

// TODO: if no plugin and is PrivateName, should error be handled here or elsewhere?
if (prop.key.type !== "PrivateName") {
// ClassPrivateProperty is never computed, so we don't assign in that case.
prop.computed = false;
Expand Down
92 changes: 46 additions & 46 deletions src/parser/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ export default class StatementParser extends ExpressionParser {
method.computed = false;
method.key = key;
method.static = false;
this.parseClassMethod(
this.pushClassMethod(
classBody,
method,
false,
Expand Down Expand Up @@ -982,15 +982,15 @@ export default class StatementParser extends ExpressionParser {

if (method.key.type === "PrivateName") {
// Private generator method
this.parseClassPrivateMethod(classBody, method, true, false);
this.pushClassPrivateMethod(classBody, method, true, false);
return;
}

if (this.isNonstaticConstructor(method)) {
this.raise(method.key.start, "Constructor can't be a generator");
}

this.parseClassMethod(
this.pushClassMethod(
classBody,
method,
true,
Expand All @@ -1004,7 +1004,7 @@ export default class StatementParser extends ExpressionParser {
const key = this.parseClassPropertyName(methodOrProp);
const isPrivate = key.type === "PrivateName";
// Check the key is not a computed expression or string literal.
const isSimple = key.type === 'Identifier';
const isSimple = key.type === "Identifier";

// TODO: should these be merged into pushClassProperty?
const handleClassProperty = () => {
Expand All @@ -1021,7 +1021,7 @@ export default class StatementParser extends ExpressionParser {
method.kind = "method";

if (isPrivate) {
this.parseClassPrivateMethod(classBody, method, false, false);
this.pushClassPrivateMethod(classBody, method, false, false);
return;
}

Expand All @@ -1045,7 +1045,7 @@ export default class StatementParser extends ExpressionParser {
state.hadConstructor = true;
}

this.parseClassMethod(classBody, method, false, false, isConstructor);
this.pushClassMethod(classBody, method, false, false, isConstructor);
} else if (this.isClassProperty()) {
handleClassProperty();
} else if (isSimple && key.name === "async" && !this.isLineTerminator()) {
Expand All @@ -1062,7 +1062,7 @@ export default class StatementParser extends ExpressionParser {

if (method.key.type === "PrivateName") {
// private async method
this.parseClassPrivateMethod(classBody, method, isGenerator, true);
this.pushClassPrivateMethod(classBody, method, isGenerator, true);
} else {
if (this.isNonstaticConstructor(method)) {
this.raise(
Expand All @@ -1071,7 +1071,7 @@ export default class StatementParser extends ExpressionParser {
);
}

this.parseClassMethod(
this.pushClassMethod(
classBody,
method,
isGenerator,
Expand All @@ -1092,15 +1092,15 @@ export default class StatementParser extends ExpressionParser {

if (method.key.type === "PrivateName") {
// private getter/setter
this.parseClassPrivateMethod(classBody, method, false, false);
this.pushClassPrivateMethod(classBody, method, false, false);
} else {
if (this.isNonstaticConstructor(method)) {
this.raise(
method.key.start,
"Constructor can't have get/set modifier",
);
}
this.parseClassMethod(
this.pushClassMethod(
classBody,
method,
false,
Expand Down Expand Up @@ -1161,6 +1161,42 @@ export default class StatementParser extends ExpressionParser {
classBody.body.push(this.parseClassPrivateProperty(prop));
}

pushClassMethod(
classBody: N.ClassBody,
method: N.ClassMethod,
isGenerator: boolean,
isAsync: boolean,
isConstructor: boolean,
): void {
classBody.body.push(
this.parseMethod(
method,
isGenerator,
isAsync,
isConstructor,
"ClassMethod",
),
);
}

pushClassPrivateMethod(
classBody: N.ClassBody,
method: N.ClassMethod,
isGenerator: boolean,
isAsync: boolean,
): void {
this.expectPlugin("classPrivateMethods", method.key.start);
classBody.body.push(
this.parseMethod(
method,
isGenerator,
isAsync,
/* isConstructor */ false,
"ClassPrivateMethod",
),
);
}

// Overridden in typescript.js
parsePostMemberNameModifiers(
// eslint-disable-next-line no-unused-vars
Expand Down Expand Up @@ -1202,42 +1238,6 @@ export default class StatementParser extends ExpressionParser {
return this.finishNode(node, "ClassProperty");
}

parseClassMethod(
classBody: N.ClassBody,
method: N.ClassMethod,
isGenerator: boolean,
isAsync: boolean,
isConstructor: boolean,
): void {
classBody.body.push(
this.parseMethod(
method,
isGenerator,
isAsync,
isConstructor,
"ClassMethod",
),
);
}

parseClassPrivateMethod(
classBody: N.ClassBody,
method: N.ClassMethod,
isGenerator: boolean,
isAsync: boolean,
): void {
this.expectPlugin("classPrivateMethods", method.key.start);
classBody.body.push(
this.parseMethod(
method,
isGenerator,
isAsync,
/* isConstructor */ false,
"ClassPrivateMethod",
),
);
}

parseClassId(
node: N.Class,
isStatement: boolean,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/estree.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
delete node.directives;
}

parseClassMethod(
pushClassMethod(
classBody: N.ClassBody,
method: N.ClassMethod,
isGenerator: boolean,
Expand Down
21 changes: 19 additions & 2 deletions src/plugins/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}

// parse type parameters for class methods
parseClassMethod(
pushClassMethod(
classBody: N.ClassBody,
method: N.ClassMethod,
isGenerator: boolean,
Expand All @@ -1541,7 +1541,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
method.typeParameters = this.flowParseTypeParameterDeclaration();
}

super.parseClassMethod(
super.pushClassMethod(
classBody,
method,
isGenerator,
Expand All @@ -1550,6 +1550,23 @@ export default (superClass: Class<Parser>): Class<Parser> =>
);
}

pushClassPrivateMethod(
classBody: N.ClassBody,
method: N.ClassPrivateMethod,
isGenerator: boolean,
isAsync: boolean,
): void {
if (method.variance) {
this.unexpected(method.variance.start);
}
delete method.variance;
if (this.isRelational("<")) {
method.typeParameters = this.flowParseTypeParameterDeclaration();
}

super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
}

// parse a the super class type parameters and implements
parseClassSuper(node: N.Class): void {
super.parseClassSuper(node);
Expand Down
15 changes: 13 additions & 2 deletions src/plugins/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -1639,7 +1639,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
return super.parseClassProperty(node);
}

parseClassMethod(
pushClassMethod(
classBody: N.ClassBody,
method: N.ClassMethod,
isGenerator: boolean,
Expand All @@ -1648,7 +1648,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
): void {
const typeParameters = this.tsTryParseTypeParameters();
if (typeParameters) method.typeParameters = typeParameters;
super.parseClassMethod(
super.pushClassMethod(
classBody,
method,
isGenerator,
Expand All @@ -1657,6 +1657,17 @@ export default (superClass: Class<Parser>): Class<Parser> =>
);
}

pushClassPrivateMethod(
classBody: N.ClassBody,
method: N.ClassPrivateMethod,
isGenerator: boolean,
isAsync: boolean,
): void {
const typeParameters = this.tsTryParseTypeParameters();
if (typeParameters) method.typeParameters = typeParameters;
super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
}

parseClassSuper(node: N.Class): void {
super.parseClassSuper(node);
if (node.superClass && this.isRelational("<")) {
Expand Down

0 comments on commit 8b5c2d5

Please sign in to comment.