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

Function parseDecorator

packages/babel-parser/src/parser/statement.ts:669–720  ·  view source on GitHub ↗
(this: Parser)

Source from the content-addressed store, hash-verified

667 }
668
669 parseDecorator(this: Parser): N.Decorator {
670 this.expectOnePlugin(["decorators", "decorators-legacy"]);
671
672 const node = this.startNode<N.Decorator>();
673 this.next();
674
675 if (this.hasPlugin("decorators")) {
676 const startLoc = this.state.startLoc;
677 let expr: N.Expression;
678
679 if (this.match(tt.parenL)) {
680 const startLoc = this.state.startLoc;
681 this.next(); // eat '('
682 expr = this.parseExpression();
683 this.expect(tt.parenR);
684 expr = this.wrapParenthesis(startLoc, expr);
685
686 const paramsStartLoc = this.state.startLoc;
687 node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
688 if (node.expression !== expr) {
689 this.raise(
690 Errors.DecoratorArgumentsOutsideParentheses,
691 paramsStartLoc,
692 );
693 }
694 } else {
695 expr = this.parseIdentifier(false);
696
697 while (this.eat(tt.dot)) {
698 const node = this.startNodeAt<N.MemberExpression>(startLoc);
699 node.object = expr;
700 if (this.match(tt.privateName)) {
701 this.classScope.usePrivateName(
702 this.state.value,
703 this.state.startLoc,
704 );
705 node.property = this.parsePrivateName();
706 } else {
707 node.property = this.parseIdentifier(true);
708 }
709 node.computed = false;
710 expr = this.finishNode(node, "MemberExpression");
711 }
712
713 node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
714 }
715 } else {
716 this.state.canStartArrow = false;
717 node.expression = this.parseExprSubscripts();
718 }
719 return this.finishNode(node, "Decorator");
720 }
721
722 parseMaybeDecoratorArguments(
723 this: Parser,

Callers

nothing calls this directly

Calls 8

nextMethod · 0.80
hasPluginMethod · 0.80
matchMethod · 0.80
parseIdentifierMethod · 0.80
usePrivateNameMethod · 0.80
parsePrivateNameMethod · 0.80
finishNodeMethod · 0.80

Tested by

no test coverage detected