All files / pxi-args/src/dsl/fp combine.js

91.67% Statements 33/36
80.77% Branches 21/26
100% Functions 1/1
90.32% Lines 28/31

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 39 40 41 42 43 44 45 46 47 48 49 50 511x   1x 300x 300x   300x 1447x   1447x     1447x   1447x 1447x 1447x 1447x 1357x 368x   989x 989x 989x 100x   889x 889x         90x 90x 90x 90x 90x   90x 90x                   300x  
const {invalidTypesInArgument, nonMatchingArgumentTypes, invalidOptionsListInCombine} = require('../../errors')
 
module.exports = (...options) => {
  let errs2   = []
  const args2 = {}
 
  for (let i = 0; i < options.length; i++) {
    const {errs = [], args} = options[i]
 
    Iif (errs.length > 0) {
      errs2 = errs2.concat(errs)
    } else {
      const keys = Object.keys(args)
 
      for (let j = 0; j < keys.length; j++) {
        const arg  = keys[j]
        const list = args[arg]
        if (typeof args2[arg] === 'undefined') {
          if (typeof list === 'undefined' || list === null || list.length === 0) {
            errs2.push(invalidOptionsListInCombine({list, arg, option: options[i]}))
          } else {
            for (let k = 0; k < list.length; k++) {
              const argument = list[k]
              if (!(Array.isArray(argument.types) || argument.types === null)) {
                errs2.push(invalidTypesInArgument({types: argument.types, argument}))
              } else {
                Eif (typeof args2[arg] === 'undefined') args2[arg] = []
                args2[arg].push(argument)
              }
            }
          }
        } else {
          const ref   = args2[arg][0]
          const types = ref.types
          for (let k = 0; k < list.length; k++) {
            const argument = list[k]
            Iif (!(Array.isArray(argument.types) || argument.types === null)) {
              errs2.push(invalidTypesInArgument({types: argument.types, argument}))
            } else Eif ((argument.types || []).length === (types || []).length) {
              args2[arg].push(argument)
            } else {
              errs2.push(nonMatchingArgumentTypes({arg, ref, argument}))
            }
          }
        }
      }
    }
  }
 
  return {errs: errs2, args: args2}
}