All files / src Documentation.js

90.48% Statements 19/21
83.33% Branches 5/6
83.33% Functions 5/6
90.48% Lines 19/21
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66                                    17x 17x 17x               41x       15x       15x 15x 5x   15x       13x   13x 26x     13x 5x 5x 5x       13x     13x       3x  
/*
 *  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
 *
 */
 
class Documentation {
  _props: Object;
  _composes: Set<string>;
  _data: Object;
 
  constructor() {
    this._props = new Map();
    this._composes = new Set();
    this._data = new Map();
  }
 
  addComposes(moduleName: string) {
    this._composes.add(moduleName);
  }
 
  set(key: string, value: any) {
    this._data.set(key, value);
  }
 
  get(key: string): any {
    return this._data.get(key);
  }
 
  getPropDescriptor(propName: string): PropDescriptor {
    var propDescriptor = this._props.get(propName);
    if (!propDescriptor) {
      this._props.set(propName, propDescriptor = {});
    }
    return propDescriptor;
  }
 
  toObject(): Object {
    var obj = {};
 
    for (var [key, value] of this._data) {
      obj[key] = value;
    }
 
    if (this._props.size > 0) {
      obj.props = {};
      for (var [name, descriptor] of this._props) {
        obj.props[name] = descriptor;
      }
    }
 
    Iif (this._composes.size > 0) {
      obj.composes = Array.from(this._composes);
    }
    return obj;
  }
}
 
module.exports = Documentation;