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

Function parseClassBody

packages/babel-parser/src/parser/statement.ts:1661–1718  ·  view source on GitHub ↗
(
    this: Parser,
    hadSuperClass: boolean,
    oldStrict: boolean,
  )

Source from the content-addressed store, hash-verified

1659
1660 // https://tc39.es/ecma262/#prod-ClassBody
1661 parseClassBody(
1662 this: Parser,
1663 hadSuperClass: boolean,
1664 oldStrict: boolean,
1665 ): N.ClassBody {
1666 this.classScope.enter();
1667
1668 const state: N.ParseClassMemberState = {
1669 hadConstructor: false,
1670 hadSuperClass,
1671 };
1672 let decorators: N.Decorator[] = [];
1673 const classBody = this.startNode<N.ClassBody>();
1674 classBody.body = [];
1675
1676 this.expect(tt.braceL);
1677
1678 // Parse the contents within the braces.
1679 while (!this.match(tt.braceR)) {
1680 if (this.eat(tt.semi)) {
1681 if (decorators.length > 0) {
1682 throw this.raise(
1683 Errors.DecoratorSemicolon,
1684 this.state.lastTokEndLoc!,
1685 );
1686 }
1687 continue;
1688 }
1689
1690 if (this.match(tt.at)) {
1691 decorators.push(this.parseDecorator());
1692 continue;
1693 }
1694
1695 const member = this.startNode<N.ClassMember>();
1696
1697 // steal the decorators if there are any
1698 if (decorators.length) {
1699 member.decorators = decorators;
1700 this.resetStartLocationFromNode(member, decorators[0]);
1701 decorators = [];
1702 }
1703
1704 this.parseClassMember(classBody, member, state);
1705 }
1706
1707 this.state.strict = oldStrict;
1708
1709 this.next(); // eat `}`
1710
1711 if (decorators.length) {
1712 throw this.raise(Errors.TrailingDecorator, this.state.startLoc);
1713 }
1714
1715 this.classScope.exit();
1716
1717 return this.finishNode(classBody, "ClassBody");
1718 }

Callers

nothing calls this directly

Calls 7

matchMethod · 0.80
nextMethod · 0.80
finishNodeMethod · 0.80
enterMethod · 0.45
pushMethod · 0.45
parseClassMemberMethod · 0.45
exitMethod · 0.45

Tested by

no test coverage detected