# All files / src/parser fragment.js

100% Statements 4/4
100% Branches 0/0
100% Functions 1/1
100% Lines 4/4

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

    24x

    24x

    4x

    4x

     /**
     * Syntax Analysis
     *
     * The parser below creates the "bare" Abstract Syntax Tree.
     */

    // @flow
    import curry from 'curry';
    import type { NodeType } from '../flow/types';

    export const makeFragment = curry(
      (parser: string => NodeType, source: string): NodeType => {
        // For fragments we must wrap the source in a function
        // otherwise the parser will fail as it's not a valid
        // place for an expression
        const program = parser(`function fragment() {
        ${source};
      }`);
        // 1st node is a function.
        // 3rd node of a function is a block, containing a single expression
        return program.params[0].params[2].params[0];
      }
    );