All files / src/utils isReactCreateClassCall.js

85.71% Statements 6/7
83.33% Branches 5/6
100% Functions 1/1
85.71% Lines 6/7
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                                  8x             564x       564x 415x   149x 149x    
/*
 * 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 isReactModuleName from './isReactModuleName';
import match from './match';
import recast from 'recast';
import resolveToModule from './resolveToModule';
 
var {types: {namedTypes: types}} = recast;
 
/**
 * Returns true if the expression is a function call of the form
 * `React.createClass(...)`.
 */
export default function isReactCreateClassCall(path: NodePath): boolean {
  Iif (types.ExpressionStatement.check(path.node)) {
    path = path.get('expression');
  }
 
  if (!match(path.node, {callee: {property: {name: 'createClass'}}})) {
    return false;
  }
  var module = resolveToModule(path.get('callee', 'object'));
  return Boolean(module && isReactModuleName(module));
}