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

Function parseFunctionOrFunctionSent

packages/babel-parser/src/parser/expression.ts:1633–1665  ·  view source on GitHub ↗
(
    this: Parser,
  )

Source from the content-addressed store, hash-verified

1631 }
1632
1633 parseFunctionOrFunctionSent(
1634 this: Parser,
1635 ): N.FunctionExpression | N.MetaProperty {
1636 const node = this.startNode<N.FunctionExpression | N.MetaProperty>();
1637
1638 // We do not do parseIdentifier here because when parseFunctionOrFunctionSent
1639 // is called we already know that the current token is a "name" with the value "function"
1640 // This will improve perf a tiny little bit as we do not do validation but more importantly
1641 // here is that parseIdentifier will remove an item from the expression stack
1642 // if "function" or "class" is parsed as identifier (in objects e.g.), which should not happen here.
1643 this.next(); // eat `function`
1644
1645 if (this.prodParam.hasYield && this.match(tt.dot)) {
1646 const meta = this.createIdentifier(
1647 this.startNodeAtNode<N.Identifier>(node),
1648 "function",
1649 );
1650 this.next(); // eat `.`
1651 // https://github.com/tc39/proposal-function.sent#syntax-1
1652 if (this.match(tt._sent)) {
1653 this.expectPlugin("functionSent");
1654 } else if (!this.hasPlugin("functionSent")) {
1655 // The code wasn't `function.sent` but just `function.`, so a simple error is less confusing.
1656 this.unexpected();
1657 }
1658 return this.parseMetaProperty(
1659 node as Undone<N.MetaProperty>,
1660 meta,
1661 "sent",
1662 );
1663 }
1664 return this.parseFunction(node as Undone<N.FunctionExpression>);
1665 }
1666
1667 parseMetaProperty(
1668 node: Undone<N.MetaProperty>,

Callers

nothing calls this directly

Calls 3

nextMethod · 0.80
matchMethod · 0.80
hasPluginMethod · 0.80

Tested by

no test coverage detected