@@ -1498,11 +1498,12 @@ export default class ExpressionParser extends LValParser {
|
||||
return node;
|
||||
}
|
||||
|
||||
// Parse arrow function expression with given parameters.
|
||||
|
||||
// Parse arrow function expression.
|
||||
// If the parameters are provided, they will be converted to an
|
||||
// assignable list.
|
||||
parseArrowExpression(
|
||||
node: N.ArrowFunctionExpression,
|
||||
params: N.Expression[],
|
||||
params?: ?(N.Expression[]),
|
||||
isAsync?: boolean,
|
||||
): N.ArrowFunctionExpression {
|
||||
// if we got there, it's no more "yield in possible arrow parameters";
|
||||
@@ -1518,7 +1519,7 @@ export default class ExpressionParser extends LValParser {
|
||||
const oldInFunc = this.state.inFunction;
|
||||
this.state.inFunction = true;
|
||||
this.initFunction(node, isAsync);
|
||||
this.setArrowFunctionParameters(node, params);
|
||||
if (params) this.setArrowFunctionParameters(node, params);
|
||||
|
||||
const oldInGenerator = this.state.inGenerator;
|
||||
const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
|
||||
|
||||
@@ -2219,8 +2219,45 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
node.callee = base;
|
||||
node.arguments = this.parseCallExpressionArguments(tt.parenR, false);
|
||||
base = this.finishNode(node, "CallExpression");
|
||||
} else if (
|
||||
base.type === "Identifier" &&
|
||||
base.name === "async" &&
|
||||
this.isRelational("<")
|
||||
) {
|
||||
const state = this.state.clone();
|
||||
let error;
|
||||
try {
|
||||
const node = this.parseAsyncArrowWithTypeParameters(
|
||||
startPos,
|
||||
startLoc,
|
||||
);
|
||||
if (node) return node;
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
this.state = state;
|
||||
try {
|
||||
return super.parseSubscripts(base, startPos, startLoc, noCalls);
|
||||
} catch (e) {
|
||||
throw error || e;
|
||||
}
|
||||
}
|
||||
|
||||
return super.parseSubscripts(base, startPos, startLoc, noCalls);
|
||||
}
|
||||
|
||||
parseAsyncArrowWithTypeParameters(
|
||||
startPos: number,
|
||||
startLoc: Position,
|
||||
): ?N.ArrowFunctionExpression {
|
||||
const node = this.startNodeAt(startPos, startLoc);
|
||||
this.parseFunctionParams(node);
|
||||
if (!this.parseArrow(node)) return;
|
||||
return this.parseArrowExpression(
|
||||
node,
|
||||
/* params */ undefined,
|
||||
/* isAsync */ true,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user