File tree 2 files changed +23
-2
lines changed
packages/babel-plugin-minify-simplify
2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -2512,4 +2512,24 @@ describe("simplify-plugin", () => {
2512
2512
const b = () => {};
2513
2513
`
2514
2514
) ;
2515
+
2516
+ thePlugin (
2517
+ "should NOT remove block for early continue transforms - fix issue#560" ,
2518
+ `
2519
+ function foo() {
2520
+ while (true) {
2521
+ const {x} = a;
2522
+ const {y} = b;
2523
+ }
2524
+ }
2525
+ ` ,
2526
+ `
2527
+ function foo() {
2528
+ for (; true;) {
2529
+ const { x } = a;
2530
+ const { y } = b;
2531
+ }
2532
+ }
2533
+ `
2534
+ ) ;
2515
2535
} ) ;
Original file line number Diff line number Diff line change @@ -1519,7 +1519,8 @@ module.exports = ({ types: t }) => {
1519
1519
t . isTryStatement ( parent ) ||
1520
1520
t . isCatchClause ( parent ) ||
1521
1521
t . isSwitchStatement ( parent ) ||
1522
- ( isSingleBlockScopeDeclaration ( node ) && t . isIfStatement ( parent ) )
1522
+ ( isSingleBlockScopeDeclaration ( node ) &&
1523
+ ( t . isIfStatement ( parent ) || t . isLoop ( parent ) ) )
1523
1524
) ;
1524
1525
}
1525
1526
@@ -1581,7 +1582,7 @@ module.exports = ({ types: t }) => {
1581
1582
}
1582
1583
1583
1584
// We may have reduced the body to a single statement.
1584
- if ( node . body . body . length === 1 ) {
1585
+ if ( node . body . body . length === 1 && ! needsBlock ( node . body , node ) ) {
1585
1586
path . get ( "body" ) . replaceWith ( node . body . body [ 0 ] ) ;
1586
1587
}
1587
1588
}
You can’t perform that action at this time.
0 commit comments