File size: 744 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/**
 * @file Utility for retrieving callee identifier node from a CallExpression
 * @author Automattic
 * @copyright 2016 Automattic. All rights reserved.
 * See LICENSE.md file in root directory for full license.
 */

/**
 * Returns the callee identifier node from a CallExpression.
 * @param  {Object} node CallExpression node
 * @returns {Object}      First non-sequence callee
 */
const getCallee = ( module.exports = function ( node ) {
	const callee = node.callee;
	if ( ! callee ) {
		return node;
	}

	if ( 'SequenceExpression' === callee.type ) {
		return getCallee( callee.expressions[ callee.expressions.length - 1 ] );
	}

	if ( 'MemberExpression' === callee.type ) {
		return getCallee( callee.property );
	}

	return callee;
} );