44 */
55"use strict" ;
66
7+ const {
8+ isMethod,
9+ getParent,
10+ isOnObject
11+ } = require ( "../lib/helpers/call-expression" ) ;
12+ const { ARROW_FUNCTION_EXPRESSION } = require ( "../lib/type" ) ;
13+
714module . exports = {
815 meta : {
916 docs : {
@@ -16,13 +23,13 @@ module.exports = {
1623 create ( context ) {
1724 return {
1825 "CallExpression:exit" ( node ) {
19- if ( ! node . callee || node . callee . type !== "MemberExpression" || node . callee . property . name !== " map") {
26+ if ( ! isMethod ( node , " map") ) {
2027 return ;
2128 }
2229 const { callee } = node ,
23- { object : parent } = callee ;
30+ parent = getParent ( node ) ;
2431
25- if ( ! parent . callee || parent . callee . type !== "MemberExpression" || parent . callee . property . name !== " from" || ! parent . callee . object || parent . callee . object . type !== "Identifier" || parent . callee . object . name !== " Array") {
32+ if ( ! isMethod ( parent , " from") || ! isOnObject ( parent , " Array") ) {
2633 return ;
2734 }
2835
@@ -56,7 +63,7 @@ module.exports = {
5663 paramString = params . map ( ( p ) => p . name ) . join ( PARAM_SEPARATOR ) ,
5764 getCallback = ( cbk , targ , ps ) => {
5865 const source = `(${ sourceCode . getText ( cbk ) } )` ;
59- if ( targ && cbk . type !== "ArrowFunctionExpression" ) {
66+ if ( targ && cbk . type !== ARROW_FUNCTION_EXPRESSION ) {
6067 return `${ source } .call(${ targ . name } ${ PARAM_SEPARATOR } ${ ps } )` ;
6168 }
6269 return `${ source } (${ ps } )` ;
@@ -67,7 +74,7 @@ module.exports = {
6774 let functionStart = `(${ paramString } ) => ` ,
6875 functionEnd = "" ,
6976 restParamString = '' ;
70- if ( thisArg && callback . type !== "ArrowFunctionExpression" ) {
77+ if ( thisArg && callback . type !== ARROW_FUNCTION_EXPRESSION ) {
7178 functionStart = `function(${ paramString } ) { return ` ;
7279 functionEnd = "; }" ;
7380 }
0 commit comments