Parser refactoring (#11871)

* refactor: parseMaybeUnary => parseUnary

* refactor: extract shouldExitDescending method

* refactor: add parseUpdate

* refactor: avoid comparing with hardcoded token value

* refactor: add ParseNewOrNewTarget

* refactor: add parseCoverCallAndAsyncArrowHead

* add parseBind

* refactor: polish parseTaggedTemplateExpression interface

* refactor: add parseMember method

* refactor: add parseSuper method

* refactor: add parseAsyncArrowUnaryFunction method

* fix: disallow line break before async binding arrow

* refactor: simplify tt.name logic

* refactor: add parseDo method

* refactor: misc

* refactor: rename parseObjectMember by parsePropertyDefinition

* refactor: unify set/get/async keyword parsing in ObjectMethod

* refactor: misc

* refactor: add parseArrayLike method

* refactor: move fsharp epilogure and prologue inside parseObjectLike

* fixup

* refactor: rename parseFunctionExpression to parseFunctionOrFunctionSent

* refactor: remove redundant logic

* refactor: rename parseClassPropertyName by parseClassElementName

* refactor: avoid unecessary lookahead when parsing tt._export

* fix: export-default-from should support escaped async as export binding

* address review comments

* parseUnary -> parseMaybeUnary
This commit is contained in:
Huáng Jùnliàng
2020-07-31 20:36:04 -04:00
committed by GitHub
parent ad60153a98
commit a4ebe29b3f
29 changed files with 620 additions and 430 deletions

View File

@@ -313,14 +313,14 @@ export default (superClass: Class<Parser>): Class<Parser> =>
isGenerator: boolean,
isAsync: boolean,
isPattern: boolean,
containsEsc: boolean,
isAccessor: boolean,
): ?N.ObjectMethod {
const node: N.EstreeProperty = (super.parseObjectMethod(
prop,
isGenerator,
isAsync,
isPattern,
containsEsc,
isAccessor,
): any);
if (node) {

View File

@@ -2362,8 +2362,8 @@ export default (superClass: Class<Parser>): Class<Parser> =>
isGenerator: boolean,
isAsync: boolean,
isPattern: boolean,
isAccessor: boolean,
refExpressionErrors: ?ExpressionErrors,
containsEsc: boolean,
): void {
if ((prop: $FlowFixMe).variance) {
this.unexpected((prop: $FlowFixMe).variance.start);
@@ -2373,7 +2373,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
let typeParameters;
// method shorthand
if (this.isRelational("<")) {
if (this.isRelational("<") && !isAccessor) {
typeParameters = this.flowParseTypeParameterDeclaration();
if (!this.match(tt.parenL)) this.unexpected();
}
@@ -2385,8 +2385,8 @@ export default (superClass: Class<Parser>): Class<Parser> =>
isGenerator,
isAsync,
isPattern,
isAccessor,
refExpressionErrors,
containsEsc,
);
// add typeParameters if we found them

View File

@@ -1823,13 +1823,14 @@ export default (superClass: Class<Parser>): Class<Parser> =>
node.typeParameters = typeArguments;
return this.finishCallExpression(node, state.optionalChainMember);
} else if (this.match(tt.backQuote)) {
return this.parseTaggedTemplateExpression(
const result = this.parseTaggedTemplateExpression(
base,
startPos,
startLoc,
base,
state,
typeArguments,
);
result.typeParameters = typeArguments;
return result;
}
}