{"size": 1916, "ext": "js", "max_stars_repo_path": "vizceral/node_modules/documentation/lib/flow_doctrine.js", "max_stars_repo_name": "Nrupesh29/Web-Traffic-Visualizer", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "vizceral/node_modules/documentation/lib/flow_doctrine.js", "max_issues_repo_name": "Nrupesh29/Web-Traffic-Visualizer", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "vizceral/node_modules/documentation/lib/flow_doctrine.js", "max_forks_repo_name": "Nrupesh29/Web-Traffic-Visualizer", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.2790697674, "max_line_length": 84, "alphanum_fraction": 0.6487473904}
var namedTypes = {
  'NumberTypeAnnotation': 'number',
  'BooleanTypeAnnotation': 'boolean',
  'ObjectTypeAnnotation': 'Object',
  'StringTypeAnnotation': 'string'
};

var oneToOne = {
  'AnyTypeAnnotation': {
    type: 'AllLiteral'
  }
};

var literalTypes = {
  'StringLiteralTypeAnnotation': 'StringLiteral',
  'NumericLiteralTypeAnnotation': 'NumberLiteral',
  'BooleanLiteralTypeAnnotation': 'BooleanLiteral'
};

/**
 * Babel parses Flow annotations in JavaScript into AST nodes. documentation.js uses
 * Babel to parse JavaScript. This method restructures those Babel-generated
 * objects into objects that fit the output of Doctrine, the module we use
 * to parse JSDoc annotations. This lets us use Flow annotations _as_
 * JSDoc annotations.
 *
 * @private
 * @param {Object} type babel-parsed flow type
 * @returns {Object} doctrine compatible type
 */
function flowDoctrine(type) {

  if (type.type in namedTypes) {
    return {
      type: 'NameExpression',
      name: namedTypes[type.type]
    };
  }

  if (type.type in oneToOne) {
    return oneToOne[type.type];
  }

  if (type.type === 'NullableTypeAnnotation') {
    return {
      type: 'NullableType',
      expression: flowDoctrine(type.typeAnnotation)
    };
  }

  if (type.type === 'UnionTypeAnnotation') {
    return {
      type: 'UnionType',
      elements: type.types.map(flowDoctrine)
    };
  }

  if (type.type === 'GenericTypeAnnotation') {

    if (type.typeParameters) {
      return {
        type: 'TypeApplication',
        expression: {
          type: 'NameExpression',
          name: type.id.name
        },
        applications: type.typeParameters.params.map(flowDoctrine)
      };
    }

    return {
      type: 'NameExpression',
      name: type.id.name
    };
  }

  if (type.type in literalTypes) {
    return {
      type: literalTypes[type.type],
      name: type.value
    };
  }
}

module.exports = flowDoctrine;
