Add more parser test cases (#11923)

* remove unused codes

* refactor: remove unused parseAccessModifier

* refactor: remove redundant async function checks

* refactor: remove redundant class check in checkExport

* add more parser test cases

* Update packages/babel-parser/src/parser/statement.js

Co-authored-by: Brian Ng <bng412@gmail.com>

* chore: add sourceType: unambiguous test

Co-authored-by: Brian Ng <bng412@gmail.com>
This commit is contained in:
Huáng Jùnliàng
2020-08-14 11:53:17 -04:00
committed by GitHub
parent 9c565a97d5
commit 66c6b3b949
28 changed files with 246 additions and 37 deletions

View File

@@ -1258,20 +1258,6 @@ export default class StatementParser extends ExpressionParser {
return this.finishNode(classBody, "ClassBody");
}
// Check grammar production:
// IdentifierName *_opt ClassElementName
// It is used in `parsePropertyDefinition` to detect AsyncMethod and Accessors
maybeClassModifier(prop: N.ObjectProperty): boolean {
return (
!prop.computed &&
prop.key.type === "Identifier" &&
(this.isLiteralPropertyName() ||
this.match(tt.bracketL) ||
this.match(tt.star) ||
this.match(tt.hash))
);
}
// returns true if the current identifier is a method/field name,
// false if it is a modifier
parseClassMemberFromModifier(
@@ -1611,11 +1597,6 @@ export default class StatementParser extends ExpressionParser {
methodOrProp: N.ClassMethod | N.ClassProperty,
): void {}
// Overridden in typescript.js
parseAccessModifier(): ?N.Accessibility {
return undefined;
}
parseClassPrivateProperty(
node: N.ClassPrivateProperty,
): N.ClassPrivateProperty {
@@ -1784,19 +1765,9 @@ export default class StatementParser extends ExpressionParser {
maybeParseExportDeclaration(node: N.Node): boolean {
if (this.shouldParseExportDeclaration()) {
if (this.isContextual("async")) {
const next = this.nextTokenStart();
// export async;
if (!this.isUnparsedContextual(next, "function")) {
this.unexpected(next, tt._function);
}
}
node.specifiers = [];
node.source = null;
node.declaration = this.parseExportDeclaration(node);
return true;
}
return false;
@@ -1999,15 +1970,10 @@ export default class StatementParser extends ExpressionParser {
const currentContextDecorators = this.state.decoratorStack[
this.state.decoratorStack.length - 1
];
// If node.declaration is a class, it will take all decorators in the current context.
// Thus we should throw if we see non-empty decorators here.
if (currentContextDecorators.length) {
const isClass =
node.declaration &&
(node.declaration.type === "ClassDeclaration" ||
node.declaration.type === "ClassExpression");
if (!node.declaration || !isClass) {
throw this.raise(node.start, Errors.UnsupportedDecoratorExport);
}
this.takeDecorators(node.declaration);
throw this.raise(node.start, Errors.UnsupportedDecoratorExport);
}
}