3
3
module . exports = {
4
4
configs : {
5
5
"getify-says" : {
6
- plugins : [ "@getify/proper-arrows" , ] ,
7
6
rules : {
8
7
"@getify/proper-arrows/params" : [ "error" , { "unused" : "trailing" , "count" : 2 , "length" : 3 , "allowed" : [ "e" , "v" , "cb" , "fn" , "pr" , ] , } , ] ,
9
8
"@getify/proper-arrows/name" : "error" ,
@@ -110,7 +109,8 @@ module.exports = {
110
109
111
110
// handle "unused" mode
112
111
if ( ! noneUnusedMode ) {
113
- let scope = context . getScope ( ) ;
112
+ let sourceCode = getSourceCode ( context ) ;
113
+ let scope = getScope ( context , sourceCode , node ) ;
114
114
let checkParamNames = checkParamIds . map ( function getName ( paramId ) {
115
115
return paramId . name ;
116
116
} ) ;
@@ -301,7 +301,9 @@ module.exports = {
301
301
return ;
302
302
}
303
303
304
- var globalArrow = currentlyInGlobalScope ( context . parserOptions , context . getScope ( ) ) ;
304
+ var sourceCode = getSourceCode ( context ) ;
305
+ var scope = getScope ( context , sourceCode , node ) ;
306
+ var globalArrow = currentlyInGlobalScope ( context . parserOptions , scope ) ;
305
307
var globalArrowDeclaration = (
306
308
globalArrow &&
307
309
node . parent . type == "VariableDeclarator"
@@ -414,12 +416,13 @@ module.exports = {
414
416
var sequenceMode = defaultsOnly || ! ( "sequence" in extraOptions ) || extraOptions . sequence === true ;
415
417
var ignoreTrivial = ! ( extraOptions && extraOptions . trivial === true ) ;
416
418
417
- var sourceCode = context . getSourceCode ( ) ;
419
+ var sourceCode = getSourceCode ( context ) ;
418
420
var ternaryBodyStack = new Map ( ) ;
419
421
420
422
return {
421
423
"ConditionalExpression:exit" : function exit ( node ) {
422
- var parentArrow = getParentArrowFunction ( context . getAncestors ( ) , /*onlyFromBody=*/ true ) ;
424
+ var ancestors = getAncestors ( context , sourceCode , node ) ;
425
+ var parentArrow = getParentArrowFunction ( ancestors , /*onlyFromBody=*/ true ) ;
423
426
if ( parentArrow ) {
424
427
if ( ! ternaryBodyStack . has ( parentArrow ) ) {
425
428
ternaryBodyStack . set ( parentArrow , [ ] ) ;
@@ -562,7 +565,9 @@ module.exports = {
562
565
563
566
return {
564
567
"ThisExpression" : function enter ( node ) {
565
- var parentArrow = getParentArrowFunction ( context . getAncestors ( ) ) ;
568
+ var sourceCode = getSourceCode ( context ) ;
569
+ var ancestors = getAncestors ( context , sourceCode , node ) ;
570
+ var parentArrow = getParentArrowFunction ( ancestors ) ;
566
571
thisFoundIn . add ( parentArrow ) ;
567
572
} ,
568
573
"ArrowFunctionExpression:exit" : function exit ( node ) {
@@ -571,7 +576,9 @@ module.exports = {
571
576
return ;
572
577
}
573
578
574
- var globalArrow = currentlyInGlobalScope ( context . parserOptions , context . getScope ( ) ) ;
579
+ var sourceCode = getSourceCode ( context ) ;
580
+ var scope = getScope ( context , sourceCode , node ) ;
581
+ var globalArrow = currentlyInGlobalScope ( context . parserOptions , scope ) ;
575
582
var foundThis = thisFoundIn . has ( node ) ;
576
583
577
584
// `this` found in arrow function?
@@ -605,7 +612,8 @@ module.exports = {
605
612
606
613
// need to track nested `this`?
607
614
if ( nestedThis || neverGlobalThis ) {
608
- let parentArrow = getParentArrowFunction ( context . getAncestors ( ) ) ;
615
+ let ancestors = getAncestors ( context , sourceCode , node ) ;
616
+ let parentArrow = getParentArrowFunction ( ancestors ) ;
609
617
if ( parentArrow ) {
610
618
thisFoundIn . add ( parentArrow ) ;
611
619
}
@@ -801,3 +809,26 @@ function currentlyInGlobalScope(parserOptions,scope) {
801
809
)
802
810
) ;
803
811
}
812
+
813
+ var getSourceCode = ( context ) => {
814
+ getSourceCode = ( context ) => context . sourceCode ?? context . getSourceCode ( ) ;
815
+ return getSourceCode ( context ) ;
816
+ } ;
817
+
818
+ var getScope = ( context , sourceCode , node ) => {
819
+ getScope = (
820
+ sourceCode . getScope ?
821
+ ( context , sourceCode , node ) => sourceCode . getScope ( node ) :
822
+ ( context , sourceCode , node ) => context . getScope ( )
823
+ ) ;
824
+ return getScope ( context , sourceCode , node ) ;
825
+ } ;
826
+
827
+ var getAncestors = ( context , sourceCode , node ) => {
828
+ getAncestors = (
829
+ sourceCode . getAncestors ?
830
+ ( context , sourceCode , node ) => sourceCode . getAncestors ( node ) :
831
+ ( context , sourceCode , node ) => context . getAncestors ( )
832
+ ) ;
833
+ return getAncestors ( context , sourceCode , node ) ;
834
+ } ;
0 commit comments