All files / src/parsers identifier.js

100% Statements 5/5
100% Branches 2/2
100% Functions 2/2
100% Lines 5/5

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              950x 950x 946x   4x     946x          
// @flow
 
import P from 'parsimmon'
import type { IdentifierNodeType } from '../types'
 
export default P.regexp(/[a-zA-Z][0-9a-zA-Z_$]*/i)
  .chain((identifier: string): IdentifierNodeType => {
    const exceptions = ['null', 'false', 'true', 'if', 'each']
    if (exceptions.indexOf(identifier) < 0) {
      return P.of(identifier)
    } else {
      return P.fail(`identifier but got keyword ${identifier}`)
    }
  })
  .map((value: string): IdentifierNodeType => ({
    name: 'identifier',
    value
  }))
  .desc('identifier')