<commit_before>/**
 * @copyright   2016-2017, <NAME>
 * @license     https://opensource.org/licenses/MIT
 * @flow
 */

import Renderer from '../Renderer';
import Schematic from '../Schematic';
import Definition from '../Definition';
import ArrayDefinition from '../definitions/Array';
import BoolDefinition from '../definitions/Bool';
import EnumDefinition from '../definitions/Enum';
import InstanceDefinition from '../definitions/Instance';
import NumberDefinition from '../definitions/Number';
import ObjectDefinition from '../definitions/Object';
import ReferenceDefinition from '../definitions/Reference';
import ShapeDefinition from '../definitions/Shape';
import StringDefinition from '../definitions/String';
import UnionDefinition from '../definitions/Union';

import type { Options } from '../types';

export default class ReactRenderer extends Renderer {
  constructor(options: Options, schematic: Schematic) {
    super(options, schematic);

    this.suffix = 'Shape';
  }

  beforeParse() {
    this.imports.push('import PropTypes from \'prop-types\';');
  }

  render(setName: string, attributes: Definition[] = []) {
    const shape = this.formatObject(this.renderObjectProps(attributes, 1), 0);

    return `export const ${setName} = PropTypes.shape(${shape});`;
  }

  renderArray(definition: ArrayDefinition, depth: number): string {
    return this.wrapPropType(definition,
      this.wrapFunction('arrayOf', this.renderAttribute(definition.valueType, depth)));
  }

  renderBool(definition: BoolDefinition): string {
    return this.wrapPropType(definition, 'bool');
  }

  renderEnum(definition: EnumDefinition, depth: number): string {<commit_msg>Adding smaller production transpilation for PropTypes<commit_after>/**
 * @copyright   2016-2017, <NAME>
 * @license     https://opensource.org/licenses/MIT
 * @flow
 */

import Renderer from '../Renderer';
import Schematic from '../Schematic';
import Definition from '../Definition';
import ArrayDefinition from '../definitions/Array';
import BoolDefinition from '../definitions/Bool';
import EnumDefinition from '../definitions/Enum';
import InstanceDefinition from '../definitions/Instance';
import NumberDefinition from '../definitions/Number';
import ObjectDefinition from '../definitions/Object';
import ReferenceDefinition from '../definitions/Reference';
import ShapeDefinition from '../definitions/Shape';
import StringDefinition from '../definitions/String';
import UnionDefinition from '../definitions/Union';

import type { Options } from '../types';

export default class ReactRenderer extends Renderer {
  constructor(options: Options, schematic: Schematic) {
    super(options, schematic);

    this.suffix = 'Shape';
  }

  beforeParse() {
    this.imports.push('import PropTypes from \'prop-types\';');
    this.header.push('const __productionShape__ = () => {}');
  }

  render(setName: string, attributes: Definition[] = []) {
    const shape = this.formatObject(this.renderObjectProps(attributes, 1), 0);

    return `export const ${setName} = process.env.NODE_ENV === 'production' ? __productionShape__ : PropTypes.shape(${shape});`;
  }

  renderArray(definition: ArrayDefinition, depth: number): string {
    return this.wrapPropType(definition,
      this.wrapFunction('arrayOf', this.renderAttribute(definition.valueType, depth)));
  }

  renderBool(definition: BoolDefinition): string {
    return this.wrapPropType(definition, 'bool');
  }

  renderEnum(definition: EnumDefinition, depth: number): string {
{'fraction_non_alphanumeric': 0.14020559680182754, 'fraction_numerical': 0.0057110222729868645, 'mean_word_length': 4.7805280528052805, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5288182', 'n_tokens_mistral': 928, 'n_tokens_neox': 887, 'n_words': 246}