# All files / src/parser maybe-identifier.js

100% Statements 11/11
100% Branches 2/2
100% Functions 1/1
100% Lines 11/11

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    28x
    28x

    28x
    552x
    552x

    552x
    45x
    45x

    45x
    45x

    507x

     // @flow
    import Syntax from "../Syntax";
    import expression from "./expression";
    import type Context from "./context";
    import type { NodeType } from "../flow/types";

    // Maybe identifier, maybe function call
    const maybeIdentifier = (ctx: Context): NodeType => {
      const node = ctx.startNode();
      ctx.eat(null, Syntax.Identifier);

      if (ctx.eat(["("])) {
        const params = [expression(ctx)];
        const functionCall = ctx.endNode(
          {
            ...node,
            params: params.filter(Boolean),
          },
          Syntax.FunctionCall
        );
        ctx.expect([")"]);
        return functionCall;
      }

      return ctx.endNode(node, Syntax.Identifier);
    };

    export default maybeIdentifier;