File tree Expand file tree Collapse file tree 1 file changed +26
-12
lines changed
packages/plugin-remove-unreachable-code/lib Expand file tree Collapse file tree 1 file changed +26
-12
lines changed Original file line number Diff line number Diff line change @@ -17,24 +17,38 @@ module.exports.fix = ({siblings}) => {
1717 }
1818} ;
1919
20- module . exports . traverse = ( { push} ) => ( {
21- 'ReturnStatement|ThrowStatement' ( path ) {
22- const siblings = path . getAllNextSiblings ( ) ;
23-
24- if ( ! siblings . length )
25- return ;
26-
20+ const processBlock = ( push , path , leaf ) => {
21+ const siblings = path . getAllNextSiblings ( ) ;
22+
23+ if ( ! siblings . length )
24+ return ;
25+
26+ if ( leaf ) {
2727 const [ first ] = siblings ;
2828
2929 if ( ! path . node . argument && ( isBlockStatement ( first ) || isExpressionStatement ( first ) ) )
3030 return false ;
31-
32- if ( siblings . find ( isFunctionDeclaration ) )
33- return ;
31+ }
32+
33+ for ( const sibling of siblings ) {
34+ if ( isFunctionDeclaration ( sibling ) )
35+ continue ;
3436
3537 push ( {
36- path : siblings [ 0 ] ,
37- siblings,
38+ path : sibling ,
39+ siblings : [ sibling ] ,
3840 } ) ;
41+ }
42+ } ;
43+
44+ module . exports . traverse = ( { push} ) => ( {
45+ 'ReturnStatement|ThrowStatement' ( path ) {
46+ let leaf = true ;
47+
48+ while ( path . parentPath ?. isBlockStatement ( ) ) {
49+ processBlock ( push , path , leaf ) ;
50+ path = path . parentPath ;
51+ leaf = false ;
52+ }
3953 } ,
4054} ) ;
You can’t perform that action at this time.
0 commit comments