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

100% Statements 15/15
100% Branches 8/8
100% Functions 1/1
100% Lines 15/15

    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
    30
    31
    32
    33
    34
    35
    27x
    27x

    27x
    2793x
    2793x

    2793x
    19x
    19x
    19x

    2774x
    226x
    226x

    226x
    226x

    2548x

     // @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 (node.value === 'false' || node.value === 'true') {
        node.type = 'bool';
        node.value = node.value === 'true' ? '1' : '0';
        return ctx.endNode(node, Syntax.Constant);
      }

      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;