Skip to content

Commit

Permalink
docs(types): fix type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
layershifter committed May 14, 2017
1 parent a14cb23 commit 8a37929
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions gulp/plugins/util/parseType.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
require('babel-register')
const _ = require('lodash')
const SUI = require('../../../src/lib/SUI')
const SUI = require('../../../src/lib/SUI') // eslint-disable-line no-unused-vars

module.exports = (propDef) => {
const { type } = propDef
const { name, value } = type
const evalValue = (values) => _.uniq(eval(values)).map(value => ({ // eslint-disable-line no-eval
computed: true,
value: `'${value}'`,
}))

if (name !== 'enum') return type
if (!_.startsWith(value, 'SUI') && !_.startsWith(value, '_.without(SUI')) return type
return _.assign(type, { value: eval(value) })
const transformValues = (items) => _.flatMap(items, item => {
const { value } = item

if (_.startsWith(value, '...SUI')) return evalValue(value.substring(3))
return item
})

const parseEnum = type => {
const { value } = type

if (typeof value === 'string' && value.includes('SUI')) {
return Object.assign(type, { value: evalValue(value) })
}

return Object.assign(type, { value: transformValues(value) })
}

const parsers = {
enum: parseEnum,
}

module.exports = ({ type }) => {
const parser = parsers[type.name]

return parser ? parser(type) : type
}

0 comments on commit 8a37929

Please sign in to comment.