Do not allow member expressions to start async arrows (#10332)

* Do not allow member expressions to start async arrows

* Boolean -> boolean
This commit is contained in:
Nicolò Ribaudo
2019-10-01 11:40:42 +02:00
committed by GitHub
parent 94fcabc4e3
commit 80d99b4d4e
6 changed files with 210 additions and 24 deletions

View File

@@ -578,21 +578,16 @@ export default class ExpressionParser extends LValParser {
startLoc: Position,
noCalls?: ?boolean,
): N.Expression {
const maybeAsyncArrow = this.atPossibleAsync(base);
const state = {
optionalChainMember: false,
maybeAsyncArrow: this.atPossibleAsync(base),
stop: false,
};
do {
base = this.parseSubscript(
base,
startPos,
startLoc,
noCalls,
state,
maybeAsyncArrow,
);
base = this.parseSubscript(base, startPos, startLoc, noCalls, state);
// After parsing a subscript, this isn't "async" for sure.
state.maybeAsyncArrow = false;
} while (!state.stop);
return base;
}
@@ -607,7 +602,6 @@ export default class ExpressionParser extends LValParser {
startLoc: Position,
noCalls: ?boolean,
state: N.ParseSubscriptState,
maybeAsyncArrow: boolean,
): N.Expression {
if (!noCalls && this.eat(tt.doubleColon)) {
const node = this.startNodeAt(startPos, startLoc);
@@ -695,7 +689,7 @@ export default class ExpressionParser extends LValParser {
node.arguments = this.parseCallExpressionArguments(
tt.parenR,
maybeAsyncArrow,
state.maybeAsyncArrow,
base.type === "Import",
base.type !== "Super",
);
@@ -705,7 +699,7 @@ export default class ExpressionParser extends LValParser {
this.finishOptionalCallExpression(node);
}
if (maybeAsyncArrow && this.shouldParseAsyncArrow()) {
if (state.maybeAsyncArrow && this.shouldParseAsyncArrow()) {
state.stop = true;
this.checkCommaAfterRestFromSpread();

View File

@@ -2634,7 +2634,6 @@ export default (superClass: Class<Parser>): Class<Parser> =>
startLoc: Position,
noCalls: ?boolean,
subscriptState: N.ParseSubscriptState,
maybeAsyncArrow: boolean,
): N.Expression {
if (this.match(tt.questionDot) && this.isLookaheadRelational("<")) {
this.expectPlugin("optionalChaining");
@@ -2687,7 +2686,6 @@ export default (superClass: Class<Parser>): Class<Parser> =>
startLoc,
noCalls,
subscriptState,
maybeAsyncArrow,
);
}

View File

@@ -1568,7 +1568,6 @@ export default (superClass: Class<Parser>): Class<Parser> =>
startLoc: Position,
noCalls: ?boolean,
state: N.ParseSubscriptState,
maybeAsyncArrow: boolean,
): N.Expression {
if (!this.hasPrecedingLineBreak() && this.match(tt.bang)) {
this.state.exprAllowed = false;
@@ -1631,14 +1630,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
if (result) return result;
}
return super.parseSubscript(
base,
startPos,
startLoc,
noCalls,
state,
maybeAsyncArrow,
);
return super.parseSubscript(base, startPos, startLoc, noCalls, state);
}
parseNewArguments(node: N.NewExpression): void {

View File

@@ -1447,5 +1447,6 @@ export type Placeholder<N: PlaceholderTypes> = NodeBase & {
export type ParseSubscriptState = {
optionalChainMember: boolean,
maybeAsyncArrow: boolean,
stop: boolean,
};