Parse class fields and private methods by default (#13175)

* feat: materialize class features

* chore: move testcases to es2022

* chore: update test fixtures

* chore: remove classPr\w+ from options.json

* chore: remove empty options.json

* update flow test allowlist

* update typescript allowlist
This commit is contained in:
Huáng Jùnliàng
2021-04-20 13:00:05 -04:00
committed by Nicolò Ribaudo
parent b116865077
commit ceaab0bae7
481 changed files with 202 additions and 586 deletions

View File

@@ -189,7 +189,8 @@ export const ErrorMessages = makeErrorTemplates(
"Leading decorators must be attached to a class declaration.",
UnexpectedLexicalDeclaration:
"Lexical declaration cannot appear in a single-statement context.",
UnexpectedNewTarget: "`new.target` can only be used in functions.",
UnexpectedNewTarget:
"`new.target` can only be used in functions or class properties.",
UnexpectedNumericSeparator:
"A numeric separator is only allowed between two digits.",
UnexpectedPrivateField:

View File

@@ -1283,7 +1283,6 @@ export default class ExpressionParser extends LValParser {
const isPrivate = this.match(tt.hash);
if (isPrivate) {
this.expectOnePlugin(["classPrivateProperties", "classPrivateMethods"]);
if (!isPrivateNameAllowed) {
this.raise(this.state.pos, Errors.UnexpectedPrivateField);
}
@@ -1520,15 +1519,7 @@ export default class ExpressionParser extends LValParser {
const metaProp = this.parseMetaProperty(node, meta, "target");
if (!this.scope.inNonArrowFunction && !this.scope.inClass) {
const errorTemplate = { ...Errors.UnexpectedNewTarget };
if (this.hasPlugin("classProperties")) {
errorTemplate.template += " or class properties";
}
/* eslint-disable @babel/development-internal/dry-error-messages */
this.raise(metaProp.start, errorTemplate);
/* eslint-enable @babel/development-internal/dry-error-messages */
this.raise(metaProp.start, Errors.UnexpectedNewTarget);
}
return metaProp;

View File

@@ -1564,8 +1564,6 @@ export default class StatementParser extends ExpressionParser {
classBody: N.ClassBody,
prop: N.ClassPrivateProperty,
) {
this.expectPlugin("classPrivateProperties", prop.key.start);
const node = this.parseClassPrivateProperty(prop);
classBody.body.push(node);
@@ -1603,8 +1601,6 @@ export default class StatementParser extends ExpressionParser {
isGenerator: boolean,
isAsync: boolean,
): void {
this.expectPlugin("classPrivateMethods", method.key.start);
const node = this.parseMethod(
method,
isGenerator,
@@ -1650,9 +1646,6 @@ export default class StatementParser extends ExpressionParser {
// https://tc39.es/proposal-class-fields/#prod-FieldDefinition
parseClassProperty(node: N.ClassProperty): N.ClassProperty {
if (!node.typeAnnotation || this.match(tt.eq)) {
this.expectPlugin("classProperties");
}
this.parseInitializer(node);
this.semicolon();
return this.finishNode(node, "ClassProperty");