File tree 2 files changed +21
-3
lines changed
2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -480,8 +480,12 @@ merge(Compressor.prototype, {
480
480
// Constant single use vars can be replaced in any scope.
481
481
if ( var_decl . value . is_constant ( ) ) {
482
482
var ctt = new TreeTransformer ( function ( node ) {
483
- if ( node === ref )
484
- return replace_var ( node , ctt . parent ( ) , true ) ;
483
+ if ( node === ref ) {
484
+ var parent = ctt . parent ( ) ;
485
+ if ( ! ( parent instanceof AST_ForIn && parent . init === node ) ) {
486
+ return replace_var ( node , parent , true ) ;
487
+ }
488
+ }
485
489
} ) ;
486
490
stat . transform ( ctt ) ;
487
491
continue ;
@@ -570,7 +574,7 @@ merge(Compressor.prototype, {
570
574
// Further optimize statement after substitution.
571
575
stat . reset_opt_flags ( compressor ) ;
572
576
573
- compressor . warn ( "Replacing " + ( is_constant ? "constant" : "variable" ) +
577
+ compressor . warn ( "Collapsing " + ( is_constant ? "constant" : "variable" ) +
574
578
" " + var_name + " [{file}:{line},{col}]" , node . start ) ;
575
579
CHANGED = true ;
576
580
return value ;
Original file line number Diff line number Diff line change @@ -1315,3 +1315,17 @@ collapse_vars_regexp: {
1315
1315
} ) ( ) ;
1316
1316
}
1317
1317
}
1318
+
1319
+ issue_1537: {
1320
+ options = {
1321
+ collapse_vars : true ,
1322
+ }
1323
+ input: {
1324
+ var k = '' ;
1325
+ for ( k in { prop : 'val' } ) { }
1326
+ }
1327
+ expect: {
1328
+ var k = '' ;
1329
+ for ( k in { prop : 'val' } ) ;
1330
+ }
1331
+ }
You can’t perform that action at this time.
0 commit comments