Skip to content

Commit

Permalink
parseUnary -> parseMaybeUnary
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Jul 27, 2020
1 parent 03789f3 commit 206786e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
13 changes: 7 additions & 6 deletions packages/babel-parser/src/parser/expression.js
Expand Up @@ -188,6 +188,7 @@ export default class ExpressionParser extends LValParser {
// Parse an assignment expression. This includes applications of
// operators like `+=`.

// https://tc39.es/ecma262/#prod-AssignmentExpression
parseMaybeAssign(
noIn?: ?boolean,
refExpressionErrors?: ?ExpressionErrors,
Expand Down Expand Up @@ -320,7 +321,7 @@ export default class ExpressionParser extends LValParser {
const startPos = this.state.start;
const startLoc = this.state.startLoc;
const potentialArrowAt = this.state.potentialArrowAt;
const expr = this.parseUnary(refExpressionErrors);
const expr = this.parseMaybeUnary(refExpressionErrors);

if (this.shouldExitDescending(expr, potentialArrowAt)) {
return expr;
Expand Down Expand Up @@ -471,7 +472,7 @@ export default class ExpressionParser extends LValParser {
const startLoc = this.state.startLoc;

return this.parseExprOp(
this.parseUnary(),
this.parseMaybeUnary(),
startPos,
startLoc,
op.rightAssociative ? prec - 1 : prec,
Expand All @@ -481,7 +482,7 @@ export default class ExpressionParser extends LValParser {

// Parse unary operators, both prefix and postfix.
// https://tc39.es/ecma262/#prod-UnaryExpression
parseUnary(refExpressionErrors: ?ExpressionErrors): N.Expression {
parseMaybeUnary(refExpressionErrors: ?ExpressionErrors): N.Expression {
if (this.isContextual("await") && this.isAwaitAllowed()) {
return this.parseAwait();
}
Expand All @@ -497,7 +498,7 @@ export default class ExpressionParser extends LValParser {
const isDelete = this.match(tt._delete);
this.next();

node.argument = this.parseUnary();
node.argument = this.parseMaybeUnary();

this.checkExpressionErrors(refExpressionErrors, true);

Expand Down Expand Up @@ -2424,7 +2425,7 @@ export default class ExpressionParser extends LValParser {
}

if (!this.state.soloAwait) {
node.argument = this.parseUnary();
node.argument = this.parseMaybeUnary();
}

return this.finishNode(node, "AwaitExpression");
Expand Down Expand Up @@ -2642,7 +2643,7 @@ export default class ExpressionParser extends LValParser {
this.state.inFSharpPipelineDirectBody = true;

const ret = this.parseExprOp(
this.parseUnary(),
this.parseMaybeUnary(),
startPos,
startLoc,
prec,
Expand Down
10 changes: 5 additions & 5 deletions packages/babel-parser/src/plugins/typescript/index.js
Expand Up @@ -762,7 +762,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
if (nextToken.type !== tt.num && nextToken.type !== tt.bigint) {
throw this.unexpected();
}
node.literal = this.parseUnary();
node.literal = this.parseMaybeUnary();
return this.finishNode(node, "TSLiteralType");
}
break;
Expand Down Expand Up @@ -1118,7 +1118,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
const _const = this.tsTryNextParseConstantContext();
node.typeAnnotation = _const || this.tsNextThenParseType();
this.expectRelational(">");
node.expression = this.parseUnary();
node.expression = this.parseMaybeUnary();
return this.finishNode(node, "TSTypeAssertion");
}

Expand Down Expand Up @@ -2384,7 +2384,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
// (Because in JSX the '<' should be a jsxTagStart and not a relational.
assert(!this.hasPlugin("jsx"));

// This will start with a type assertion (via parseUnary).
// This will start with a type assertion (via parseMaybeUnary).
// But don't directly call `this.tsParseTypeAssertion` because we want to handle any binary after it.
typeCast = this.tryParse(() => super.parseMaybeAssign(...args), state);
/*:: invariant(!typeCast.aborted) */
Expand Down Expand Up @@ -2417,11 +2417,11 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}

// Handle type assertions
parseUnary(refExpressionErrors?: ?ExpressionErrors): N.Expression {
parseMaybeUnary(refExpressionErrors?: ?ExpressionErrors): N.Expression {
if (!this.hasPlugin("jsx") && this.isRelational("<")) {
return this.tsParseTypeAssertion();
} else {
return super.parseUnary(refExpressionErrors);
return super.parseMaybeUnary(refExpressionErrors);
}
}

Expand Down

0 comments on commit 206786e

Please sign in to comment.