# All files / src/generators list.js

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

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    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
    36
    37
    38

    12x
    211x
    211x

    12x

    143x

    12x
    166x

    12x
    153x

    13x

    153x

     // @flow

    import type {
      ListNodeType,
      GeneratedCodeType,
      NodeType,
      CollectionCoreValueType,
      CollectionCoreSegmentType,
      SimpleListSegmentType
    } from '../types'

    const CompileListSegmentItem = (item: NodeType): GeneratedCodeType => {
      const Generator = require('./generator').default
      return Generator(item)
    }

    const CompileSimpleListSegment = (
      segment: SimpleListSegmentType
    ): GeneratedCodeType =>
      `[${segment.value.map(CompileListSegmentItem).join(', ')}]`

    const CompileListSegment = (segment: CollectionCoreSegmentType): GeneratedCodeType =>
      segment.name === 'simpleList'
        ? CompileSimpleListSegment(segment)
        : CompileListSegmentItem(segment.value)

    const CompileListSegments = (segments: CollectionCoreValueType): GeneratedCodeType =>
      segments.reduce(
        (a: GeneratedCodeType, b: CollectionCoreSegmentType): GeneratedCodeType =>
          `${a}.concat(_.__spread__(${CompileListSegment(b)}))`,
        ''
      )

    export default ({ value }: ListNodeType): GeneratedCodeType =>
      `Array.from(${CompileListSegment(value[0])}${CompileListSegments(
        value.slice(1)
      )})`