All files / src/utils resolveExportDeclaration.js

92.86% Statements 13/14
72.73% Branches 8/11
100% Functions 4/4
92.31% Lines 12/13
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                            4x           150x 150x   150x 106x 59x 86x     47x   44x 44x 80x         213x    
/*
 * 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 recast from 'recast';
import resolveToValue from './resolveToValue';
 
var {types: {namedTypes: _types}} = recast; //eslint-disable-line no-unused-vars
 
export default function resolveExportDeclaration(
  path: NodePath,
  types: Object = _types
): Array<NodePath> {
  var definitions = [];
  Iif (path.node.default) {
    definitions.push(path.get('declaration'));
  } else if (path.node.declaration) {
    if (types.VariableDeclaration.check(path.node.declaration)) {
      path.get('declaration', 'declarations').each(
        declarator => definitions.push(declarator)
      );
    } else {
      definitions.push(path.get('declaration'));
    }
  } else Eif (path.node.specifiers) {
    path.get('specifiers').each(
      specifier => definitions.push(
        specifier.node.id ? specifier.get('id') : specifier.get('local')
      )
    );
  }
  return definitions.map(definition => resolveToValue(definition));
}