Skip to content

Commit 712cae0

Browse files
committed
refactor(minifier): run the compressor on all test cases (#8604)
Running individual plugins causes too much confusion. - [x] fix 110 failed tests :-)
1 parent 8c8b5fa commit 712cae0

13 files changed

+1576
-1770
lines changed

crates/oxc_minifier/src/ast_passes/collapse_variable_declarations.rs

+20-29
Original file line numberDiff line numberDiff line change
@@ -235,19 +235,7 @@ impl<'a> CollapseVariableDeclarations {
235235
/// <https://github.com/google/closure-compiler/blob/v20240609/test/com/google/javascript/jscomp/CollapseVariableDeclarationsTest.java>
236236
#[cfg(test)]
237237
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};
251239

252240
mod join_vars {
253241
use super::{test, test_same};
@@ -286,7 +274,7 @@ mod test {
286274

287275
test(
288276
"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",
290278
);
291279
}
292280

@@ -304,9 +292,9 @@ mod test {
304292

305293
#[test]
306294
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");
308296
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");
310298
}
311299

312300
#[test]
@@ -354,9 +342,9 @@ mod test {
354342

355343
#[test]
356344
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");
358346
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");
360348
}
361349

362350
#[test]
@@ -374,16 +362,19 @@ mod test {
374362

375363
// do not redeclare function parameters
376364
// 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; }");
378366
}
379367

380368
#[test]
381369
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+
);
383374

384375
// do not redeclare function parameters
385376
// 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; })()");
387378
}
388379

389380
#[test]
@@ -430,7 +421,7 @@ mod test {
430421
// Verify FOR inside IFs.
431422
test(
432423
"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()",
434425
);
435426

436427
// Any other expression.
@@ -441,7 +432,7 @@ mod test {
441432
"function f(){ var a; for(; a < 2 ; a++) foo() }",
442433
"function f(){ for(var a; a < 2 ; a++) foo() }",
443434
);
444-
test_same("function f(){ return; for(; a < 2 ; a++) foo() }");
435+
test_same("function f(){ for(; a < 2 ; a++) foo() }");
445436

446437
// TODO
447438
// Verify destructuring assignments are moved.
@@ -459,21 +450,21 @@ mod test {
459450
#[test]
460451
fn test_for_in() {
461452
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();");
463454
test_same("var a = 0; for(a in b) foo()");
464455

465456
// We don't handle labels yet.
466457
test_same("var a; a:for(a in b) foo()");
467458
test_same("var a; a:b:for(a in b) foo()");
468459

469460
// 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()");
471462

472463
// 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();");
474465

475466
// 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() }");
477468

478469
// We don't handle destructuring patterns yet.
479470
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 {
490481
test_same("var a; a: b: for (a of b) foo()");
491482

492483
// 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()");
494485

495486
// Any other expression.
496487
test_same("init(); for (a of b) foo()");
497488

498489
// 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() }");
500491

501492
// We don't handle destructuring patterns yet.
502493
test("var a; var b; for ([a, b] of c) foo();", "var a, b; for ([a, b] of c) foo();");

crates/oxc_minifier/src/ast_passes/convert_to_dotted_properties.rs

+9-21
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,7 @@ impl<'a> ConvertToDottedProperties {
6767

6868
#[cfg(test)]
6969
mod test {
70-
use oxc_allocator::Allocator;
71-
72-
use crate::tester;
73-
74-
fn test(source_text: &str, expected: &str) {
75-
let allocator = Allocator::default();
76-
let mut pass = super::ConvertToDottedProperties::new(false);
77-
tester::test(&allocator, source_text, expected, &mut pass);
78-
}
79-
80-
fn test_same(source_text: &str) {
81-
test(source_text, source_text);
82-
}
70+
use crate::tester::{test, test_same};
8371

8472
#[test]
8573
fn test_computed_to_member_expression() {
@@ -117,7 +105,7 @@ mod test {
117105
test_same("a[':']");
118106
test_same("a['.']");
119107
test_same("a['p ']");
120-
test_same("a['p' + '']");
108+
test("a['p' + '']", "a.p");
121109
test_same("a[p]");
122110
test_same("a[P]");
123111
test_same("a[$]");
@@ -134,10 +122,10 @@ mod test {
134122

135123
#[test]
136124
fn test_convert_to_dotted_properties_quoted_props() {
137-
test_same("({'':0})");
138-
test_same("({'1.0':0})");
139-
test_same("({'\\u1d17A':0})");
140-
test_same("({'a\\u0004b':0})");
125+
test("({'':0})", "");
126+
test("({'1.0':0})", "");
127+
test("({'\\u1d17A':0})", "");
128+
test("({'a\\u0004b':0})", "");
141129
}
142130

143131
#[test]
@@ -160,7 +148,7 @@ mod test {
160148
test_same("a?.['.']");
161149
test_same("a?.['0']");
162150
test_same("a?.['p ']");
163-
test_same("a?.['p' + '']");
151+
test("a?.['p' + '']", "a?.p");
164152
test_same("a?.[p]");
165153
test_same("a?.[P]");
166154
test_same("a?.[$]");
@@ -296,8 +284,8 @@ mod test {
296284
test_same("x?.['y z']");
297285
test("x?.['y']()", "x?.y();");
298286
test_same("x?.['y z']()");
299-
test_same("x['y' + 'z']");
300-
test_same("x?.['y' + 'z']");
287+
test("x['y' + 'z']", "x.yz");
288+
test("x?.['y' + 'z']", "x?.yz");
301289
test("x['0']", "x[0];");
302290
test("x['123']", "x[123];");
303291
test("x['-123']", "x[-123];");

crates/oxc_minifier/src/ast_passes/exploit_assigns.rs

+1-13
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,7 @@ impl ExploitAssigns {
3232
/// <https://github.com/google/closure-compiler/blob/v20240609/test/com/google/javascript/jscomp/ExploitAssignsTest.java>
3333
#[cfg(test)]
3434
mod test {
35-
use oxc_allocator::Allocator;
36-
37-
use crate::tester;
38-
39-
fn test(source_text: &str, expected: &str) {
40-
let allocator = Allocator::default();
41-
let mut pass = super::ExploitAssigns::new();
42-
tester::test(&allocator, source_text, expected, &mut pass);
43-
}
44-
45-
fn test_same(source_text: &str) {
46-
test(source_text, source_text);
47-
}
35+
use crate::tester::{test, test_same};
4836

4937
#[test]
5038
#[ignore]

0 commit comments

Comments
 (0)