All files / src/handlers propDocBlockHandler.js

90% Statements 9/10
87.5% Branches 7/8
100% Functions 2/2
90% Lines 9/10
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                                      2x           21x 21x 4x   17x 17x       17x   25x 23x        
/*
 * Copyright (c) 2015, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 *
 * @flow
 *
 */
 
import type Documentation from '../Documentation';
 
import getMemberValuePath from '../utils/getMemberValuePath';
import recast from 'recast';
import resolveToValue from '../utils/resolveToValue';
import setPropDescription from '../utils/setPropDescription';
 
var {types: {namedTypes: types}} = recast;
 
export default function propDocBlockHandler(
  documentation: Documentation,
  path: NodePath
) {
  var propTypesPath = getMemberValuePath(path, 'propTypes');
  if (!propTypesPath) {
    return;
  }
  propTypesPath = resolveToValue(propTypesPath);
  Iif (!propTypesPath || !types.ObjectExpression.check(propTypesPath.node)) {
    return;
  }
 
  propTypesPath.get('properties').each(propertyPath => {
    // we only support documentation of actual properties, not spread
    if (types.Property.check(propertyPath.node)) {
      setPropDescription(documentation, propertyPath);
    }
  });
}