@@ -235,19 +235,7 @@ impl<'a> CollapseVariableDeclarations {
235
235
/// <https://github.com/google/closure-compiler/blob/v20240609/test/com/google/javascript/jscomp/CollapseVariableDeclarationsTest.java>
236
236
#[ cfg( test) ]
237
237
mod test {
238
- use oxc_allocator:: Allocator ;
239
-
240
- use crate :: tester;
241
-
242
- fn test ( source_text : & str , expected : & str ) {
243
- let allocator = Allocator :: default ( ) ;
244
- let mut pass = super :: CollapseVariableDeclarations :: new ( ) ;
245
- tester:: test ( & allocator, source_text, expected, & mut pass) ;
246
- }
247
-
248
- fn test_same ( source_text : & str ) {
249
- test ( source_text, source_text) ;
250
- }
238
+ use crate :: tester:: { test, test_same} ;
251
239
252
240
mod join_vars {
253
241
use super :: { test, test_same} ;
@@ -286,7 +274,7 @@ mod test {
286
274
287
275
test (
288
276
"var x = 2; foo(x); x = 3; x = 1; var y = 2; var z = 4; x = 5" ,
289
- "var x = 2; foo(x); x = 3; x = 1; var y = 2, z = 4; x = 5" ,
277
+ "var x = 2; foo(x), x = 3, x = 1; var y = 2, z = 4; x = 5" ,
290
278
) ;
291
279
}
292
280
@@ -304,9 +292,9 @@ mod test {
304
292
305
293
#[ test]
306
294
fn test_aggressive_redeclaration_in_for ( ) {
307
- test_same ( "for(var x = 1; x = 2; x = 3) { x = 4} " ) ;
295
+ test_same ( "for(var x = 1; x = 2; x = 3) x = 4" ) ;
308
296
test_same ( "for(var x = 1; y = 2; z = 3) {var a = 4}" ) ;
309
- test_same ( "var x; for(x = 1; x = 2; z = 3) { x = 4} " ) ;
297
+ test_same ( "var x; for(x = 1; x = 2; z = 3) x = 4" ) ;
310
298
}
311
299
312
300
#[ test]
@@ -354,9 +342,9 @@ mod test {
354
342
355
343
#[ test]
356
344
fn test_aggressive_redeclaration_of_let_in_for ( ) {
357
- test_same ( "for(let x = 1; x = 2; x = 3) { x = 4} " ) ;
345
+ test_same ( "for(let x = 1; x = 2; x = 3) x = 4" ) ;
358
346
test_same ( "for(let x = 1; y = 2; z = 3) {let a = 4}" ) ;
359
- test_same ( "let x; for(x = 1; x = 2; z = 3) { x = 4} " ) ;
347
+ test_same ( "let x; for(x = 1; x = 2; z = 3) x = 4" ) ;
360
348
}
361
349
362
350
#[ test]
@@ -374,16 +362,19 @@ mod test {
374
362
375
363
// do not redeclare function parameters
376
364
// incompatible with strict mode
377
- test_same ( "function f(x) { let y = 3; x = 4; x + y; }" ) ;
365
+ test_same ( "function f(x) { let y = 3; x = 4, x + y; }" ) ;
378
366
}
379
367
380
368
#[ test]
381
369
fn test_arrow_function ( ) {
382
- test ( "() => {let x = 1; let y = 2; x + y; }" , "() => {let x = 1, y = 2; x + y; }" ) ;
370
+ test (
371
+ "(() => { let x = 1; let y = 2; x + y; })()" ,
372
+ "(() => { let x = 1, y = 2; x + y; })()" ,
373
+ ) ;
383
374
384
375
// do not redeclare function parameters
385
376
// incompatible with strict mode
386
- test_same ( "(x) => {x = 4; let y = 2; x + y; }" ) ;
377
+ test_same ( "(( x) => { x = 4; let y = 2; x + y; })() " ) ;
387
378
}
388
379
389
380
#[ test]
@@ -430,7 +421,7 @@ mod test {
430
421
// Verify FOR inside IFs.
431
422
test (
432
423
"if(x){var a = 0; for(; c < b; c++) foo()}" ,
433
- "if(x){ for(var a = 0; c < b; c++) foo()} " ,
424
+ "if(x)for(var a = 0; c < b; c++) foo()" ,
434
425
) ;
435
426
436
427
// Any other expression.
@@ -441,7 +432,7 @@ mod test {
441
432
"function f(){ var a; for(; a < 2 ; a++) foo() }" ,
442
433
"function f(){ for(var a; a < 2 ; a++) foo() }" ,
443
434
) ;
444
- test_same ( "function f(){ return; for(; a < 2 ; a++) foo() }" ) ;
435
+ test_same ( "function f(){ for(; a < 2 ; a++) foo() }" ) ;
445
436
446
437
// TODO
447
438
// Verify destructuring assignments are moved.
@@ -459,21 +450,21 @@ mod test {
459
450
#[ test]
460
451
fn test_for_in ( ) {
461
452
test ( "var a; for(a in b) foo()" , "for (var a in b) foo()" ) ;
462
- test_same ( "a = 0; for(a in b) foo()" ) ;
453
+ test ( "a = 0; for(a in b) foo()" , "for (a in a = 0, b) foo(); ") ;
463
454
test_same ( "var a = 0; for(a in b) foo()" ) ;
464
455
465
456
// We don't handle labels yet.
466
457
test_same ( "var a; a:for(a in b) foo()" ) ;
467
458
test_same ( "var a; a:b:for(a in b) foo()" ) ;
468
459
469
460
// Verify FOR inside IFs.
470
- test ( "if(x){var a; for(a in b) foo()}" , "if(x){ for(var a in b) foo()} " ) ;
461
+ test ( "if(x){var a; for(a in b) foo()}" , "if(x) for(var a in b) foo()" ) ;
471
462
472
463
// Any other expression.
473
- test_same ( "init(); for(a in b) foo()" ) ;
464
+ test ( "init(); for(a in b) foo()" , "for (a in init(), b) foo(); ") ;
474
465
475
466
// Other statements are left as is.
476
- test_same ( "function f(){ return; for(a in b) foo() }" ) ;
467
+ test_same ( "function f(){ for(a in b) foo() }" ) ;
477
468
478
469
// We don't handle destructuring patterns yet.
479
470
test ( "var a; var b; for ([a, b] in c) foo();" , "var a, b; for ([a, b] in c) foo();" ) ;
@@ -490,13 +481,13 @@ mod test {
490
481
test_same ( "var a; a: b: for (a of b) foo()" ) ;
491
482
492
483
// Verify FOR inside IFs.
493
- test ( "if (x) { var a; for (a of b) foo() }" , "if (x) { for (var a of b) foo() } " ) ;
484
+ test ( "if (x) { var a; for (a of b) foo() }" , "if (x) for (var a of b) foo()" ) ;
494
485
495
486
// Any other expression.
496
487
test_same ( "init(); for (a of b) foo()" ) ;
497
488
498
489
// Other statements are left as is.
499
- test_same ( "function f() { return; for (a of b) foo() }" ) ;
490
+ test_same ( "function f() { for (a of b) foo() }" ) ;
500
491
501
492
// We don't handle destructuring patterns yet.
502
493
test ( "var a; var b; for ([a, b] of c) foo();" , "var a, b; for ([a, b] of c) foo();" ) ;
0 commit comments