File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -62,8 +62,7 @@ export const hooks = [
6262
6363 function ( self : NodePath , parent : NodePath ) {
6464 if (
65- ( parent . isIfStatement ( ) &&
66- ( self . key === "consequent" || self . key === "alternate" ) ) ||
65+ ( parent . isIfStatement ( ) && self . key === "consequent" ) ||
6766 ( self . key === "body" &&
6867 ( parent . isLoop ( ) || parent . isArrowFunctionExpression ( ) ) )
6968 ) {
Original file line number Diff line number Diff line change @@ -45,4 +45,22 @@ describe("removal", function () {
4545
4646 expect ( generate ( ast ) . code ) . toBe ( "" ) ;
4747 } ) ;
48+
49+ describe ( "within an IfStatement" , function ( ) {
50+ it ( "does not make consequent null" , function ( ) {
51+ const rootPath = getPath ( "if (x) foo(); else bar();" ) ;
52+ const ifPath = rootPath . get ( "body.0" ) ;
53+ ifPath . get ( "consequent" ) . remove ( ) ;
54+
55+ expect ( ifPath . get ( "consequent" ) . type ) . toBe ( "BlockStatement" ) ;
56+ } ) ;
57+
58+ it ( "completely removes alternate" , function ( ) {
59+ const rootPath = getPath ( "if (x) foo(); else bar();" ) ;
60+ const ifPath = rootPath . get ( "body.0" ) ;
61+ ifPath . get ( "alternate" ) . remove ( ) ;
62+
63+ expect ( ifPath . get ( "alternate" ) . node ) . toBeNull ( ) ;
64+ } ) ;
65+ } ) ;
4866} ) ;
You can’t perform that action at this time.
0 commit comments