MCPcopy Create free account
hub / github.com/babel/babel / parseMaybeUnary

Function parseMaybeUnary

packages/babel-parser/src/parser/expression.ts:660–730  ·  view source on GitHub ↗
(
    this: Parser,
    refExpressionErrors?: ExpressionErrors | null,
    sawUnary?: boolean,
  )

Source from the content-addressed store, hash-verified

658 // Parse unary operators, both prefix and postfix.
659 // https://tc39.es/ecma262/#prod-UnaryExpression
660 parseMaybeUnary(
661 this: Parser,
662 refExpressionErrors?: ExpressionErrors | null,
663 sawUnary?: boolean,
664 ): N.Expression {
665 const startLoc = this.state.startLoc;
666 const isAwait = this.isContextual(tt._await);
667
668 if (isAwait && this.recordAwaitIfAllowed()) {
669 this.next();
670 const expr = this.parseAwait(startLoc);
671 if (!sawUnary) this.checkExponentialAfterUnary(expr);
672 return expr;
673 }
674 if (tokenIsPrefix(this.state.type)) {
675 const update = this.match(tt.incDec);
676 const node = this.startNode<N.UnaryExpression | N.UpdateExpression>();
677 node.operator = this.state.value;
678 node.prefix = true;
679 this.state.canStartArrow = false;
680
681 if (this.match(tt._throw)) {
682 this.expectPlugin("throwExpressions");
683 }
684 const isDelete = this.match(tt._delete);
685 this.next();
686
687 node.argument = this.parseMaybeUnary(null, true);
688
689 this.checkExpressionErrors(refExpressionErrors, true);
690
691 if (this.state.strict && isDelete) {
692 const arg = unwrapParenthesizedExpression(node.argument);
693
694 if (arg.type === "Identifier") {
695 this.raise(Errors.StrictDelete, node);
696 } else if (this.hasPropertyAsPrivateName(arg)) {
697 this.raise(Errors.DeletePrivateField, node);
698 }
699 }
700
701 if (!update) {
702 if (!sawUnary) {
703 this.checkExponentialAfterUnary(node as Undone<N.UnaryExpression>);
704 }
705 return this.finishNode(node, "UnaryExpression");
706 }
707
708 const result = this.finishNode(
709 node as Undone<N.UpdateExpression>,
710 "UpdateExpression",
711 );
712 this.checkLVal(result.argument, result);
713 return result;
714 }
715
716 const expr = this.parseUpdate(refExpressionErrors);
717

Callers

nothing calls this directly

Calls 9

tokenIsPrefixFunction · 0.90
tokenCanStartExpressionFunction · 0.90
nextMethod · 0.80
matchMethod · 0.80
parseMaybeUnaryMethod · 0.80
finishNodeMethod · 0.80
hasPluginMethod · 0.80

Tested by

no test coverage detected