File tree Expand file tree Collapse file tree 1 file changed +16
-19
lines changed
packages/plugin-remove-nested-blocks/lib Expand file tree Collapse file tree 1 file changed +16
-19
lines changed Original file line number Diff line number Diff line change @@ -5,22 +5,6 @@ const {isReturnStatement} = types;
55const { replaceWithMultiple} = operator ;
66const { keys} = Object ;
77
8- const isIntersect = ( bindingsA , path ) => {
9- if ( path . removed )
10- return false ;
11-
12- path . scope . crawl ( ) ;
13-
14- const keysA = keys ( bindingsA ) ;
15-
16- for ( const key of keysA ) {
17- if ( path . scope . hasBinding ( key ) )
18- return true ;
19- }
20-
21- return false ;
22- } ;
23-
248module . exports . report = ( ) => 'Avoid nested blocks' ;
259
2610module . exports . fix = ( path ) => {
@@ -47,12 +31,13 @@ module.exports.filter = (path) => {
4731 if ( isSwitch )
4832 return false ;
4933
50- const is = ! isIntersect ( bindings , path . parentPath ) ;
51-
5234 if ( ! parentPath . isBlockStatement ( ) && ! parentPath . isProgram ( ) )
5335 return false ;
5436
55- return is || path . container . length === 1 ;
37+ if ( ! isIntersect ( parentPath , bindings ) )
38+ return true ;
39+
40+ return path . container . length === 1 ;
5641} ;
5742
5843function isReturnWithoutArg ( path ) {
@@ -63,3 +48,15 @@ function isReturnWithoutArg(path) {
6348
6449 return ! prevPath . node . argument ;
6550}
51+
52+ const isIntersect = ( path , bindings ) => {
53+ path . scope . crawl ( ) ;
54+
55+ for ( const key of keys ( bindings ) ) {
56+ if ( path . scope . hasBinding ( key ) )
57+ return true ;
58+ }
59+
60+ return false ;
61+ } ;
62+
You can’t perform that action at this time.
0 commit comments