All files / src/utils resolveHOC.js

100% Statements 6/6
83.33% Branches 5/6
100% Functions 1/1
100% Lines 6/6
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                                        4x                 109x 109x 26x 26x       83x    
/*
 * 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 isReactCreateClassCall from './isReactCreateClassCall';
 
var {
  types: {
    NodePath,
    namedTypes: types,
  },
} = recast;
 
/**
 * If the path is a call expression, it recursively resolves to the
 * rightmost argument, stopping if it finds a React.createClass call expression
 *
 * Else the path itself is returned.
 */
export default function resolveHOC(path: NodePath): NodePath {
  var node = path.node;
  if (types.CallExpression.check(node) && !isReactCreateClassCall(path)) {
    Eif (node.arguments.length) {
      return resolveHOC(path.get('arguments', node.arguments.length - 1));
    }
  }
 
  return path;
}